import { groupBy } from "../../../../utils/util"; import { AnalysisException, AnalysisModel } from "../../model/health.model"; // module/health/components/card-analysis/card-analysis-content.ts Component({ lifetimes: { attached() { if(this.properties.type==='files'){ this.setData({ isShowType: true }); } } }, /** * 组件的属性列表 */ properties: { tongue: { type: Object, value: null }, face: { type: Object, value: null }, simple: { type: Object, value: { tongue: false, face: false } }, exception: { type: Object, value: { tongue: false, face: false } }, type: { type: String, value: '' }, }, observers: { 'exception.tongue, tongue'(show: boolean, tongue: AnalysisModel) { if (show === void 0) { show = true; } if (!show || !tongue) return; const exception = this._getException(tongue.exception, 'list'); this.setData({ tongueException: exception }); }, 'exception.face, face'(show: boolean, face: AnalysisModel) { if (show === void 0) { show = true; } if (!show || !face) return; const exception = this._getException(face.exception, 'group'); this.setData({ faceException: exception }); } }, data: { tongueException: [], faceException: [], isShowType: '', }, methods: { async preview(event: WechatMiniprogram.TouchEvent) { const type: 'tongue' | 'face' = event.mark?.type; const [operation = '', dataType] = event.mark?.operation?.split('-') ?? []; const data = (this.data as any)[type]?.[operation]; if (!data) return; const { eventChannel } = await wx.navigateTo({ url: `/module/health/pages/tongue-analysis/tongue-analysis` }); eventChannel.emit('load', { dataset: this._getException(data, dataType), title: { tongue: '异常舌象分析', face: '异常面象分析' }[type] }); }, _getException(data: AnalysisException[], type: 'list' | 'group') { switch (type) { case 'list': return data.map(({ descriptions, ...item }) => ({ ...item, exception: [{ key: item.key, descriptions }] })); case 'group': const group = groupBy(data, (item) => item.cover ?? ''); return Object.entries(group).map(([key, exception]) => ({ key, cover: key, exception, })); default: return []; } } } })