diff --git a/packages/examination/src/api/examPaper/index.tsx b/packages/examination/src/api/examPaper/index.tsx index 87d112e..702003b 100644 --- a/packages/examination/src/api/examPaper/index.tsx +++ b/packages/examination/src/api/examPaper/index.tsx @@ -39,7 +39,33 @@ export function deleteMultiple(ids: any) { } /* -* 新增题目 +* 变更状态 +*/ +export function updatePaperStatus(id: number, paperStatus:number) { + const data = { + id: id, + paperStatus:paperStatus + }; + return axios({ + url: '/ex/examPaper/updatePaperStatus', + method: 'post', + data: data + }); +} + +/* +* 批量变更状态 +*/ +export function batchUpdatePaperStatus(data: any) { + return axios({ + url: '/ex/examPaper/batchUpdatePaperStatus', + method: 'post', + data: data + }); +} + +/* +* 新增试卷 */ export function add(questionData: object) { return axios({ diff --git a/packages/examination/src/views/examPaper/examPaperList.tsx b/packages/examination/src/views/examPaper/examPaperList.tsx index f99e5b9..83817df 100644 --- a/packages/examination/src/views/examPaper/examPaperList.tsx +++ b/packages/examination/src/views/examPaper/examPaperList.tsx @@ -1,7 +1,7 @@ import React, { Component } from'react'; import {Form, Input, Button, Table, Select, message, Modal} from 'antd'; import { TableRowSelection } from 'antd/lib/table/interface'; -import {deleteSingle, deleteMultiple, findIndustry, getList} from 'api/examPaper'; +import {deleteSingle, deleteMultiple, findIndustry, getList, updatePaperStatus, batchUpdatePaperStatus} from 'api/examPaper'; const { Option } = Select; @@ -56,6 +56,7 @@ class ExamPaperList extends Component { componentDidMount() { this.findIndustry(); + this.getList(); } // 监管行业 @@ -180,6 +181,80 @@ class ExamPaperList extends Component { } }; + // 更新试卷状态 + updatePaperStatus = (id: number, paperStatus: number) => { + const newStatus = paperStatus === 0? '启用' : '停用'; + Modal.confirm({ + title: `确认${newStatus}`, + content: `你确定要${newStatus}这张试卷吗?`, + onOk: () => { + updatePaperStatus(id, paperStatus).then((res) => { + const isSuccess = res.data; + if (isSuccess) { + message.success(`${newStatus}成功`); + const status = paperStatus === 0? 1 : 0; + this.setState((prevState) => ({ + list: prevState.list.map((item) => + item.id === id? { ...item, paperStatus: status } : item + ) + })); + } else { + message.error(`${newStatus}失败,请稍后重试`); + } + }).catch(() => { + message.error(`${newStatus}时发生错误,请检查`); + }); + }, + onCancel: () => { + }, + }); + }; + + // 批量更新试卷状态 + batchUpdatePaperStatus = (paperStatus: number) => { + const { selectedRowKeys } = this.state; + if (selectedRowKeys.length === 0) { + message.warning('请选择要操作的试卷'); + return; + } + const newStatus = paperStatus === 0? '启用' : '停用'; + const { list } = this.state; + const selectedRecords = list.filter(record => selectedRowKeys.includes(record.id)); + const invalidRecords = selectedRecords.filter(record => record.paperStatus !== paperStatus); + if (invalidRecords.length > 0) { + message.warning(`部分试卷已经处于${newStatus}状态,请重新选择`); + return; + } + + Modal.confirm({ + title: `确认${newStatus}`, + content: `你确定要${newStatus}这些选中的试卷吗?`, + onOk: () => { + batchUpdatePaperStatus(selectedRecords) + .then((res) => { + const isSuccess = res.data; + if (isSuccess) { + message.success(`${newStatus}成功`); + const status = paperStatus === 0? 1 : 0; + this.setState((prevState) => ({ + list: prevState.list.map((item) => + selectedRowKeys.includes(item.id) + ? { ...item, paperStatus: status } : item + ) + })); + } else { + message.error(`${newStatus}失败,请稍后重试`); + } + }) + .catch(() => { + message.error(`${newStatus}时发生错误,请检查`); + }); + }, + onCancel: () => { + }, + }); + }; + render() { const onFinish = (values: object) => { const _listQuery = { ...this.state.listQuery, ...values }; @@ -225,7 +300,7 @@ class ExamPaperList extends Component { { title: '状态', dataIndex: 'paperStatus', key: 'paperStatus', align: 'center', width: 60, render: (paperStatus:any) => { if (paperStatus === 0) { - return '禁用'; + return '停用'; } else if (paperStatus === 1) { return '启用'; } @@ -234,7 +309,7 @@ class ExamPaperList extends Component { { title: '操作', key: 'operation', align: 'center', fixed: 'right', width: 200, render: (record: any) => [ { - this.setState({title: '删除', modalWidth: '85%'}) + this.setState({title: '编辑', modalWidth: '85%'}) this.props.history.push(`/questionUp/${record.id}`); }}>编辑, { @@ -242,11 +317,10 @@ class ExamPaperList extends Component { this.deleteSingle(record.id); }}>预览, { - this.setState({title: '停用', modalWidth: '85%'}) - this.deleteSingle(record.id); - }}>停用, + this.updatePaperStatus(record.id, record.paperStatus); // 调用更新状态的方法 + }}>{record.paperStatus === 0? '启用' : '停用'}, // 根 { - this.setState({title: '停用', modalWidth: '85%'}) + this.setState({title: '删除', modalWidth: '85%'}) this.deleteSingle(record.id); }}>删除 ] @@ -328,10 +402,10 @@ class ExamPaperList extends Component { - + - + diff --git a/packages/examination/src/views/question/questionAdd.tsx b/packages/examination/src/views/question/questionAdd.tsx index c7794ce..59040cd 100644 --- a/packages/examination/src/views/question/questionAdd.tsx +++ b/packages/examination/src/views/question/questionAdd.tsx @@ -296,6 +296,7 @@ class QuestionAdd extends Component { { label="题干:" name={`questionContent_${index}`} style={{marginTop: 10 }} + rules={[{ required: true, message: '请输入题干内容' }]} > { style={{ width: 1100, height: 60 }} /> - +
{question.questionTypes === '1'? ( diff --git a/packages/examination/src/views/question/questionUp.tsx b/packages/examination/src/views/question/questionUp.tsx index 09b9e2f..b4c04b0 100644 --- a/packages/examination/src/views/question/questionUp.tsx +++ b/packages/examination/src/views/question/questionUp.tsx @@ -213,6 +213,7 @@ class QuestionUp extends Component { { label="题干:" name="questionContent" style={{ marginTop: 10 }} + rules={[{ required: true, message: '请输入题干内容' }]} >