status-record.ts 2.7 KB

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