pulse.page.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <script setup lang="ts">
  2. import { Notify } from '@/platform';
  3. import { tryOnMounted, tryOnUnmounted } from '@vueuse/core';
  4. import { useRequest } from 'alova/client';
  5. import { putPulseMethod } from '@/request/api/pulse.api';
  6. import { processMethod3 } from '@/request/api';
  7. import type { Flow } from '@/request/model';
  8. import { useVisitor } from '@/stores';
  9. import NavHomeSelect from '@/assets/images/nav-home.select.png?url';
  10. import HandLeft from '@/assets/images/pulse-hand-left.png?url';
  11. import HandRight from '@/assets/images/pulse-hand-right.png?url';
  12. const router = useRouter();
  13. const Visitor = useVisitor();
  14. const pending = ref(false);
  15. const finished = ref(false);
  16. const supported = ref(true);
  17. async function handle() {
  18. if (pending.value) return;
  19. pending.value = true;
  20. clearInterval(timer);
  21. const patientId = Visitor.patientId;
  22. try {
  23. await load();
  24. const result = await Bridge.pulse(patientId!!);
  25. await submit(patientId, result);
  26. } catch (e: any) {
  27. let message = e.message;
  28. if (e instanceof ReferenceError) {
  29. supported.value = false;
  30. message = '当前环境不支持脉诊设备,请联系管理员';
  31. }
  32. if (!supported.value || process.value?.current?.optional) {
  33. done.value = next.value?.optional
  34. ? { ...next.value, countdown: 5 }
  35. : {
  36. title: '返回首页',
  37. route: '/screen',
  38. countdown: 5,
  39. };
  40. next.value = void 0;
  41. start();
  42. } else {
  43. done.value = void 0;
  44. message = '请再次测量脉诊';
  45. }
  46. Notify.warning(message);
  47. }
  48. pending.value = false;
  49. }
  50. const done = shallowRef<Partial<Flow> & { countdown: number }>();
  51. const next = shallowRef<Partial<Flow>>();
  52. const {
  53. data: process,
  54. loading,
  55. send: load,
  56. } = useRequest(processMethod3, { immediate: false }).onSuccess(({ data }) => {
  57. if (data.next.route === '/screen') {
  58. done.value = { title: '返回首页', route: '/screen', countdown: 30 };
  59. next.value = void 0;
  60. } else if (data.next.route === '/pulse/result') {
  61. done.value = data.next.optional ? { title: '返回首页', route: '/screen', countdown: 10 } : void 0;
  62. next.value = { title: data.next.title || '查看报告', route: data.next.route };
  63. } else {
  64. done.value = { title: data.next.title || '获取健康调理方案', route: data.next.route, countdown: 10 };
  65. next.value = void 0;
  66. }
  67. });
  68. const {
  69. data: report,
  70. loading: submitting,
  71. send: submit,
  72. } = useRequest((id, result) => putPulseMethod(id, result), { immediate: false }).onSuccess(() => {
  73. finished.value = true;
  74. start();
  75. });
  76. let timer: ReturnType<typeof setInterval>;
  77. const countdown = ref(5);
  78. function start(value?: number) {
  79. if (!done.value) return;
  80. countdown.value = value ?? done.value.countdown ?? 3;
  81. timer = setInterval(() => {
  82. const _countdown = countdown.value - 1;
  83. if (_countdown <= 0) {
  84. replace(done.value?.route);
  85. } else {
  86. countdown.value = _countdown;
  87. }
  88. }, 1000);
  89. }
  90. function replace(path: string = '/screen') {
  91. return router.replace({ path });
  92. }
  93. tryOnMounted(() => {
  94. setTimeout(() => handle(), 300);
  95. });
  96. tryOnUnmounted(() => {
  97. clearInterval(timer);
  98. });
  99. </script>
  100. <template>
  101. <div>
  102. <div class="page-header flex py-4 px-4">
  103. <div class="grow shrink-0 h-full min-w-16"></div>
  104. <div class="grow-[3] shrink mx-2 flex flex-col justify-center overflow-hidden">
  105. <div class="font-bold text-3xl text-nowrap text-center tracking-wide overflow-ellipsis overflow-hidden">
  106. {{ finished ? '完成脉诊采集' : '脉诊采集' }}
  107. </div>
  108. </div>
  109. <div class="grow shrink-0 h-full min-w-16 flex items-center justify-end overflow-hidden">
  110. <router-link :to="{ path: '/screen' }" replace>
  111. <img class="size-8 object-scale-down" :src="NavHomeSelect" alt="返回首页" />
  112. </router-link>
  113. </div>
  114. </div>
  115. <div class="page-content flex flex-col">
  116. <header></header>
  117. <main class="flex flex-col justify-evenly px-8">
  118. <template v-if="finished && report">
  119. <img class="size-40 mx-auto" src="@/assets/images/tips.png" alt="" />
  120. <div>
  121. <div class="text-3xl text-center">恭喜您!</div>
  122. <div class="text-3xl text-center my-8">完成脉诊采集</div>
  123. </div>
  124. <div v-if="report">
  125. <div v-if="report.summaryLabel" class="flex justify-evenly">
  126. <div v-if="report.summaryLabel?.left" class="flex flex-row-reverse justify-center">
  127. <img style="width: 100px;height: 200px;" :src="HandLeft" alt="左手" />
  128. <div class="flex flex-col justify-evenly translate-y-2 h-40 text-xl">
  129. <div>
  130. 寸:<span style="letter-spacing: 4px">{{ report.summaryLabel.left.cun }}</span>
  131. </div>
  132. <div>
  133. 关:<span style="letter-spacing: 4px">{{ report.summaryLabel.left.guan }}</span>
  134. </div>
  135. <div>
  136. 尺:<span style="letter-spacing: 4px">{{ report.summaryLabel.left.chi }}</span>
  137. </div>
  138. </div>
  139. </div>
  140. <div v-if="report.summaryLabel?.right">
  141. <div class="flex justify-center">
  142. <img style="width: 100px;height: 200px;" :src="HandRight" alt="右手" />
  143. <div class="flex flex-col justify-evenly translate-y-2 h-40 text-xl">
  144. <div>
  145. 寸:<span style="letter-spacing: 4px">{{ report.summaryLabel.right.cun }}</span>
  146. </div>
  147. <div>
  148. 关:<span style="letter-spacing: 4px">{{ report.summaryLabel.right.guan }}</span>
  149. </div>
  150. <div>
  151. 尺:<span style="letter-spacing: 4px">{{ report.summaryLabel.right.chi }}</span>
  152. </div>
  153. </div>
  154. </div>
  155. </div>
  156. </div>
  157. <p v-if="report.results" class="text-2xl text-center">
  158. 总体脉象:<span class="text-primary-400" style="letter-spacing: 4px">{{ report.results }}</span>
  159. </p>
  160. </div>
  161. </template>
  162. </main>
  163. <footer class="flex flex-col justify-center items-center">
  164. <van-button
  165. v-if="!pending && finished && next"
  166. class="decorate !text-xl !text-primary-400"
  167. @click="replace(next.route)"
  168. >
  169. {{ next.title }}
  170. </van-button>
  171. <van-button
  172. v-if="!pending && done"
  173. class="decorate !text-xl !text-primary-400 !mb-6"
  174. @click="replace(done.route)"
  175. >
  176. {{ done.title }}({{ countdown }})
  177. </van-button>
  178. <div v-if="supported && !finished" class="van-button decorate" @click="handle()">
  179. <div class="van-button__content">
  180. <van-loading v-if="loading || pending || submitting" />
  181. <span v-else class="van-button__text">连接脉诊</span>
  182. </div>
  183. </div>
  184. </footer>
  185. </div>
  186. </div>
  187. </template>
  188. <style scoped lang="scss">
  189. header {
  190. flex: 1 1 10%;
  191. }
  192. footer {
  193. flex: 1 1 30%;
  194. }
  195. main {
  196. position: relative;
  197. flex: 1 1 50%;
  198. }
  199. .decorate {
  200. margin: 24px 0;
  201. }
  202. </style>