import React from 'react'; import PropTypes from 'prop-types'; import { Button, Drawer, Flex, Form, Input, Select, Typography } from "antd"; import CourseTypeTag from "../../../component/Workload/CourseTypeTag"; const EditDataManageDrawer = props => { const { open, setOpen, commonAxios, fetchWorkload, messageApi, initialValues } = props; // 表单布局配置,与添加组件保持一致 const formLayout = { labelCol: { span: 5 }, wrapperCol: { span: 20 }, }; const [form] = Form.useForm(); const { Title } = Typography; // 课程性质选项(根据实际业务调整) const courseNatureOptions = [ { label: '必修课', value: '必修课' }, { label: '选修课', value: '选修课' }, { label: '通识课', value: '通识课' }, { label: '实践课', value: '实践课' } ]; // 当抽屉打开且有初始值时,填充表单数据 React.useEffect(() => { if (open && initialValues) { form.setFieldsValue({ semesterInfo: initialValues.semesterInfo, courseName: initialValues.courseName, teacherName: initialValues.teacherName, courseNature: initialValues.courseNature, teachingMajor: initialValues.teachingMajor, actualClassSize: initialValues.actualClassSize, teachingGrade: initialValues.teachingGrade, totalClassHours: initialValues.totalClassHours }); } else { form.resetFields(); } }, [open, initialValues, form]); // 提交编辑表单 const onSubmit = (values) => { // 拼接ID用于后端识别更新对象 const updateData = { ...values, id: initialValues.id }; commonAxios.put('/api/v1/workload/update', updateData).then(response => { const result = response.data.data || false; if (result) { messageApi.success('编辑工作量信息成功'); setOpen(false); fetchWorkload(); // 刷新列表 } else { messageApi.error('编辑工作量信息失败'); } }).catch(error => { messageApi.error('网络错误,编辑失败'); }); }; return ( setOpen(false)} title={'编辑工作量'} destroyOnClose >
编辑工作量信息
); }; // 属性校验,与添加组件保持一致 EditDataManageDrawer.propTypes = { open: PropTypes.bool.isRequired, setOpen: PropTypes.func.isRequired, commonAxios: PropTypes.func.isRequired, fetchWorkload: PropTypes.func.isRequired, messageApi: PropTypes.object.isRequired, initialValues: PropTypes.object // 编辑的初始数据 }; export default EditDataManageDrawer;