1
0
mirror of synced 2025-11-06 11:20:40 +08:00

修复树表格获取修改状态失效问题 #2159

This commit is contained in:
xuliangzhan
2023-08-25 23:38:54 +08:00
parent 602405278f
commit bafbac848d
9 changed files with 44 additions and 31 deletions

View File

@@ -12,7 +12,7 @@
[![pull requests closed](https://img.shields.io/github/issues-pr-closed/x-extends/vxe-table.svg)](https://github.com/x-extends/vxe-table/pulls?q=is%3Apr+is%3Aclosed)
[![npm license](https://img.shields.io/github/license/mashape/apistatus.svg)](LICENSE)
A [vue](https://www.npmjs.com/package/vue) based PC form component, support add, delete, change, virtual list, virtual tree, lazy load, shortcut menu, data validation, print export, form rendering, data paging, modal window, custom template, renderer, JSON configuration designed for zero code...
A [vue](https://www.npmjs.com/package/vue) based PC form component, support add, delete, change, virtual list, virtual tree, lazy load, shortcut menu, data validation, print export, form rendering, data paging, modal window, custom template, renderer, JSON configuration...
* Design concept
* Efficient and concise API design for modern browsers.

View File

@@ -12,7 +12,7 @@
[![pull requests closed](https://img.shields.io/github/issues-pr-closed/x-extends/vxe-table.svg)](https://github.com/x-extends/vxe-table/pulls?q=is%3Apr+is%3Aclosed)
[![npm license](https://img.shields.io/github/license/mashape/apistatus.svg)](LICENSE)
一个基于 [vue](https://www.npmjs.com/package/vue) 的 PC 端表单/表格组件支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器、JSON 配置式为零代码而设计...
一个基于 [vue](https://www.npmjs.com/package/vue) 的 PC 端表单/表格组件支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器、JSON 配置式...
* 设计理念
* 面向现代浏览器,高效的简洁 API 设计

View File

@@ -12,7 +12,7 @@
[![pull requests closed](https://img.shields.io/github/issues-pr-closed/x-extends/vxe-table.svg)](https://github.com/x-extends/vxe-table/pulls?q=is%3Apr+is%3Aclosed)
[![npm license](https://img.shields.io/github/license/mashape/apistatus.svg)](LICENSE)
一個基於 [vue](https://www.npmjs.com/package/vue) 的PC端表格組件支持增删改查、虛擬清單、虛擬樹、懶加載、快捷選單、數據校驗、列印匯出、表單渲染、數據分頁、彈窗、自定義範本、渲染器、JSON 配置式爲零代碼而設計
一個基於 [vue](https://www.npmjs.com/package/vue) 的PC端表格組件支持增删改查、虛擬清單、虛擬樹、懶加載、快捷選單、數據校驗、列印匯出、表單渲染、數據分頁、彈窗、自定義範本、渲染器、JSON 配置式…
* 設計理念
* 面向現代瀏覽器,高效的簡潔 API 設計

View File

@@ -28,7 +28,7 @@
"style": "lib/style.css",
"typings": "types/index.d.ts",
"dependencies": {
"dom-zindex": "^0.4.0"
"dom-zindex": "^0.5.0"
},
"devDependencies": {
"@types/resize-observer-browser": "^0.1.7",

View File

@@ -330,6 +330,7 @@ const tableExportHook: VxeGlobalHooksHandles.HookOptions = {
htmlCellElem = document.createElement('div')
}
if (treeConfig) {
const childrenField = treeOpts.children || treeOpts.childrenField
// 如果是树表格只允许导出数据源
const rest: any[] = []
const expandMaps: Map<any, number> = new Map()
@@ -396,7 +397,7 @@ const tableExportHook: VxeGlobalHooksHandles.HookOptions = {
expandMaps.set(row, 1)
rest.push(Object.assign(item, row))
}
}, treeOpts)
}, { children: childrenField })
return rest
}
return datas.map((row, $rowIndex) => {

View File

@@ -295,11 +295,12 @@ const tableKeyboardHook: VxeGlobalHooksHandles.HookOptions = {
const { currentRow } = reactData
const { afterFullData } = internalData
const treeOpts = computeTreeOpts.value
const childrenField = treeOpts.children || treeOpts.childrenField
let targetRow
evnt.preventDefault()
if (currentRow) {
if (treeConfig) {
const { index, items } = XEUtils.findTree(afterFullData, item => item === currentRow, treeOpts)
const { index, items } = XEUtils.findTree(afterFullData, item => item === currentRow, { children: childrenField })
if (isUpArrow && index > 0) {
targetRow = items[index - 1]
} else if (isDwArrow && index < items.length - 1) {

View File

@@ -1281,7 +1281,7 @@ export default defineComponent({
fullDataRowIdData[rowid] = rest
}
fullMaps[rowid] = row
}, { children: treeOpts.transform ? treeOpts.mapChildrenField : (childrenField) })
}, { children: treeOpts.transform ? treeOpts.mapChildrenField : childrenField })
} else {
afterFullData.forEach((row, index) => {
const rowid = getRowid($xetable, row)
@@ -1854,6 +1854,7 @@ export default defineComponent({
const { selectCheckboxMaps } = reactData
const { afterFullData, afterFullRowMaps, checkboxReserveRowMap } = internalData
const treeOpts = computeTreeOpts.value
const childrenField = treeOpts.children || treeOpts.childrenField
const checkboxOpts = computeCheckboxOpts.value
const { checkField, reserve, checkStrictly, checkMethod } = checkboxOpts
const indeterminateField = checkboxOpts.indeterminateField || checkboxOpts.halfField
@@ -1891,7 +1892,7 @@ export default defineComponent({
// 如果存在选中方法
// 如果方法成立,则更新值,否则忽略该数据
if (treeConfig) {
XEUtils.eachTree(afterFullData, checkValFn, treeOpts)
XEUtils.eachTree(afterFullData, checkValFn, { children: childrenField })
} else {
afterFullData.forEach(checkValFn)
}
@@ -1910,7 +1911,7 @@ export default defineComponent({
if (isForce || (!checkMethod || checkMethod({ row }))) {
selectRowMaps[getRowid($xetable, row)] = row
}
}, treeOpts)
}, { children: childrenField })
} else {
/**
* 如果是树取消
@@ -1922,7 +1923,7 @@ export default defineComponent({
if (checkMethod({ row }) ? 0 : selectCheckboxMaps[rowid]) {
selectRowMaps[rowid] = row
}
}, treeOpts)
}, { children: childrenField })
}
}
} else {
@@ -2029,13 +2030,14 @@ export default defineComponent({
const { tableFullData } = internalData
const treeOpts = computeTreeOpts.value
const { expandAll, expandRowKeys } = treeOpts
const childrenField = treeOpts.children || treeOpts.childrenField
if (expandAll) {
tableMethods.setAllTreeExpand(true)
} else if (expandRowKeys) {
const defExpandeds: any[] = []
const rowkey = getRowkey($xetable)
expandRowKeys.forEach((rowid: any) => {
const matchObj = XEUtils.findTree(tableFullData, item => rowid === XEUtils.get(item, rowkey), treeOpts)
const matchObj = XEUtils.findTree(tableFullData, item => rowid === XEUtils.get(item, rowkey), { children: childrenField })
if (matchObj) {
defExpandeds.push(matchObj.item)
}
@@ -2557,7 +2559,7 @@ export default defineComponent({
if (accordion) {
validRows = validRows.length ? [validRows[validRows.length - 1]] : []
// 同一级只能展开一个
const matchObj = XEUtils.findTree(tableFullData, item => item === validRows[0], treeOpts)
const matchObj = XEUtils.findTree(tableFullData, item => item === validRows[0], { children: childrenField })
if (matchObj) {
matchObj.items.forEach(item => {
const rowid = getRowid($xetable, item)
@@ -2803,7 +2805,7 @@ export default defineComponent({
return tableMethods.createData(childRecords).then((rows) => {
if (keepSource) {
const rowid = getRowid($xetable, row)
const matchObj = XEUtils.findTree(tableSourceData, (item) => rowid === getRowid($xetable, item), treeOpts)
const matchObj = XEUtils.findTree(tableSourceData, (item) => rowid === getRowid($xetable, item), { children: childrenField })
if (matchObj) {
matchObj.item[childrenField] = XEUtils.clone(rows, true)
}
@@ -2813,7 +2815,7 @@ export default defineComponent({
const rest = { row: childRow, rowid, seq: -1, index, _index: -1, $index: -1, items, parent, level: parentLevel + nodes.length }
fullDataRowIdData[rowid] = rest
fullAllDataRowIdData[rowid] = rest
}, treeOpts)
}, { children: childrenField })
row[childrenField] = rows
if (transform) {
row[mapChildrenField] = rows
@@ -3462,6 +3464,7 @@ export default defineComponent({
const { fullDataRowIdData, radioReserveRow, afterFullData } = internalData
const radioOpts = computeRadioOpts.value
const treeOpts = computeTreeOpts.value
const childrenField = treeOpts.children || treeOpts.childrenField
if (radioOpts.reserve && radioReserveRow) {
const rowid = getRowid($xetable, radioReserveRow)
if (isFull) {
@@ -3471,7 +3474,7 @@ export default defineComponent({
} else {
const rowkey = getRowkey($xetable)
if (treeConfig) {
const matchObj = XEUtils.findTree(afterFullData, row => rowid === XEUtils.get(row, rowkey), treeOpts)
const matchObj = XEUtils.findTree(afterFullData, row => rowid === XEUtils.get(row, rowkey), { children: childrenField })
if (matchObj) {
return radioReserveRow
}
@@ -3496,13 +3499,14 @@ export default defineComponent({
const { afterFullData, fullDataRowIdData, checkboxReserveRowMap } = internalData
const checkboxOpts = computeCheckboxOpts.value
const treeOpts = computeTreeOpts.value
const childrenField = treeOpts.children || treeOpts.childrenField
const reserveSelection: any[] = []
if (checkboxOpts.reserve) {
const afterFullIdMaps: { [key: string]: number } = {}
if (treeConfig) {
XEUtils.eachTree(afterFullData, row => {
afterFullIdMaps[getRowid($xetable, row)] = 1
}, treeOpts)
}, { children: childrenField })
} else {
afterFullData.forEach(row => {
afterFullIdMaps[getRowid($xetable, row)] = 1
@@ -3543,6 +3547,7 @@ export default defineComponent({
const { treeConfig } = props
const { tableFullData } = internalData
const treeOpts = computeTreeOpts.value
const childrenField = treeOpts.children || treeOpts.childrenField
const checkboxOpts = computeCheckboxOpts.value
const { checkField, reserve } = checkboxOpts
const indeterminateField = checkboxOpts.indeterminateField || checkboxOpts.halfField
@@ -3554,7 +3559,7 @@ export default defineComponent({
XEUtils.set(item, checkField, false)
}
if (treeConfig) {
XEUtils.eachTree(tableFullData, handleClearChecked, treeOpts)
XEUtils.eachTree(tableFullData, handleClearChecked, { children: childrenField })
} else {
tableFullData.forEach(handleClearChecked)
}
@@ -3840,11 +3845,12 @@ export default defineComponent({
setAllRowExpand (expanded) {
const treeOpts = computeTreeOpts.value
const { tableFullData, tableFullTreeData } = internalData
const childrenField = treeOpts.children || treeOpts.childrenField
let expandedRows: any[] = []
if (props.treeConfig) {
XEUtils.eachTree(tableFullTreeData, (row) => {
expandedRows.push(row)
}, treeOpts)
}, { children: childrenField })
} else {
expandedRows = tableFullData
}
@@ -4032,7 +4038,7 @@ export default defineComponent({
if (lazy || (rowChildren && rowChildren.length)) {
expandeds.push(row)
}
}, treeOpts)
}, { children: childrenField })
return tableMethods.setTreeExpand(expandeds, expanded).then(() => {
if (transform) {
handleVirtualTreeToList()
@@ -4079,11 +4085,12 @@ export default defineComponent({
clearTreeExpand () {
const { tableFullTreeData } = internalData
const treeOpts = computeTreeOpts.value
const childrenField = treeOpts.children || treeOpts.childrenField
const { transform, reserve } = treeOpts
const expList = tableMethods.getTreeExpandRecords()
reactData.treeExpandedMaps = {}
if (reserve) {
XEUtils.eachTree(tableFullTreeData, row => handleTreeExpandReserve(row, false), treeOpts)
XEUtils.eachTree(tableFullTreeData, row => handleTreeExpandReserve(row, false), { children: childrenField })
}
return tablePrivateMethods.handleTableData().then(() => {
if (transform) {
@@ -4697,7 +4704,7 @@ export default defineComponent({
}
} else if (isBack && keyboardOpts.isArrow && treeConfig && (rowOpts.isCurrent || highlightCurrentRow) && currentRow) {
// 如果树形表格回退键关闭当前行返回父节点
const { parent: parentRow } = XEUtils.findTree(internalData.afterFullData, item => item === currentRow, treeOpts)
const { parent: parentRow } = XEUtils.findTree(internalData.afterFullData, item => item === currentRow, { children: childrenField })
if (parentRow) {
evnt.preventDefault()
params = {
@@ -5001,7 +5008,7 @@ export default defineComponent({
}
fullAllDataRowIdData = internalData.fullAllDataRowIdData = {}
if (treeConfig) {
XEUtils.eachTree(tableFullTreeData, handleRow, treeOpts)
XEUtils.eachTree(tableFullTreeData, handleRow, { children: childrenField })
} else {
tableFullData.forEach(handleRow)
}
@@ -5022,8 +5029,9 @@ export default defineComponent({
sourceDataRowIdData[rowid] = row
}
// 源数据缓存
if (treeConfig && !treeOpts.transform) {
XEUtils.eachTree(sourceData, handleSourceRow, treeOpts)
if (treeConfig) {
const childrenField = treeOpts.children || treeOpts.childrenField
XEUtils.eachTree(sourceData, handleSourceRow, { children: treeOpts.transform ? treeOpts.mapChildrenField : childrenField })
} else {
sourceData.forEach(handleSourceRow)
}
@@ -5260,6 +5268,7 @@ export default defineComponent({
const selectRowMaps = { ...selectCheckboxMaps }
const { afterFullData } = internalData
const treeOpts = computeTreeOpts.value
const childrenField = treeOpts.children || treeOpts.childrenField
const checkboxOpts = computeCheckboxOpts.value
const { checkField, checkStrictly, checkMethod } = checkboxOpts
const indeterminateField = checkboxOpts.indeterminateField || checkboxOpts.halfField
@@ -5285,10 +5294,10 @@ export default defineComponent({
delete treeIndeterminateMaps[getRowid($xetable, item)]
handleCheckboxReserveRow(row, value)
}
}, treeOpts)
}, { children: childrenField })
}
// 如果存在父节点,更新父节点状态
const matchObj = XEUtils.findTree(afterFullData, item => $xetable.eqRow(item, row), treeOpts)
const matchObj = XEUtils.findTree(afterFullData, item => $xetable.eqRow(item, row), { children: childrenField })
if (matchObj && matchObj.parent) {
let parentStatus
const vItems: any[] = []
@@ -5359,10 +5368,10 @@ export default defineComponent({
delete treeIndeterminateMaps[getRowid($xetable, item)]
handleCheckboxReserveRow(row, value)
}
}, treeOpts)
}, { children: childrenField })
}
// 如果存在父节点,更新父节点状态
const matchObj = XEUtils.findTree(afterFullData, item => $xetable.eqRow(item, row), treeOpts)
const matchObj = XEUtils.findTree(afterFullData, item => $xetable.eqRow(item, row), { children: childrenField })
if (matchObj && matchObj.parent) {
let parentStatus
const vItems: any[] = []
@@ -5819,7 +5828,8 @@ export default defineComponent({
const rests: Promise<any>[] = []
if (treeConfig) {
const treeOpts = computeTreeOpts.value
const matchObj = XEUtils.findTree(tableFullData, item => $xetable.eqRow(item, row), treeOpts)
const childrenField = treeOpts.children || treeOpts.childrenField
const matchObj = XEUtils.findTree(tableFullData, item => $xetable.eqRow(item, row), { children: childrenField })
if (matchObj) {
const nodes = matchObj.nodes
nodes.forEach((row, index) => {

View File

@@ -110,6 +110,7 @@ const validatorHook: VxeGlobalHooksHandles.HookOptions = {
const { editRules, treeConfig } = props
const { afterFullData } = internalData
const treeOpts = computeTreeOpts.value
const childrenField = treeOpts.children || treeOpts.childrenField
const validOpts = computeValidOpts.value
let vaildDatas
if (rows === true) {
@@ -180,7 +181,7 @@ const validatorHook: VxeGlobalHooksHandles.HookOptions = {
}
}
if (treeConfig) {
XEUtils.eachTree(vaildDatas, handleVaild, treeOpts)
XEUtils.eachTree(vaildDatas, handleVaild, { children: childrenField })
} else {
vaildDatas.forEach(handleVaild)
}

View File

@@ -137,7 +137,7 @@ export interface VXETableCore {
}
/**
* 一个基于 vue 的 PC 端表单/表格组件支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器、JSON 配置式为低/零代码而设计...
* 一个基于 vue 的 PC 端表单/表格组件支持增删改查、虚拟列表、虚拟树、懒加载、快捷菜单、数据校验、树形结构、打印导出、表单渲染、数据分页、弹窗、自定义模板、渲染器、JSON 配置式...
*/
export const VXETable: VXETableCore