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

合并table

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>玻璃样品检测数据表</title><link rel="stylesheet" href="./vue/element_ui.css" /><link rel="stylesheet" href="./css/index.css" /><script src="./vue/unocss.js"></script><script src="./vue/vue.js"></script><script src="./vue/element_ui.js"></script><style>.el-table .warning-row {background: #fdf6ec;}.el-table .success-row {background: #f0f9eb;}.el-table__header th {background-color: #f5f7fa !important;color: #606266;font-weight: bold;}.position-cell {font-weight: bold;color: #409eff;}.summary-cell {font-weight: bold;color: #303133;background-color: #f5f7fa;}</style></head><body><div id="app"><div class="p-20px"><el-table:data="tableData":span-method="objectSpanMethod"borderstripe><!-- 产线列 --><el-table-column prop="locLine" label="产线" align="center"></el-table-column><!-- 厚度列 --><el-table-column prop="thickness" label="厚度" align="center"><template #default="{row}"> {{ row.thickness }}mm </template></el-table-column><!-- 位置列 --><el-table-column prop="location" label="位置" align="center"></el-table-column><!-- 锡计数列 --><el-table-column prop="measureSnNum" label="锡计数" align="center"><template #default="{row}"><el-tooltip :content="row.ceshi" placement="top"><div>{{ row.measureSnNum }}</div></el-tooltip></template></el-table-column></el-table></div></div><script>new Vue({el: "#app",data() {return {tableData: [],};},created() {// 初始化表格数据this.initTableData();},methods: {// 初始化表格数据initTableData() {const rawData = [// A线数据{locLine: "A线",thickness: 2.5,location: "前端",measureSnNum: 15,ceshi: 1,},{locLine: "A线",thickness: 2.5,location: "前端",measureSnNum: 15,ceshi: 2,},{locLine: "A线",thickness: 2,location: "前端",measureSnNum: 18,ceshi: 3,},{locLine: "A线",thickness: 2.5,location: "中端",measureSnNum: 22,ceshi: 4,},{locLine: "A线",thickness: 3.0,location: "前端",measureSnNum: 16,ceshi: 5,},{locLine: "A线",thickness: 3.0,location: "前端",measureSnNum: 19,ceshi: 6,},// B线数据{locLine: "B线",thickness: 3,location: "前端",measureSnNum: 14,ceshi: 7,},{locLine: "B线",thickness: 2.0,location: "前端",measureSnNum: 17,ceshi: 8,},{locLine: "B线",thickness: 2.0,location: "前端",measureSnNum: 13,ceshi: 9,},{locLine: "B线",thickness: 2.0,location: "中端",measureSnNum: 21,ceshi: 10,},{locLine: "B线",thickness: 2.5,location: "后端",measureSnNum: 25,ceshi: 11,},{locLine: "B线",thickness: 2.5,location: "后端",measureSnNum: 28,ceshi: 12,},];// 处理数据,添加合并信息this.tableData = this.processDataForMerge(rawData);},// 处理数据,为合并做准备processDataForMerge(data) {const processedData = [];for (let i = 0; i < data.length; i++) {const currentRow = { ...data[i] };// 初始化合并标记currentRow.locLineFirst = false;currentRow.thicknessFirst = false;currentRow.locationFirst = false;// 检查是否是产线的第一行if (i === 0 || data[i - 1].locLine !== currentRow.locLine) {currentRow.locLineFirst = true;// 计算产线合并行数let count = 1;for (let j = i + 1; j < data.length; j++) {if (data[j].locLine === currentRow.locLine) {count++;} else {break;}}currentRow.locLineSpan = count;}// 检查是否是厚度的第一行if (i === 0 ||data[i - 1].locLine !== currentRow.locLine ||data[i - 1].thickness !== currentRow.thickness) {currentRow.thicknessFirst = true;// 计算厚度合并行数let count = 1;for (let j = i + 1; j < data.length; j++) {if (data[j].locLine === currentRow.locLine &&data[j].thickness === currentRow.thickness) {count++;} else {break;}}currentRow.thicknessSpan = count;}// 检查是否是位置的第一行if (i === 0 ||data[i - 1].locLine !== currentRow.locLine ||data[i - 1].thickness !== currentRow.thickness ||data[i - 1].location !== currentRow.location) {currentRow.locationFirst = true;// 计算位置合并行数let count = 1;for (let j = i + 1; j < data.length; j++) {if (data[j].locLine === currentRow.locLine &&data[j].thickness === currentRow.thickness &&data[j].location === currentRow.location) {count++;} else {break;}}currentRow.locationSpan = count;}processedData.push(currentRow);}return processedData;},// 合并单元格方法objectSpanMethod({ row, column, rowIndex, columnIndex }) {if (columnIndex === 0) {// 产线列if (row.locLineFirst) {return {rowspan: row.locLineSpan,colspan: 1,};} else {return {rowspan: 0,colspan: 0,};}} else if (columnIndex === 1) {// 厚度列if (row.thicknessFirst) {return {rowspan: row.thicknessSpan,colspan: 1,};} else {return {rowspan: 0,colspan: 0,};}} else if (columnIndex === 2) {// 位置列if (row.locationFirst) {return {rowspan: row.locationSpan,colspan: 1,};} else {return {rowspan: 0,colspan: 0,};}}},},});</script></body>
</html>
http://www.dtcms.com/a/257631.html

相关文章:

  • Java后端与Vue前端项目部署全流程:从环境配置到Nginx反向代理
  • 【基础篇-消息队列】——详解 RocketMQ 和 Kafka 的消息模型
  • vue组件转html
  • qt常用控件--02
  • 互联网大数据求职面试:从Zookeeper到Flink的技术探讨
  • Docker 永久换源步骤
  • 四核 A53+工业级存储:移远 SC200L 与 pSLC SD NAND 如何重构 T-BOX 性能边界?
  • APO:自动化技术提升大语言模型在各类任务中的表现
  • Python基础之函数
  • 构建轻量级RTSP服务的正确方式:从RFC到工程实践
  • 1.1、CAN总线简介
  • AI+地图打车:如何用机器学习实现小程序订单智能匹配与路径优化?
  • PicHome结合容器化与内网穿透实现跨平台影像管理
  • <3>_Linux环境基础开发工具使用
  • 处理器指令中的位域处理指令(Bit Field Instructions)是什么?
  • Vue3 中 ref 与 reactive 使用场景总结(含对比与示例)
  • 小程序 顶部栏标题栏 下拉滚动 渐显白色背景
  • 7.4.2B+树
  • 制造业B端页面个性化设计案例:生产流程监控的专属布局打造
  • 【数据结构】_二叉树基础OJ
  • 数字孪生:为UI前端设计带来沉浸式交互新体验
  • 逆变器工作原理
  • 文章以及好用网站分享
  • Elasticsearch 索引文档的流程
  • WebSocket长连接在小程序中的实践:消息推送与断线重连机制设计
  • 移远 SC200L 与 贴片 SD 卡 MKDN064GIL-ZA:开启 T-BOX 智能网联新时代
  • spring-core 资源管理- Resource 接口讲解
  • 历史项目依赖库Bugfix技巧-类覆盖
  • 正则表达式详解:从基础到高级应用的全面指南
  • 【文件】Linux 内核优化实战 - fs.inotify.max_user_watches