diff --git a/entry/src/main/ets/pages/Index.ets b/entry/src/main/ets/pages/Index.ets index 7ce3bd8eebd36039111ececb19fc237230a8721a..947d7a5da15b1e000075ea6e4c49cf26978b19f9 100644 --- a/entry/src/main/ets/pages/Index.ets +++ b/entry/src/main/ets/pages/Index.ets @@ -18,7 +18,6 @@ struct Index { { "field": "A", "title": "工号", - "cellType": "text", "width": "auto", "editor": "input-editor" }, @@ -101,7 +100,7 @@ struct Index { "columnResizeMode": "none", "rowResizeMode": "none" }, - "heightMode":"autoHeight" + "heightMode": "autoHeight" } imageRecords: Record[] = [ { @@ -382,7 +381,6 @@ struct Index { onChangeCellValue(event: CellChangeEvent) { - if (this.floatingWindowType !== 5) { return; } @@ -517,7 +515,7 @@ struct Index { right: 10 }) .backgroundColor(Color.Gray) - .onClick(()=>{ + .onClick(() => { this.vTableController.setZoom(true) }) @@ -536,7 +534,7 @@ struct Index { right: 5 }) .backgroundColor(Color.Gray) - .onClick(()=>{ + .onClick(() => { this.vTableController.setZoom(false) }) } @@ -619,8 +617,26 @@ struct Index { .backgroundColor('#70949292') .fontColor(Color.Black) .onClick(() => { - this.vTableController.cancelCustomRender(this.mergeCellParams[0], this.mergeCellParams[1], - this.mergeCellParams[2], this.mergeCellParams[3]) + this.vTableController.cancelCustomRender( + Math.min(this.mergeCellParams[0], this.mergeCellParams[2]), + Math.min(this.mergeCellParams[1], this.mergeCellParams[3]), + Math.max(this.mergeCellParams[0], this.mergeCellParams[2]), + Math.max(this.mergeCellParams[1], this.mergeCellParams[3]) + ) + }) + Button('aaa') + .borderRadius(0) + .backgroundColor('#70949292') + .fontColor(Color.Black) + .onClick(() => { + this.vTableController.setDiagonal(this.mergeCellParams[0], this.mergeCellParams[1]) + }) + Button('bbb') + .borderRadius(0) + .backgroundColor('#70949292') + .fontColor(Color.Black) + .onClick(() => { + this.vTableController.deleteDiagonal(this.mergeCellParams[0], this.mergeCellParams[1]) }) } } diff --git a/library/src/main/ets/util/VTableController.ets b/library/src/main/ets/util/VTableController.ets index 907bde515c4ebd5c680892576a172d239fc3a0aa..7c0aa1a9aaca9499b08c0bb103fe0d650eaac7d4 100644 --- a/library/src/main/ets/util/VTableController.ets +++ b/library/src/main/ets/util/VTableController.ets @@ -262,15 +262,25 @@ export class VTableController { }) } - // clearSelected() { - // if (!this.checkInitialized()) { - // return; - // } - // this.controller!.runJavaScript(`clearSelected()`) - // .catch((error: Error) => { - // console.error("Error clearSelected:", error); - // }) - // } + setDiagonal(row: number, col: number) { + if (!this.checkInitialized()) { + return; + } + this.controller!.runJavaScript(`setDiagonal(${row},${col})`) + .catch((error: Error) => { + console.error("Error setDiagonal:", error); + }) + } + + deleteDiagonal(row: number, col: number) { + if (!this.checkInitialized()) { + return; + } + this.controller!.runJavaScript(`deleteDiagonal(${row},${col})`) + .catch((error: Error) => { + console.error("Error deleteDiagonal:", error); + }) + } renderWithRecreateCells() { if (!this.checkInitialized()) { @@ -298,6 +308,7 @@ export class VTableController { } } + release() { if (!this.checkInitialized()) { return; diff --git a/library/src/main/resources/rawfile/vtable_util.js b/library/src/main/resources/rawfile/vtable_util.js index d0dfc3871846979ac5862e8dd96dacacf10c798c..8ab74340e9d9065a59410703bf81b9bcf2bcf735 100644 --- a/library/src/main/resources/rawfile/vtable_util.js +++ b/library/src/main/resources/rawfile/vtable_util.js @@ -123,9 +123,7 @@ function mergeCell(startCol, startRow, endCol, endRow) { return; } console.log("=====> unmergeCells", JSON.stringify(window.tableInstance.editorManager.editingEditor)) - const cellrecord = window.tableInstance.getRecordByCell(startCol, startRow); const cellnumber = window.tableInstance.getCellValue(startCol, startRow, true); - console.log("=====> mergeCell", JSON.stringify(cellrecord)) console.log("=====> mergeCell", JSON.stringify(cellnumber)) for (let i = startCol; i <= endCol; i++) { for (let j = startRow; j <= endRow; j++) { @@ -234,7 +232,6 @@ function initializeTable(option) { const input_editor = new VTable.editors.InputEditor(); VTable.register.editor('input-editor', input_editor); - console.log("=====> initializeTable", JSON.stringify(option.theme.frozenColumnLine)) const tableInstance = new VTable.ListTable(document.getElementById('tableContainer'), option); eventList.forEach(eventName => { tableInstance.on(VTable.ListTable.EVENT_TYPE[eventName], (event) => { @@ -242,9 +239,6 @@ function initializeTable(option) { }); }) window.tableInstance = tableInstance; - - - // window.tableInstance.scaleTo(2,2) } // 滚动到行 @@ -394,4 +388,60 @@ function zoomOut() { } } window.tableInstance.updateColumns(newColums); +} + +var arr = [] + +function setDiagonal(col_, row_) { + const newColumns = window.tableInstance.options.columns; + + arr.push({ col: col_, row: row_ }) + + newColumns.map((item, index) => { + if (index == col_) { + 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(col_, row_) { + const index = arr.findIndex(item => item.col === col_ && item.row === row_); + if (index !== -1) { + arr.splice(index, 1); + } + renderWithRecreateCells(); } \ No newline at end of file