Component({ properties: { option: { type: Object }, data: { type: Array } }, data: { systemInfo: { windowWidth: 375, rate: 0 }, html: `` }, observers: { 'data,option': async function () { if (this.properties.data.length && Object.keys(this.properties.option).length) { if (!this.data.systemInfo.rate) await this.setSystemInfo(); this.initHtml(); } } }, methods: { async setSystemInfo() { return new Promise(resolve => { wx.getSystemInfo({ success: (result: any) => { this.data.systemInfo.windowWidth = result.windowWidth; this.data.systemInfo.rate = result.windowWidth / 375; resolve(1); }, }) }) }, initHtml() { const option = this.properties.option; const data = this.properties.data; const r = this.data.systemInfo.rate; const thStickyStyle = option.headOption.thStickyStyle; const thStyle = option.headOption.thStyle; const tdStickyStyle = option.bodyOption.tdStickyStyle; const tdStyle = option.bodyOption.tdStyle; const tableWidth = option.colOption.reduce((p: number, v: number) => p + v); let col = ``; let thead = ``; let tbody = ``; let html = `
` option.colOption.forEach((v: number) => { col += `` }) option.headOption.row.forEach((row: [], rowIndex: number, rowArr: []) => { thead += ``; row.forEach((cell: any, cellIndex: number) => { if (cell.sticky) { thead += `` } else { thead += ` ` } if (cellIndex === row.length - 1) { thead += `` } }) if (rowIndex === rowArr.length - 1) { thead += `` } }) data.forEach((data, dataIndex, dataArr) => { option.bodyOption.row.forEach((row: []) => { tbody += ``; row.forEach((cell: any, cellIndex: number) => { if (cell.sticky) { tbody += `` } else { tbody += ` ` } if (cellIndex === row.length - 1) { tbody += `` } }) }) if (dataIndex === dataArr.length - 1) { tbody += `` } }) html = html + col + thead + tbody + `
${cell.value}${cell.value}
${cell.value ? cell.value : data[cell.prop]}${cell.value ? cell.value : data[cell.prop]}
`; this.setData({ html: html }); } }, lifetimes: { attached() { } }, })