From 6225334233a9f0067a3ff9703fb39aa27b749eb5 Mon Sep 17 00:00:00 2001 From: xuliangzhan Date: Fri, 20 Dec 2024 09:48:03 +0800 Subject: [PATCH] releases 3.11.36 --- package.json | 4 +- packages/table/module/edit/mixin.ts | 91 +++++++++++++++++---------- packages/table/module/export/mixin.ts | 44 +++++++------ packages/table/src/methods.ts | 2 +- styles/components/table.scss | 25 +------- 5 files changed, 88 insertions(+), 78 deletions(-) diff --git a/package.json b/package.json index 39d8861944..30af5a2fcb 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "vxe-table", - "version": "3.11.35", + "version": "3.11.36", "description": "一个基于 vue 的 PC 端表格组件,支持增删改查、虚拟树、拖拽排序,懒加载、快捷菜单、数据校验、树形结构、打印、导入导出、自定义模板、渲染器、JSON 配置式...", "scripts": { "update": "npm install --legacy-peer-deps", @@ -28,7 +28,7 @@ "style": "lib/style.css", "typings": "types/index.d.ts", "dependencies": { - "vxe-pc-ui": "^3.3.40" + "vxe-pc-ui": "^3.3.41" }, "devDependencies": { "@babel/plugin-transform-modules-commonjs": "^7.25.7", diff --git a/packages/table/module/edit/mixin.ts b/packages/table/module/edit/mixin.ts index a6585e6543..1228ef964b 100644 --- a/packages/table/module/edit/mixin.ts +++ b/packages/table/module/edit/mixin.ts @@ -48,8 +48,7 @@ function insertTreeRow (_vm: any, newRecords: any[], isAppend: any) { }) } -function handleInsertRowAt (_vm: any, records: any[], row: any, isInsertNextRow?: any) { - const $xeTable = _vm +function handleInsertRowAt ($xeTable: any, records: any[], targetRow: any, isInsertNextRow?: any) { const props = $xeTable const reactData = $xeTable const internalData = $xeTable @@ -63,11 +62,11 @@ function handleInsertRowAt (_vm: any, records: any[], row: any, isInsertNextRow? if (!XEUtils.isArray(records)) { records = [records] } - const newRecords: any[] = _vm.defineField(records.map(record => Object.assign(treeConfig && transform ? { [mapChildrenField]: [], [childrenField]: [] } : {}, record))) - if (XEUtils.eqNull(row)) { + const newRecords: any[] = $xeTable.defineField(records.map(record => Object.assign(treeConfig && transform ? { [mapChildrenField]: [], [childrenField]: [] } : {}, record))) + if (XEUtils.eqNull(targetRow)) { // 如果为虚拟树 if (treeConfig && transform) { - insertTreeRow(_vm, newRecords, false) + insertTreeRow($xeTable, newRecords, false) } else { newRecords.forEach(item => { const rowid = getRowid($xeTable, item) @@ -86,10 +85,10 @@ function handleInsertRowAt (_vm: any, records: any[], row: any, isInsertNextRow? }) } } else { - if (row === -1) { + if (targetRow === -1) { // 如果为虚拟树 if (treeConfig && transform) { - insertTreeRow(_vm, newRecords, true) + insertTreeRow($xeTable, newRecords, true) } else { newRecords.forEach(item => { const rowid = getRowid($xeTable, item) @@ -110,14 +109,14 @@ function handleInsertRowAt (_vm: any, records: any[], row: any, isInsertNextRow? } else { // 如果为虚拟树 if (treeConfig && transform) { - const matchMapObj = XEUtils.findTree(tableFullTreeData, (item: any) => row[rowField] === item[rowField], { children: mapChildrenField }) + const matchMapObj = XEUtils.findTree(tableFullTreeData, (item: any) => targetRow[rowField] === item[rowField], { children: mapChildrenField }) if (matchMapObj) { const { parent: parentRow } = matchMapObj as any const parentMapChilds = parentRow ? parentRow[mapChildrenField] : tableFullTreeData - const parentRest = fullAllDataRowIdData[getRowid(_vm, parentRow)] + const parentRest = fullAllDataRowIdData[getRowid($xeTable, parentRow)] const parentLevel = parentRest ? parentRest.level : 0 newRecords.forEach((item: any, i: any) => { - const rowid = getRowid(_vm, item) + const rowid = getRowid($xeTable, item) if (process.env.VUE_APP_VXE_ENV === 'development') { if (item[treeOpts.parentField]) { if (parentRow && item[treeOpts.parentField] !== parentRow[rowField]) { @@ -140,7 +139,7 @@ function handleInsertRowAt (_vm: any, records: any[], row: any, isInsertNextRow? // 源 if (parentRow) { - const matchObj = XEUtils.findTree(tableFullTreeData, (item: any) => row[rowField] === item[rowField], { children: childrenField }) + const matchObj = XEUtils.findTree(tableFullTreeData, (item: any) => targetRow[rowField] === item[rowField], { children: childrenField }) if (matchObj) { const parentChilds = matchObj.items let targetIndex = matchObj.index @@ -154,7 +153,7 @@ function handleInsertRowAt (_vm: any, records: any[], row: any, isInsertNextRow? if (process.env.VUE_APP_VXE_ENV === 'development') { warnLog('vxe.error.unableInsert') } - insertTreeRow(_vm, newRecords, true) + insertTreeRow($xeTable, newRecords, true) } } else { if (treeConfig) { @@ -162,12 +161,12 @@ function handleInsertRowAt (_vm: any, records: any[], row: any, isInsertNextRow? } let afIndex = -1 // 如果是可视索引 - if (XEUtils.isNumber(row)) { - if (row < afterFullData.length) { - afIndex = row + if (XEUtils.isNumber(targetRow)) { + if (targetRow < afterFullData.length) { + afIndex = targetRow } } else { - afIndex = _vm.findRowIndexOf(afterFullData, row) + afIndex = $xeTable.findRowIndexOf(afterFullData, targetRow) } // 如果是插入指定行的下一行 if (isInsertNextRow) { @@ -177,7 +176,7 @@ function handleInsertRowAt (_vm: any, records: any[], row: any, isInsertNextRow? throw new Error(errLog('vxe.error.unableInsert')) } afterFullData.splice(afIndex, 0, ...newRecords) - tableFullData.splice(_vm.findRowIndexOf(tableFullData, row), 0, ...newRecords) + tableFullData.splice($xeTable.findRowIndexOf(tableFullData, targetRow), 0, ...newRecords) // 刷新单元格合并 mergeList.forEach((mergeItem: any) => { const { row: mergeRowIndex, rowspan: mergeRowspan } = mergeItem @@ -195,20 +194,20 @@ function handleInsertRowAt (_vm: any, records: any[], row: any, isInsertNextRow? const rowid = getRowid($xeTable, newRow) insertMaps[rowid] = newRow }) - _vm.cacheRowMap() - _vm.updateScrollYStatus() - _vm.handleTableData(treeConfig && transform) + $xeTable.cacheRowMap() + $xeTable.updateScrollYStatus() + $xeTable.handleTableData(treeConfig && transform) if (!(treeConfig && transform)) { - _vm.updateAfterDataIndex() + $xeTable.updateAfterDataIndex() } - _vm.updateFooter() - _vm.checkSelectionStatus() - if (_vm.scrollYLoad) { - _vm.updateScrollYSpace() + $xeTable.updateFooter() + $xeTable.checkSelectionStatus() + if ($xeTable.scrollYLoad) { + $xeTable.updateScrollYSpace() } - return _vm.$nextTick().then(() => { - _vm.updateCellAreas() - return _vm.recalculate() + return $xeTable.$nextTick().then(() => { + $xeTable.updateCellAreas() + return $xeTable.recalculate() }).then(() => { return { row: newRecords.length ? newRecords[newRecords.length - 1] : null, @@ -217,6 +216,23 @@ function handleInsertRowAt (_vm: any, records: any[], row: any, isInsertNextRow? }) } +function handleInsertChildRowAt ($xeTable: any, records: any, parentRow: any, targetRow: any, isInsertNextRow?: boolean) { + const props = $xeTable + + const { treeConfig } = props + const treeOpts = $xeTable.computeTreeOpts + const { transform, rowField, parentField } = treeOpts + if (treeConfig && transform) { + if (!XEUtils.isArray(records)) { + records = [records] + } + return handleInsertRowAt($xeTable, records.map((item: any) => Object.assign({}, item, { [parentField]: parentRow[rowField] })), targetRow, isInsertNextRow) + } else { + errLog('vxe.error.errProp', ['tree-config.treeConfig=false', 'tree-config.treeConfig=true']) + } + return Promise.resolve({ row: null, rows: [] }) +} + export default { methods: { /** @@ -233,14 +249,23 @@ export default { * 如果 row 为 -1 则从插入到底部 * 如果 row 为有效行则插入到该行的位置 * @param {Object/Array} records 新的数据 - * @param {Row} row 指定行 + * @param {Row} targetRow 指定行 * @returns */ - _insertAt (records: any, row: any) { - return handleInsertRowAt(this, records, row) + _insertAt (records: any, targetRow: any) { + return handleInsertRowAt(this, records, targetRow) + }, + _insertNextAt (records: any, targetRow: any) { + return handleInsertRowAt(this, records, targetRow, true) + }, + _insertChild (records: any, parentRow: any) { + return handleInsertChildRowAt(this, records, parentRow, null) + }, + _insertChildAt (records: any, parentRow: any, targetRow: any) { + return handleInsertChildRowAt(this, records, parentRow, targetRow) }, - _insertNextAt (records: any, row: any) { - return handleInsertRowAt(this, records, row, true) + _insertChildNextAt (records: any, parentRow: any, targetRow: any) { + return handleInsertChildRowAt(this, records, parentRow, targetRow, true) }, /** * 删除指定行数据 diff --git a/packages/table/module/export/mixin.ts b/packages/table/module/export/mixin.ts index 18201b738a..358e82adba 100644 --- a/packages/table/module/export/mixin.ts +++ b/packages/table/module/export/mixin.ts @@ -1,7 +1,7 @@ import XEUtils from 'xe-utils' import { VxeUI } from '../../../ui' import { isColumnInfo, mergeBodyMethod, getCellValue } from '../../src/util' -import { parseFile, formatText } from '../../../ui/src/utils' +import { parseFile, formatText, eqEmptyValue } from '../../../ui/src/utils' import { browse } from '../../../ui/src/dom' import { createHtmlPage, getExportBlobByContent } from './util' import { warnLog, errLog } from '../../../ui/src/log' @@ -66,9 +66,13 @@ function toBooleanValue (cellValue: any) { return XEUtils.isBoolean(cellValue) ? (cellValue ? 'TRUE' : 'FALSE') : cellValue } -function getBodyLabelData ($xetable: any, opts: any, columns: any[], datas: any[]) { +const toStringValue = (cellValue: any) => { + return eqEmptyValue(cellValue) ? '' : `${cellValue}` +} + +function getBodyLabelData ($xeTable: any, opts: any, columns: any[], datas: any[]) { const { isAllExpand, mode } = opts - const { treeConfig, treeOpts, radioOpts, checkboxOpts, columnOpts } = $xetable + const { treeConfig, treeOpts, radioOpts, checkboxOpts, columnOpts } = $xeTable const childrenField = treeOpts.children || treeOpts.childrenField if (!htmlCellElem) { htmlCellElem = document.createElement('div') @@ -80,13 +84,13 @@ function getBodyLabelData ($xetable: any, opts: any, columns: any[], datas: any[ XEUtils.eachTree(datas, (item, $rowIndex, items, path, parent, nodes) => { const row = item._row || item const parentRow = parent && parent._row ? parent._row : parent - if ((isAllExpand || !parentRow || (expandMaps.has(parentRow) && $xetable.isTreeExpandByRow(parentRow)))) { - const hasRowChild = hasTreeChildren($xetable, row) + if ((isAllExpand || !parentRow || (expandMaps.has(parentRow) && $xeTable.isTreeExpandByRow(parentRow)))) { + const hasRowChild = hasTreeChildren($xeTable, row) const item: any = { _row: row, _level: nodes.length - 1, _hasChild: hasRowChild, - _expand: hasRowChild && $xetable.isTreeExpandByRow(row) + _expand: hasRowChild && $xeTable.isTreeExpandByRow(row) } columns.forEach((column, $columnIndex) => { let cellValue = '' @@ -102,21 +106,21 @@ function getBodyLabelData ($xetable: any, opts: any, columns: any[], datas: any[ bodyExportMethod = columnOpts.exportMethod } if (bodyExportMethod) { - cellValue = bodyExportMethod({ $table: $xetable, row, column, options: opts }) + cellValue = bodyExportMethod({ $table: $xeTable, row, column, options: opts }) } else { switch (column.type) { case 'seq': { const seqValue = path.map((num, i) => i % 2 === 0 ? (Number(num) + 1) : '.').join('') - cellValue = mode === 'all' ? seqValue : getSeq($xetable, seqValue, row, $rowIndex, column, $columnIndex) + cellValue = mode === 'all' ? seqValue : getSeq($xeTable, seqValue, row, $rowIndex, column, $columnIndex) break } case 'checkbox': - cellValue = toBooleanValue($xetable.isCheckedByCheckboxRow(row)) + cellValue = toBooleanValue($xeTable.isCheckedByCheckboxRow(row)) item._checkboxLabel = checkboxOpts.labelField ? XEUtils.get(row, checkboxOpts.labelField) : '' item._checkboxDisabled = checkboxOpts.checkMethod && !checkboxOpts.checkMethod({ row }) break case 'radio': - cellValue = toBooleanValue($xetable.isCheckedByRadioRow(row)) + cellValue = toBooleanValue($xeTable.isCheckedByRadioRow(row)) item._radioLabel = radioOpts.labelField ? XEUtils.get(row, radioOpts.labelField) : '' item._radioDisabled = radioOpts.checkMethod && !radioOpts.checkMethod({ row }) break @@ -124,12 +128,12 @@ function getBodyLabelData ($xetable: any, opts: any, columns: any[], datas: any[ if (opts.original) { cellValue = getCellValue(row, column) } else { - cellValue = $xetable.getCellLabel(row, column) + cellValue = $xeTable.getCellLabel(row, column) if (column.type === 'html') { htmlCellElem.innerHTML = cellValue cellValue = htmlCellElem.innerText.trim() } else { - const cell = $xetable.getCellElement(row, column) + const cell = $xeTable.getCellElement(row, column) if (cell) { cellValue = cell.innerText.trim() } @@ -137,7 +141,7 @@ function getBodyLabelData ($xetable: any, opts: any, columns: any[], datas: any[ } } } - item[column.id] = XEUtils.toValueString(cellValue) + item[column.id] = toStringValue(cellValue) }) expandMaps.set(row, 1) rest.push(Object.assign(item, row)) @@ -163,21 +167,21 @@ function getBodyLabelData ($xetable: any, opts: any, columns: any[], datas: any[ bodyExportMethod = columnOpts.exportMethod } if (bodyExportMethod) { - cellValue = bodyExportMethod({ $table: $xetable, row, column, options: opts }) + cellValue = bodyExportMethod({ $table: $xeTable, row, column, options: opts }) } else { switch (column.type) { case 'seq': { const seqValue = $rowIndex + 1 - cellValue = mode === 'all' ? seqValue : getSeq($xetable, seqValue, row, $rowIndex, column, $columnIndex) + cellValue = mode === 'all' ? seqValue : getSeq($xeTable, seqValue, row, $rowIndex, column, $columnIndex) break } case 'checkbox': - cellValue = toBooleanValue($xetable.isCheckedByCheckboxRow(row)) + cellValue = toBooleanValue($xeTable.isCheckedByCheckboxRow(row)) item._checkboxLabel = checkboxOpts.labelField ? XEUtils.get(row, checkboxOpts.labelField) : '' item._checkboxDisabled = checkboxOpts.checkMethod && !checkboxOpts.checkMethod({ row }) break case 'radio': - cellValue = toBooleanValue($xetable.isCheckedByRadioRow(row)) + cellValue = toBooleanValue($xeTable.isCheckedByRadioRow(row)) item._radioLabel = radioOpts.labelField ? XEUtils.get(row, radioOpts.labelField) : '' item._radioDisabled = radioOpts.checkMethod && !radioOpts.checkMethod({ row }) break @@ -185,12 +189,12 @@ function getBodyLabelData ($xetable: any, opts: any, columns: any[], datas: any[ if (opts.original) { cellValue = getCellValue(row, column) } else { - cellValue = $xetable.getCellLabel(row, column) + cellValue = $xeTable.getCellLabel(row, column) if (column.type === 'html') { htmlCellElem.innerHTML = cellValue cellValue = htmlCellElem.innerText.trim() } else { - const cell = $xetable.getCellElement(row, column) + const cell = $xeTable.getCellElement(row, column) if (cell) { cellValue = cell.innerText.trim() } @@ -198,7 +202,7 @@ function getBodyLabelData ($xetable: any, opts: any, columns: any[], datas: any[ } } } - item[column.id] = XEUtils.toValueString(cellValue) + item[column.id] = toStringValue(cellValue) }) return item }) diff --git a/packages/table/src/methods.ts b/packages/table/src/methods.ts index e3d245689d..7d7132794a 100644 --- a/packages/table/src/methods.ts +++ b/packages/table/src/methods.ts @@ -7442,7 +7442,7 @@ const Methods = { } as any // Module methods -const funcs = 'setFilter,openFilter,clearFilter,saveFilterPanel,resetFilterPanel,getCheckedFilters,updateFilterOptionStatus,closeMenu,setActiveCellArea,getActiveCellArea,getCellAreas,clearCellAreas,copyCellArea,cutCellArea,pasteCellArea,getCopyCellArea,getCopyCellAreas,clearCopyCellArea,setCellAreas,openFNR,openFind,openReplace,closeFNR,getSelectedCell,clearSelected,insert,insertAt,insertNextAt,remove,removeCheckboxRow,removeRadioRow,removeCurrentRow,getRecordset,getInsertRecords,getRemoveRecords,getUpdateRecords,clearEdit,clearActived,getEditRecord,getActiveRecord,isEditByRow,isActiveByRow,setEditRow,setActiveRow,setEditCell,setActiveCell,setSelectCell,clearValidate,fullValidate,validate,fullValidateField,validateField,openExport,closeExport,openPrint,closePrint,getPrintHtml,exportData,openImport,closeImport,importData,saveFile,readFile,importByFile,print,openCustom,closeCustom,saveCustom,cancelCustom,resetCustom,toggleCustomAllCheckbox,setCustomAllCheckbox'.split(',') +const funcs = 'setFilter,openFilter,clearFilter,saveFilterPanel,resetFilterPanel,getCheckedFilters,updateFilterOptionStatus,closeMenu,setActiveCellArea,getActiveCellArea,getCellAreas,clearCellAreas,copyCellArea,cutCellArea,pasteCellArea,getCopyCellArea,getCopyCellAreas,clearCopyCellArea,setCellAreas,openFNR,openFind,openReplace,closeFNR,getSelectedCell,clearSelected,insert,insertAt,insertNextAt,insertChild,insertChildAt,insertChildNextAt,remove,removeCheckboxRow,removeRadioRow,removeCurrentRow,getRecordset,getInsertRecords,getRemoveRecords,getUpdateRecords,clearEdit,clearActived,getEditRecord,getActiveRecord,isEditByRow,isActiveByRow,setEditRow,setActiveRow,setEditCell,setActiveCell,setSelectCell,clearValidate,fullValidate,validate,fullValidateField,validateField,openExport,closeExport,openPrint,closePrint,getPrintHtml,exportData,openImport,closeImport,importData,saveFile,readFile,importByFile,print,openCustom,closeCustom,saveCustom,cancelCustom,resetCustom,toggleCustomAllCheckbox,setCustomAllCheckbox'.split(',') funcs.forEach(name => { Methods[name] = function (...args: any[]) { diff --git a/styles/components/table.scss b/styles/components/table.scss index 02e6147c65..56f72d10fb 100644 --- a/styles/components/table.scss +++ b/styles/components/table.scss @@ -78,17 +78,6 @@ .vxe-ico-picker { width: 100%; } - .vxe-cell--tree-node { - .vxe-input, - .vxe-textarea, - .vxe-select, - .vxe-tree-select, - .vxe-date-picker, - .vxe-number-input, - .vxe-ico-picker { - width: 100%; - } - } } } } @@ -110,6 +99,9 @@ width: 100%; } & > .vxe-cell--tree-node { + .vxe-default-input, + .vxe-default-textarea, + .vxe-default-select, .vxe-input, .vxe-textarea, .vxe-select, @@ -138,17 +130,6 @@ & > .vxe-ico-picker { width: 100%; } - & > .vxe-cell--tree-node { - .vxe-input, - .vxe-textarea, - .vxe-select, - .vxe-tree-select, - .vxe-date-picker, - .vxe-number-input, - .vxe-ico-picker { - width: 100%; - } - } } .vxe-cell, .vxe-table--filter-template {