mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-25 02:58:43 +08:00
解决deleteTableRecord删除树形表格的行记录时,无法删除,无法找到子节点的问题 (#2461)
* feat(axiosSuccess): 操作成功后根据传入提示模式进行相应 * fix(axiosRetry): 解决get重试请求返回的headers造成无法成功请求的问题 * fix(axiosRetry): 参数首字母小写 * fix(useDataSource): 解决deleteTableRecord删除树形表格的行记录时,无法删除,无法找到子节点的问题
This commit is contained in:
parent
8c2ba755c1
commit
9435b480ab
@ -165,30 +165,42 @@ export function useDataSource(
|
||||
const rowKeyName = unref(getRowKey);
|
||||
if (!rowKeyName) return;
|
||||
const rowKeys = !Array.isArray(rowKey) ? [rowKey] : rowKey;
|
||||
for (const key of rowKeys) {
|
||||
let index: number | undefined = dataSourceRef.value.findIndex((row) => {
|
||||
let targetKeyName: string;
|
||||
if (typeof rowKeyName === 'function') {
|
||||
targetKeyName = rowKeyName(row);
|
||||
} else {
|
||||
targetKeyName = rowKeyName as string;
|
||||
}
|
||||
return row[targetKeyName] === key;
|
||||
});
|
||||
if (index >= 0) {
|
||||
dataSourceRef.value.splice(index, 1);
|
||||
|
||||
function deleteRow(data, key) {
|
||||
const row: { index: number; data: [] } = findRow(data, key);
|
||||
if (row === null || row.index === -1) {
|
||||
return;
|
||||
}
|
||||
index = unref(propsRef).dataSource?.findIndex((row) => {
|
||||
let targetKeyName: string;
|
||||
if (typeof rowKeyName === 'function') {
|
||||
targetKeyName = rowKeyName(row);
|
||||
} else {
|
||||
targetKeyName = rowKeyName as string;
|
||||
row.data.splice(row.index, 1);
|
||||
|
||||
function findRow(data, key) {
|
||||
if (data === null || data === undefined) {
|
||||
return null;
|
||||
}
|
||||
return row[targetKeyName] === key;
|
||||
});
|
||||
if (typeof index !== 'undefined' && index !== -1)
|
||||
unref(propsRef).dataSource?.splice(index, 1);
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
const row = data[i];
|
||||
let targetKeyName: string = rowKeyName as string;
|
||||
if (isFunction(rowKeyName)) {
|
||||
targetKeyName = rowKeyName(row);
|
||||
}
|
||||
if (row[targetKeyName] === key) {
|
||||
return { index: i, data };
|
||||
}
|
||||
if (row.children?.length > 0) {
|
||||
console.log(row.children, i);
|
||||
const result = findRow(row.children, key);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
for (const key of rowKeys) {
|
||||
deleteRow(dataSourceRef.value, key);
|
||||
deleteRow(unref(propsRef).dataSource, key);
|
||||
}
|
||||
setPagination({
|
||||
total: unref(propsRef).dataSource?.length,
|
||||
|
Loading…
Reference in New Issue
Block a user