fix: 直接回填日计划编辑数据
This commit is contained in:
@@ -42,7 +42,7 @@ function handleCreate() {
|
||||
}
|
||||
|
||||
function handleEdit(row: LmsDailyPlanApi.DailyPlan) {
|
||||
formDrawerApi.setData({ dailyPlanId: row.dailyPlanId, isUpdate: true }).open();
|
||||
formDrawerApi.setData({ isUpdate: true, row }).open();
|
||||
}
|
||||
|
||||
function handleDetail(row: LmsDailyPlanApi.DailyPlan) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import { useVbenDrawer, useVbenModal } from '@vben/common-ui';
|
||||
import { message } from 'antdv-next';
|
||||
|
||||
import { useVbenForm } from '#/adapter/form';
|
||||
import { createDailyPlan, getDailyPlan, updateDailyPlan } from '#/api/lms/dailyplan';
|
||||
import { createDailyPlan, updateDailyPlan } from '#/api/lms/dailyplan';
|
||||
import MaterialSelectModalComponent from '#/views/base/materialbase/components/MaterialSelectModal.vue';
|
||||
|
||||
import { usePlanFormSchema } from '../data';
|
||||
@@ -18,11 +18,10 @@ const emit = defineEmits(['success']);
|
||||
const formData = ref<LmsDailyPlanApi.DailyPlan>();
|
||||
const isUpdate = ref(false);
|
||||
const title = computed(() => isUpdate.value ? '编辑日计划' : '新增日计划');
|
||||
let loadSerial = 0;
|
||||
|
||||
interface DrawerData {
|
||||
dailyPlanId?: LmsDailyPlanApi.ApiId;
|
||||
isUpdate: boolean;
|
||||
row?: LmsDailyPlanApi.DailyPlan;
|
||||
}
|
||||
|
||||
const [MaterialSelectModal, materialSelectModalApi] = useVbenModal({
|
||||
@@ -88,31 +87,18 @@ const [Drawer, drawerApi] = useVbenDrawer({
|
||||
},
|
||||
async onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
loadSerial += 1;
|
||||
isUpdate.value = false;
|
||||
formData.value = undefined;
|
||||
void formApi.resetForm();
|
||||
return;
|
||||
}
|
||||
const currentSerial = ++loadSerial;
|
||||
const data = drawerApi.getData<DrawerData>();
|
||||
isUpdate.value = Boolean(data?.isUpdate);
|
||||
await formApi.resetForm();
|
||||
if (!data?.dailyPlanId) {
|
||||
if (!data?.row) {
|
||||
formData.value = undefined;
|
||||
await formApi.setValues({ sortSeq: 1, weight: 1 });
|
||||
return;
|
||||
}
|
||||
try {
|
||||
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;
|
||||
}
|
||||
formData.value = data.row;
|
||||
await formApi.setValues(data.row);
|
||||
},
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user