From ad59aaef2de7da182387e568a54fe823d6085212 Mon Sep 17 00:00:00 2001 From: Vectorune Date: Tue, 11 Nov 2025 10:41:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E6=9C=AC=E5=AE=9E=E7=8E=B0=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E6=8A=BD=E5=B1=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Dashboard/DataManager/DataManageTable.jsx | 28 ++- .../DataManager/EditDataManageDrawer.jsx | 163 ++++++++++++++++++ .../DataManager/ManageTableColumn.js | 54 ++++-- 3 files changed, 221 insertions(+), 24 deletions(-) create mode 100644 src/page/Dashboard/DataManager/EditDataManageDrawer.jsx diff --git a/src/page/Dashboard/DataManager/DataManageTable.jsx b/src/page/Dashboard/DataManager/DataManageTable.jsx index b3b423d..45b7049 100644 --- a/src/page/Dashboard/DataManager/DataManageTable.jsx +++ b/src/page/Dashboard/DataManager/DataManageTable.jsx @@ -2,6 +2,7 @@ import React, {useState} from 'react'; import {Button, Flex, message, Popconfirm, Table, Typography} from "antd"; import ManageTableColumn from "./ManageTableColumn"; import ImportDataDrawer from "./ImportDataDrawer"; +import EditDataManageDrawer from './EditDataManageDrawer'; import creatMessageCommonAxios from "../../../http/CreatMessageCommonAxios"; const DataManageTable = props => { @@ -13,6 +14,9 @@ const DataManageTable = props => { const [selectIds, setSelectIds] = useState([]); + // 新增编辑抽屉相关状态 + const [editDrawerOpen, setEditDrawerOpen] = useState(false); + const [currentEditData, setCurrentEditData] = useState({}); const rowSelection = { type: 'checkbox', onChange: (selectedRowKeys, selectedRows) => { @@ -34,7 +38,12 @@ const DataManageTable = props => { } }) } - + // 编辑按钮点击处理(关键:此函数将打开抽屉) + const handleEdit = (record) => { + console.log("编辑数据:", record); // 用于调试,确认是否触发 + setCurrentEditData(record); + setEditDrawerOpen(true); // 打开抽屉 + }; const [importDataOpen, setImportDataOpen] = useState(false); const importDataDrawerOnClose = () => { @@ -49,6 +58,16 @@ const DataManageTable = props => { onClose={importDataDrawerOnClose} fetchWorkloadData={fetWorkload} /> + {/* 编辑抽屉 */} + +

数据管理

@@ -56,12 +75,11 @@ const DataManageTable = props => {
+ {/* 关键修复:传递 handleEdit 到表格列 */} record.id} - columns={ManageTableColumn(commonAxios, messageApi, fetWorkload)} + columns={ManageTableColumn(commonAxios, messageApi, fetWorkload, handleEdit)} // 新增 handleEdit 参数 dataSource={workloadData.list} pagination={false} /> diff --git a/src/page/Dashboard/DataManager/EditDataManageDrawer.jsx b/src/page/Dashboard/DataManager/EditDataManageDrawer.jsx new file mode 100644 index 0000000..4037b14 --- /dev/null +++ b/src/page/Dashboard/DataManager/EditDataManageDrawer.jsx @@ -0,0 +1,163 @@ +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; \ No newline at end of file diff --git a/src/page/Dashboard/DataManager/ManageTableColumn.js b/src/page/Dashboard/DataManager/ManageTableColumn.js index 57de09c..cb08712 100644 --- a/src/page/Dashboard/DataManager/ManageTableColumn.js +++ b/src/page/Dashboard/DataManager/ManageTableColumn.js @@ -1,7 +1,8 @@ import {Button, Space} from "antd"; +import { EditOutlined } from "@ant-design/icons"; // 引入编辑图标(解决第一个错误) import CourseTypeTag from "../../../component/Workload/CourseTypeTag"; -const ManageTableColumn = (commonAxios, messageApi, fetchWorkload) => [ +const ManageTableColumn = (commonAxios, messageApi, fetchWorkload, handleEdit) => [ //{ // title: 'ID', // dataIndex: 'id', @@ -67,24 +68,39 @@ const ManageTableColumn = (commonAxios, messageApi, fetchWorkload) => [ title: '操作', dataIndex: 'operation', key: 'operation', - render: (_, record) => ( - - - - ) + render: (_, record) => { + // 确保handleEdit存在再调用,避免参数未传递时出错 + const handleEditClick = () => { + if (typeof handleEdit === 'function') { + handleEdit(record); + } + }; + + return ( + + + + + ); + } }, ];