|
|
@@ -1,11 +1,11 @@
|
|
|
<script setup lang="ts">
|
|
|
import { Notify } from '@/platform';
|
|
|
-import { tryOnMounted, tryOnUnmounted } from '@vueuse/core';
|
|
|
+import { tryOnBeforeMount, tryOnUnmounted, useCountdown } from '@vueuse/core';
|
|
|
|
|
|
import { useRequest } from 'alova/client';
|
|
|
import { putPulseMethod } from '@/request/api/pulse.api';
|
|
|
-import { processMethod3 } from '@/request/api';
|
|
|
-import type { Flow } from '@/request/model';
|
|
|
+import type { Flow, FlowRoute } from '@/request/model';
|
|
|
+import { getRoutePath, useRouteNext } from '@/computable/useRouteNext';
|
|
|
|
|
|
import { useVisitor } from '@/stores';
|
|
|
|
|
|
@@ -14,104 +14,65 @@ import NavHomeSelect from '@/assets/images/nav-home.select.png?url';
|
|
|
const router = useRouter();
|
|
|
const Visitor = useVisitor();
|
|
|
|
|
|
-const pending = ref(false);
|
|
|
const finished = ref(false);
|
|
|
const supported = ref(true);
|
|
|
+const actionText = computed(() => supported.value ? `获取健康调理方案` : `下一步`);
|
|
|
+/* 倒计时完成动作 */
|
|
|
+const done = shallowRef<Flow>();
|
|
|
+/* 下一动作可选 */
|
|
|
+const next = shallowRef<Flow>();
|
|
|
+
|
|
|
+const { handle, loading } = useRouteNext({
|
|
|
+ onSuccess(flow) { return pulse(flow); },
|
|
|
+ onError(error) { Notify.warning(error.message); },
|
|
|
+});
|
|
|
+
|
|
|
+const { remaining, start, stop } = useCountdown(5, {
|
|
|
+ onComplete() { replace(done.value!); },
|
|
|
+ immediate: false,
|
|
|
+});
|
|
|
+const countdown = computed(() => remaining.value.toString().padStart(2, '0'));
|
|
|
|
|
|
-async function handle() {
|
|
|
- if (pending.value) return;
|
|
|
- pending.value = true;
|
|
|
- clearInterval(timer);
|
|
|
+tryOnBeforeMount(() => handle());
|
|
|
+tryOnUnmounted(() => stop());
|
|
|
|
|
|
- const patientId = Visitor.patientId;
|
|
|
+async function pulse(flow: FlowRoute) {
|
|
|
+ stop();
|
|
|
+ const showReport = flow.next.route === '/pulse/result';
|
|
|
try {
|
|
|
- await load();
|
|
|
+ const patientId = Visitor.patientId;
|
|
|
const result = await Bridge.pulse(patientId!!);
|
|
|
await submit(patientId, result);
|
|
|
- } catch (e: any) {
|
|
|
- let message = e.message;
|
|
|
+ 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;
|
|
|
+
|
|
|
if (e instanceof ReferenceError) {
|
|
|
supported.value = false;
|
|
|
- message = '当前环境不支持脉诊设备,请联系管理员';
|
|
|
- }
|
|
|
- if (!supported.value || process.value?.current?.optional) {
|
|
|
- done.value = next.value?.optional
|
|
|
- ? { ...next.value, countdown: 5 }
|
|
|
- : {
|
|
|
- title: '返回首页',
|
|
|
- route: '/screen',
|
|
|
- countdown: 5,
|
|
|
- };
|
|
|
- next.value = void 0;
|
|
|
- start();
|
|
|
+ message = `当前环境不支持脉诊设备,请联系管理员!`;
|
|
|
+ countdown = 5;
|
|
|
} else {
|
|
|
- done.value = void 0;
|
|
|
- message = '请再次测量脉诊';
|
|
|
+ message = `请再次测量脉诊!`;
|
|
|
+ countdown = 10;
|
|
|
}
|
|
|
+ done.value = flow.value.optional && !showReport ? flow.next : { title: '返回首页', route: '/screen' };
|
|
|
+ start(countdown);
|
|
|
Notify.warning(message);
|
|
|
}
|
|
|
- pending.value = false;
|
|
|
}
|
|
|
|
|
|
-const done = shallowRef<Partial<Flow> & { countdown: number }>();
|
|
|
-const next = shallowRef<Partial<Flow>>();
|
|
|
-
|
|
|
-const {
|
|
|
- data: process,
|
|
|
- loading,
|
|
|
- send: load,
|
|
|
-} = useRequest(processMethod3, { immediate: false }).onSuccess(({ data }) => {
|
|
|
- if (data.next.route === '/screen') {
|
|
|
- done.value = { title: '返回首页', route: '/screen', countdown: 30 };
|
|
|
- next.value = void 0;
|
|
|
- } else if (data.next.route === '/pulse/result') {
|
|
|
- done.value = data.next.optional ? { title: '返回首页', route: '/screen', countdown: 10 } : void 0;
|
|
|
- next.value = { title: data.next.title || '查看报告', route: data.next.route };
|
|
|
- } else {
|
|
|
- done.value = { title: data.next.title || '获取健康调理方案', route: data.next.route, countdown: 10 };
|
|
|
- next.value = void 0;
|
|
|
- }
|
|
|
-});
|
|
|
-
|
|
|
-const {
|
|
|
- data: report,
|
|
|
- loading: submitting,
|
|
|
- send: submit,
|
|
|
-} = useRequest((id, result) => putPulseMethod(id, result), { immediate: false }).onSuccess(({ data }) => {
|
|
|
+const { data: report, loading: submitting, send: submit, } = useRequest((id, result) => putPulseMethod(id, result), { immediate: false }).onSuccess(({ data }) => {
|
|
|
Visitor.updatePulseReport(data);
|
|
|
- finished.value = true;
|
|
|
- start();
|
|
|
});
|
|
|
|
|
|
-let timer: ReturnType<typeof setInterval>;
|
|
|
-const countdown = ref(5);
|
|
|
-
|
|
|
-function start(value?: number) {
|
|
|
- if (!done.value) {
|
|
|
- if (next.value?.route === '/pulse/result') replace(next.value.route);
|
|
|
- return;
|
|
|
- }
|
|
|
- countdown.value = value ?? done.value.countdown ?? 3;
|
|
|
- timer = setInterval(() => {
|
|
|
- const _countdown = countdown.value - 1;
|
|
|
- if (_countdown <= 0) {
|
|
|
- replace(done.value?.route);
|
|
|
- } else {
|
|
|
- countdown.value = _countdown;
|
|
|
- }
|
|
|
- }, 1000);
|
|
|
-}
|
|
|
-
|
|
|
-function replace(path: string = '/screen') {
|
|
|
- return router.replace({ path });
|
|
|
-}
|
|
|
-
|
|
|
-tryOnMounted(() => {
|
|
|
- setTimeout(() => handle(), 300);
|
|
|
-});
|
|
|
-tryOnUnmounted(() => {
|
|
|
- clearInterval(timer);
|
|
|
-});
|
|
|
+const replace = (flow: Flow) => router.push({ path: getRoutePath(flow), replace: true });
|
|
|
</script>
|
|
|
<template>
|
|
|
<div>
|
|
|
@@ -145,23 +106,18 @@ tryOnUnmounted(() => {
|
|
|
</template>
|
|
|
</main>
|
|
|
<footer class="flex flex-col justify-center items-center">
|
|
|
- <van-button
|
|
|
- v-if="!pending && finished && next"
|
|
|
- class="decorate !text-xl !text-primary-400"
|
|
|
- @click="replace(next.route)"
|
|
|
- >
|
|
|
- {{ next.title }}
|
|
|
- </van-button>
|
|
|
- <van-button
|
|
|
- v-if="!pending && done"
|
|
|
- class="decorate !text-xl !text-primary-400 !mb-6"
|
|
|
- @click="replace(done.route)"
|
|
|
- >
|
|
|
- {{ done.title }}({{ countdown }})
|
|
|
- </van-button>
|
|
|
- <div v-if="supported && !finished" class="van-button decorate" @click="handle()">
|
|
|
+ <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 class="van-button__content">
|
|
|
- <van-loading v-if="loading || pending || submitting" />
|
|
|
+ <van-loading v-if="loading || submitting" />
|
|
|
<span v-else class="van-button__text">连接脉诊</span>
|
|
|
</div>
|
|
|
</div>
|