当前位置: 首页 > wzjs >正文

江西房地产网站建设西安网站公司

江西房地产网站建设,西安网站公司,贵阳网站开发价格,市场调研报告总结1. 功能概述 本教程将介绍如何使用 Vue 3 和 arco 组件库实现表格合并功能。具体来说,我们会根据表格数据中的某个字段(如 type)对表格的某一列(如入库类型列)进行合并,同时将质检说明列合并为一列。 2. …
1. 功能概述

本教程将介绍如何使用 Vue 3 和 arco 组件库实现表格合并功能。具体来说,我们会根据表格数据中的某个字段(如 type)对表格的某一列(如入库类型列)进行合并,同时将质检说明列合并为一列。

2. 数据准备

首先,我们需要准备一份数据示例:

import { ref, computed } from 'vue';const storageGoodsVosdata = ref([{id: 1,workOrderId: 'WO001',goodsNo: 'G001',goodsName: 'Test Product 1',skuCode: 'SKU001',skuInfo: 'Color: White; Style: Simple',quantity: 1,type: 0,typeName: 'Defective Incoming',reasonCode: 'R01',reasonCodeStr: 'Label/Certificate/Manual/Missing or Damaged',logisticReceiptsUrls: ['https://example.com/image1.jpg','https://example.com/image2.jpg',],outerPackagingUrls: ['https://example.com/image3.jpg','https://example.com/image4.jpg',],housekeepingDiagramUrls: ['https://example.com/image5.jpg','https://example.com/image6.jpg',],createTime: '2025-02-12 09:43:31',},{id: 2,workOrderId: 'WO001',goodsNo: 'G001',goodsName: 'Test Product 1',skuCode: 'SKU001',skuInfo: 'Color: White; Style: Simple',quantity: 1,type: 0,typeName: 'Defective Incoming',reasonCode: 'R01',reasonCodeStr: 'Label/Certificate/Manual/Missing or Damaged',logisticReceiptsUrls: ['https://example.com/image1.jpg','https://example.com/image2.jpg',],outerPackagingUrls: ['https://example.com/image3.jpg','https://example.com/image4.jpg',],housekeepingDiagramUrls: ['https://example.com/image5.jpg','https://example.com/image6.jpg',],createTime: '2025-02-12 09:43:31',},{id: 3,workOrderId: 'WO001',goodsNo: 'G002',goodsName: 'Test Product 2',skuCode: 'SKU002',skuInfo: 'Color: Black; Style: Modern',quantity: 1,type: 1,typeName: 'Goods Incoming',reasonCode: 'R01',reasonCodeStr: 'Label/Certificate/Manual/Missing or Damaged',logisticReceiptsUrls: ['https://example.com/image7.jpg','https://example.com/image8.jpg',],outerPackagingUrls: ['https://example.com/image9.jpg','https://example.com/image10.jpg',],housekeepingDiagramUrls: ['https://example.com/image11.jpg','https://example.com/image12.jpg',],createTime: '2025-02-12 09:43:31',},{id: 4,workOrderId: 'WO001',goodsNo: 'G002',goodsName: 'Test Product 2',skuCode: 'SKU002',skuInfo: 'Color: Black; Style: Modern',quantity: 1,type: 1,typeName: 'Goods Incoming',reasonCode: 'R01',reasonCodeStr: 'Label/Certificate/Manual/Missing or Damaged',logisticReceiptsUrls: ['https://example.com/image7.jpg','https://example.com/image8.jpg',],outerPackagingUrls: ['https://example.com/image9.jpg','https://example.com/image10.jpg',],housekeepingDiagramUrls: ['https://example.com/image11.jpg','https://example.com/image12.jpg',],createTime: '2025-02-12 09:43:31',},
]);const sortedStorageData = computed(() => {return [...storageGoodsVosdata.value].sort((a, b) => a.type - b.type);
});
3. 表格合并方法

接下来,我们定义一个 spanMethod 函数来处理表格合并逻辑:

