report.page.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <script setup lang="ts">
  2. import NavHomeSelect from '@/assets/images/nav-home.select.png?url';
  3. import NavPrint from '@/assets/images/nav-print.png?url';
  4. import NavScheme from '@/assets/images/nav-scheme.png?url';
  5. import PhysiqueChart from '@/modules/report/PhysiqueChart.vue';
  6. import SyndromeChart from '@/modules/report/SyndromeChart.vue';
  7. import { Notify, platformIsAIO, Toast } from '@/platform';
  8. import { getReportMethod, updateReportMethod } from '@/request/api';
  9. import { useRouteParams } from '@vueuse/router';
  10. import { useRequest, useWatcher } from 'alova/client';
  11. import MiniProgram from '@/components/MiniProgram.vue';
  12. import { useFlowStore, useVisitor } from '@/stores';
  13. const miniProgramRef = useTemplateRef<InstanceType<typeof MiniProgram>>('mini-program');
  14. const hidePulseExceptionTemplate = computed(() => platformIsAIO())
  15. const Visitor = useVisitor();
  16. const id = useRouteParams<string>('id', Visitor.reportId);
  17. const scrollable = ref(true);
  18. const closeable = computed(() => !data.value.payLock);
  19. const { data, loading } = useWatcher(() => getReportMethod(id.value), [ id ], {
  20. initialData: {
  21. descriptionsTable: { column: [], data: [] },
  22. tongue: {},
  23. face: {},
  24. pulse: {},
  25. },
  26. immediate: true,
  27. }).onSuccess(({ data }) => {
  28. if ( data?.miniProgramURL && data.payLock ) {
  29. scrollable.value = false;
  30. nextTick(() => miniProgramRef.value?.open());
  31. }
  32. })
  33. const { loading: uploading, send: upload } = useRequest(() => updateReportMethod(id.value, data.value), {
  34. immediate: false,
  35. middleware(_, next) {
  36. if (data.value.reportURL) return;
  37. const hasConstitutionGroupImg = data.value.constitutionGroupImg;
  38. const hasFactorItemRadarImg = data.value[ '中医证素' ]?.length ? data.value.factorItemRadarImg : true;
  39. if ( hasConstitutionGroupImg && hasFactorItemRadarImg ) { next(); }
  40. },
  41. }).onSuccess(({ data: url }) => { data.value.reportURL = url; });
  42. let ReportPreview: Component;
  43. const reportPreviewProps = reactive({
  44. show: false,
  45. title: '',
  46. url: '',
  47. mode: '' as 'img' | 'qr',
  48. });
  49. async function print() {
  50. let url = data.value.reportURL;
  51. if ( !url ) url = await upload();
  52. if (!url) {
  53. Notify.warning(`未获取到报告地址,请联系管理员或重试`);
  54. return;
  55. }
  56. try {
  57. try {
  58. await Bridge.print({ url });
  59. } catch (e) {
  60. window.AIO?.print?.(url)
  61. }
  62. Toast.success(`开始打印`);
  63. } catch ( e ) {
  64. Notify.warning(`打印失败 (${ e.message })`, { duration: 1500 });
  65. setTimeout(() => {
  66. ReportPreview = defineAsyncComponent(() => import('./ReportPreview.vue'));
  67. reportPreviewProps.mode = 'qr';
  68. reportPreviewProps.title = '扫一扫 获取报告';
  69. reportPreviewProps.url = url;
  70. reportPreviewProps.show = true;
  71. }, 1500);
  72. }
  73. }
  74. const Flow = useFlowStore();
  75. function toggle() {
  76. const path = `${Flow.current}/${id.value}/scheme`.replace(/\/{2,}/g, '/') as any
  77. Flow.router.push(path);
  78. }
  79. </script>
  80. <template>
  81. <div class="report-wrapper">
  82. <div class="page-header flex py-4 px-4">
  83. <div class="grow shrink-0 h-full min-w-16"></div>
  84. <div class="grow-[3] shrink mx-2 flex flex-col justify-center overflow-hidden">
  85. <div class="font-bold text-3xl text-nowrap text-center tracking-wide overflow-ellipsis overflow-hidden">
  86. 健康分析报告
  87. </div>
  88. </div>
  89. <div class="grow shrink-0 h-full min-w-16">
  90. <router-link :to="{ path: '/screen' }" replace>
  91. <img class="size-8 object-scale-down" :src="NavHomeSelect" alt="返回首页" />
  92. </router-link>
  93. </div>
  94. </div>
  95. <div class="page-content flex flex-col overflow-hidden">
  96. <van-skeleton class="flex-auto" title :row="3" :loading>
  97. <div class="flex-auto" :class="[scrollable ? 'overflow-y-auto' : 'overflow-hidden']">
  98. <div class="my-6 text-primary text-2xl text-center">报告日期:{{ data.date }}</div>
  99. <div class="card m-6 text-lg">
  100. <div class="card__title text-primary text-3xl font-bold"></div>
  101. <div class="card__content flex">
  102. <div class="flex-auto">
  103. <div class="flex items-center my-2">
  104. <span class="text-primary">结果显示您是:</span>
  105. <van-button class="decorate !text-primary-400">{{ data[ '结果' ] }}</van-button>
  106. </div>
  107. <div class="flex items-center my-2" v-if="data[ '程度' ]">
  108. <span class="text-grey">程度:</span>
  109. <span class="px-4 py-2 rounded-lg border border-primary-400 text-primary">{{ data[ '程度' ] }}</span>
  110. </div>
  111. <div class="my-2 text-grey" v-if="data[ '表现' ]">表现:{{ data[ '表现' ] }}</div>
  112. <div class="my-2 text-grey" v-if="data[ '体质' ]">体质:{{ data[ '体质' ] }}</div>
  113. </div>
  114. <div class="flex-none size-48 ml-4">
  115. <img class="size-full object-cover" src="@/assets/images/report-cover.png" alt="封面">
  116. </div>
  117. </div>
  118. </div>
  119. <div class="card m-6 text-lg">
  120. <div class="card__title mb-3 text-primary text-2xl font-bold">体质分析</div>
  121. <div class="card__content">
  122. <PhysiqueChart
  123. :dataset="data['体质图表']"
  124. v-model:snapshot="data.constitutionGroupImg"
  125. />
  126. <div class="my-2 text-primary" v-if="data[ '体质描述' ]">{{ data[ '体质描述' ] }}</div>
  127. <table class="mt-8 mb-2 w-full table-auto border border-collapse border-primary">
  128. <thead>
  129. <tr>
  130. <th class="border border-primary min-w-[140px]"
  131. v-for="(value, i) in data.descriptionsTable.column" :key="i"
  132. v-html="value"
  133. ></th>
  134. </tr>
  135. </thead>
  136. <tbody>
  137. <tr v-for="item in data.descriptionsTable?.data" :key="item[0]">
  138. <td class="py-4 px-2 border border-primary min-w-[140px]"
  139. :class="{'text-grey': i, 'text-primary': !i}"
  140. v-for="(value, i) in item" :key="i"
  141. v-html="value"
  142. ></td>
  143. </tr>
  144. </tbody>
  145. </table>
  146. </div>
  147. </div>
  148. <AnalysisComponent title="舌象分析" v-bind="data.tongue" :cover="[]"></AnalysisComponent>
  149. <AnalysisComponent title="面象分析" v-bind="data.face">
  150. <template #content="{result, cover}">
  151. <div class="card__content flex">
  152. <div class="flex-auto text-grey mt-6">{{ result }}</div>
  153. <div class="flex-none w-2/4 max-h-96 ml-4">
  154. <img class="size-full object-scale-down" v-for="src in cover" :key="src" :src="src" alt="面象">
  155. </div>
  156. </div>
  157. </template>
  158. <template #exception><div><!--空占位符--></div></template>
  159. </AnalysisComponent>
  160. <AnalysisPulseComponent title="脉象分析" v-bind="data.pulse" simple>
  161. <template #exception v-if="hidePulseExceptionTemplate"><div><!--空占位符--></div></template>
  162. </AnalysisPulseComponent>
  163. <div class="card m-6 text-lg" v-if="data['中医证素']?.length">
  164. <div class="card__title mb-3 text-primary text-2xl font-bold">中医证素</div>
  165. <div class="card__content">
  166. <SyndromeChart
  167. :dataset="data['中医证素']"
  168. v-model:snapshot="data.factorItemRadarImg"
  169. />
  170. <table class="mt-8 mb-2 w-full table-auto border border-collapse border-primary">
  171. <tbody>
  172. <tr v-for="item in data['中医证素']" :key="item.label">
  173. <td class="py-4 px-2 border border-primary text-primary text-center" v-html="item.label"></td>
  174. <td class="py-4 px-2 border border-primary text-grey" v-html="item.value"></td>
  175. </tr>
  176. </tbody>
  177. </table>
  178. </div>
  179. </div>
  180. <div class="card m-6 text-lg" v-if="data['中医证型']?.length">
  181. <div class="card__title mb-3 text-primary text-2xl font-bold">中医证型</div>
  182. <div class="card__content">
  183. <div class="my-6 text-grey" v-for="item in data['中医证型']" :key="item.label">
  184. <div class="my-2 text-primary" v-html="item.label"></div>
  185. <div style="text-indent: 2em;" v-html="item.value"></div>
  186. </div>
  187. </div>
  188. </div>
  189. </div>
  190. </van-skeleton>
  191. <div class="flex-none flex justify-between py-2 nav-wrapper" style="background-color: #12312c;">
  192. <div v-if="data.page?.jumpable && data.scheme" class="m-auto min-w-16 text-center hover:text-primary" @click="toggle()">
  193. <img class="nav-img" :src="NavScheme" alt="调理方案">
  194. <div class="mt-2">调理方案</div>
  195. </div>
  196. <mini-program ref="mini-program" :url="data.miniProgramURL" :closeable="closeable"></mini-program>
  197. <div v-if="data.page?.printable" class="m-auto min-w-16 text-center hover:text-primary" @click="print()">
  198. <van-loading v-if="uploading" color="#38ff6e" style="font-size: 24px;" />
  199. <img class="nav-img" v-else :src="NavPrint" alt="打印">
  200. <div class="mt-2">打印</div>
  201. </div>
  202. </div>
  203. <Component :is="ReportPreview" v-bind="reportPreviewProps" v-model:show="reportPreviewProps.show"></Component>
  204. </div>
  205. </div>
  206. </template>
  207. <style scoped lang="scss">
  208. .van-button.decorate {
  209. font-size: 20px;
  210. height: 62px;
  211. width: 240px;
  212. background-size: 80%;
  213. letter-spacing: 2px;
  214. }
  215. .text-grey {
  216. color: #e3e3e3;
  217. }
  218. .report-wrapper {
  219. .panel-content {
  220. padding: 0 var(--van-floating-panel-header-height) var(--van-floating-panel-header-height);
  221. }
  222. .v-enter-active,
  223. .v-leave-active {
  224. transition: opacity 0.5s ease;
  225. }
  226. .v-enter-from,
  227. .v-leave-to {
  228. opacity: 0;
  229. }
  230. }
  231. .overflow-y-auto {
  232. overflow-y: auto;
  233. }
  234. </style>
  235. <style lang="scss">
  236. .report-wrapper .card {
  237. padding: 24px;
  238. border-radius: 24px;
  239. box-shadow: inset 0 0 80px 0 #34a76b60;
  240. }
  241. .nav-wrapper {
  242. .nav-img {
  243. margin: auto;
  244. width: 36px;
  245. height: 36px;
  246. object-fit: scale-down;
  247. }
  248. }
  249. </style>