card-analysis-content.ts 2.4 KB

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