|
|
@@ -1,78 +1,77 @@
|
|
|
<script setup lang="ts">
|
|
|
import { Notify } from '@/platform';
|
|
|
-import { tryOnBeforeMount, tryOnUnmounted, useCountdown } from '@vueuse/core';
|
|
|
-
|
|
|
+import { tryOnMounted, tryOnUnmounted, useCountdown } from '@vueuse/core';
|
|
|
import { useRequest } from 'alova/client';
|
|
|
+import { useFlowStore, useVisitor } from '@/stores';
|
|
|
import { putPulseMethod } from '@/request/api/pulse.api';
|
|
|
-import type { Flow, FlowRoute } from '@/request/model';
|
|
|
-import { getRoutePath, useRouteNext } from '@/computable/useRouteNext';
|
|
|
-
|
|
|
-import { useVisitor } from '@/stores';
|
|
|
|
|
|
import NavHomeSelect from '@/assets/images/nav-home.select.png?url';
|
|
|
|
|
|
-const router = useRouter();
|
|
|
-const Visitor = useVisitor();
|
|
|
+type Operate = { title: string; countdown?: number; handle?: () => void };
|
|
|
|
|
|
-const finished = ref(false);
|
|
|
-const supported = ref(true);
|
|
|
-const actionText = computed(() => supported.value ? `获取健康调理方案` : `下一步`);
|
|
|
+const Visitor = useVisitor();
|
|
|
+const Flow = useFlowStore();
|
|
|
+const { flow } = storeToRefs(Flow);
|
|
|
/* 倒计时完成动作 */
|
|
|
-const done = shallowRef<Flow>();
|
|
|
+const done = shallowRef<Operate>();
|
|
|
/* 下一动作可选 */
|
|
|
-const next = shallowRef<Flow>();
|
|
|
-
|
|
|
-const { handle, loading } = useRouteNext({
|
|
|
- onSuccess(flow) { return pulse(flow); },
|
|
|
- onError(error) { Notify.warning(error.message); },
|
|
|
-});
|
|
|
+const next = shallowRef<Operate>();
|
|
|
|
|
|
const { remaining, start, stop } = useCountdown(5, {
|
|
|
- onComplete() { replace(done.value!); },
|
|
|
+ onComplete() {
|
|
|
+ done.value?.handle?.();
|
|
|
+ },
|
|
|
immediate: false,
|
|
|
});
|
|
|
const countdown = computed(() => remaining.value.toString().padStart(2, '0'));
|
|
|
|
|
|
-tryOnBeforeMount(() => handle());
|
|
|
-tryOnUnmounted(() => stop());
|
|
|
+tryOnMounted(pulse);
|
|
|
+tryOnUnmounted(stop);
|
|
|
|
|
|
-async function pulse(flow: FlowRoute) {
|
|
|
- stop();
|
|
|
- const showReport = flow.next.route === '/pulse/result';
|
|
|
+const supported = ref(true);
|
|
|
+const loading = ref(false);
|
|
|
+const error = shallowRef({ message: '' });
|
|
|
+async function pulse() {
|
|
|
+ loading.value = true;
|
|
|
try {
|
|
|
const patientId = Visitor.patientId;
|
|
|
const result = await Bridge.pulse(patientId!!);
|
|
|
await submit(patientId, result);
|
|
|
- if (showReport) await replace(flow.next);
|
|
|
- else {
|
|
|
- finished.value = true;
|
|
|
- done.value = flow.next.optional ? { title: '返回首页', route: '/screen' } : flow.next;
|
|
|
- next.value = flow.next.optional ? flow.next : void 0;
|
|
|
- start(10);
|
|
|
- }
|
|
|
} catch (e) {
|
|
|
- let message;
|
|
|
- let countdown;
|
|
|
-
|
|
|
+ done.value = { title: '返回首页', countdown: flow.value.done?.countdown ?? 20, handle: () => Flow.router.done() };
|
|
|
+ next.value = flow.value.optional && !Flow.router.hasNext('/pulse/result') ? { title: '下一步', handle: () => Flow.router.push() } : void 0;
|
|
|
if (e instanceof ReferenceError) {
|
|
|
supported.value = false;
|
|
|
- message = `当前环境不支持脉诊设备,请联系管理员!`;
|
|
|
- countdown = 5;
|
|
|
+ error.value = { message: `当前环境不支持脉诊设备,请联系管理员!` };
|
|
|
+ done.value.countdown = 5;
|
|
|
} else {
|
|
|
- message = `请再次测量脉诊!`;
|
|
|
- countdown = 10;
|
|
|
+ error.value = { message: `请再次测量脉诊` };
|
|
|
+ done.value.countdown = 10;
|
|
|
}
|
|
|
- done.value = flow.value.optional && !showReport ? flow.next : { title: '返回首页', route: '/screen' };
|
|
|
- start(countdown);
|
|
|
- Notify.warning(message);
|
|
|
+ if (done.value.countdown) start(done.value.countdown);
|
|
|
+ if (error.value?.message) Notify.warning(error.value.message);
|
|
|
}
|
|
|
+ loading.value = false;
|
|
|
}
|
|
|
|
|
|
+const finished = ref(false);
|
|
|
+const previewable = ref(false);
|
|
|
+const loadReport = computed(() => flow.value?.next === '/pulse/result');
|
|
|
const { data: report, loading: submitting, send: submit, } = useRequest((id, result) => putPulseMethod(id, result), { immediate: false }).onSuccess(({ data }) => {
|
|
|
Visitor.updatePulseReport(data);
|
|
|
+ if (loadReport.value) Flow.router.push();
|
|
|
+ else {
|
|
|
+ finished.value = true;
|
|
|
+ done.value = { title: '返回首页', countdown: flow.value.done?.countdown ?? 10, handle: () => Flow.router.done() };
|
|
|
+ next.value = flow.value.next ? { title: '获取健康调理方案', handle: () => Flow.router.push() } : void 0;
|
|
|
+ if (!flow.value.done) {
|
|
|
+ done.value = { ...done.value, ...next.value };
|
|
|
+ next.value = void 0;
|
|
|
+ }
|
|
|
+ if (previewable.value) done.value.countdown = 0;
|
|
|
+ if (done.value.countdown) start(done.value.countdown);
|
|
|
+ }
|
|
|
});
|
|
|
-
|
|
|
-const replace = (flow: Flow) => router.push({ path: getRoutePath(flow), replace: true });
|
|
|
</script>
|
|
|
<template>
|
|
|
<div>
|
|
|
@@ -98,29 +97,28 @@ const replace = (flow: Flow) => router.push({ path: getRoutePath(flow), replace:
|
|
|
<div class="text-3xl text-center">恭喜您!</div>
|
|
|
<div class="text-3xl text-center my-8">完成脉诊采集</div>
|
|
|
</div>
|
|
|
- <AnalysisPulseComponent title="" v-bind="report" disabled>
|
|
|
+ <AnalysisPulseComponent title="" v-bind="report" :disabled="!previewable">
|
|
|
<template #exception>
|
|
|
<div><!--空占位符--></div>
|
|
|
</template>
|
|
|
</AnalysisPulseComponent>
|
|
|
</template>
|
|
|
+ <div v-else-if="error.message" class="text-center">{{ error.message }}</div>
|
|
|
</main>
|
|
|
<footer class="flex flex-col justify-center items-center">
|
|
|
- <template v-if="!loading">
|
|
|
- <van-button v-if="next" class="decorate !text-xl" @click="replace(next)">
|
|
|
- {{ next.title ?? actionText }}
|
|
|
- </van-button>
|
|
|
- <van-button v-if="done" class="decorate !text-xl !text-primary-400" @click="replace(done)">
|
|
|
- {{ done.title ?? actionText }}
|
|
|
- <template v-if="remaining">({{ countdown }}s)</template>
|
|
|
- </van-button>
|
|
|
- </template>
|
|
|
- <div v-if="supported && !finished" class="van-button decorate" @click="!loading && handle()">
|
|
|
+ <div v-if="supported && !report" class="van-button decorate" @click="!loading && pulse()">
|
|
|
<div class="van-button__content">
|
|
|
<van-loading v-if="loading || submitting" />
|
|
|
<span v-else class="van-button__text">连接脉诊</span>
|
|
|
</div>
|
|
|
</div>
|
|
|
+ <van-button v-if="next" class="decorate !text-xl" @click="next.handle">
|
|
|
+ {{ next.title }}
|
|
|
+ </van-button>
|
|
|
+ <van-button v-if="done" class="decorate !text-xl !text-primary-400" @click="done.handle">
|
|
|
+ {{ done.title }}
|
|
|
+ <template v-if="done.countdown">({{ countdown }}s)</template>
|
|
|
+ </van-button>
|
|
|
</footer>
|
|
|
</div>
|
|
|
</div>
|