diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 042979e9a06ce564896e49dc50186ffe853eca73..7cf0aa883705fe518fb86b2c3eed3529c1a21b1f 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -93,14 +93,14 @@ struct Index { "columns": [], "records": [], "autoWrapText": true, - "defaultRowHeight": 30, + // "defaultRowHeight": 30, "editor": "input", "editCellTrigger": "doubleclick", "resize": { "columnResizeMode": "none", "rowResizeMode": "none" }, - "heightMode": "autoHeight" + // "heightMode": "autoHeight" } imageRecords: Record[] = [ { diff --git a/library/src/main/resources/rawfile/vtable_util.js b/library/src/main/resources/rawfile/vtable_util.js index a10b014073d91a2beae30b95779d93b7f4bdc031..78865f9997e345ded0d0825465f1e8c7edd20f66 100644 --- a/library/src/main/resources/rawfile/vtable_util.js +++ b/library/src/main/resources/rawfile/vtable_util.js @@ -127,6 +127,7 @@ function frozenRow(index) { return; } window.tableInstance.frozenRowCount = index; + renderWithRecreateCells() } // 合并指定范围的单元格 @@ -135,14 +136,25 @@ function mergeCell(startCol, startRow, endCol, endRow) { console.error('表格实例未找到'); return; } + console.log("=====> unmergeCells", JSON.stringify(window.tableInstance.editorManager.editingEditor)) + for (let i = startCol; i <= endCol; i++) { + for (let j = startRow; j <= endRow; j++) { + a_ = window.tableInstance.getCellRange(i, j) + console.log("=====> unmergeCellsrange a_", JSON.stringify(a_.start)) + console.log("=====> unmergeCellsrange a_", JSON.stringify(a_.end)) + if (a_.start.col != a_.end.col || a_.start.row != a_.end.row) { + return + } + } + } + const cellnumber = window.tableInstance.getCellValue(startCol, startRow, true); console.log("=====> mergeCell", JSON.stringify(cellnumber)) for (let i = startCol; i <= endCol; i++) { for (let j = startRow; j <= endRow; j++) { window.tableInstance.changeCellValue(i, j, cellnumber); } - } window.tableInstance.mergeCells(startCol, startRow, endCol, endRow); } @@ -157,30 +169,34 @@ function unmergeCells(startCol, startRow, endCol, endRow) { let a for (let i = startCol; i <= endCol; i++) { for (let j = startRow; j <= endRow; j++) { - a = window.tableInstance.getCellRange(i, j) - if (a.isCustom) { - hasMergeCells = a.isCustom + a_ = window.tableInstance.getCellRange(i, j) + console.log("=====> unmergeCellsrange a_", JSON.stringify(a_.start)) + console.log("=====> unmergeCellsrange a_", JSON.stringify(a_.end)) + if (a_.start.col != a_.end.col || a_.start.row != a_.end.row) { + hasMergeCells = true + a = a_ + console.log("=====> unmergeCellsrange", JSON.stringify(a)) } - console.log("=====> unmergeCellsrange", JSON.stringify(a)) } } console.log("=====> unmergeCells", JSON.stringify(hasMergeCells)) if (hasMergeCells) { // if (startCol !== endCol || startRow !== endRow) { - const cellnumber = window.tableInstance.getCellValue(startCol, startRow, true); - console.log("=====> unmergeCells", JSON.stringify(a.start.col)) - - for (let i = a.start.col; i <= a.end.col; i++) { - for (let j = a.start.row; j <= a.end.row; j++) { - if (i === a.start.col && j === a.start.row) { - window.tableInstance.changeCellValue(i, j, cellnumber); - } else { - window.tableInstance.changeCellValue(i, j, ''); - } + const cellnumber = window.tableInstance.getCellValue(startCol, startRow, true); + console.log("=====> unmergeCells", JSON.stringify(a)) + + for (let i = a.start.col; i <= a.end.col; i++) { + for (let j = a.start.row; j <= a.end.row; j++) { + if (i === a.start.col && j === a.start.row) { + window.tableInstance.changeCellValue(i, j, cellnumber); + console.log("=====> unmergeCells", JSON.stringify(i), JSON.stringify(j)) + } else { + window.tableInstance.changeCellValue(i, j, ''); } - } - window.tableInstance.unmergeCells(a.start.col, a.start.row, a.end.col, a.end.row); + + } + window.tableInstance.unmergeCells(a.start.col, a.start.row, a.end.col, a.end.row); // } } } @@ -268,10 +284,8 @@ function initializeTable(option) { eventList.forEach(eventName => { tableInstance.on(VTable.ListTable.EVENT_TYPE[eventName], (event) => { if (eventName === 'CLICK_CELL') { - tableInstance.eventManager.isDraging = false; - // console.log("=====> CLICK_CELL", JSON.stringify(tableInstance.eventManager.isDraging)) - // tableInstance.stateManager.interactionState = VTable.InteractionState.default; - // console.log("=====> CLICK_CELL2", JSON.stringify(tableInstance.eventManager.isDraging)) + // tableInstance.eventManager.isDraging = false; + // renderWithRecreateCells(); // 仅执行单选(可选,确保点击只选中当前单元格) // tableInstance.stateManager.updateSelectPosition( @@ -283,6 +297,9 @@ function initializeTable(option) { }); }) window.tableInstance = tableInstance; + + const height = tableInstance.getRowHeight(1) + tableInstance.setRowHeight(1, height) } // 滚动到行 @@ -437,61 +454,76 @@ function zoomOut() { var arr = [] function setDiagonal(startCol, startRow, endCol, endRow) { - const newColumns = window.tableInstance.options.columns; - - const keySet = new Set(arr.map(item => `${item.col},${item.row}`)); - + let hasMergeCells = false; + let a for (let i = startCol; i <= endCol; i++) { for (let j = startRow; j <= endRow; j++) { - const key = `${i},${j}`; - if (!keySet.has(key)) { - keySet.add(key); - arr.push({ col: i, row: j }); + a = window.tableInstance.getCellRange(i, j) + if (a.start.col != a.end.col || a.start.row != a.end.row) { + hasMergeCells = true } + console.log("=====> unmergeCellsrange", JSON.stringify(a)) } } + console.log("=====> unmergeCells", JSON.stringify(hasMergeCells)) + if (!hasMergeCells) { + const newColumns = window.tableInstance.options.columns; - console.log("=====> setDiagonal", arr) - - - newColumns.map((item) => { - item.customRender = (args) => { - colRow_ = { col: args.col, row: args.row } - - const exactExists = arr.some(item => - item.col === colRow_.col && item.row === colRow_.row - ); - - if (exactExists) { - return { - elements: [ - { - type: 'line', - elementKey: 'diagonal-line', - x: 0, - y: 0, - points: [ - { x: 0, y: 0 }, - { x: args.rect.width, y: args.rect.height } - ], - stroke: '#ff0000', - lineWidth: 2, - pickable: false, - cursor: 'default' - } - ], - renderDefault: true - } - } else { - return { - renderDefault: true + const keySet = new Set(arr.map(item => `${item.col},${item.row}`)); + + for (let i = startCol; i <= endCol; i++) { + for (let j = startRow; j <= endRow; j++) { + const key = `${i},${j}`; + if (!keySet.has(key)) { + keySet.add(key); + arr.push({ col: i, row: j }); } } } - }) - window.tableInstance.updateColumns(newColumns, { clearColWidthCache: true }); + + console.log("=====> setDiagonal", arr) + + + newColumns.map((item) => { + item.customRender = (args) => { + colRow_ = { col: args.col, row: args.row } + + const exactExists = arr.some(item => + item.col === colRow_.col && item.row === colRow_.row + ); + + if (exactExists) { + return { + elements: [ + { + type: 'line', + elementKey: 'diagonal-line', + x: 0, + y: 0, + points: [ + { x: 0, y: 0 }, + { x: args.rect.width, y: args.rect.height } + ], + stroke: '#ff0000', + lineWidth: 2, + pickable: false, + cursor: 'default' + } + ], + renderDefault: true + } + } else { + return { + renderDefault: true + } + } + } + }) + + window.tableInstance.updateColumns(newColumns, { clearColWidthCache: true }); + } } function deleteDiagonal(startCol, startRow, endCol, endRow) {