| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- import I18nBehavior from "../../../../i18n/behavior";
- import tickleBehavior, { getTickleContext } from "../../../../core/behavior/tickle.behavior";
- // module/health/pages/status-record/status-record.ts
- import { getStatusRecordMethod } from "../../request";
- import { getPageOrientation } from "../../../../lib/wx/page";
- interface Column {
- label: string;
- value: string;
- width?: number;
- height?: number;
- type?: 'picture' | 'text';
- }
- const defaultColumns: Column[] = [
- { label: '', value: 'reportTime', height: 50 },
- { label: '症状', value: 'pickedSymptom' },
- { label: '联想症状', value: 'algorithmInferSymptom' },
- { label: '舌面', value: 'upImg', type: 'picture', width: 120, height: 120 },
- { label: '舌底', value: 'downImg', type: 'picture', width: 120, height: 120 },
- { label: '面部', value: 'faceImg', type: 'picture', width: 120, height: 120 },
- ]
- Component({
- behaviors: [
- I18nBehavior,
- tickleBehavior,
- ],
- lifetimes: {
- attached() { this.load(); }
- },
- properties: {},
- data: {
- i18n: {
- health: {
- status: '',
- statusRecord: {
- "症状": "结果1",
- "联想症状": "结果2",
- "舌面": "图片1",
- "舌底": "图片2",
- "面部": "图片3"
- }
- },
- },
- orientation: '' as 'portrait' | 'landscape',
- containerStyle: '',
- columns: [] as Column[],
- },
- methods: {
- async getColumns() {
- const { orientation, width, height, left = 0, right = 0, } = getPageOrientation();
- const columns = defaultColumns;
- let maxLines = 3;
- if (orientation === 'portrait') {
- const { defaultHeight, count } = columns.reduce((obj, column) => {
- if (column.height) {
- obj.defaultHeight += column.height;
- obj.count += 1;
- }
- return obj;
- }, { defaultHeight: 0, count: 0 })
- const length = columns.length - count;
- const rowHeight = Math.floor((height - defaultHeight) / length);
- for (const column of columns) { if (column.height == null) column.height = rowHeight; }
- maxLines = Math.floor(rowHeight / 22);
- }
- this.setData({
- columns,
- orientation,
- containerStyle: `width: ${width}px;height: ${height}px;margin-left: ${left}px;margin-right: ${right}px;`,
- maxLines,
- })
- },
- async load() {
- wx.showLoading({ title: '加载中' });
- try {
- await this.getColumns();
- const { data } = await getStatusRecordMethod();
- this.setData({ dataset: data });
- } catch (error) {
- getTickleContext.call(this).showErrorMessage(error.errMsg)
- }
- wx.hideLoading();
- },
- loadMore() {
- console.log('加载更多');
- },
- preview(event: WechatMiniprogram.TouchEvent) {
- const { url, item } = event.target.dataset
- const sources = [item.upImg, item.downImg, item.faceImg].filter(Boolean);
- const current = sources.findIndex(s => s === url);
- if (current !== -1) wx.previewMedia({ sources: sources.map(url => ({ url, type: 'image' })), current });
- }
- }
- })
|