Merge branch 'test_dispaly' of https://git.code.tencent.com/lian-cbtc/jl-client into test_dispaly
This commit is contained in:
commit
8dbc06409e
@ -83,3 +83,11 @@ export function testAnswer(questionId, data) {
|
||||
data
|
||||
});
|
||||
}
|
||||
|
||||
// 清空题库
|
||||
export function clearBank() {
|
||||
return request({
|
||||
url: `/api/question/org/clear`,
|
||||
method: 'get'
|
||||
});
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
<script>
|
||||
// import { UrlConfig } from '@/scripts/ConstDic';
|
||||
import { listQuestionPage, deleteQuestion, getLabelList, listQuestionAll } from '@/api/questionBank.js';
|
||||
import { listQuestionPage, deleteQuestion, getLabelList, listQuestionAll, clearBank } from '@/api/questionBank.js';
|
||||
import DialogDetail from './dialog-detail';
|
||||
import PreviewAnswer from './previewAnswer';
|
||||
import { convertSheetToList } from '@/jmapNew/theme/parser/util.js';
|
||||
@ -33,7 +33,7 @@ export default {
|
||||
queryForm: {
|
||||
reset: true,
|
||||
labelWidth: '80px',
|
||||
leftSpan: 17,
|
||||
leftSpan: 16,
|
||||
beforeQuery: this.beforeQuery,
|
||||
queryObject: {
|
||||
type: {
|
||||
@ -135,8 +135,9 @@ export default {
|
||||
{ text: '添 加', handler: this.doCreate },
|
||||
{ text: '导 入', fileType: 'file', handler: this.importQuestionBank },
|
||||
// { text: '试卷规则管理', handler: this.questionsRuleManage},
|
||||
// { text: '导出', handler: this.exportTemplate}
|
||||
{ text: '导出模板', handler: this.downloadTemplate}
|
||||
// { text: '导出', handler: this.exportTemplate},
|
||||
{ text: '导出模板', handler: this.downloadTemplate},
|
||||
{ text: '清空题库', type:'danger', handler: this.clearBank}
|
||||
]
|
||||
}
|
||||
};
|
||||
@ -249,11 +250,12 @@ export default {
|
||||
};
|
||||
if (file) {
|
||||
try {
|
||||
setTimeout(() => {
|
||||
const that = this;
|
||||
const reader = new FileReader();
|
||||
if (reader) {
|
||||
reader.onload = function (e) {
|
||||
// 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 +271,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 +337,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,14 +389,21 @@ export default {
|
||||
that.$message.error('导入题库失败!');
|
||||
});
|
||||
}
|
||||
};
|
||||
if (that.rABS) {
|
||||
reader.readAsArrayBuffer(file);
|
||||
} else {
|
||||
reader.readAsBinaryString(file);
|
||||
} catch (e) {
|
||||
that.$message.warning('导入错误!' + e);
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
reader.onerror = function (e) {
|
||||
throw e;
|
||||
};
|
||||
if (that.rABS) {
|
||||
reader.readAsArrayBuffer(file);
|
||||
} else {
|
||||
reader.readAsBinaryString(file);
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
// }, 200);
|
||||
} catch (e) {
|
||||
this.$message.error('请根据下载模板导入题目!');
|
||||
}
|
||||
@ -370,6 +419,19 @@ export default {
|
||||
// this.$router.push({ path: `/system/questionsRuleManage`});
|
||||
this.$router.push({ path: `/teaching/questionsRuleManage`});
|
||||
},
|
||||
clearBank() {
|
||||
this.$confirm('慎重!本操作可清空所有题库数据,是否继续?', '提 示', {
|
||||
confirmButtonText: '确 定',
|
||||
cancelButtonText: '取 消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
clearBank().then(resp => {
|
||||
this.reloadTable();
|
||||
}).catch(error => {
|
||||
this.$message.error(`清空题库数据失败: ${error.message}`);
|
||||
});
|
||||
}).catch( () => { });
|
||||
},
|
||||
downloadTemplate() {
|
||||
// 创建隐藏的可下载链接
|
||||
var eleLink = document.createElement('a');
|
||||
@ -386,7 +448,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 +483,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);
|
||||
});
|
||||
|
@ -153,6 +153,43 @@ export default {
|
||||
this.handlePreDataPaging();
|
||||
},
|
||||
doSave() {
|
||||
const nameList = [];
|
||||
const repetList = [];
|
||||
const mapType = {
|
||||
select: '单选题',
|
||||
multi: '多选题',
|
||||
judge: '判断题',
|
||||
fill: '填空题',
|
||||
answer: '问答题'
|
||||
};
|
||||
this.$store.state.race.preTheoryData.forEach(item => {
|
||||
const strName = `【${mapType[item.type]}】${item.topic}`;
|
||||
if (nameList.includes(strName)) {
|
||||
repetList.push(strName);
|
||||
} else {
|
||||
nameList.push(strName);
|
||||
}
|
||||
});
|
||||
if (repetList.length) {
|
||||
const test = `以下题目重复,是否继续提交?`;
|
||||
const messageData = [test];
|
||||
const h = this.$createElement;
|
||||
repetList.forEach(item => {
|
||||
messageData.push(h('p', null, item));
|
||||
});
|
||||
this.$confirm('有题目重复,是否继续提交?', '提 示', {
|
||||
message: h('div', null, messageData),
|
||||
confirmButtonText: '确 定',
|
||||
cancelButtonText: '取 消',
|
||||
type: 'warning'
|
||||
}).then(() => {
|
||||
this.submitData();
|
||||
}).catch( () => {});
|
||||
} else {
|
||||
this.submitData();
|
||||
}
|
||||
},
|
||||
submitData() {
|
||||
this.loading = true;
|
||||
let selectNum = 0;
|
||||
let judgeNum = 0;
|
||||
@ -178,7 +215,6 @@ export default {
|
||||
break;
|
||||
}
|
||||
});
|
||||
// importQuestionBand(this.$store.state.race.preTheoryData, this.companyId).then(resp => {
|
||||
importQuestion(this.$store.state.race.preTheoryData).then(resp => {
|
||||
this.$store.dispatch('race/setPreTheoryData', []);
|
||||
// this.$message.success('导入题库成功!');
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user