|
@@ -15,11 +15,6 @@ import { Icon } from '@/components/Icon';
|
|
|
|
|
|
|
|
export const TABLE_DRAG_SLOT_NAME = 'smart-table-drop-slot';
|
|
export const TABLE_DRAG_SLOT_NAME = 'smart-table-drop-slot';
|
|
|
|
|
|
|
|
-interface TableAction {
|
|
|
|
|
- getData: (rowIndex?: number) => any[];
|
|
|
|
|
- loadData: (data: any[]) => Promise<any>;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
const defaultRowDragConfig: SmartTableRowDragConfig = {
|
|
const defaultRowDragConfig: SmartTableRowDragConfig = {
|
|
|
handle: 'smart-table-drop-handle',
|
|
handle: 'smart-table-drop-handle',
|
|
|
animation: 150,
|
|
animation: 150,
|
|
@@ -34,7 +29,6 @@ const defaultRowDragConfig: SmartTableRowDragConfig = {
|
|
|
export const useTableRowDrag = (
|
|
export const useTableRowDrag = (
|
|
|
tablePropsRef: ComputedRef<SmartTableProps>,
|
|
tablePropsRef: ComputedRef<SmartTableProps>,
|
|
|
tableRef: Ref<VxeGridInstance>,
|
|
tableRef: Ref<VxeGridInstance>,
|
|
|
- { getData }: TableAction,
|
|
|
|
|
) => {
|
|
) => {
|
|
|
let sortable: Sortable | null = null;
|
|
let sortable: Sortable | null = null;
|
|
|
|
|
|
|
@@ -70,7 +64,7 @@ export const useTableRowDrag = (
|
|
|
handle: `.${config.handle}`,
|
|
handle: `.${config.handle}`,
|
|
|
onEnd: async ({ newIndex, oldIndex }) => {
|
|
onEnd: async ({ newIndex, oldIndex }) => {
|
|
|
if (newIndex !== oldIndex) {
|
|
if (newIndex !== oldIndex) {
|
|
|
- const tableData = getData();
|
|
|
|
|
|
|
+ const tableData = unref(tableRef).getTableData().tableData;
|
|
|
// 记录原顺序
|
|
// 记录原顺序
|
|
|
const keySorts = tableData.map((item) => {
|
|
const keySorts = tableData.map((item) => {
|
|
|
return item[unref(getKeyField)!] + '';
|
|
return item[unref(getKeyField)!] + '';
|
|
@@ -80,7 +74,7 @@ export const useTableRowDrag = (
|
|
|
// 还原顺序
|
|
// 还原顺序
|
|
|
sortable?.sort(keySorts);
|
|
sortable?.sort(keySorts);
|
|
|
// 更新数据排序
|
|
// 更新数据排序
|
|
|
- unref(tableRef).reactData.tableData = tableData;
|
|
|
|
|
|
|
+ unref(tableRef).loadData(tableData);
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
};
|
|
};
|