card-analysis-content.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { groupBy } from "../../../../utils/util";
  2. import { AnalysisException, AnalysisModel } from "../../model/health.model";
  3. // module/health/components/card-analysis/card-analysis-content.ts
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. tongue: { type: Object, value: null },
  10. face: { type: Object, value: null },
  11. simple: { type: Object, value: { tongue: false, face: false } },
  12. exception: { type: Object, value: { tongue: false, face: false } },
  13. },
  14. observers: {
  15. 'exception.tongue, tongue'(show: boolean, tongue: AnalysisModel) {
  16. if (show === void 0) { show = true; }
  17. if (!show || !tongue) return;
  18. const exception = this._getException(tongue.exception, 'list');
  19. this.setData({ tongueException: exception });
  20. },
  21. 'exception.face, face'(show: boolean, face: AnalysisModel) {
  22. if (show === void 0) { show = true; }
  23. if (!show || !face) return;
  24. const exception = this._getException(face.exception, 'group');
  25. this.setData({ faceException: exception });
  26. }
  27. },
  28. data: {
  29. tongueException: [],
  30. faceException: [],
  31. },
  32. methods: {
  33. async preview(event: WechatMiniprogram.TouchEvent) {
  34. const type: 'tongue' | 'face' = event.mark?.type;
  35. const [operation = '', dataType] = event.mark?.operation?.split('-') ?? [];
  36. const data = (this.data as any)[type]?.[operation];
  37. if (!data) return;
  38. const { eventChannel } = await wx.navigateTo({ url: `/module/health/pages/tongue-analysis/tongue-analysis` });
  39. eventChannel.emit('load', {
  40. dataset: this._getException(data, dataType),
  41. title: { tongue: '异常舌象分析', face: '异常面象分析' }[type]
  42. });
  43. },
  44. _getException(data: AnalysisException[], type: 'list' | 'group') {
  45. switch (type) {
  46. case 'list':
  47. return data.map(({ descriptions, ...item }) => ({
  48. ...item,
  49. exception: [{ key: item.key, descriptions }]
  50. }));
  51. case 'group':
  52. const group = groupBy<AnalysisException>(data, (item) => item.cover ?? '');
  53. return Object.entries(group).map(([key, exception]) => ({ key, cover: key, exception, }));
  54. default:
  55. return [];
  56. }
  57. }
  58. }
  59. })