fix: 修复日计划编辑抽屉状态
This commit is contained in:
@@ -38,11 +38,11 @@ function handleRefresh() {
|
||||
}
|
||||
|
||||
function handleCreate() {
|
||||
formDrawerApi.setData(null).open();
|
||||
formDrawerApi.setData({ isUpdate: false }).open();
|
||||
}
|
||||
|
||||
function handleEdit(row: LmsDailyPlanApi.DailyPlan) {
|
||||
formDrawerApi.setData(row).open();
|
||||
formDrawerApi.setData({ dailyPlanId: row.dailyPlanId, isUpdate: true }).open();
|
||||
}
|
||||
|
||||
function handleDetail(row: LmsDailyPlanApi.DailyPlan) {
|
||||
|
||||
@@ -16,7 +16,14 @@ import { usePlanFormSchema } from '../data';
|
||||
|
||||
const emit = defineEmits(['success']);
|
||||
const formData = ref<LmsDailyPlanApi.DailyPlan>();
|
||||
const title = computed(() => formData.value ? '编辑日计划' : '新增日计划');
|
||||
const isUpdate = ref(false);
|
||||
const title = computed(() => isUpdate.value ? '编辑日计划' : '新增日计划');
|
||||
let loadSerial = 0;
|
||||
|
||||
interface DrawerData {
|
||||
dailyPlanId?: LmsDailyPlanApi.ApiId;
|
||||
isUpdate: boolean;
|
||||
}
|
||||
|
||||
const [MaterialSelectModal, materialSelectModalApi] = useVbenModal({
|
||||
connectedComponent: MaterialSelectModalComponent,
|
||||
@@ -81,21 +88,30 @@ const [Drawer, drawerApi] = useVbenDrawer({
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
loadSerial += 1;
|
||||
isUpdate.value = false;
|
||||
formData.value = undefined;
|
||||
await formApi.resetForm();
|
||||
void formApi.resetForm();
|
||||
return;
|
||||
}
|
||||
const row = drawerApi.getData<LmsDailyPlanApi.DailyPlan>();
|
||||
if (!row?.dailyPlanId) {
|
||||
const currentSerial = ++loadSerial;
|
||||
const data = drawerApi.getData<DrawerData>();
|
||||
isUpdate.value = Boolean(data?.isUpdate);
|
||||
await formApi.resetForm();
|
||||
if (!data?.dailyPlanId) {
|
||||
await formApi.setValues({ sortSeq: 1, weight: 1 });
|
||||
return;
|
||||
}
|
||||
drawerApi.lock();
|
||||
try {
|
||||
formData.value = await getDailyPlan(row.dailyPlanId);
|
||||
await formApi.setValues(formData.value);
|
||||
} finally {
|
||||
drawerApi.unlock();
|
||||
const detail = await getDailyPlan(data.dailyPlanId);
|
||||
if (currentSerial !== loadSerial) return;
|
||||
formData.value = detail;
|
||||
await formApi.setValues(detail);
|
||||
} catch (error) {
|
||||
if (currentSerial === loadSerial) {
|
||||
message.error('加载日计划详情失败');
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user