|
@@ -1,17 +1,20 @@
|
|
|
<script setup lang="ts">
|
|
|
-import { Dialog, Notify } from '@/platform';
|
|
|
-import { copyrightMethod, processMethod } from '@/request/api';
|
|
|
-import { useVisitor } from '@/stores';
|
|
|
-import getBubbles from '@/tools/bubble';
|
|
|
-import { useElementSize } from '@vueuse/core';
|
|
|
-import { useRequest } from 'alova/client';
|
|
|
-import p5 from 'p5';
|
|
|
+import { Dialog, Notify } from '@/platform';
|
|
|
+
|
|
|
+import { copyrightMethod, processMethod, registerVisitorMethod } from '@/request/api';
|
|
|
+
|
|
|
+import { useVisitor } from '@/stores';
|
|
|
+import getBubbles from '@/tools/bubble';
|
|
|
+import { useElementSize } from '@vueuse/core';
|
|
|
+import { useRequest } from 'alova/client';
|
|
|
+import p5 from 'p5';
|
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
const Visitor = useVisitor();
|
|
|
|
|
|
const title = import.meta.env.SIX_APP_TITLE;
|
|
|
+const { data: visitor, loading: registering, send: register } = useRequest(registerVisitorMethod, { immediate: false, });
|
|
|
const { data: copyright, send: load } = useRequest(copyrightMethod).onError(async ({ error }) => {
|
|
|
await Dialog.show({
|
|
|
message: error.message,
|
|
@@ -23,7 +26,15 @@ const { data: copyright, send: load } = useRequest(copyrightMethod).onError(asyn
|
|
|
await load();
|
|
|
});
|
|
|
const { send: handle, loading } = useRequest(processMethod, { immediate: false })
|
|
|
- .onSuccess(({ data }) => { router.push({ path: data, replace: true }).then(() => Visitor.$reset()); })
|
|
|
+ .onSuccess(({ data }) => {
|
|
|
+ router.push({ path: data, replace: true }).then(
|
|
|
+ () => {
|
|
|
+ Visitor.$reset();
|
|
|
+ if (visitor.value) Visitor.patientId = visitor.value;
|
|
|
+ },
|
|
|
+ () => {}
|
|
|
+ );
|
|
|
+ })
|
|
|
.onError(({ error }) => Notify.warning(error.message));
|
|
|
|
|
|
const container = useTemplateRef<HTMLDivElement>('container');
|
|
@@ -167,6 +178,11 @@ function init({ width, height, container }: { width: number; height: number; con
|
|
|
};
|
|
|
}, container);
|
|
|
}
|
|
|
+
|
|
|
+onBeforeRouteLeave((to, from) => {
|
|
|
+ if (to.path === '/register') return true;
|
|
|
+ return register().then((data) => !!data, () => false);
|
|
|
+});
|
|
|
</script>
|
|
|
<template>
|
|
|
<div class="wrapper">
|
|
@@ -177,7 +193,7 @@ function init({ width, height, container }: { width: number; height: number; con
|
|
|
</div>
|
|
|
<div class="flex-auto flex flex-col">
|
|
|
<div class="flex-auto flex justify-center items-center">
|
|
|
- <van-button class="decorate" :loading @click="handle()">开始检测</van-button>
|
|
|
+ <van-button class="decorate" :loading="loading || registering" @click="handle()">开始检测</van-button>
|
|
|
</div>
|
|
|
<div class="flex-none text-xl p-8 text-center" v-html="copyright"></div>
|
|
|
</div>
|