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