理论题目导入和导出功能
This commit is contained in:
parent
248661e0d7
commit
01f9a2abaa
@ -10,6 +10,14 @@ export function listQuestionPage(params) {
|
||||
});
|
||||
}
|
||||
|
||||
// 查询所有理论试题
|
||||
export function listQuestionAll() {
|
||||
return request({
|
||||
url: `/api/question/org`,
|
||||
method: 'get'
|
||||
});
|
||||
}
|
||||
|
||||
// 标签列表
|
||||
export function getLabelList() {
|
||||
return request({
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
<script>
|
||||
// import { UrlConfig } from '@/scripts/ConstDic';
|
||||
import { listQuestionPage, deleteQuestion, getLabelList } from '@/api/questionBank.js';
|
||||
import { listQuestionPage, deleteQuestion, getLabelList, listQuestionAll } from '@/api/questionBank.js';
|
||||
import DialogDetail from './dialog-detail';
|
||||
import PreviewAnswer from './previewAnswer';
|
||||
import { convertSheetToList } from '@/jmapNew/theme/parser/util.js';
|
||||
@ -134,7 +134,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}
|
||||
]
|
||||
}
|
||||
};
|
||||
@ -239,11 +239,11 @@ export default {
|
||||
},
|
||||
handleImport(file) {
|
||||
const questionTypeMap = {
|
||||
'单选': 'select',
|
||||
'多选': 'multi',
|
||||
'判断': 'judge',
|
||||
'填空': 'fill',
|
||||
'问答': 'answer'
|
||||
'单选题': 'select',
|
||||
'多选题': 'multi',
|
||||
'判断题': 'judge',
|
||||
'填空题': 'fill',
|
||||
'问答题': 'answer'
|
||||
};
|
||||
if (file) {
|
||||
try {
|
||||
@ -274,29 +274,35 @@ export default {
|
||||
let option2Index;
|
||||
let option3Index;
|
||||
let option4Index;
|
||||
let option5Index;
|
||||
let option6Index;
|
||||
let answerIndex;
|
||||
dataList.forEach((item, ii) => {
|
||||
if (item[0] === '题型') {
|
||||
if (!item[0] && !item[1] && item[2] === '题型(必填)') {
|
||||
questionTypeIndex = ii;
|
||||
} else if (item[0] === '题目') {
|
||||
} else if (!item[0] && !item[1] && item[2] === '题干(必填)') {
|
||||
topicIndex = ii;
|
||||
} else if (item[0] === '标签') {
|
||||
} else if (!item[0] && !item[1] && item[2] === '标签') {
|
||||
tagsIndex = ii;
|
||||
} else if ( item[0] === '选项' && item[1] === 'A') {
|
||||
} else if (!item[0] && !item[1] && item[2] === '选项A(必填)') {
|
||||
option1Index = ii;
|
||||
} else if (!item[0] && item[1] === 'B') {
|
||||
} else if (!item[0] && !item[1] && item[2] === '选项B(必填)') {
|
||||
option2Index = ii;
|
||||
} else if (!item[0] && item[1] === 'C') {
|
||||
} else if (!item[0] && !item[1] && item[2] === '选项C') {
|
||||
option3Index = ii;
|
||||
} else if (!item[0] && item[1] === 'D') {
|
||||
} else if (!item[0] && !item[1] && item[2] === '选项D') {
|
||||
option4Index = ii;
|
||||
} else if (item[0] === '答案') {
|
||||
} 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;
|
||||
}
|
||||
});
|
||||
if (questionTypeIndex || questionTypeIndex === 0) {
|
||||
dataList[questionTypeIndex].forEach((item, index) => {
|
||||
if (item && item !== '题型') {
|
||||
if (item && item !== '题型(必填)') {
|
||||
const param = {
|
||||
type: questionTypeMap[item],
|
||||
topic: dataList[topicIndex][index],
|
||||
@ -320,6 +326,12 @@ export default {
|
||||
if (dataList[option4Index][index]) {
|
||||
param.optionList.push({content:dataList[option4Index][index], correct: dataList[answerIndex][index].includes('D')});
|
||||
}
|
||||
if (dataList[option5Index][index]) {
|
||||
param.optionList.push({content:dataList[option5Index][index], correct: dataList[answerIndex][index].includes('E')});
|
||||
}
|
||||
if (dataList[option6Index][index]) {
|
||||
param.optionList.push({content:dataList[option6Index][index], correct: dataList[answerIndex][index].includes('F')});
|
||||
}
|
||||
}
|
||||
param.id = questionList.length;
|
||||
questionList.push(param);
|
||||
@ -358,56 +370,117 @@ export default {
|
||||
},
|
||||
exportTemplate() {
|
||||
const wb = XLSX.utils.book_new();
|
||||
const data1 = [{A: '序号', B: '题型', C:'题目', D:'标签', E:'答案', F: '选项', G: '', H: '', I: ''}];
|
||||
const data2 = [{A: '', B: '', C:'', D:'', E: '', F: 'A', G: 'B', H: 'C', I: 'D'}];
|
||||
const data3 = [{A: '1', B: '判断', C:'题目一', D:'信号机,道岔', E:'√', F: '', G: '', H: '', I: ''}];
|
||||
const data4 = [{A: '2', B: '判断', C:'题目二', D:'重点', E:'×', F: '', G: '', H: '', I: ''}];
|
||||
const data5 = [{A: '3', B: '单选', C:'题目三', D:'测试,检验', E:'A', F: '选项A', G: '选项B', H: '选项C', I: '选项D'}];
|
||||
const data6 = [{A: '4', B: '多选', C:'题目四', D:'', E:'ABCD', F: '选项A', G: '选项B', H: '选项C', I: '选项D'}];
|
||||
// const data7 = [{A: '5', B: '填空', C:'题目五', D:'第一空答案&&第二空答案&&第三空答案', E: '', F: '', G: '', H: ''}];
|
||||
// const data8 = [{A: '6', B: '问答', C:'题目六', D:'问答题答案', E: '', F: '', G: '', H: '问答题答案'}];
|
||||
// const data = [...data1, ...data2, ...data3, ...data4, ...data5, ...data6, ...data7, ...data8];
|
||||
const data = [...data1, ...data2, ...data3, ...data4, ...data5, ...data6];
|
||||
const ws = XLSX.utils.json_to_sheet(data, {skipHeader:true});
|
||||
ws['!merges'] = [
|
||||
{
|
||||
s: {c: 5, r: 0},
|
||||
e: {c: 8, r: 0}
|
||||
},
|
||||
{
|
||||
s: {c: 0, r: 0},
|
||||
e: {c: 0, r: 1}
|
||||
},
|
||||
{
|
||||
s: {c: 1, r: 0},
|
||||
e: {c: 1, r: 1}
|
||||
},
|
||||
{
|
||||
s: {c: 2, r: 0},
|
||||
e: {c: 2, r: 1}
|
||||
},
|
||||
{
|
||||
s: {c: 3, r: 0},
|
||||
e: {c: 3, r: 1}
|
||||
},
|
||||
{
|
||||
s: {c: 4, r: 0},
|
||||
e: {c: 4, r: 1}
|
||||
}
|
||||
];
|
||||
ws['!cols'] = [
|
||||
{width: 10},
|
||||
{width: 10},
|
||||
{width: 50},
|
||||
{width: 15},
|
||||
{width: 15},
|
||||
{width: 15},
|
||||
{width: 15},
|
||||
{width: 15},
|
||||
{width: 15}
|
||||
];
|
||||
XLSX.utils.book_append_sheet(wb, ws, 'file');
|
||||
XLSX.writeFile(wb, '题库模板' + '.xlsx');
|
||||
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 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 = {
|
||||
select: '单选题',
|
||||
multi: '多选题',
|
||||
judge: '判断题',
|
||||
fill: '填空题',
|
||||
answer: '问答题'
|
||||
};
|
||||
listQuestionAll().then(res => {
|
||||
console.log(res, '---res===');
|
||||
res.data.forEach((item, index) => {
|
||||
let as = item.answer;
|
||||
const arr = ['select', 'multi', 'judge'];
|
||||
if (arr.includes(item.type)) {
|
||||
as = [];
|
||||
item.optionList.forEach((it, ind) => {
|
||||
if (it.correct) {
|
||||
as.push(this.$asc2chart(ind + 65));
|
||||
}
|
||||
});
|
||||
as = as.join(',');
|
||||
}
|
||||
const obj = {
|
||||
A: index + 1,
|
||||
B: item.topic,
|
||||
C: mapType[item.type] || '',
|
||||
D: item.optionList[0].content,
|
||||
E: item.optionList[1].content,
|
||||
F: item.optionList[2] ? item.optionList[2].content : '',
|
||||
G: item.optionList[3] ? item.optionList[3].content : '',
|
||||
H: item.optionList[4] ? item.optionList[4].content : '',
|
||||
I: item.optionList[5] ? item.optionList[5].content : '',
|
||||
J: as,
|
||||
K: item.tags
|
||||
};
|
||||
data.push(obj);
|
||||
});
|
||||
const ws = XLSX.utils.json_to_sheet(data, {skipHeader:true});
|
||||
ws['!merges'] = [
|
||||
{
|
||||
s: {c: 0, r: 0},
|
||||
e: {c: 10, r: 0}
|
||||
},
|
||||
{
|
||||
s: {c: 0, r: 1},
|
||||
e: {c: 10, r: 1}
|
||||
},
|
||||
{
|
||||
s: {c: 0, r: 2},
|
||||
e: {c: 0, r: 2}
|
||||
},
|
||||
{
|
||||
s: {c: 1, r: 2},
|
||||
e: {c: 1, r: 2}
|
||||
},
|
||||
{
|
||||
s: {c: 2, r: 2},
|
||||
e: {c: 2, r: 2}
|
||||
},
|
||||
{
|
||||
s: {c: 3, r: 2},
|
||||
e: {c: 3, r: 2}
|
||||
},
|
||||
{
|
||||
s: {c: 4, r: 2},
|
||||
e: {c: 4, r: 2}
|
||||
},
|
||||
{
|
||||
s: {c: 5, r: 2},
|
||||
e: {c: 5, r: 2}
|
||||
},
|
||||
{
|
||||
s: {c: 6, r: 2},
|
||||
e: {c: 6, r: 2}
|
||||
},
|
||||
{
|
||||
s: {c: 7, r: 2},
|
||||
e: {c: 7, r: 2}
|
||||
},
|
||||
{
|
||||
s: {c: 8, r: 2},
|
||||
e: {c: 8, r: 2}
|
||||
},
|
||||
{
|
||||
s: {c: 9, r: 2},
|
||||
e: {c: 9, r: 2}
|
||||
},
|
||||
{
|
||||
s: {c: 10, r: 2},
|
||||
e: {c: 10, r: 2}
|
||||
}
|
||||
];
|
||||
ws['!cols'] = [
|
||||
{width: 10},
|
||||
{width: 50},
|
||||
{width: 15},
|
||||
{width: 15},
|
||||
{width: 15},
|
||||
{width: 15},
|
||||
{width: 15},
|
||||
{width: 15},
|
||||
{width: 15},
|
||||
{width: 15},
|
||||
{width: 15}
|
||||
];
|
||||
XLSX.utils.book_append_sheet(wb, ws, 'file');
|
||||
XLSX.writeFile(wb, '题库模板' + '.xlsx');
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -7,8 +7,9 @@
|
||||
</template>
|
||||
<template v-if="type=='judge'">
|
||||
<el-radio-group v-model="active" @change="onChange">
|
||||
<el-radio :label="0"> √ </el-radio>
|
||||
<el-radio :label="1"> × </el-radio>
|
||||
<!-- <el-radio :label="0"> √ </el-radio>
|
||||
<el-radio :label="1"> × </el-radio> -->
|
||||
<el-radio v-for="(el,i) in optionList" :key="i" :label="i"> {{ el.content }} </el-radio>
|
||||
</el-radio-group>
|
||||
</template>
|
||||
<template v-if="type=='multi'">
|
||||
|
@ -13,7 +13,11 @@
|
||||
</div>
|
||||
</div>
|
||||
<el-table :data="tableData" border style="width: 100%">
|
||||
<el-table-column prop="topic" label="题目" />
|
||||
<el-table-column prop="topic" label="题目">
|
||||
<template slot-scope="scope">
|
||||
<div v-html="scope.row.topic" />
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="tags" label="标签" width="200">
|
||||
<template slot-scope="scope">
|
||||
<el-tag v-for="item in getTagesArr(scope.row.tags)" :key="item" type="primary" disable-transitions style="margin-right: 10px;">{{ item }}</el-tag>
|
||||
|
Loading…
Reference in New Issue
Block a user