mirror of
https://github.com/vbenjs/vben-admin-thin-next.git
synced 2025-01-23 01:30:23 +08:00
fix(table): deleteTableDataRecord
not work
This commit is contained in:
parent
5902886798
commit
456a661488
@ -12,12 +12,14 @@
|
||||
- 修复`useTable`与`BasicTable`实例的`reload`方法`await`表现不一致的问题
|
||||
- 修复`clickToRowSelect`会无视行选择框 disabled 状态的问题
|
||||
- 修复`BasicTable`在某些情况下,分页会被重置的问题
|
||||
- 修改 `deleteTableDataRecord` 方法
|
||||
- **BasicModal**
|
||||
- 修复点击遮罩、按下`Esc`键都不能关闭`Modal`的问题
|
||||
- 修复点击关闭按钮、最大化按钮旁边的空白区域也会导致`Modal`关闭的问题
|
||||
- **BasicTree** 修复节点插槽不起作用的问题
|
||||
- **CodeEditor** 修复可能会造成的`Build`失败的问题
|
||||
- **BasicForm** 修复自定义 FormItem 组件的内容宽度可能超出范围的问题
|
||||
- **ApiTreeSelect** 修复`params`变化未能触发重新请求 api 数据的问题
|
||||
- **其它**
|
||||
- 修复多标签在某些情况下关闭页签不会跳转路由的问题
|
||||
- 修复部分组件可能会造成热更新异常的问题
|
||||
|
@ -160,21 +160,39 @@ export function useDataSource(
|
||||
}
|
||||
}
|
||||
|
||||
function deleteTableDataRecord(record: Recordable | Recordable[]): Recordable | undefined {
|
||||
function deleteTableDataRecord(rowKey: string | number | string[] | number[]) {
|
||||
if (!dataSourceRef.value || dataSourceRef.value.length == 0) return;
|
||||
const records = !Array.isArray(record) ? [record] : record;
|
||||
const recordIndex = records
|
||||
.map((item) => dataSourceRef.value.findIndex((s) => s.key === item.key)) // 取序号
|
||||
.filter((item) => item !== undefined)
|
||||
.sort((a, b) => b - a); // 从大到小排序
|
||||
for (const index of recordIndex) {
|
||||
unref(dataSourceRef).splice(index, 1);
|
||||
unref(propsRef).dataSource?.splice(index, 1);
|
||||
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);
|
||||
}
|
||||
index = unref(propsRef).dataSource?.findIndex((row) => {
|
||||
let targetKeyName: string;
|
||||
if (typeof rowKeyName === 'function') {
|
||||
targetKeyName = rowKeyName(row);
|
||||
} else {
|
||||
targetKeyName = rowKeyName as string;
|
||||
}
|
||||
return row[targetKeyName] === key;
|
||||
});
|
||||
if (typeof index !== 'undefined' && index !== -1)
|
||||
unref(propsRef).dataSource?.splice(index, 1);
|
||||
}
|
||||
setPagination({
|
||||
total: unref(propsRef).dataSource?.length,
|
||||
});
|
||||
return unref(propsRef).dataSource;
|
||||
}
|
||||
|
||||
function insertTableDataRecord(record: Recordable, index: number): Recordable | undefined {
|
||||
|
@ -122,8 +122,8 @@ export function useTable(tableProps?: Props): [
|
||||
updateTableData: (index: number, key: string, value: any) => {
|
||||
return getTableInstance().updateTableData(index, key, value);
|
||||
},
|
||||
deleteTableDataRecord: (record: Recordable | Recordable[]) => {
|
||||
return getTableInstance().deleteTableDataRecord(record);
|
||||
deleteTableDataRecord: (rowKey: string | number | string[] | number[]) => {
|
||||
return getTableInstance().deleteTableDataRecord(rowKey);
|
||||
},
|
||||
insertTableDataRecord: (record: Recordable | Recordable[], index?: number) => {
|
||||
return getTableInstance().insertTableDataRecord(record, index);
|
||||
|
@ -95,7 +95,7 @@ export interface TableActionType {
|
||||
setPagination: (info: Partial<PaginationProps>) => void;
|
||||
setTableData: <T = Recordable>(values: T[]) => void;
|
||||
updateTableDataRecord: (rowKey: string | number, record: Recordable) => Recordable | void;
|
||||
deleteTableDataRecord: (record: Recordable | Recordable[]) => Recordable | void;
|
||||
deleteTableDataRecord: (rowKey: string | number | string[] | number[]) => void;
|
||||
insertTableDataRecord: (record: Recordable, index?: number) => Recordable | void;
|
||||
findTableDataRecord: (rowKey: string | number) => Recordable | void;
|
||||
getColumns: (opt?: GetColumnsParams) => BasicColumn[];
|
||||
|
Loading…
Reference in New Issue
Block a user