试卷管理代码提交

main
hujunpeng 4 months ago
parent bea86b017b
commit 7857eb3e38
  1. 28
      packages/examination/src/api/examPaper/index.tsx
  2. 92
      packages/examination/src/views/examPaper/examPaperList.tsx
  3. 7
      packages/examination/src/views/question/questionAdd.tsx
  4. 3
      packages/examination/src/views/question/questionUp.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) { export function add(questionData: object) {
return axios({ return axios({

@ -1,7 +1,7 @@
import React, { Component } from'react'; import React, { Component } from'react';
import {Form, Input, Button, Table, Select, message, Modal} from 'antd'; import {Form, Input, Button, Table, Select, message, Modal} from 'antd';
import { TableRowSelection } from 'antd/lib/table/interface'; 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; const { Option } = Select;
@ -56,6 +56,7 @@ class ExamPaperList extends Component<any, States> {
componentDidMount() { componentDidMount() {
this.findIndustry(); this.findIndustry();
this.getList();
} }
// 监管行业 // 监管行业
@ -180,6 +181,80 @@ class ExamPaperList extends Component<any, States> {
} }
}; };
// 更新试卷状态
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() { render() {
const onFinish = (values: object) => { const onFinish = (values: object) => {
const _listQuery = { ...this.state.listQuery, ...values }; const _listQuery = { ...this.state.listQuery, ...values };
@ -225,7 +300,7 @@ class ExamPaperList extends Component<any, States> {
{ title: '状态', dataIndex: 'paperStatus', key: 'paperStatus', align: 'center', width: 60, { title: '状态', dataIndex: 'paperStatus', key: 'paperStatus', align: 'center', width: 60,
render: (paperStatus:any) => { render: (paperStatus:any) => {
if (paperStatus === 0) { if (paperStatus === 0) {
return '用'; return '用';
} else if (paperStatus === 1) { } else if (paperStatus === 1) {
return '启用'; return '启用';
} }
@ -234,7 +309,7 @@ class ExamPaperList extends Component<any, States> {
{ title: '操作', key: 'operation', align: 'center', fixed: 'right', width: 200, { title: '操作', key: 'operation', align: 'center', fixed: 'right', width: 200,
render: (record: any) => [ render: (record: any) => [
<span className='mr10 link' onClick={() => { <span className='mr10 link' onClick={() => {
this.setState({title: '删除', modalWidth: '85%'}) this.setState({title: '编辑', modalWidth: '85%'})
this.props.history.push(`/questionUp/${record.id}`); this.props.history.push(`/questionUp/${record.id}`);
}}></span>, }}></span>,
<span className='mr10 link' onClick={() => { <span className='mr10 link' onClick={() => {
@ -242,11 +317,10 @@ class ExamPaperList extends Component<any, States> {
this.deleteSingle(record.id); this.deleteSingle(record.id);
}}></span>, }}></span>,
<span className='mr10 link' onClick={() => { <span className='mr10 link' onClick={() => {
this.setState({title: '停用', modalWidth: '85%'}) this.updatePaperStatus(record.id, record.paperStatus); // 调用更新状态的方法
this.deleteSingle(record.id); }}>{record.paperStatus === 0? '启用' : '停用'}</span>, // 根
}}></span>,
<span className="mr10 link" onClick={() => { <span className="mr10 link" onClick={() => {
this.setState({title: '停用', modalWidth: '85%'}) this.setState({title: '删除', modalWidth: '85%'})
this.deleteSingle(record.id); this.deleteSingle(record.id);
}}></span> }}></span>
] ]
@ -328,10 +402,10 @@ class ExamPaperList extends Component<any, States> {
<Button type="default" onClick={this.deleteMultiple}></Button> <Button type="default" onClick={this.deleteMultiple}></Button>
</Form.Item> </Form.Item>
<Form.Item> <Form.Item>
<Button type="default" onClick={this.deleteMultiple}></Button> <Button type="default" onClick={() => this.batchUpdatePaperStatus(1)}></Button>
</Form.Item> </Form.Item>
<Form.Item> <Form.Item>
<Button type="default" onClick={this.deleteMultiple}></Button> <Button type="default" onClick={() => this.batchUpdatePaperStatus(0)}></Button>
</Form.Item> </Form.Item>
<Form.Item> <Form.Item>
<Button type="primary" onClick={handleAddQuestion}></Button> <Button type="primary" onClick={handleAddQuestion}></Button>

@ -296,6 +296,7 @@ class QuestionAdd extends Component<any, States> {
<Form.Item <Form.Item
label="监管行业:" label="监管行业:"
name={`industryId_${index}`} name={`industryId_${index}`}
rules={[{ required: true, message: '请选择监管行业' }]}
> >
<Select placeholder="请选择监管行业" <Select placeholder="请选择监管行业"
style={{ width: 240 }} style={{ width: 240 }}
@ -321,6 +322,7 @@ class QuestionAdd extends Component<any, States> {
<Form.Item <Form.Item
label="AQ服务类型:" label="AQ服务类型:"
name={`serviceTypeId_${index}`} name={`serviceTypeId_${index}`}
rules={[{ required: true, message: '请选择AQ服务类型' }]}
> >
<Select placeholder="请选择AQ服务类型" <Select placeholder="请选择AQ服务类型"
style={{ width: 240 }} style={{ width: 240 }}
@ -351,6 +353,7 @@ class QuestionAdd extends Component<any, States> {
label="题干:" label="题干:"
name={`questionContent_${index}`} name={`questionContent_${index}`}
style={{marginTop: 10 }} style={{marginTop: 10 }}
rules={[{ required: true, message: '请输入题干内容' }]}
> >
<Input.TextArea <Input.TextArea
placeholder="请输入题干内容" placeholder="请输入题干内容"
@ -358,7 +361,9 @@ class QuestionAdd extends Component<any, States> {
style={{ width: 1100, height: 60 }} style={{ width: 1100, height: 60 }}
/> />
</Form.Item> </Form.Item>
<Form.Item style={{marginTop: 10, marginLeft: 40}}> <Form.Item
style={{marginTop: 10, marginLeft: 40}}
>
<div> <div>
<div style={{ display: 'flex' }}> <div style={{ display: 'flex' }}>
{question.questionTypes === '1'? ( {question.questionTypes === '1'? (

@ -213,6 +213,7 @@ class QuestionUp extends Component<any, States> {
<Form.Item <Form.Item
label="监管行业:" label="监管行业:"
name="industryId" name="industryId"
rules={[{ required: true, message: '请选择监管行业' }]}
> >
<Select placeholder="请选择监管行业" <Select placeholder="请选择监管行业"
style={{ width: 240 }} style={{ width: 240 }}
@ -237,6 +238,7 @@ class QuestionUp extends Component<any, States> {
<Form.Item <Form.Item
label="AQ服务类型:" label="AQ服务类型:"
name="serviceTypeId" name="serviceTypeId"
rules={[{ required: true, message: '请选择AQ服务类型' }]}
> >
<Select placeholder="请选择AQ服务类型" <Select placeholder="请选择AQ服务类型"
style={{ width: 240 }} style={{ width: 240 }}
@ -264,6 +266,7 @@ class QuestionUp extends Component<any, States> {
label="题干:" label="题干:"
name="questionContent" name="questionContent"
style={{ marginTop: 10 }} style={{ marginTop: 10 }}
rules={[{ required: true, message: '请输入题干内容' }]}
> >
<Input.TextArea <Input.TextArea
placeholder="请输入题干内容" placeholder="请输入题干内容"

Loading…
Cancel
Save