Jelajahi Sumber

拍照完成节点后可选下一步

cc12458 4 bulan lalu
induk
melakukan
a91b1b9d0f

+ 27 - 12
src/modules/camera/camera-result.page.vue

@@ -1,8 +1,7 @@
 <script setup lang="ts">
-import { processMethod } from '@/request/api';
-import { useRequest }    from 'alova/client';
-import { useRouter }     from 'vue-router';
-
+import { processMethod2 } from '@/request/api';
+import { useRequest } from 'alova/client';
+import { useRouter } from 'vue-router';
 
 defineOptions({
   name: 'CameraResult',
@@ -10,18 +9,29 @@ defineOptions({
 
 const router = useRouter();
 
-const { data, loading } = useRequest(processMethod).onSuccess(() => {init(); });
-const tips = computed(() => data.value === '/screen' ? '返回首页' : '下一步');
+const { data, loading } = useRequest(processMethod2).onSuccess(({ data }) => {
+  init(data.optional ? 10 : 5);
+});
+const tips = computed(() => (data.value.route === '/screen' || data.value.optional ? '返回首页' : '获取健康调理方案'));
 const countdown = ref(5);
 
 let timer: ReturnType<typeof setInterval>;
 
 function done() {
+  if (!data.value.optional) next();
+  else {
+    clearInterval(timer);
+    router.replace({ path: '/screen' });
+  }
+}
+
+function next() {
   clearInterval(timer);
-  router.replace({ path: data.value });
+  router.replace({ path: data.value.route });
 }
 
-function init() {
+function init(value = 5) {
+  countdown.value = value;
   timer = setInterval(() => {
     const _countdown = countdown.value - 1;
     if ( _countdown <= 0 ) { done(); } else { countdown.value = _countdown; }
@@ -45,10 +55,15 @@ onBeforeUnmount(() => {
           <div class="text-3xl text-center my-8">完成舌面象的采集</div>
         </div>
       </main>
-      <footer class="flex justify-evenly items-start" style="flex: 1 1 30%">
-        <van-button class="decorate !text-xl !text-primary-400" :loading @click="done()">
-          {{ tips }}({{ countdown }})
-        </van-button>
+      <footer class="flex flex-col items-center" style="flex: 1 1 30%">
+        <template v-if="!loading">
+          <van-button v-if="data.optional" class="decorate !text-xl !text-primary-400 !mb-6" :loading @click="next()">
+            {{ data.title || '获取健康调理方案' }}
+          </van-button>
+          <van-button class="decorate !text-xl !text-primary-400" :loading @click="done()">
+            {{ tips }}({{ countdown }})
+          </van-button>
+        </template>
       </footer>
     </div>
   </div>

+ 15 - 2
src/request/api/camera.api.ts

@@ -1,6 +1,7 @@
 import HTTP              from '@/request/alova';
-import { processMethod } from '@/request/api/flow.api';
+import { processMethod2 } from '@/request/api/flow.api';
 import { useVisitor }    from '@/stores';
+import { Dialog } from '@/platform';
 
 
 export function uploadFileMethod(file: File) {
@@ -16,7 +17,19 @@ export function saveFileMethod(params: Record<string, string>) {
     params,
     async transform(data: string, headers) {
       Visitor.resultId = data;
-      const path = await processMethod();
+      const flow = await processMethod2();
+      let path = flow.optional
+        ? await Dialog.show({
+            title: flow.title || '获取健康调理方案',
+            confirmButtonText: '好的',
+            showCancelButton: true,
+            cancelButtonText: '返回首页',
+            width: 350,
+          }).then(
+            () => flow.route,
+            () => '/screen'
+          )
+        : flow.route;
       return {
         resultId: data,
         route: { path },

+ 19 - 4
src/request/api/flow.api.ts

@@ -1,5 +1,5 @@
 import { cacheFor }     from '@/request/api/index';
-import { fromFlowData } from '@/request/model';
+import { type Flow, fromFlowData } from '@/request/model';
 import Router           from '@/router';
 
 import HTTP from '../alova';
@@ -25,9 +25,24 @@ export function processMethod() {
     transform(data) {
       const options = data.tabletProcessModules ?? [];
       const ref = fromFlowData(options);
-      const route = ref.get(path);
-      if ( !route ) throw { message: `[路由] 配置异常无法解析正确路径,请联系管理员 (${ data?.tabletProcessModules?.join(' -> ') }})` };
-      return route;
+      const flow = ref.get(path);
+      if ( !flow ) throw { message: `[路由] 配置异常无法解析正确路径,请联系管理员 (${ data?.tabletProcessModules?.join(' -> ') }})` };
+      return flow.route;
+    },
+  });
+}
+
+export function processMethod2() {
+  const path = unref(Router.currentRoute).path;
+  return HTTP.Post<Flow, { tabletProcessModules?: string[]; }>(`/fdhb-tablet/warrantManage/getPageSets`, {}, {
+    cacheFor, name: `variate:process`,
+    params: { k: 'process', p: path },
+    transform(data) {
+      const options = data.tabletProcessModules ?? [];
+      const ref = fromFlowData(options);
+      const flow = ref.get(path);
+      if ( !flow ) throw { message: `[路由] 配置异常无法解析正确路径,请联系管理员 (${ data?.tabletProcessModules?.join(' -> ') }})` };
+      return flow;
     },
   });
 }

+ 13 - 4
src/request/model/flow.model.ts

@@ -9,8 +9,14 @@ const Routes = {
   'screen': '/screen',
 } as const;
 
-export function fromFlowData(options: string[]): Map<string, string> {
-  const ref = new Map<string, string>();
+export interface Flow {
+  route: string;
+  title?: string;
+  optional?: boolean;
+}
+
+export function fromFlowData(options: string[]): Map<string, Flow> {
+  const ref = new Map<string, Flow>();
   const length = options.length;
 
   // 修正虚拟路由
@@ -22,8 +28,11 @@ export function fromFlowData(options: string[]): Map<string, string> {
   options.push('screen');
 
   for ( let i = 1; i < options.length; i++ ) {
-    const route = options[ i ] = getPath(options[ i ]);
-    ref.set(options[ i - 1 ], route);
+    const path = options[i];
+    const optional = path.includes('?');
+    const [name, title] = path.split('?');
+    const route = (options[i] = getPath(name));
+    ref.set(options[i - 1], { route, optional, title, });
   }
   return ref;
 }