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

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

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

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

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

Loading…
Cancel
Save