Merge remote-tracking branch 'origin/main'

main
liuyiliang 3 months ago
commit e5c74d2831
  1. BIN
      packages/examination/public/template.xlsx
  2. 38
      packages/examination/src/views/examPaper/examPaperAdd.tsx
  3. 25
      packages/examination/src/views/examPaper/examPaperList.tsx
  4. 6
      packages/examination/src/views/examPaper/examPaperView.tsx
  5. 55
      packages/examination/src/views/question/questionAdd.tsx
  6. 4
      packages/examination/src/views/question/questionEdit.tsx
  7. 13
      packages/examination/src/views/question/questionList.tsx

@ -69,11 +69,9 @@ class ExamPaperAdd extends Component<any, States> {
componentDidMount() {
this.handleFindDict();
const id = sessionStorage.getItem('id');
const isEdit= sessionStorage.getItem('isEdit');
const { state } = this.props.location;
const { id, isEdit } = state;
this.setState({ id: id ,isEdit: isEdit});
sessionStorage.removeItem('id');
sessionStorage.removeItem('isEdit');
if(isEdit === 'true'){
this.handleGetDetail(id);
}
@ -366,7 +364,8 @@ class ExamPaperAdd extends Component<any, States> {
questionSelectList,
selectedRowKeys,
skipValidation,
questionCountSum
questionCountSum,
total
} = this.state;
const changePage = (current: number, pageSize: number) => {
@ -584,7 +583,7 @@ class ExamPaperAdd extends Component<any, States> {
<Form.Item
label="总分值:"
name="totalScore"
style={{ width: 240 }}
style={{ width: 220 }}
rules={[{ required: true, message: '请输入总分值' }]}
>
<Input type="number" style={{ textAlign: 'right' }} placeholder="请输入总分值" min={1} />
@ -689,20 +688,23 @@ class ExamPaperAdd extends Component<any, States> {
</Button>
]}
width={1100}
style={{ top: 20 }}
style={{top: 20}}
>
<div>
<h3 style={{ fontWeight: 'bold' }}></h3>
<h3 style={{fontWeight: 'bold'}}></h3>
<div style={{textAlign: 'right'}}>
{selectedQuestionList.length}/{total}
</div>
<Table
dataSource={selectedQuestionList}
columns={columns}
bordered={true}
scroll={{ y: 200 }}
scroll={{y: 200}}
size={'small'}
/>
</div>
<div style={{ marginTop: '20px' }}>
<h3 style={{ fontWeight: 'bold' }}></h3>
<div style={{marginTop: '20px'}}>
<h3 style={{fontWeight: 'bold'}}></h3>
<Form
className="filter"
layout="inline"
@ -713,10 +715,10 @@ class ExamPaperAdd extends Component<any, States> {
name="serviceTypeId"
>
<Select placeholder="请选择AQ服务类型"
style={{ width: 240 }}
style={{width: 240}}
allowClear>
{
serviceTypeDict && serviceTypeDict.length > 0?
serviceTypeDict && serviceTypeDict.length > 0 ?
(() => {
let rows = [];
for (let i = 0; i < serviceTypeDict.length; i++) {
@ -736,7 +738,7 @@ class ExamPaperAdd extends Component<any, States> {
label="题干条件:"
name="questionContent"
>
<Input placeholder="请输入题干条件" style={{ width: 400 }}/>
<Input placeholder="请输入题干条件" style={{width: 400}}/>
</Form.Item>
<Form.Item>
<Button type="default" onClick={this.handleReset}></Button>
@ -752,12 +754,12 @@ class ExamPaperAdd extends Component<any, States> {
bordered={true}
size={'small'}
rowKey="id"
scroll={{ y: 200 }}
scroll={{y: 200}}
loading={loading}
rowSelection={{
selectedRowKeys: selectedRowKeys,
onChange: (newSelectedRowKeys, selectedRows) => {
const { selectedQuestionList,questionSelectList } = this.state;
const {selectedQuestionList, questionSelectList} = this.state;
const newSelectedQuestionList = selectedRows.reduce((acc, row) => {
if (!acc.some(item => item.id === row.id)) {
acc.push(row);
@ -766,11 +768,11 @@ class ExamPaperAdd extends Component<any, States> {
}, [...selectedQuestionList]);
const deselectedIds = questionSelectList
.filter(item =>!newSelectedRowKeys.includes(item.id))
.filter(item => !newSelectedRowKeys.includes(item.id))
.map(item => item.id);
const finalSelectedQuestionList = newSelectedQuestionList.filter(
item =>!deselectedIds.includes(item.id)
item => !deselectedIds.includes(item.id)
);
const selectedRowKeys = finalSelectedQuestionList.map(item => String(item.id));

@ -34,11 +34,6 @@ class ExamPaperList extends Component<any, States> {
componentDidMount() {
this.handleFindIndustry();
const savedFormValues = sessionStorage.getItem('examPaperListFormValues');
if (savedFormValues) {
const values = JSON.parse(savedFormValues);
this.formRef.current.setFieldsValue(values);
}
this.handlegetList('def');
}
@ -62,7 +57,6 @@ class ExamPaperList extends Component<any, States> {
page : stat && stat === 'init' ? 1 : page
};
this.setState({ page: data.page, num: data.num });
sessionStorage.setItem('examPaperListFormValues', JSON.stringify(values));
getList(data).then((res) => {
this.setState({
list: res.data.data,
@ -80,7 +74,6 @@ class ExamPaperList extends Component<any, States> {
// 重置
handleReset = () => {
sessionStorage.removeItem('examPaperListFormValues');
this.formRef.current.resetFields();
};
@ -330,13 +323,21 @@ class ExamPaperList extends Component<any, States> {
width: 200,
render: (record: any) => [
<span className='mr10 link' onClick={() => {
sessionStorage.setItem('id', String(record.id));
sessionStorage.setItem('isEdit', "true");
this.props.history.push(`/examPaperAdd`);
this.props.history.push({
pathname: '/examPaperAdd',
state: {
id: String(record.id),
isEdit: "true"
}
});
}}></span>,
<span className='mr10 link' onClick={() => {
sessionStorage.setItem('id', String(record.id));
this.props.history.push(`/examPaperView`);
this.props.history.push({
pathname: '/examPaperView',
state: {
id: String(record.id)
}
});
}}></span>,
<span className='mr10 link' onClick={() => {
this.handleUpdatePaperStatus(record.id, record.paperStatus);

@ -52,8 +52,8 @@ class ExamPaperView extends Component<any, States> {
componentDidMount() {
this.handleFindIndustry();
const id = sessionStorage.getItem('id');
sessionStorage.removeItem('id');
const { state } = this.props.location;
const { id } = state;
this.handleGetDetail(id);
}
@ -67,7 +67,7 @@ class ExamPaperView extends Component<any, States> {
}
// 试卷详情
handleGetDetail = (id: string | null) => {
handleGetDetail = (id: string) => {
getExamPaperDetail(id).then((res: any) => {
if (res.data) {
const newQuestions: QuestionState[] = res.data.data.map((questionData: any) => {

@ -3,9 +3,6 @@ import { Form, Input, Button, Radio, Checkbox, Select, message } from "antd";
import { dictionary } from "api/dict/index";
import { addQuestion, findIndustry } from "api/question";
import * as XLSX from "xlsx";
// @ts-ignore
import { saveAs } from "file-saver";
import TextArea from "antd/es/input/TextArea";
const { Option } = Select;
@ -70,7 +67,6 @@ class QuestionAdd extends Component<any, States> {
// 题型切换
handleQuestionTypeChange = (formId: string, value: string) => {
const { questionTypesMap } = this.state;
const formValues = {};
formValues[`questionTypes_${formId}`] = value;
this.formRef.current.setFieldsValue(formValues);
@ -175,22 +171,23 @@ class QuestionAdd extends Component<any, States> {
// 下载模板
handleDownloadTemplate = () => {
const headers = [
"题型",
"监管行业",
"AQ服务类型",
"题干",
"选项A",
"选项B",
"选项C",
"选项D",
"答案"
];
const ws = XLSX.utils.aoa_to_sheet([headers]);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, "试题模板");
const wbOut = XLSX.write(wb, { bookType: "xlsx", type: "array" });
saveAs(new Blob([wbOut], { type: "application/octet-stream" }), "试题模板.xlsx");
const downloadUrl = '/template.xlsx';
fetch(downloadUrl)
.then(response => {
return response.blob();})
.then(blob => {
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', '试题模板.xlsx');
document.body.appendChild(link);
link.click();
link.parentNode?.removeChild(link);
window.URL.revokeObjectURL(url);
})
.catch(error => {
console.error('下载文件时出错:', error);
});
};
// 一键导入
@ -216,9 +213,21 @@ class QuestionAdd extends Component<any, States> {
rows.forEach((row: any, index) => {
const formId = `form_${index}`;
formIds.push(formId);
formValues[`questionTypes_${formId}`] = String(row[0]);
formValues[`industryId_${formId}`] = String(row[1]);
formValues[`serviceTypeId_${formId}`] = String(row[2]);
let questionTypeId = '';
if (row[0] === '单选题') {
questionTypeId = '1';
} else if (row[0] === '多选题') {
questionTypeId = '2';
}
const {industryDict ,serviceTypeDict } = this.state
const industryItem = industryDict.find((item:any) => item.industryName === row[1]);
const industryId = industryItem ? String(industryItem.industryId) : '';
const serviceTypeItem = serviceTypeDict.find((item:any) => item.dictValue === row[2]);
const serviceTypeId = serviceTypeItem ? String(serviceTypeItem.dictKey) : '';
formValues[`questionTypes_${formId}`] = questionTypeId;
formValues[`industryId_${formId}`] = industryId;
formValues[`serviceTypeId_${formId}`] = serviceTypeId;
formValues[`questionContent_${formId}`] = String(row[3]);
formValues[`optionA_${formId}`] = String(row[4]);
formValues[`optionB_${formId}`] = String(row[5]);

@ -48,8 +48,8 @@ class QuestionEdit extends Component<any, States> {
// 试题详情
handleGetQuestionDetail = () => {
const id = sessionStorage.getItem('id');
sessionStorage.removeItem('id');
const { state } = this.props.location;
const { id } = state;
getQuestionDetail(id).then((res: any) => {
if (res.data) {
this.setState({ questionTypes: String(res.data.questionTypes) });

@ -36,11 +36,6 @@ class QuestionList extends Component<any, States> {
componentDidMount() {
this.handleFindDict();
const savedFormValues = sessionStorage.getItem('questionListFormValues');
if (savedFormValues) {
const values = JSON.parse(savedFormValues);
this.formRef.current.setFieldsValue(values);
}
this.handlegetList('def');
}
@ -81,7 +76,6 @@ class QuestionList extends Component<any, States> {
page : stat && stat === 'init' ? 1 : page
};
this.setState({ page: data.page, num: data.num });
sessionStorage.setItem('questionListFormValues', JSON.stringify(values));
getList(data)
.then((res) => {
this.setState({
@ -100,7 +94,6 @@ class QuestionList extends Component<any, States> {
// 重置
handleReset = () => {
sessionStorage.removeItem('questionListFormValues');
this.formRef.current.resetFields();
};
@ -273,8 +266,10 @@ class QuestionList extends Component<any, States> {
this.handleDeleteQuestion(record.id);
}}></span>,
<span className="mr10 link" onClick={() => {
sessionStorage.setItem('id', String(record.id));
this.props.history.push(`/questionEdit`);
this.props.history.push({
pathname: '/questionEdit',
state: { id: record.id }
});
}}></span>
]
},

Loading…
Cancel
Save