Browse Source

树表格请求数据刷新后已经展开的节点需保持展开状态

main
likunming 7 months ago
parent
commit
12c76d2bd7
  1. 27
      io.sc.platform.core.frontend/src/platform/components/grid/WGrid.vue

27
io.sc.platform.core.frontend/src/platform/components/grid/WGrid.vue

@ -882,7 +882,7 @@ const buttonObj = reactive({
const expandFun = (arr, treeExpand) => {
arr.forEach((item) => {
if (props.tree && item.children && item.children.length > 0) {
item.expand = !treeExpand;
item[rowDataExtraPropertyName.expand] = !treeExpand;
expandFun(item.children, treeExpand);
}
});
@ -1379,7 +1379,7 @@ const rowDbClick = (evt, row, index) => {
} else if (!Tools.isEmpty(row) && props.dbClickOperation === buttonObj.clone.name) {
clone(row);
} else if (!Tools.isEmpty(row) && props.dbClickOperation === buttonObj.expand.name) {
row['expand'] = Tools.isEmpty(row['expand']) ? true : !row['expand'];
row[rowDataExtraPropertyName.expand] = Tools.isEmpty(row[rowDataExtraPropertyName.expand]) ? true : !row[rowDataExtraPropertyName.expand];
} else {
view();
}
@ -1505,6 +1505,19 @@ const requestHandler = async (ops) => {
});
return resp;
};
const expandDatas = <any>[];
const extractExpandStatus = (arr) => {
arr.forEach((item) => {
if (item[rowDataExtraPropertyName.expand]) {
expandDatas.push(item[props.primaryKey]);
}
if (item.children?.length > 0) {
extractExpandStatus(item.children);
}
});
};
const onRequest = async (ops: any) => {
state.loading = true;
const resp: any = await requestHandler(ops);
@ -1525,6 +1538,10 @@ const onRequest = async (ops: any) => {
table.rows = [];
}
} else if (resp && resp.data && props.tree) {
if (!table.treeExpand && table.rows.length > 0) {
expandDatas.splice(0, expandDatas.length);
extractExpandStatus(toRaw(table.rows));
}
const responseData = resp.data;
if (Array.isArray(responseData)) {
state.pagination.rowsNumber = responseData.length;
@ -1579,9 +1596,13 @@ const initRowDataExtraProperty = (rowData) => {
rowData[rowDataExtraPropertyName.rowKey] = Tools.uuid();
rowData[rowDataExtraPropertyName.ticked] = rowData[rowDataExtraPropertyName.ticked] || false;
rowData[rowDataExtraPropertyName.selected] = rowData[rowDataExtraPropertyName.selected] || false;
if (props.tree && Tools.isEmpty(rowData[rowDataExtraPropertyName.expand])) {
if (props.tree) {
if (expandDatas.length > 0 && expandDatas.includes(rowData[props.primaryKey])) {
rowData[rowDataExtraPropertyName.expand] = true;
} else if (Tools.isEmpty(rowData[rowDataExtraPropertyName.expand])) {
rowData[rowDataExtraPropertyName.expand] = false;
}
}
};
/**
* 设置行数据附加属性

Loading…
Cancel
Save