card-analysis-content.ts 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. ],
  52. },
  53. methods: {
  54. async preview(event: WechatMiniprogram.TouchEvent) {
  55. const type: 'tongue' | 'face' = event.mark?.type;
  56. const [operation = '', dataType] = event.mark?.operation?.split('-') ?? [];
  57. const data = (this.data as any)[type]?.[operation];
  58. if (!data) return;
  59. const t2 = this.data.i18n?.analysis?.[type] ?? '';
  60. const t3 = this.data.i18n?.analysis?.['_'] ?? '';
  61. const { eventChannel } = await wx.navigateTo({ url: `/module/health/pages/tongue-analysis/tongue-analysis` });
  62. eventChannel.emit('load', {
  63. dataset: this._getException(data, dataType),
  64. title: `异常${t2}${t3}`,
  65. });
  66. },
  67. _getException(data: AnalysisException[], type: 'list' | 'group') {
  68. switch (type) {
  69. case 'list':
  70. return data.map(({ descriptions, ...item }) => ({
  71. ...item,
  72. exception: [{ key: item.key, descriptions }]
  73. }));
  74. case 'group':
  75. const group = groupBy<AnalysisException>(data, (item) => item.cover ?? '');
  76. return Object.entries(group).map(([key, exception]) => ({ key, cover: key, exception, }));
  77. default:
  78. return [];
  79. }
  80. }
  81. }
  82. })