<p>{&quot;template&quot;:&quot;\n  <div>\n    &lt;div class=&quot;table-container&quot;&gt;\n      &lt;table class=&quot;fixed-table&quot;&gt;\n        &lt;tr v-for=&quot;(row, rowIndex) in tableData&quot; :key=&quot;rowIndex&quot;&gt;\n          &lt;td v-for=&quot;(cell, cellIndex) in row&quot; :key=&quot;cellIndex&quot; :colspan=&quot;getColspan(cell)&quot;\n            :class=&quot;['cell', { 'first-cell': rowIndex === 0 &amp;&amp; cellIndex === 0, 'center-text': cell !== 1 &amp;&amp; cell !== 16 }]&quot;&gt;\n            <!-- 添加内容slot -->\n            &lt;template v-if=&quot;isTextCell(cell) &amp;&amp; cell === 16&quot;&gt;\n              <!-- 在第16单元格内的上方添加文本“其它” -->\n              &lt;div class=&quot;other-text&quot;&gt;其它</div>\n              &lt;textarea class=&quot;textarea-cell&quot; v-model=&quot;textData[cell]&quot; disabled rows=&quot;5&quot;&gt;</textarea>\n            </template>\n            &lt;template v-else-if=&quot;isTextCell(cell)&quot;&gt;\n              &lt;input :value=&quot;getTextData(cell)&quot; :class=&quot;{'center-text': cell !== 1 &amp;&amp; cell !== 16 }&quot; disabled&gt;\n            </template>\n            &lt;template v-else-if=&quot;isImageCell(cell)&quot;&gt;\n              &lt;div class=&quot;image-cell&quot;&gt;\n                &lt;img :src=&quot;getImageUrl(cell)&quot; alt=&quot;Image&quot; /&gt;\n              </div>\n            </template>\n          </td>\n        </tr>\n        <tr>\n          &lt;td :colspan=&quot;tableData[0].length&quot;&gt;\n            &lt;div class=&quot;center-align&quot;&gt;\n              &lt;div class=&quot;add-button&quot; @click=&quot;handleAddButtonClick&quot;&gt;+</div>\n            </div>\n          </td>\n        </tr>\n      </table>\n    </div>\n    &lt;div class=&quot;add-button-container&quot;&gt;\n      &lt;button class=&quot;edit-btn&quot; @click=&quot;gotoTaocan&quot; v-show=&quot;userInfo[0].position === 1&quot;&gt;编辑</button>\n      &lt;button class=&quot;home-btn&quot; @click=&quot;gotoHome&quot;&gt;主页</button>\n    </div>\n  </div>\n</template>\n\n<script>\n export default {\n  data() {\n    return {\n      userInfo: JSON.parse(localStorage.getItem(&quot;userInfo&quot;)),\n      showBackButton: false,\n      tableData: [],\n      textData: {},\n      buttonColspan: 0,\n    };\n  },\n  async created() {\n    const userInfo = JSON.parse(localStorage.getItem(&quot;userInfo&quot;));\n    const getDataList = uniCloud.importObject(&quot;combo&quot;);\n    let res = await getDataList.getList(); // 从服务器获取数据\n    console.log(&quot;收到服务器数据:&quot; + JSON.stringify(res));\n    if (res.data) {\n      const item = res.data[0];\n      const mainDishNameList = item.maindishname;\n      const mainDishPicList = item.maindishpic;\n      const otherdishes = item.otherdishes;\n\n      mainDishPicList.forEach(async (picURL, index) =&gt; {\n        if (picURL) {\n          const imageURL = await this.downloadImage(picURL);\n          this.$set(this.textData, 4 + index, imageURL);\n        } else {\n          this.$set(this.textData, 4 + index, null);\n        }\n      });\n\n      this.textData[1] = item.price + &quot; &quot; + item.name;\n      this.textData[7] = mainDishNameList[0];\n      this.textData[8] = mainDishNameList[1];\n      this.textData[9] = mainDishNameList[2];\n      this.textData[13] = mainDishNameList[3];\n      this.textData[14] = mainDishNameList[4];\n      this.textData[15] = mainDishNameList[5];\n      this.textData[16] = otherdishes;\n\n      this.generateTableData(); // 生成表格数据\n    }\n  },\n  methods: {\n    getColspan(cell) {\n      if (cell === 1 || cell === 16) {\n        return this.tableData[0].length;\n      } else {\n        return 1;\n      }\n    },\n    isTextCell(cell) {\n      const textCells = [1, 7, 8, 9, 13, 14, 15, 16];\n      return textCells.includes(cell);\n    },\n    isImageCell(cell) {\n      const imageCells = [4, 5, 6, 10, 11, 12];\n      return imageCells.includes(cell);\n    },\n    getTextData(cell) {\n      return this.textData[cell];\n    },\n    updateTextData(cell, value) {\n      this.textData[cell] = value;\n    },\n    // 请求服务器获取图片地址的逻辑\n    // 返回从服务器接收到的图片地址\n    getImageUrl(cell) {\n      const mainDishPicList = JSON.parse(localStorage.getItem(&quot;tableData&quot;))[0].mainDishPicList;\n      return mainDishPicList[cell - 4]; // 因为图片地址在mainDishPicList中的索引是cell-4\n    },\n    handleAddButtonClick() {},\n    gotoTaocan() {\n      uni.redirectTo({\n        url: &quot;/pages/index/taocan&quot;,\n      });\n    },\n    gotoHome() {\n      uni.redirectTo({\n        url: &quot;/pages/index/index&quot;,\n      });\n    },\n    generateTableData() {\n      const tableData = [];\n\n      for (let i = 0; i &lt; this.textData[16].length; i++) {\n        const newRow = [];\n\n        for (let j = 0; j &lt; this.tableData[0].length; j++) {\n          newRow.push(i + j + 1);\n        }\n\n        tableData.push(newRow);\n      }\n\n      this.tableData = tableData;\n    },\n  },\n};\n</script>\n</p>

原文地址: https://www.cveoy.top/t/topic/pyq6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录