function spanMethod({ rowIndex, columnIndex }) {if (columnIndex === 0) { // 只处理第一列(入库类型列)const arr = sortedStorageData.value;const item = arr[rowIndex];// 如果是第一行,或者当前行的类型与前一行不同if (rowIndex === 0 || arr[rowIndex - 1].type !== item.type) {// 计算当前类型的连续行数const count = arr.slice(rowIndex).findIndex(row => row.type !== item.type);return {rowspan: count === -1 ? arr.length - rowIndex : count,colspan: 1,};}// 其他行不显示return {rowspan: 0,colspan: 0,};}// 处理质检说明列(最后一列)if (columnIndex === 8) { // 质检说明列的索引if (rowIndex === 0) {return {rowspan: sortedStorageData.value.length,colspan: 1,};}return {rowspan: 0,colspan: 0,};}
}
模板部分

最后,我们在模板中使用 a-table 组件来渲染表格,并绑定数据和合并方法:

<template><a-table:data="sortedStorageData":bordered="{ cell: true }":pagination="false":span-method="spanMethod"><template #columns><a-table-column title="Incoming Type" data-index="typeName" align="center" :min-width="180"><template #cell="{ record }">{{ record.type === 1 ? 'Goods Incoming' : 'Defective Incoming' }}</template></a-table-column><a-table-columntitle="Product SKU Number"data-index="salary"align="center":min-width="180"><template #cell="{ record }">{{ record.goodsNo }}</template></a-table-column><a-table-columncell-class="custom-col"title="Product Name"data-index="goodsNo"align="center":min-width="180"><template #cell="{ record }"><div class="good-item-wrapper">{{ record.goodsName }}</div></template></a-table-column><a-table-columncell-class="custom-col"title="Quantity"data-index="goodsName"align="center":min-width="180"><template #cell="{ record }"><div class="good-item-wrapper">×{{ record.quantity }}</div></template></a-table-column><a-table-column cell-class="custom-col" title="Defective Reason" data-index="spec" align="center" :min-width="180"><template #cell="{ record }"><div class="good-item-wrapper">{{ record.type === 1 ? '--' : record.reasonCodeStr }}</div></template></a-table-column><a-table-columncell-class="custom-col"title="Logistic Receipts"data-index="quantity"align="center":min-width="180"><template #cell="{ record }"><div class="good-item-wrapper"><div v-show="record.type === 1">--</div><div style="display: flex; gap: 5px;"><a-imagev-for="item in record.logisticReceiptsUrls"v-show="record.type === 0":key="item"width="30":src="item"/></div></div></template></a-table-column><a-table-columncell-class="custom-col"title="Outer Packaging"data-index="quantity"align="center":min-width="180"><template #cell="{ record }"><div class="good-item-wrapper"><div v-show="record.type === 1">--</div><div style="display: flex; gap: 5px;"><a-imagev-for="item in record.outerPackagingUrls"v-show="record.type === 0":key="item"width="30":src="item"/></div></div></template></a-table-column><a-table-columncell-class="custom-col"title="Housekeeping Diagram"data-index="quantity"align="center":min-width="180"><template #cell="{ record }"><div class="good-item-wrapper"><div v-show="record.type === 1">--</div><div style="display: flex; gap: 5px;"><a-imagev-for="item in record.housekeepingDiagramUrls"v-show="record.type === 0":key="item"width="30":src="item"/></div></div></template></a-table-column><a-table-columncell-class="custom-col"title="Quality Inspection Note"data-index="quantity"align="center":min-width="180"><template #cell="{ record }"><div class="good-item-wrapper"><!-- 这里可以替换为实际的质检说明数据 -->质检说明</div></template></a-table-column></template></a-table>
</template><script setup>
import { ref, computed } from 'vue';
import { ATable, ATableColumn, AImage } from 'ant-design-vue';const storageGoodsVosdata = ref([{id: 1,workOrderId: 'WO001',goodsNo: 'G001',goodsName: 'Test Product 1',skuCode: 'SKU001',skuInfo: 'Color: White; Style: Simple',quantity: 1,type: 0,typeName: 'Defective Incoming',reasonCode: 'R01',reasonCodeStr: 'Label/Certificate/Manual/Missing or Damaged',logisticReceiptsUrls: ['https://example.com/image1.jpg','https://example.com/image2.jpg',],outerPackagingUrls: ['https://example.com/image3.jpg','https://example.com/image4.jpg',],housekeepingDiagramUrls: ['https://example.com/image5.jpg','https://example.com/image6.jpg',],createTime: '2025-02-12 09:43:31',},{id: 2,workOrderId: 'WO001',goodsNo: 'G001',goodsName: 'Test Product 1',skuCode: 'SKU001',skuInfo: 'Color: White; Style: Simple',quantity: 1,type: 0,typeName: 'Defective Incoming',reasonCode: 'R01',reasonCodeStr: 'Label/Certificate/Manual/Missing or Damaged',logisticReceiptsUrls: ['https://example.com/image1.jpg','https://example.com/image2.jpg',],outerPackagingUrls: ['https://example.com/image3.jpg','https://example.com/image4.jpg',],housekeepingDiagramUrls: ['https://example.com/image5.jpg','https://example.com/image6.jpg',],createTime: '2025-02-12 09:43:31',},{id: 3,workOrderId: 'WO001',goodsNo: 'G002',goodsName: 'Test Product 2',skuCode: 'SKU002',skuInfo: 'Color: Black; Style: Modern',quantity: 1,type: 1,typeName: 'Goods Incoming',reasonCode: 'R01',reasonCodeStr: 'Label/Certificate/Manual/Missing or Damaged',logisticReceiptsUrls: ['https://example.com/image7.jpg','https://example.com/image8.jpg',],outerPackagingUrls: ['https://example.com/image9.jpg','https://example.com/image10.jpg',],housekeepingDiagramUrls: ['https://example.com/image11.jpg','https://example.com/image12.jpg',],createTime: '2025-02-12 09:43:31',},{id: 4,workOrderId: 'WO001',goodsNo: 'G002',goodsName: 'Test Product 2',skuCode: 'SKU002',skuInfo: 'Color: Black; Style: Modern',quantity: 1,type: 1,typeName: 'Goods Incoming',reasonCode: 'R01',reasonCodeStr: 'Label/Certificate/Manual/Missing or Damaged',logisticReceiptsUrls: ['https://example.com/image7.jpg','https://example.com/image8.jpg',],outerPackagingUrls: ['https://example.com/image9.jpg','https://example.com/image10.jpg',],housekeepingDiagramUrls: ['https://example.com/image11.jpg','https://example.com/image12.jpg',],createTime: '2025-02-12 09:43:31',},
]);const sortedStorageData = computed(() => {return [...storageGoodsVosdata.value].sort((a, b) => a.type - b.type);
});
function spanMethod({ rowIndex, columnIndex }) {if (columnIndex === 0) { // 只处理第一列(入库类型列)const arr = sortedStorageData.value;const item = arr[rowIndex];// 如果是第一行,或者当前行的类型与前一行不同if (rowIndex === 0 || arr[rowIndex - 1].type !== item.type) {// 计算当前类型的连续行数const count = arr.slice(rowIndex).findIndex(row => row.type !== item.type);return {rowspan: count === -1 ? arr.length - rowIndex : count,colspan: 1,};}// 其他行不显示return {rowspan: 0,colspan: 0,};}// 处理质检说明列(最后一列)if (columnIndex === 8) { // 质检说明列的索引if (rowIndex === 0) {return {rowspan: sortedStorageData.value.length,colspan: 1,};}return {rowspan: 0,colspan: 0,};}
}
</script><style scoped>
.custom-col {/* 可以添加自定义样式 */
}.good-item-wrapper {/* 可以添加自定义样式 */
}
</style>
5. 解释
  • 数据排序:使用 computed 计算属性对数据进行排序,确保相同类型的数据相邻。
  • 表格合并逻辑spanMethod 函数根据列索引和行索引来决定哪些单元格需要合并。对于入库类型列,根据 type 字段合并相同类型的行;对于质检说明列,将所有行合并为一列。
  • 模板渲染:使用 a-table 组件渲染表格,并通过 #columns 插槽定义表格列。每个列可以通过 #cell 插槽自定义单元格内容。

通过以上步骤,你就可以实现一个带有合并单元格功能的表格。

6. 效果

在这里插入图片描述

http://www.dtcms.com/wzjs/557379.html

相关文章:

  • 校园论坛网站建设论文铸铁加工平台
  • 做网站咋赚钱郑州企业网站怎么优化
  • 广州手机建站模板重庆好玩还是成都好玩
  • 现在淘客做网站还行吗关键字排名查询工具
  • 山东网站建设公司哪家专业广州网站建设教程
  • 淘宝联盟 做网站wordpress 太慢了
  • 网站后台维护系统手机网站开发 视频教程
  • 东莞网站竞价推广运营免费网站大全下载
  • 微信里有人发做任务网站个人静态网站
  • 网站建设系统哪个好wordpress基于什么
  • 织梦cms做视频网站广告网络推广
  • 起名算命网站如何做赚钱网站开发非常之旅
  • 四川网站建设有哪些注塑模具东莞网站建设
  • 建设部网站退休注册人员在线排名优化工具
  • 为什么网站不见了网站开发方案
  • 网站没备案能访问吗四川建设网官网住房和城乡厅官网
  • 建设网站的网址设计头像网站免费推荐
  • 大连做网站孙晓龙淘宝客怎么做推广
  • 注册网站商标多少钱贸易公司名称大全简单大气
  • 网站建设丶金手指下拉13wordpress插件
  • 网站建设多久可以学会重庆编程培训机构
  • 找柳市做网站通辽市做网站公司
  • 免费设计app的网站建设做国外贸易的网站
  • 中国贸易网站哔哩哔哩推广网站
  • 广州网站建设加q.479185700wordpress多账号
  • 网站开发专业成功人士做网店的网站
  • 企业服务网站开发企业公众号怎么制作
  • 做网站一定要用ps吗苏州网站开发外包公司
  • 鲜花店网站建设专业seo推广
  • 高平市网站建设公司微信上的网站怎么做