card-analysis-content.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. type: { type: String, value: '' },
  14. },
  15. observers: {
  16. 'exception.tongue, tongue'(show: boolean, tongue: AnalysisModel) {
  17. if (show === void 0) { show = true; }
  18. if (!show || !tongue) return;
  19. const exception = this._getException(tongue.exception, 'list');
  20. this.setData({ tongueException: exception });
  21. },
  22. 'exception.face, face'(show: boolean, face: AnalysisModel) {
  23. if (show === void 0) { show = true; }
  24. if (!show || !face) return;
  25. const exception = this._getException(face.exception, 'group');
  26. this.setData({ faceException: exception });
  27. }
  28. },
  29. data: {
  30. tongueException: [],
  31. faceException: [],
  32. },
  33. methods: {
  34. async preview(event: WechatMiniprogram.TouchEvent) {
  35. const type: 'tongue' | 'face' = event.mark?.type;
  36. const [operation = '', dataType] = event.mark?.operation?.split('-') ?? [];
  37. const data = (this.data as any)[type]?.[operation];
  38. if (!data) return;
  39. const { eventChannel } = await wx.navigateTo({ url: `/module/health/pages/tongue-analysis/tongue-analysis` });
  40. eventChannel.emit('load', {
  41. dataset: this._getException(data, dataType),
  42. title: { tongue: '异常舌象分析', face: '异常面象分析' }[type]
  43. });
  44. },
  45. _getException(data: AnalysisException[], type: 'list' | 'group') {
  46. switch (type) {
  47. case 'list':
  48. return data.map(({ descriptions, ...item }) => ({
  49. ...item,
  50. exception: [{ key: item.key, descriptions }]
  51. }));
  52. case 'group':
  53. const group = groupBy<AnalysisException>(data, (item) => item.cover ?? '');
  54. return Object.entries(group).map(([key, exception]) => ({ key, cover: key, exception, }));
  55. default:
  56. return [];
  57. }
  58. }
  59. }
  60. })