AnalysisPulseComponent.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. <script setup lang="ts">
  2. import type { SimplePulseModel } from '../../@types/pulse';
  3. import { createReusableTemplate, tryOnMounted } from '@vueuse/core';
  4. import { useRequest } from 'alova/client';
  5. import { getPulseAgentMethod } from '@/request/api/pulse.api';
  6. import { getURLSearchParamsByUrl } from '@/tools';
  7. import HandLeft from '@/assets/images/pulse-hand-left.png?url';
  8. import HandRight from '@/assets/images/pulse-hand-right.png?url';
  9. import { useVisitor } from '@/stores';
  10. type Props = Partial<SimplePulseModel> & { title?: string; results?: string; disabled?: boolean; simple?: boolean };
  11. const { title = '分析', disabled = false, simple = false, results, ..._report } = defineProps<Props>();
  12. const slots = defineSlots();
  13. const Visitor = useVisitor();
  14. const report = computed(() => (unref(results) ? Object.assign(_report, { results }) : Visitor.pulseReport));
  15. const parseUrl = (value?: string) => {
  16. const [url, query = ''] = (value ?? report.value?.url)?.split('report.html') ?? [];
  17. const params = getURLSearchParamsByUrl(query);
  18. if (url && params.has('appId') && params.has('access_session')) {
  19. const replace /* 绘制 3D 跨域 */ = () => [
  20. `https://wx.hzliuzhi.com/mz/hybrid/`,
  21. ].includes(url) ? 'https://hybrid.reborn-tech.com/' : url;
  22. return {
  23. appId: params.get('appId')!!,
  24. token: params.get('access_session')!!,
  25. url: `${replace()}report.html#/`,
  26. };
  27. }
  28. };
  29. const stringifyUrl = (panel: 'left' | 'right', simple = false, overall = true) => {
  30. const fragment = overall ? [`overall-${panel}`] : [];
  31. if (!simple) fragment.push(`${panel}-hand`);
  32. if (!fragment.length) return '';
  33. const value = fragment.map((value) => `${value.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())}=true`).join('&');
  34. return `${agent.value!.url}single?appId=${agent.value!.appId}&access_session=${agent.value!.token}&mid=${report.value?.measureId}&${value}`;
  35. };
  36. const { data: agent, loading, send: getPulseAgent } = useRequest(() => getPulseAgentMethod(), {
  37. initialData: void 0,
  38. immediate: false,
  39. });
  40. const card = useTemplateRef('card');
  41. const panelConfig = reactive({
  42. height: 0,
  43. anchors: [0],
  44. });
  45. const offset = computed(() => panelConfig.anchors[panelConfig.anchors.length - 1] - panelConfig.height);
  46. const getHeightAndScrollTop = () => {
  47. const el = card.value;
  48. if (!el) return;
  49. el.scrollIntoView({ behavior: 'instant', block: 'start' });
  50. const rect = el.getBoundingClientRect();
  51. const maxHeight = window.innerHeight - rect.top;
  52. const height = maxHeight - rect.height;
  53. panelConfig.anchors = [0, height, maxHeight];
  54. panelConfig.height = height;
  55. };
  56. const preview = reactive({
  57. clickMainPanelPreviewable: true,
  58. leftUrl: void 0 as string | void,
  59. rightUrl: void 0 as string | void,
  60. leftPanelUrl: void 0 as string | void,
  61. rightPanelUrl: void 0 as string | void,
  62. showLeftPanel: false,
  63. showRightPanel: false,
  64. });
  65. const load = async (panel: 'left' | 'right' | boolean = true, simple = false) => {
  66. if (loading.value) return;
  67. if (!agent.value) {
  68. try {
  69. const { promise, ...resolvers } = Promise.withResolvers<string>();
  70. await window.bridge.postMessage('pulse:url:get', report.value?.measureId, resolvers);
  71. agent.value = parseUrl(await promise);
  72. } catch (e) {
  73. const value = await getPulseAgent().catch(() => void 0);
  74. if (!value) agent.value = parseUrl();
  75. }
  76. }
  77. if (!agent.value) return;
  78. if (panel === false) {
  79. preview.leftUrl ??= stringifyUrl('left', simple);
  80. preview.rightUrl ??= stringifyUrl('right', simple);
  81. } else {
  82. if (!slots.exception) {
  83. preview.leftPanelUrl = void 0;
  84. preview.rightPanelUrl = void 0;
  85. }
  86. await nextTick();
  87. if (panel === true || panel === 'left') {
  88. preview.leftPanelUrl ??= stringifyUrl('left', simple);
  89. preview.showLeftPanel = true;
  90. } else {
  91. preview.showLeftPanel = false;
  92. }
  93. if (panel === true || panel === 'right') {
  94. preview.rightPanelUrl ??= stringifyUrl('right', simple);
  95. preview.showRightPanel = true;
  96. } else {
  97. preview.showRightPanel = false;
  98. }
  99. }
  100. };
  101. const open = async (panel?: 'left' | 'right', scroll = true) => {
  102. if (disabled) return;
  103. await load(panel);
  104. if (scroll) getHeightAndScrollTop();
  105. else {
  106. const height = window.innerHeight * 0.8;
  107. panelConfig.anchors = [0, height];
  108. panelConfig.height = height;
  109. }
  110. };
  111. tryOnMounted(() => {
  112. if (!slots.exception) load(false, simple);
  113. preview.clickMainPanelPreviewable = !!slots.exception;
  114. });
  115. const { define: PreviewSlot, reuse: ReusePreview } = createReusableTemplate<{ src: string | void }>();
  116. watchPostEffect(() => {
  117. if (panelConfig.height === 0) {
  118. preview.showLeftPanel = false;
  119. preview.showRightPanel = false;
  120. }
  121. });
  122. </script>
  123. <template>
  124. <van-skeleton class="analysis" :row="5" :loading="report?.results == null" v-if="report?.results !== ''">
  125. <PreviewSlot v-slot="{ src }">
  126. <iframe v-if="src" :src="src" :class="{ simple: !src.includes('Hand=true') }"></iframe>
  127. </PreviewSlot>
  128. <slot>
  129. <div ref="card" class="card m-6 text-lg" @click="panelConfig.height = 0">
  130. <div v-if="title" class="card__title mb-3 text-primary text-2xl font-bold">{{ title }}</div>
  131. <slot name="content" :report="report">
  132. <div class="card__content">
  133. <div v-if="report?.summaryLabel" class="flex justify-evenly">
  134. <div v-if="report?.summaryLabel?.left" class="flex flex-row-reverse justify-center" @click.stop="preview.clickMainPanelPreviewable && open('left')">
  135. <img style="width: 100px; height: 200px" :src="HandLeft" alt="左手" />
  136. <div class="flex flex-col justify-evenly translate-y-2 h-40 text-xl" :class="{ highlight: preview.showLeftPanel }">
  137. <div>寸:<span style="letter-spacing: 4px">{{ report.summaryLabel.left.cun }}</span></div>
  138. <div>关:<span style="letter-spacing: 4px">{{ report.summaryLabel.left.guan }}</span></div>
  139. <div>尺:<span style="letter-spacing: 4px">{{ report.summaryLabel.left.chi }}</span>
  140. </div>
  141. </div>
  142. </div>
  143. <div v-if="report?.summaryLabel?.right" class="flex justify-center" @click.stop="preview.clickMainPanelPreviewable && open('right')">
  144. <img style="width: 100px; height: 200px" :src="HandRight" alt="右手" />
  145. <div class="flex flex-col justify-evenly translate-y-2 h-40 text-xl" :class="{ highlight: preview.showRightPanel }">
  146. <div>寸:<span style="letter-spacing: 4px">{{ report.summaryLabel.right.cun }}</span></div>
  147. <div>关:<span style="letter-spacing: 4px">{{ report.summaryLabel.right.guan }}</span></div>
  148. <div>尺:<span style="letter-spacing: 4px">{{ report.summaryLabel.right.chi }}</span></div>
  149. </div>
  150. </div>
  151. </div>
  152. <p v-if="report?.results" class="text-2xl text-center" @click.stop="preview.clickMainPanelPreviewable && open()">
  153. 总体脉象:<span class="text-primary-400" style="letter-spacing: 4px">{{ report.results }}</span>
  154. </p>
  155. </div>
  156. </slot>
  157. </div>
  158. <slot name="exception">
  159. <div v-if="agent" class="grid grid-rows-1 grid-cols-1 gap-8 m-6">
  160. <div class="card text-lg" v-if="report?.summaryLabel?.left" @click="panelConfig.height = 0">
  161. <div class="card__title mb-3 text-primary text-2xl font-bold flex justify-between" @click.stop="simple && open('left', false)">
  162. <div>左手脉象: {{ report.summaryLabel.left.summary?.join('、') }}</div>
  163. <van-icon v-if="simple" class="text-xl" name="arrow" />
  164. </div>
  165. <div class="card__content">
  166. <ReusePreview v-if="panelConfig.height < 100" :src="preview.leftUrl"></ReusePreview>
  167. </div>
  168. </div>
  169. <div class="card text-lg" v-if="report?.summaryLabel?.right" @click="panelConfig.height = 0">
  170. <div class="card__title mb-3 text-primary text-2xl font-bold flex justify-between" @click.stop="simple && open('right', false)">
  171. <div>右手脉象: {{ report.summaryLabel.right.summary?.join('、') }}</div>
  172. <van-icon v-if="simple" class="text-xl" name="arrow" />
  173. </div>
  174. <div class="card__content">
  175. <ReusePreview v-if="panelConfig.height < 100" :src="preview.rightUrl"></ReusePreview>
  176. </div>
  177. </div>
  178. </div>
  179. </slot>
  180. </slot>
  181. <van-floating-panel class="pulse-info-panel" :content-draggable="false" :lock-scroll="true" :anchors="panelConfig.anchors" v-model:height="panelConfig.height">
  182. <template #header>
  183. <div class="van-floating-panel__header !justify-between">
  184. <div></div>
  185. <div class="van-floating-panel__header-bar"></div>
  186. <van-icon class="pr-2" name="cross" @click="panelConfig.height = 0" />
  187. </div>
  188. </template>
  189. <div class="area" :class="{ last: !preview.showRightPanel }" v-if="report?.summaryLabel?.left" v-show="preview.showLeftPanel">
  190. <div class="title">左手脉象: {{ report.summaryLabel.left.summary?.join('、') }}</div>
  191. <ReusePreview :src="preview.leftPanelUrl"></ReusePreview>
  192. </div>
  193. <div class="area" v-if="report?.summaryLabel?.right" v-show="preview.showRightPanel">
  194. <div class="title">右手脉象: {{ report.summaryLabel.right.summary?.join('、') }}</div>
  195. <ReusePreview :src="preview.rightPanelUrl"></ReusePreview>
  196. </div>
  197. </van-floating-panel>
  198. </van-skeleton>
  199. </template>
  200. <style scoped lang="scss">
  201. .highlight {
  202. color: rgb(52 167 107 / var(--tw-text-opacity, 1));
  203. }
  204. $h: 1660px;
  205. iframe {
  206. width: 100%;
  207. height: $h;
  208. border: none;
  209. &.simple {
  210. height: 432px;
  211. }
  212. }
  213. .pulse-info-panel {
  214. --van-floating-panel-background: #fff;
  215. .van-icon {
  216. color: var(--van-floating-panel-bar-color);
  217. }
  218. .area {
  219. margin: auto;
  220. padding-left: 12px;
  221. min-width: 320px;
  222. max-width: 1200px;
  223. .title {
  224. padding-left: 9px;
  225. font-family:
  226. Helvetica Neue,
  227. Helvetica,
  228. Roboto,
  229. Tahoma,
  230. Arial,
  231. PingFang SC,
  232. sans-serif;
  233. font-size: 18px;
  234. font-weight: 700;
  235. color: #1f2d3d;
  236. line-height: 36px;
  237. }
  238. &:last-of-type,
  239. &.last {
  240. iframe {
  241. height: calc(#{$h} + v-bind(offset) * 1px);
  242. }
  243. }
  244. }
  245. }
  246. </style>