diff --git a/packages/examination/public/template.xlsx b/packages/examination/public/template.xlsx new file mode 100644 index 0000000..5484058 Binary files /dev/null and b/packages/examination/public/template.xlsx differ diff --git a/packages/examination/src/views/examPaper/examPaperAdd.tsx b/packages/examination/src/views/examPaper/examPaperAdd.tsx index ca83f9d..9f91e23 100644 --- a/packages/examination/src/views/examPaper/examPaperAdd.tsx +++ b/packages/examination/src/views/examPaper/examPaperAdd.tsx @@ -69,11 +69,9 @@ class ExamPaperAdd extends Component { 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 { questionSelectList, selectedRowKeys, skipValidation, - questionCountSum + questionCountSum, + total } = this.state; const changePage = (current: number, pageSize: number) => { @@ -584,7 +583,7 @@ class ExamPaperAdd extends Component { @@ -689,20 +688,23 @@ class ExamPaperAdd extends Component { ]} width={1100} - style={{ top: 20 }} + style={{top: 20}} >
-

已选列表

+

已选列表

+
+ {selectedQuestionList.length}/{total} +
-
-

试题选择

+
+

试题选择

{ name="serviceTypeId" > + @@ -752,12 +754,12 @@ class ExamPaperAdd extends Component { 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 { }, [...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)); diff --git a/packages/examination/src/views/examPaper/examPaperList.tsx b/packages/examination/src/views/examPaper/examPaperList.tsx index 4825e56..4a3c0db 100644 --- a/packages/examination/src/views/examPaper/examPaperList.tsx +++ b/packages/examination/src/views/examPaper/examPaperList.tsx @@ -34,11 +34,6 @@ class ExamPaperList extends Component { 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 { 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 { // 重置 handleReset = () => { - sessionStorage.removeItem('examPaperListFormValues'); this.formRef.current.resetFields(); }; @@ -330,13 +323,21 @@ class ExamPaperList extends Component { width: 200, render: (record: any) => [ { - 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" + } + }); }}>编辑, { - sessionStorage.setItem('id', String(record.id)); - this.props.history.push(`/examPaperView`); + this.props.history.push({ + pathname: '/examPaperView', + state: { + id: String(record.id) + } + }); }}>预览, { this.handleUpdatePaperStatus(record.id, record.paperStatus); diff --git a/packages/examination/src/views/examPaper/examPaperView.tsx b/packages/examination/src/views/examPaper/examPaperView.tsx index 87a2339..f296bff 100644 --- a/packages/examination/src/views/examPaper/examPaperView.tsx +++ b/packages/examination/src/views/examPaper/examPaperView.tsx @@ -52,8 +52,8 @@ class ExamPaperView extends Component { 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 { } // 试卷详情 - handleGetDetail = (id: string | null) => { + handleGetDetail = (id: string) => { getExamPaperDetail(id).then((res: any) => { if (res.data) { const newQuestions: QuestionState[] = res.data.data.map((questionData: any) => { diff --git a/packages/examination/src/views/question/questionAdd.tsx b/packages/examination/src/views/question/questionAdd.tsx index 91adbbb..9e1e67a 100644 --- a/packages/examination/src/views/question/questionAdd.tsx +++ b/packages/examination/src/views/question/questionAdd.tsx @@ -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 { // 题型切换 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 { // 下载模板 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 { 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]); diff --git a/packages/examination/src/views/question/questionEdit.tsx b/packages/examination/src/views/question/questionEdit.tsx index 2885d77..d62c230 100644 --- a/packages/examination/src/views/question/questionEdit.tsx +++ b/packages/examination/src/views/question/questionEdit.tsx @@ -48,8 +48,8 @@ class QuestionEdit extends Component { // 试题详情 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) }); diff --git a/packages/examination/src/views/question/questionList.tsx b/packages/examination/src/views/question/questionList.tsx index 8b28b0a..517f4b4 100644 --- a/packages/examination/src/views/question/questionList.tsx +++ b/packages/examination/src/views/question/questionList.tsx @@ -36,11 +36,6 @@ class QuestionList extends Component { 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 { 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 { // 重置 handleReset = () => { - sessionStorage.removeItem('questionListFormValues'); this.formRef.current.resetFields(); }; @@ -273,8 +266,10 @@ class QuestionList extends Component { this.handleDeleteQuestion(record.id); }}>删除, { - sessionStorage.setItem('id', String(record.id)); - this.props.history.push(`/questionEdit`); + this.props.history.push({ + pathname: '/questionEdit', + state: { id: record.id } + }); }}>修正 ] },