status-record.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. import I18nBehavior from "../../../../i18n/behavior";
  2. import tickleBehavior, { getTickleContext } from "../../../../core/behavior/tickle.behavior";
  3. // module/health/pages/status-record/status-record.ts
  4. import { getStatusRecordMethod } from "../../request";
  5. import { getPageOrientation } from "../../../../lib/wx/page";
  6. interface Column {
  7. label: string;
  8. value: string;
  9. width?: number;
  10. height?: number;
  11. type?: 'picture' | 'text';
  12. }
  13. const defaultColumns: Column[] = [
  14. { label: '', value: 'reportTime', height: 50 },
  15. { label: '症状', value: 'pickedSymptom' },
  16. { label: '联想症状', value: 'algorithmInferSymptom' },
  17. { label: '舌面', value: 'upImg', type: 'picture', width: 120, height: 120 },
  18. { label: '舌底', value: 'downImg', type: 'picture', width: 120, height: 120 },
  19. { label: '面部', value: 'faceImg', type: 'picture', width: 120, height: 120 },
  20. ]
  21. Component({
  22. behaviors: [
  23. I18nBehavior,
  24. tickleBehavior,
  25. ],
  26. lifetimes: {
  27. attached() { this.load(); }
  28. },
  29. properties: {},
  30. data: {
  31. i18n: {
  32. health: {
  33. status: '',
  34. statusRecord: {
  35. "症状": "结果1",
  36. "联想症状": "结果2",
  37. "舌面": "图片1",
  38. "舌底": "图片2",
  39. "面部": "图片3"
  40. }
  41. },
  42. },
  43. orientation: '' as 'portrait' | 'landscape',
  44. containerStyle: '',
  45. columns: [] as Column[],
  46. },
  47. methods: {
  48. async getColumns() {
  49. const { orientation, width, height, left = 0, right = 0, } = getPageOrientation();
  50. const columns = defaultColumns;
  51. let maxLines = 3;
  52. if (orientation === 'portrait') {
  53. const { defaultHeight, count } = columns.reduce((obj, column) => {
  54. if (column.height) {
  55. obj.defaultHeight += column.height;
  56. obj.count += 1;
  57. }
  58. return obj;
  59. }, { defaultHeight: 0, count: 0 })
  60. const length = columns.length - count;
  61. const rowHeight = Math.floor((height - defaultHeight) / length);
  62. for (const column of columns) { if (column.height == null) column.height = rowHeight; }
  63. maxLines = Math.floor(rowHeight / 22);
  64. }
  65. this.setData({
  66. columns,
  67. orientation,
  68. containerStyle: `width: ${width}px;height: ${height}px;margin-left: ${left}px;margin-right: ${right}px;`,
  69. maxLines,
  70. })
  71. },
  72. async load() {
  73. wx.showLoading({ title: '加载中' });
  74. try {
  75. await this.getColumns();
  76. const { data } = await getStatusRecordMethod();
  77. this.setData({ dataset: data });
  78. } catch (error) {
  79. getTickleContext.call(this).showErrorMessage(error.errMsg)
  80. }
  81. wx.hideLoading();
  82. },
  83. loadMore() {
  84. console.log('加载更多');
  85. },
  86. preview(event: WechatMiniprogram.TouchEvent) {
  87. const { url, item } = event.target.dataset
  88. const sources = [item.upImg, item.downImg, item.faceImg].filter(Boolean);
  89. const current = sources.findIndex(s => s === url);
  90. if (current !== -1) wx.previewMedia({ sources: sources.map(url => ({ url, type: 'image' })), current });
  91. }
  92. }
  93. })