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 27bfaf1eb0116c983a53698b7368e4f1aa45ed77..29f46c716f162f25df82a7d39a83de5b92bc8e8d 100644 --- a/library/src/main/resources/rawfile/vtable_util.js +++ b/library/src/main/resources/rawfile/vtable_util.js @@ -123,6 +123,7 @@ function frozenRow(index) { return; } window.tableInstance.frozenRowCount = index; + renderWithRecreateCells() } // 合并指定范围的单元格 @@ -137,13 +138,23 @@ function mergeCell(startCol, startRow, endCol, endRow) { } 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); } @@ -158,27 +169,32 @@ 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)) + 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); // } @@ -270,10 +286,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( @@ -285,6 +299,9 @@ function initializeTable(option) { }); }) window.tableInstance = tableInstance; + + const height = tableInstance.getRowHeight(1) + tableInstance.setRowHeight(1, height) } // 滚动到行 @@ -439,19 +456,19 @@ 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) { newColumns.map((item) => { item.customRender = (args) => { @@ -487,7 +504,6 @@ function setDiagonal(startCol, startRow, endCol, endRow) { } } } - }) window.tableInstance.updateColumns(newColumns, { clearColWidthCache: true });