|
|
|
@ -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]); |
|
|
|
|