mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-26 12:48:48 +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);
|
const rowKeyName = unref(getRowKey);
|
||||||
if (!rowKeyName) return;
|
if (!rowKeyName) return;
|
||||||
const rowKeys = !Array.isArray(rowKey) ? [rowKey] : rowKey;
|
const rowKeys = !Array.isArray(rowKey) ? [rowKey] : rowKey;
|
||||||
for (const key of rowKeys) {
|
|
||||||
let index: number | undefined = dataSourceRef.value.findIndex((row) => {
|
function deleteRow(data, key) {
|
||||||
let targetKeyName: string;
|
const row: { index: number; data: [] } = findRow(data, key);
|
||||||
if (typeof rowKeyName === 'function') {
|
if (row === null || row.index === -1) {
|
||||||
targetKeyName = rowKeyName(row);
|
return;
|
||||||
} else {
|
|
||||||
targetKeyName = rowKeyName as string;
|
|
||||||
}
|
|
||||||
return row[targetKeyName] === key;
|
|
||||||
});
|
|
||||||
if (index >= 0) {
|
|
||||||
dataSourceRef.value.splice(index, 1);
|
|
||||||
}
|
}
|
||||||
index = unref(propsRef).dataSource?.findIndex((row) => {
|
row.data.splice(row.index, 1);
|
||||||
let targetKeyName: string;
|
|
||||||
if (typeof rowKeyName === 'function') {
|
function findRow(data, key) {
|
||||||
targetKeyName = rowKeyName(row);
|
if (data === null || data === undefined) {
|
||||||
} else {
|
return null;
|
||||||
targetKeyName = rowKeyName as string;
|
|
||||||
}
|
}
|
||||||
return row[targetKeyName] === key;
|
for (let i = 0; i < data.length; i++) {
|
||||||
});
|
const row = data[i];
|
||||||
if (typeof index !== 'undefined' && index !== -1)
|
let targetKeyName: string = rowKeyName as string;
|
||||||
unref(propsRef).dataSource?.splice(index, 1);
|
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({
|
setPagination({
|
||||||
total: unref(propsRef).dataSource?.length,
|
total: unref(propsRef).dataSource?.length,
|
||||||
|
Loading…
Reference in New Issue
Block a user