From ad528ad10fbddf4ea68de6119e8bc64961bc77ed Mon Sep 17 00:00:00 2001 From: yaojn Date: Wed, 6 Aug 2025 15:06:01 +0800 Subject: [PATCH] =?UTF-8?q?-=20[=E4=BF=AE=E5=A4=8D]=E5=8E=9F=E6=9C=89TsShe?= =?UTF-8?q?et=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/resources/plugins/TsSheet/TsSheet.vue | 72 ++++++++--------------- 1 file changed, 25 insertions(+), 47 deletions(-) diff --git a/src/resources/plugins/TsSheet/TsSheet.vue b/src/resources/plugins/TsSheet/TsSheet.vue index efcea042..462826c3 100644 --- a/src/resources/plugins/TsSheet/TsSheet.vue +++ b/src/resources/plugins/TsSheet/TsSheet.vue @@ -568,8 +568,7 @@ export default { actionType: '', //当前操作类型,'add'新增组件,'copy'复制组件 windowKeypressHandler: null, // 用于存储事件处理函数的引用 formStyleData: {}, //表单样式设置 - extendConfigList: this.defaultExtendConfigList || [], //扩展配置列表 - spanMap: new Map() + extendConfigList: this.defaultExtendConfigList || [] //扩展配置列表 }; }, beforeCreate() { @@ -582,8 +581,6 @@ export default { this.initSheet(); this.initReactionWatch(); this.initResolve(); - this.rowCells(-1); - this.spanMap = this.buildSpanMap(this.spanCells); }, beforeMount() {}, mounted() { @@ -607,18 +604,6 @@ export default { }, destroyed() {}, methods: { - buildSpanMap(spanCells) { - const map = new Map(); - spanCells.forEach(sp => { - const rowStart = sp.row; - const rowEnd = sp.row + (sp.rowspan || 1); - for (let r = rowStart; r < rowEnd; r++) { - if (!map.has(r)) map.set(r, []); - map.get(r).push(sp); - } - }); - return map; - }, enqueueReaction(componentUuid, updateFunction) { //this.reactionFnQueue.push(updateFunction); this.reactionFnQueue.set(componentUuid, updateFunction); @@ -1784,8 +1769,8 @@ export default { }, //检查当前单元格是否在其他单元格的span范围 checkCellIsInSpan(cell) { - const rowSpanList = this.spanMap.get(cell.row) || []; - for (const spancell of rowSpanList) { + for (let i = 0; i < this.spanCells.length; i++) { + const spancell = this.spanCells[i]; if (spancell.row <= cell.row && spancell.row + (spancell.rowspan || 1) >= cell.row + (cell.rowspan || 1) && spancell.col <= cell.col && spancell.col + (spancell.colspan || 1) >= cell.col + (cell.colspan || 1) && spancell != cell) { return true; } @@ -2084,27 +2069,10 @@ export default { if (this.mode === 'edit') { event.preventDefault(); } - }, - rowCells(rowindex) { - const tableList = this.cellMapByRow[rowindex] || []; - return tableList; } }, filter: {}, computed: { - cellMapByRow() { - const map = {}; - this.cellList.forEach(cell => { - if (!this.checkCellIsInSpan(cell)) { - if (!map[cell.row]) map[cell.row] = []; - map[cell.row].push({ - ...cell, - keyUuid: this.$utils.setUuid() - }); - } - }); - return map; - }, hasCopy() { if (this.handlerCell && this.handlerCell.component && !this.$utils.isEmpty(this.handlerCell.component) && !this.handlerCell.component.hasOwnProperty('inherit')) { return true; @@ -2175,22 +2143,18 @@ export default { }, //计算实际需要显示的行 shownLefterList() { - const hiddenSet = new Set(this.config.hiddenRowList); const lefterList = []; - for (let i = 0; i < this.config.lefterList.length; i++) { - if (!hiddenSet.has(i)) { - lefterList.push({ ...this.config.lefterList[i], index: i }); + this.config.lefterList.forEach((left, index) => { + if (!this.config.hiddenRowList.includes(index)) { + const newLeft = this.$utils.deepClone(left); + newLeft.index = index; + lefterList.push(newLeft); } - } + }); if (this.mode !== 'edit') { - const validRowSet = new Set(); - for (const cell of this.config.tableList) { - if (cell.component || cell.content || this.checkCellIsInSpan(cell)) { - validRowSet.add(cell.row); - } - } + //只读模式,从下面消除所有没有设置组件的单元格 for (let i = lefterList.length - 1; i >= 0; i--) { - if (!validRowSet.has(lefterList[i].index)) { + if (!this.config.tableList.find(cell => cell.row === lefterList[i].index && (cell.component || cell.content || this.checkCellIsInSpan(cell)))) { lefterList.splice(i, 1); } } @@ -2329,6 +2293,20 @@ export default { return tableList; }; }, + //每一行应该显示的单元格数据 + rowCells() { + return rowindex => { + const tableList = []; + this.cellList.forEach(cell => { + if (cell.row == rowindex) { + if (!this.checkCellIsInSpan(cell)) { + tableList.push(cell); + } + } + }); + return tableList; + }; + }, rowCount() { //总行数 let rowcount = 0; -- Gitee