理论题目导入调整
This commit is contained in:
parent
daa05eb67b
commit
0d6f6dda1c
@ -135,7 +135,7 @@ export default {
|
||||
{ text: '添 加', handler: this.doCreate },
|
||||
{ text: '导 入', fileType: 'file', handler: this.importQuestionBank },
|
||||
// { text: '试卷规则管理', handler: this.questionsRuleManage},
|
||||
// { text: '导出', handler: this.exportTemplate}
|
||||
// { text: '导出', handler: this.exportTemplate},
|
||||
{ text: '导出模板', handler: this.downloadTemplate}
|
||||
]
|
||||
}
|
||||
@ -249,11 +249,12 @@ export default {
|
||||
};
|
||||
if (file) {
|
||||
try {
|
||||
setTimeout(() => {
|
||||
// setTimeout(() => {
|
||||
const that = this;
|
||||
const reader = new FileReader();
|
||||
if (reader) {
|
||||
reader.onload = function (e) {
|
||||
try {
|
||||
let wb;
|
||||
const data = e.target.result;
|
||||
if (that.rABS) {
|
||||
@ -269,46 +270,46 @@ export default {
|
||||
if (wb && wb.Sheets) {
|
||||
for (const index in wb.Sheets) {
|
||||
const dataList = convertSheetToList(wb.Sheets[index], true);
|
||||
let questionTypeIndex;
|
||||
let topicIndex;
|
||||
let tagsIndex;
|
||||
let option1Index;
|
||||
let option2Index;
|
||||
let option3Index;
|
||||
let option4Index;
|
||||
let option5Index;
|
||||
let option6Index;
|
||||
let answerIndex;
|
||||
const objHeader = {
|
||||
questionTypeIndex: '题型(必填)',
|
||||
topicIndex: '题干(必填)',
|
||||
tagsIndex: '标签',
|
||||
option1Index: '选项A(必填)',
|
||||
option2Index: '选项B(必填)',
|
||||
option3Index: '选项C',
|
||||
option4Index: '选项D',
|
||||
option5Index: '选项E',
|
||||
option6Index: '选项F',
|
||||
answerIndex: '正确答案(必填)'
|
||||
};
|
||||
const indexHeader = JSON.parse(JSON.stringify(objHeader));
|
||||
dataList.forEach((item, ii) => {
|
||||
if (!item[0] && !item[1] && item[2] === '题型(必填)') {
|
||||
questionTypeIndex = ii;
|
||||
} else if (!item[0] && !item[1] && item[2] === '题干(必填)') {
|
||||
topicIndex = ii;
|
||||
} else if (!item[0] && !item[1] && item[2] === '标签') {
|
||||
tagsIndex = ii;
|
||||
} else if (!item[0] && !item[1] && item[2] === '选项A(必填)') {
|
||||
option1Index = ii;
|
||||
} else if (!item[0] && !item[1] && item[2] === '选项B(必填)') {
|
||||
option2Index = ii;
|
||||
} else if (!item[0] && !item[1] && item[2] === '选项C') {
|
||||
option3Index = ii;
|
||||
} else if (!item[0] && !item[1] && item[2] === '选项D') {
|
||||
option4Index = ii;
|
||||
} else if (!item[0] && !item[1] && item[2] === '选项E') {
|
||||
option5Index = ii;
|
||||
} else if (!item[0] && !item[1] && item[2] === '选项F') {
|
||||
option6Index = ii;
|
||||
} else if (!item[0] && !item[1] && item[2] === '正确答案(必填)') {
|
||||
answerIndex = ii;
|
||||
Object.keys(objHeader).forEach(key => {
|
||||
if (!item[0] && !item[1] && item[2] === objHeader[key]) {
|
||||
indexHeader[key] = ii;
|
||||
}
|
||||
});
|
||||
});
|
||||
const errHeader = [];
|
||||
Object.keys(objHeader).forEach(key => {
|
||||
if (typeof indexHeader[key] != 'number') {
|
||||
errHeader.push(objHeader[key]);
|
||||
}
|
||||
});
|
||||
let errInfo = errHeader.join(';');
|
||||
if (errInfo) {
|
||||
const error = `以下列:${errInfo},无法找到`;
|
||||
throw error;
|
||||
}
|
||||
const errRow = [];
|
||||
const {questionTypeIndex, topicIndex, tagsIndex, option1Index, option2Index, option3Index, option4Index, option5Index, option6Index, answerIndex } = indexHeader;
|
||||
if (questionTypeIndex || questionTypeIndex === 0) {
|
||||
dataList[questionTypeIndex].forEach((item, index) => {
|
||||
if (item && item !== '题型(必填)') {
|
||||
if (item && item !== '题型(必填)' && index > 2) {
|
||||
const param = {
|
||||
type: questionTypeMap[item],
|
||||
topic: dataList[topicIndex][index],
|
||||
tags: dataList[tagsIndex][index],
|
||||
tags: dataList[tagsIndex][index] ? dataList[tagsIndex][index].replace(/\s+/g, ',') : '',
|
||||
optionList: []
|
||||
};
|
||||
if (param.type === 'fill') {
|
||||
@ -335,11 +336,51 @@ export default {
|
||||
param.optionList.push({content:dataList[option6Index][index], correct: dataList[answerIndex][index].includes('F')});
|
||||
}
|
||||
}
|
||||
param.id = questionList.length;
|
||||
// param.id = questionList.length;
|
||||
questionList.push(param);
|
||||
|
||||
if (!param.type || !param.topic || !dataList[option1Index][index] || !dataList[option2Index][index] || !dataList[answerIndex][index]) {
|
||||
errRow.push(index + 1);
|
||||
}
|
||||
if (param.type === 'judge') {
|
||||
const arr = ['√', '正确', '×', '错误'];
|
||||
const asJudge = ['A', 'B'];
|
||||
if (!arr.includes(dataList[option1Index][index]) || !arr.includes(dataList[option2Index][index]) || !asJudge.includes(dataList[answerIndex][index])) {
|
||||
if (!errRow.includes(index + 1)) {
|
||||
errRow.push(index + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
const asList = ['A', 'B', 'C', 'D', 'E', 'F'];
|
||||
if (param.type === 'select') {
|
||||
if (!asList.includes(dataList[answerIndex][index])) {
|
||||
if (!errRow.includes(index + 1)) {
|
||||
errRow.push(index + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (param.type === 'multi') {
|
||||
if (dataList[answerIndex][index]) {
|
||||
const list = dataList[answerIndex][index].split('');
|
||||
const sortNew = list.sort(function(a, b) {
|
||||
return a.localeCompare(b);
|
||||
});
|
||||
const fArr = sortNew.filter((item, ii) => {
|
||||
return !asList.includes(item) || item == sortNew[ii + 1];
|
||||
});
|
||||
if (!errRow.includes(index + 1) && fArr.length) {
|
||||
errRow.push(index + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
errInfo = errRow.join(',');
|
||||
if (errInfo) {
|
||||
const error = `第${errInfo}行,数据错误,请检查!`;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
that.$store.dispatch('race/setPreTheoryData', questionList).then(() => {
|
||||
that.$router.push({ path: `/teaching/preTheoryImport`});
|
||||
@ -347,6 +388,13 @@ export default {
|
||||
that.$message.error('导入题库失败!');
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
that.$message.warning('导入错误!' + e);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
reader.onerror = function (e) {
|
||||
throw e;
|
||||
};
|
||||
if (that.rABS) {
|
||||
reader.readAsArrayBuffer(file);
|
||||
@ -354,7 +402,7 @@ export default {
|
||||
reader.readAsBinaryString(file);
|
||||
}
|
||||
}
|
||||
}, 200);
|
||||
// }, 200);
|
||||
} catch (e) {
|
||||
this.$message.error('请根据下载模板导入题目!');
|
||||
}
|
||||
@ -386,7 +434,7 @@ export default {
|
||||
exportTemplate() {
|
||||
const wb = XLSX.utils.book_new();
|
||||
const data1 = [{A: '理论试题导入模板', B: '', C:'', D:'', E:'', F: '', G: '', H: '', I: '', J: '', K: ''}];
|
||||
const data2 = [{A: '说明:1、本表表头(第一行到第三行)内容不能修改删除;\n 2、支持批量导入的题型:单选题,多选题,判断题,题型不能自定义,只能按照表格提供的进行录入;\n 3、【判断题】在选项A中可填写√ 或正确,选项B中填写× 或错误,答案填写A或B\n 4、【分类】多个分类项使用空格隔开', B: '', C:'', D:'', E:'', F: '', G: '', H: '', I: '', J: '', K: ''}];
|
||||
const data2 = [{A: '说明:1、本表表头(第一行到第三行)内容不能修改删除;\n 2、支持批量导入的题型:单选题,多选题,判断题,题型不能自定义,只能按照表格提供的进行录入;\n 3、【判断题】在选项A中可填写√ 或正确,选项B中填写× 或错误,答案填写A或B\n 4、【标签】多个标签项使用空格隔开', B: '', C:'', D:'', E:'', F: '', G: '', H: '', I: '', J: '', K: ''}];
|
||||
const data3 = [{A: '序号', B: '题干(必填)', C:'题型(必填)', D:'选项A(必填)', E:'选项B(必填)', F: '选项C', G: '选项D', H: '选项E', I: '选项F', J: '正确答案(必填)', K: '标签'}];
|
||||
const data = [...data1, ...data2, ...data3];
|
||||
const mapType = {
|
||||
@ -421,7 +469,7 @@ export default {
|
||||
H: item.optionList[4] ? item.optionList[4].content : '',
|
||||
I: item.optionList[5] ? item.optionList[5].content : '',
|
||||
J: as,
|
||||
K: item.tags
|
||||
K: item.tags ? item.tags.replace(',', ' ') : ''
|
||||
};
|
||||
data.push(obj);
|
||||
});
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user