理论题目导入调整
This commit is contained in:
parent
daa05eb67b
commit
0d6f6dda1c
@ -135,7 +135,7 @@ export default {
|
|||||||
{ text: '添 加', handler: this.doCreate },
|
{ text: '添 加', handler: this.doCreate },
|
||||||
{ text: '导 入', fileType: 'file', handler: this.importQuestionBank },
|
{ text: '导 入', fileType: 'file', handler: this.importQuestionBank },
|
||||||
// { text: '试卷规则管理', handler: this.questionsRuleManage},
|
// { text: '试卷规则管理', handler: this.questionsRuleManage},
|
||||||
// { text: '导出', handler: this.exportTemplate}
|
// { text: '导出', handler: this.exportTemplate},
|
||||||
{ text: '导出模板', handler: this.downloadTemplate}
|
{ text: '导出模板', handler: this.downloadTemplate}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@ -249,11 +249,12 @@ export default {
|
|||||||
};
|
};
|
||||||
if (file) {
|
if (file) {
|
||||||
try {
|
try {
|
||||||
setTimeout(() => {
|
// setTimeout(() => {
|
||||||
const that = this;
|
const that = this;
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
if (reader) {
|
if (reader) {
|
||||||
reader.onload = function (e) {
|
reader.onload = function (e) {
|
||||||
|
try {
|
||||||
let wb;
|
let wb;
|
||||||
const data = e.target.result;
|
const data = e.target.result;
|
||||||
if (that.rABS) {
|
if (that.rABS) {
|
||||||
@ -269,46 +270,46 @@ export default {
|
|||||||
if (wb && wb.Sheets) {
|
if (wb && wb.Sheets) {
|
||||||
for (const index in wb.Sheets) {
|
for (const index in wb.Sheets) {
|
||||||
const dataList = convertSheetToList(wb.Sheets[index], true);
|
const dataList = convertSheetToList(wb.Sheets[index], true);
|
||||||
let questionTypeIndex;
|
const objHeader = {
|
||||||
let topicIndex;
|
questionTypeIndex: '题型(必填)',
|
||||||
let tagsIndex;
|
topicIndex: '题干(必填)',
|
||||||
let option1Index;
|
tagsIndex: '标签',
|
||||||
let option2Index;
|
option1Index: '选项A(必填)',
|
||||||
let option3Index;
|
option2Index: '选项B(必填)',
|
||||||
let option4Index;
|
option3Index: '选项C',
|
||||||
let option5Index;
|
option4Index: '选项D',
|
||||||
let option6Index;
|
option5Index: '选项E',
|
||||||
let answerIndex;
|
option6Index: '选项F',
|
||||||
|
answerIndex: '正确答案(必填)'
|
||||||
|
};
|
||||||
|
const indexHeader = JSON.parse(JSON.stringify(objHeader));
|
||||||
dataList.forEach((item, ii) => {
|
dataList.forEach((item, ii) => {
|
||||||
if (!item[0] && !item[1] && item[2] === '题型(必填)') {
|
Object.keys(objHeader).forEach(key => {
|
||||||
questionTypeIndex = ii;
|
if (!item[0] && !item[1] && item[2] === objHeader[key]) {
|
||||||
} else if (!item[0] && !item[1] && item[2] === '题干(必填)') {
|
indexHeader[key] = ii;
|
||||||
topicIndex = ii;
|
}
|
||||||
} else if (!item[0] && !item[1] && item[2] === '标签') {
|
});
|
||||||
tagsIndex = ii;
|
});
|
||||||
} else if (!item[0] && !item[1] && item[2] === '选项A(必填)') {
|
const errHeader = [];
|
||||||
option1Index = ii;
|
Object.keys(objHeader).forEach(key => {
|
||||||
} else if (!item[0] && !item[1] && item[2] === '选项B(必填)') {
|
if (typeof indexHeader[key] != 'number') {
|
||||||
option2Index = ii;
|
errHeader.push(objHeader[key]);
|
||||||
} 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;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
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) {
|
if (questionTypeIndex || questionTypeIndex === 0) {
|
||||||
dataList[questionTypeIndex].forEach((item, index) => {
|
dataList[questionTypeIndex].forEach((item, index) => {
|
||||||
if (item && item !== '题型(必填)') {
|
if (item && item !== '题型(必填)' && index > 2) {
|
||||||
const param = {
|
const param = {
|
||||||
type: questionTypeMap[item],
|
type: questionTypeMap[item],
|
||||||
topic: dataList[topicIndex][index],
|
topic: dataList[topicIndex][index],
|
||||||
tags: dataList[tagsIndex][index],
|
tags: dataList[tagsIndex][index] ? dataList[tagsIndex][index].replace(/\s+/g, ',') : '',
|
||||||
optionList: []
|
optionList: []
|
||||||
};
|
};
|
||||||
if (param.type === 'fill') {
|
if (param.type === 'fill') {
|
||||||
@ -335,11 +336,51 @@ export default {
|
|||||||
param.optionList.push({content:dataList[option6Index][index], correct: dataList[answerIndex][index].includes('F')});
|
param.optionList.push({content:dataList[option6Index][index], correct: dataList[answerIndex][index].includes('F')});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
param.id = questionList.length;
|
// param.id = questionList.length;
|
||||||
questionList.push(param);
|
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.$store.dispatch('race/setPreTheoryData', questionList).then(() => {
|
||||||
that.$router.push({ path: `/teaching/preTheoryImport`});
|
that.$router.push({ path: `/teaching/preTheoryImport`});
|
||||||
@ -347,14 +388,21 @@ export default {
|
|||||||
that.$message.error('导入题库失败!');
|
that.$message.error('导入题库失败!');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
} catch (e) {
|
||||||
if (that.rABS) {
|
that.$message.warning('导入错误!' + e);
|
||||||
reader.readAsArrayBuffer(file);
|
throw e;
|
||||||
} else {
|
|
||||||
reader.readAsBinaryString(file);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
reader.onerror = function (e) {
|
||||||
|
throw e;
|
||||||
|
};
|
||||||
|
if (that.rABS) {
|
||||||
|
reader.readAsArrayBuffer(file);
|
||||||
|
} else {
|
||||||
|
reader.readAsBinaryString(file);
|
||||||
}
|
}
|
||||||
}, 200);
|
}
|
||||||
|
// }, 200);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.$message.error('请根据下载模板导入题目!');
|
this.$message.error('请根据下载模板导入题目!');
|
||||||
}
|
}
|
||||||
@ -386,7 +434,7 @@ export default {
|
|||||||
exportTemplate() {
|
exportTemplate() {
|
||||||
const wb = XLSX.utils.book_new();
|
const wb = XLSX.utils.book_new();
|
||||||
const data1 = [{A: '理论试题导入模板', B: '', C:'', D:'', E:'', F: '', G: '', H: '', I: '', J: '', K: ''}];
|
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 data3 = [{A: '序号', B: '题干(必填)', C:'题型(必填)', D:'选项A(必填)', E:'选项B(必填)', F: '选项C', G: '选项D', H: '选项E', I: '选项F', J: '正确答案(必填)', K: '标签'}];
|
||||||
const data = [...data1, ...data2, ...data3];
|
const data = [...data1, ...data2, ...data3];
|
||||||
const mapType = {
|
const mapType = {
|
||||||
@ -421,7 +469,7 @@ export default {
|
|||||||
H: item.optionList[4] ? item.optionList[4].content : '',
|
H: item.optionList[4] ? item.optionList[4].content : '',
|
||||||
I: item.optionList[5] ? item.optionList[5].content : '',
|
I: item.optionList[5] ? item.optionList[5].content : '',
|
||||||
J: as,
|
J: as,
|
||||||
K: item.tags
|
K: item.tags ? item.tags.replace(',', ' ') : ''
|
||||||
};
|
};
|
||||||
data.push(obj);
|
data.push(obj);
|
||||||
});
|
});
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user