report.page.vue 12 KB

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