report.page.vue 11 KB

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