gtsoft-snail-job-admin/src/views/category/modules/table.ts
2025-03-12 11:18:23 +08:00

51 lines
1.3 KiB
TypeScript

import { ref, Ref, Reactive } from 'vue';
import { jsonClone } from '@sa/utils';
import { useBoolean } from '@sa/hooks';
import { $t } from '@/locales';
export function useFormOperate<T extends Record<string, any>>(config: {
getData: () => Promise<void>;
}) {
const { getData } = config;
const { bool: drawerVisible, setTrue: openDrawer, setFalse: closeDrawer } = useBoolean();
const operateType: Ref<NaiveUI.TableOperateType> = ref('add');
const editingData: Ref<Api.Category.Category | null> = ref(null);
// 打开添加表单
function handleAdd(id: number) {
operateType.value = 'add';
editingData.value = {
id: id,
parentId: id,
categoryName: "",
level: "",
createTime: "",
categoryType: "网站"
};
openDrawer();
}
// 打开编辑表单
function handleEdit(data: Api.Category.Category) {
operateType.value = 'edit';
editingData.value = data;
openDrawer();
}
async function onDeleted() {
window.$message?.success($t('common.deleteSuccess'));
await getData();
}
return {
drawerVisible, // 抽屉是否可见
operateType, // 操作类型
editingData, // 传入侧边栏的数据
openDrawer, // 打开抽屉
closeDrawer, // 关闭抽屉
handleAdd, // 添加操作
handleEdit, // 编辑操作
onDeleted
};
}