From bcc599054e94954e25c4af312ec08dfb4a5a759e Mon Sep 17 00:00:00 2001 From: Miosas Date: Mon, 5 Jan 2026 15:57:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=9B=91=E5=90=AC=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/rawfile/vtable_util.js | 122 +++++------------- 1 file changed, 31 insertions(+), 91 deletions(-) diff --git a/library/src/main/resources/rawfile/vtable_util.js b/library/src/main/resources/rawfile/vtable_util.js index c5ce163..f4603a0 100644 --- a/library/src/main/resources/rawfile/vtable_util.js +++ b/library/src/main/resources/rawfile/vtable_util.js @@ -27,7 +27,6 @@ var eventList = [ 'CHANGE_CELL_VALUE' ] -// 提取 CellClickData 需要的字段 function extractCellClickData(data) { if (!data) return null; @@ -53,95 +52,29 @@ function extractCellClickData(data) { }; } -// 提取 CellSelectionData 需要的字段 -function extractCellSelectionData(data) { - if (!data) return { ranges: [] }; - - const result = { ranges: [] }; - - if (data.ranges && Array.isArray(data.ranges) && data.ranges.length > 0) { - const range = data.ranges[0]; - result.ranges = [{ - start: { - col: range.start?.col || 0, - row: range.start?.row || 0 - }, - end: { - col: range.end?.col || 0, - row: range.end?.row || 0 - } - }]; - } - - return result; -} - -// 提取 ScrollEventData 需要的字段 -function extractScrollData(data) { - if (!data) return null; - - return { - scrollTop: data.scrollTop || 0, - scrollLeft: data.scrollLeft || 0, - scrollWidth: data.scrollWidth || 0, - scrollHeight: data.scrollHeight || 0 - }; -} - -// 提取 CellChangeEvent 需要的字段 -function extractCellChangeData(data) { - if (!data) return null; - - return { - col: data.col || 0, - row: data.row || 0, - field: data.field || '', - value: String(data.value || ''), - dataValue: String(data.dataValue || ''), - oldValue: String(data.oldValue || ''), - oldDataValue: String(data.oldDataValue || '') - }; -} - var eventCallback = (type, data) => { let filteredData = null; - // 根据事件类型提取需要的字段 switch (type) { - case "SELECTED_CHANGED": - filteredData = extractCellSelectionData(data); - break; - case "CLICK_CELL": case "DBLCLICK_CELL": filteredData = extractCellClickData(data); break; - case "SCROLL": - filteredData = extractScrollData(data); - break; - + case "SELECTED_CHANGED": case "CHANGE_CELL_VALUE": - filteredData = extractCellChangeData(data); + case "SCROLL_VERTICAL_END": + case "SCROLL_HORIZONTAL_END": + case "SCROLL": + filteredData = data break; case "UPDATED": - case "INITIALIZED": - filteredData = {}; - break; - case "SELECTED_CLEAR": + case "INITIALIZED": filteredData = {}; break; - case "SCROLL_VERTICAL_END": - filteredData = data - break; - - case "SCROLL_HORIZONTAL_END": - filteredData = data - break; - default: console.warn(`Unknown event type: ${type}`); return; @@ -189,9 +122,9 @@ function mergeCell(startCol, startRow, endCol, endRow) { return; } 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)) + 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++) { window.tableInstance.changeCellValue(i, j, cellnumber); @@ -206,12 +139,12 @@ function unmergeCells(startCol, startRow, endCol, endRow) { console.error('表格实例未找到'); return; } - const cellnumber = window.tableInstance.getCellValue(startCol, startRow,true); + const cellnumber = window.tableInstance.getCellValue(startCol, startRow, true); for (let i = startCol; i <= endCol; i++) { for (let j = startRow; j <= endRow; j++) { if (i === startCol && j === startRow) { - window.tableInstance.changeCellValue(i, j, cellnumber); - }else{ + window.tableInstance.changeCellValue(i, j, cellnumber); + } else { window.tableInstance.changeCellValue(i, j, ''); } } @@ -223,7 +156,7 @@ function unmergeCells(startCol, startRow, endCol, endRow) { function customRender(startCol, startRow, endCol, endRow, id, style) { const newcolumn = { ...optionTemp.columns[2], - + } // const aa = window.tableInstance.getCustomCellStyle(startCol, startRow) console.log("=====> customRender", JSON.stringify(optionTemp.columns[2])) @@ -253,20 +186,20 @@ function customRender(startCol, startRow, endCol, endRow, id, style) { function customRenderRestore(startCol, startRow, endCol, endRow) { const style = window.tableInstance.theme.style - window.tableInstance.registerCustomCellStyle('none',style) + window.tableInstance.registerCustomCellStyle('none', style) const pos = { - range:{ - start:{ + range: { + start: { col: startCol, row: startRow }, - end:{ + end: { col: endCol, row: endRow } } } - window.tableInstance.arrangeCustomCellStyle(pos,'none') + window.tableInstance.arrangeCustomCellStyle(pos, 'none') } var optionTemp function customIcon() { @@ -299,7 +232,7 @@ 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)) + 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) => { @@ -307,6 +240,9 @@ function initializeTable(option) { }); }) window.tableInstance = tableInstance; + + + // window.tableInstance.scaleTo(2,2) } // 滚动到行 @@ -342,11 +278,11 @@ function updateColumns(newColumns) { // 设置分割线颜色 function setSplitLineColor(colors) { const currentTheme = window.tableInstance.theme.extends({ - headerStyle:{ - borderColor:colors + headerStyle: { + borderColor: colors }, - bodyStyle:{ - borderColor:colors + bodyStyle: { + borderColor: colors } }); window.tableInstance.updateTheme(currentTheme); @@ -400,6 +336,10 @@ function updateOption(options) { window.tableInstance.updateOption(options); } -function renderWithRecreateCells(){ +function renderWithRecreateCells() { window.tableInstance.renderWithRecreateCells(); +} + +function setZoom() { + } \ No newline at end of file -- Gitee