修改媒体类型和区域新建子集不刷新问题

This commit is contained in:
wangchengming 2025-10-15 21:09:51 +08:00
parent 6e9c66c82d
commit 08cc123cb4
2 changed files with 131 additions and 62 deletions

View File

@ -161,8 +161,7 @@ const loadChildren = async (row, treeNode, resolve) => {
}
resolve(response.data);
} catch (error) {
console.error('加载子节点失败:', error);
} catch (error) {
resolve([]);
}
}
@ -242,7 +241,41 @@ const submitForm = () => {
}
} else {
//
getsysRegionTreeList(form.value.parentId || 0);
const parentId = form.value.parentId || 0;
if (parentId === '0' || parentId === 0) {
// -
getsysRegionTreeList();
} else {
// -
const parentRow = findRowById(parentId);
if (parentRow) {
//
queryParams.value.parentId = parentId;
sysRegionListByPid(queryParams.value).then(res => {
// 使 splice
if (!parentRow.childList) {
parentRow.childList = [];
}
parentRow.childList.splice(0, parentRow.childList.length, ...res.data);
parentRow.hasChildren = res.data && res.data.length > 0;
//
nextTick(() => {
//
tableRef.value?.toggleRowExpansion(parentRow, false);
setTimeout(() => {
tableRef.value?.toggleRowExpansion(parentRow, true);
tableRef.value?.doLayout();
}, 50);
});
});
} else {
//
getsysRegionTreeList();
}
}
}
//

View File

@ -115,14 +115,14 @@ const findParentId = (id, rows = mediaTypeTreeList.value, parentId = 0) => {
// -
const findParentNode = (id, rows = mediaTypeTreeList.value, parent = null) => {
for (const row of rows) {
if (row.id === id) return parent;
if (row.childList) {
const found = findParentNode(id, row.childList, row);
if (found) return found;
}
}
return null;
for (const row of rows) {
if (row.id === id) return parent;
if (row.childList) {
const found = findParentNode(id, row.childList, row);
if (found) return found;
}
}
return null;
};
// handleExpandChange
@ -160,8 +160,7 @@ const loadChildren = async (row, treeNode, resolve) => {
}
resolve(response.data);
} catch (error) {
console.error('加载子节点失败:', error);
} catch (error) {
resolve([]);
}
};
@ -240,7 +239,44 @@ const submitForm = () => {
}
} else {
//
getsysMediaTypeTreeList(form.value.parentId || 0);
const parentId = form.value.parentId || 0;
if (parentId === '0' || parentId === 0) {
// -
getsysMediaTypeTreeList();
} else {
// - 使
const parentRow = findRowById(parentId);
if (parentRow) {
// 1: 使
if (!parentRow.childList) {
//
parentRow.childList = [];
}
//
queryParams.value.parentId = parentId;
sysMediaTypeListByPid(queryParams.value).then(res => {
// 使 splice
parentRow.childList.splice(0, parentRow.childList.length, ...res.data);
parentRow.hasChildren = res.data && res.data.length > 0;
//
nextTick(() => {
//
tableRef.value?.toggleRowExpansion(parentRow, false);
setTimeout(() => {
tableRef.value?.toggleRowExpansion(parentRow, true);
tableRef.value?.doLayout();
}, 50);
});
});
} else {
//
getsysMediaTypeTreeList();
}
}
}
//
@ -260,56 +296,56 @@ const submitForm = () => {
};
/** 删除按钮操作 */
const handleDelete = async (row) => {
try {
await proxy.$modal.confirm(`是否确认删除媒体类型名称为"${row.name}"的数据项?`);
// 1.
const saveExpanded = new Set(expandedKeys.value);
// 2.
const parentNode = findParentNode(row.id);
// 3. API
await deleteSysMediaType(row.id);
// 4.
saveExpanded.delete(row.id);
expandedKeys.value = new Set(saveExpanded);
// 5.
if (!parentNode) {
// -
mediaTypeTreeList.value = [];
await getsysMediaTypeTreeList();
} else {
// - childList
const index = parentNode.childList.findIndex(item => item.id === row.id);
if (index !== -1) {
parentNode.childList.splice(index, 1); //
//
nextTick(() => {
tableRef.value?.doLayout();
});
try {
await proxy.$modal.confirm(`是否确认删除媒体类型名称为"${row.name}"的数据项?`);
// 1.
const saveExpanded = new Set(expandedKeys.value);
// 2.
const parentNode = findParentNode(row.id);
// 3. API
await deleteSysMediaType(row.id);
// 4.
saveExpanded.delete(row.id);
expandedKeys.value = new Set(saveExpanded);
// 5.
if (!parentNode) {
// -
mediaTypeTreeList.value = [];
await getsysMediaTypeTreeList();
} else {
// - childList
const index = parentNode.childList.findIndex(item => item.id === row.id);
if (index !== -1) {
parentNode.childList.splice(index, 1); //
//
nextTick(() => {
tableRef.value?.doLayout();
});
}
}
}
proxy.$modal.msgSuccess("删除成功");
// 6.
nextTick(() => {
saveExpanded.forEach(id => {
const row = findRowById(id);
if (row) {
tableRef.value?.toggleRowExpansion(row, true);
}
proxy.$modal.msgSuccess("删除成功");
// 6.
nextTick(() => {
saveExpanded.forEach(id => {
const row = findRowById(id);
if (row) {
tableRef.value?.toggleRowExpansion(row, true);
}
});
});
});
} catch (error) {
if (error !== 'cancel') {
console.error('删除失败:', error);
proxy.$modal.msgError("删除失败");
}
}
} catch (error) {
if (error !== 'cancel') {
console.error('删除失败:', error);
proxy.$modal.msgError("删除失败");
}
}
};
//