card-analysis-content.ts 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import I18nBehavior from "../../../../i18n/behavior";
  2. import { groupBy } from "../../../../utils/util";
  3. import { AnalysisException, AnalysisModel } from "../../model/health.model";
  4. // module/health/components/card-analysis/card-analysis-content.ts
  5. Component({
  6. behaviors: [I18nBehavior],
  7. lifetimes: {
  8. attached() {
  9. if (this.properties.type === 'files') {
  10. this.setData({ isShowType: true });
  11. }
  12. }
  13. },
  14. /**
  15. * 组件的属性列表
  16. */
  17. properties: {
  18. tongue: { type: Object, value: null },
  19. face: { type: Object, value: null },
  20. simple: { type: Object, value: { tongue: false, face: false } },
  21. exception: { type: Object, value: { tongue: false, face: false } },
  22. type: { type: String, value: '' },
  23. },
  24. observers: {
  25. 'exception.tongue, tongue'(show: boolean, tongue: AnalysisModel) {
  26. if (show === void 0) { show = true; }
  27. if (!show || !tongue) return;
  28. const exception = this._getException(tongue.exception, 'list');
  29. this.setData({ tongueException: exception });
  30. },
  31. 'exception.face, face'(show: boolean, face: AnalysisModel) {
  32. if (show === void 0) { show = true; }
  33. if (!show || !face) return;
  34. const exception = this._getException(face.exception, 'group');
  35. this.setData({ faceException: exception });
  36. }
  37. },
  38. data: {
  39. tongueException: [],
  40. faceException: [],
  41. isShowType: '',
  42. i18n: [
  43. 'analysis._',
  44. 'analysis.tongue',
  45. 'analysis.face',
  46. 'analysis.tongue_1',
  47. 'analysis.tongue_2',
  48. 'analysis.face_1',
  49. 'analysis.__show__',
  50. 'analysis.__showContent__',
  51. 'analysis.__showException__',
  52. ],
  53. },
  54. methods: {
  55. async preview(event: WechatMiniprogram.TouchEvent) {
  56. const type: 'tongue' | 'face' = event.mark?.type;
  57. const [operation = '', dataType] = event.mark?.operation?.split('-') ?? [];
  58. const data = (this.data as any)[type]?.[operation];
  59. if (!data) return;
  60. const t2 = this.data.i18n?.analysis?.[type] ?? '';
  61. const t3 = this.data.i18n?.analysis?.['_'] ?? '';
  62. const { eventChannel } = await wx.navigateTo({ url: `/module/health/pages/tongue-analysis/tongue-analysis` });
  63. eventChannel.emit('load', {
  64. dataset: this._getException(data, dataType),
  65. title: `异常${t2}${t3}`,
  66. });
  67. },
  68. _getException(data: AnalysisException[], type: 'list' | 'group') {
  69. switch (type) {
  70. case 'list':
  71. return data.map(({ descriptions, ...item }) => ({
  72. ...item,
  73. exception: [{ key: item.key, descriptions }]
  74. }));
  75. case 'group':
  76. const group = groupBy<AnalysisException>(data, (item) => item.cover ?? '');
  77. return Object.entries(group).map(([key, exception]) => ({ key, cover: key, exception, }));
  78. default:
  79. return [];
  80. }
  81. }
  82. }
  83. })