2020-05-26 15:59:11 +08:00
|
|
|
|
<template>
|
|
|
|
|
<div>
|
|
|
|
|
<query-list-page ref="user" :pager-config="pagerConfig" :query-form="queryForm" :query-list="queryList" />
|
|
|
|
|
<dialog-detail ref="detail" />
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import { UrlConfig } from '@/scripts/ConstDic';
|
2020-05-27 14:13:47 +08:00
|
|
|
|
import { listQuestionPage, deleteQuestion } from '@/api/questionBank.js';
|
2020-05-26 15:59:11 +08:00
|
|
|
|
import DialogDetail from './dialog-detail';
|
2020-09-22 16:45:03 +08:00
|
|
|
|
import { convertSheetToList } from '@/utils/runPlan';
|
2020-10-27 10:43:55 +08:00
|
|
|
|
import { getCompanyList } from '@/api/company';
|
2020-09-22 16:45:03 +08:00
|
|
|
|
import XLSX from 'xlsx';
|
2020-05-26 15:59:11 +08:00
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
components: {
|
|
|
|
|
DialogDetail
|
|
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2020-10-27 10:43:55 +08:00
|
|
|
|
companyList: [],
|
2020-05-26 15:59:11 +08:00
|
|
|
|
pagerConfig: {
|
|
|
|
|
pageSize: 'pageSize',
|
|
|
|
|
pageIndex: 'pageNum'
|
|
|
|
|
},
|
|
|
|
|
queryForm: {
|
|
|
|
|
reset: true,
|
|
|
|
|
labelWidth: '80px',
|
2020-10-27 17:00:00 +08:00
|
|
|
|
leftSpan: 16,
|
2020-05-26 15:59:11 +08:00
|
|
|
|
queryObject: {
|
|
|
|
|
type: {
|
|
|
|
|
type: 'select',
|
|
|
|
|
label: '类 型',
|
|
|
|
|
config: {
|
|
|
|
|
data: this.$ConstSelect.QuestionTypeList
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
topic: {
|
|
|
|
|
type: 'text',
|
|
|
|
|
label: '题 目'
|
2020-10-27 10:43:55 +08:00
|
|
|
|
},
|
|
|
|
|
companyId: {
|
|
|
|
|
type: 'select',
|
|
|
|
|
label: '单位',
|
|
|
|
|
config: {
|
|
|
|
|
data: []
|
|
|
|
|
}
|
2020-05-26 15:59:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
queryList: {
|
|
|
|
|
query: listQuestionPage,
|
|
|
|
|
selectCheckShow: false,
|
|
|
|
|
indexShow: true,
|
|
|
|
|
columns: [
|
2020-05-26 18:12:42 +08:00
|
|
|
|
{
|
|
|
|
|
title: '题 目',
|
|
|
|
|
prop: 'topic'
|
|
|
|
|
},
|
2020-05-26 15:59:11 +08:00
|
|
|
|
{
|
|
|
|
|
title: '类 型',
|
|
|
|
|
prop: 'type',
|
|
|
|
|
type: 'tag',
|
|
|
|
|
width: '120',
|
|
|
|
|
columnValue: (row) => { return this.$ConstSelect.translate(row.type, 'QuestionTypeList'); },
|
|
|
|
|
tagType: (row) => {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: '答 案',
|
|
|
|
|
prop: 'answer',
|
|
|
|
|
type: 'tagMore',
|
2020-10-20 16:48:28 +08:00
|
|
|
|
width: '200',
|
2020-05-26 15:59:11 +08:00
|
|
|
|
columnValue: (row) => { return this.answerTags(row); },
|
|
|
|
|
tagType: (row) => {
|
|
|
|
|
return '';
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-05-27 09:09:29 +08:00
|
|
|
|
// {
|
|
|
|
|
// title: '创建人',
|
|
|
|
|
// prop: 'createUserName',
|
|
|
|
|
// width: '100'
|
|
|
|
|
// },
|
2020-05-26 15:59:11 +08:00
|
|
|
|
{
|
|
|
|
|
type: 'button',
|
|
|
|
|
title: '操 作',
|
2020-10-20 16:48:28 +08:00
|
|
|
|
width: '320',
|
2020-05-26 15:59:11 +08:00
|
|
|
|
buttons: [
|
|
|
|
|
{
|
2020-05-27 14:13:47 +08:00
|
|
|
|
name: '编辑',
|
|
|
|
|
handleClick: this.edit
|
2020-05-26 15:59:11 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: '删 除',
|
|
|
|
|
handleClick: this.doDelete,
|
2020-05-26 18:30:17 +08:00
|
|
|
|
// showControl: (row) => { return row.createUserId == this.userId; },
|
2020-05-26 15:59:11 +08:00
|
|
|
|
type: 'danger'
|
|
|
|
|
},
|
|
|
|
|
{
|
2020-05-26 16:01:41 +08:00
|
|
|
|
name: '预 览',
|
2020-05-26 18:30:17 +08:00
|
|
|
|
handleClick: this.doDetail
|
2020-05-26 15:59:11 +08:00
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
actions: [
|
2020-09-22 16:45:03 +08:00
|
|
|
|
{ text: '添 加', handler: this.doCreate },
|
2020-10-20 16:48:28 +08:00
|
|
|
|
{ text: '导 入', fileType: 'file', handler: this.importQuestionBank },
|
2020-10-27 10:43:55 +08:00
|
|
|
|
{ text: '出题规则管理', handler: this.questionsRuleManage},
|
|
|
|
|
{ text: '模板导出', handler: this.exportTemplate}
|
2020-05-26 15:59:11 +08:00
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
userId() {
|
|
|
|
|
return this.$store.state.user.id;
|
|
|
|
|
}
|
|
|
|
|
},
|
2020-10-27 10:43:55 +08:00
|
|
|
|
mounted() {
|
|
|
|
|
this.companyList = [];
|
|
|
|
|
getCompanyList().then(resp => {
|
|
|
|
|
resp.data.forEach(item => {
|
|
|
|
|
this.queryForm.queryObject.companyId.config.data.push({ value: item.id, label: item.name });
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
2020-05-26 15:59:11 +08:00
|
|
|
|
methods: {
|
|
|
|
|
doCreate() {
|
|
|
|
|
this.$router.push({path: `${UrlConfig.bank.questionCreate}`});
|
|
|
|
|
},
|
|
|
|
|
|
2020-05-27 14:13:47 +08:00
|
|
|
|
edit(index, row) {
|
2020-05-26 15:59:11 +08:00
|
|
|
|
this.$router.push({path: `${UrlConfig.bank.questionUpdate}/${row.id}`});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
doDelete(index, row) {
|
|
|
|
|
this.$confirm('删除试题,是否继续?', '提 示', {
|
|
|
|
|
confirmButtonText: '确 定',
|
|
|
|
|
cancelButtonText: '取 消',
|
|
|
|
|
type: 'warning'
|
|
|
|
|
}).then(() => {
|
2020-05-26 18:12:42 +08:00
|
|
|
|
deleteQuestion(row.id).then(resp => {
|
|
|
|
|
this.reloadTable();
|
|
|
|
|
}).catch(error => {
|
|
|
|
|
this.$message.error(`删除试题失败: ${error.message}`);
|
|
|
|
|
});
|
2020-05-26 15:59:11 +08:00
|
|
|
|
}).catch( () => { });
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
doDetail(index, row) {
|
|
|
|
|
this.$refs.detail.doShow({index, row});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
answerTags(row) {
|
|
|
|
|
const answer = [];
|
|
|
|
|
row.optionList.forEach((el, i) => {
|
|
|
|
|
switch (row.type) {
|
|
|
|
|
case 'select':
|
|
|
|
|
if (el.correct) {
|
|
|
|
|
answer.push(this.$asc2chart(i + 65));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'judge':
|
|
|
|
|
if (el.correct) {
|
|
|
|
|
answer.push(el.content);
|
|
|
|
|
}
|
|
|
|
|
break;
|
2020-10-20 16:48:28 +08:00
|
|
|
|
case 'multi':
|
|
|
|
|
if (el.correct) {
|
|
|
|
|
answer.push(this.$asc2chart(i + 65));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 'fill':
|
|
|
|
|
answer.push(el.content);
|
|
|
|
|
break;
|
|
|
|
|
case 'answer':
|
|
|
|
|
answer.push(el.content);
|
|
|
|
|
break;
|
2020-05-26 15:59:11 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return answer;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
reloadTable() {
|
|
|
|
|
this.queryList.reload();
|
2020-09-22 16:45:03 +08:00
|
|
|
|
},
|
|
|
|
|
handleImport(file) {
|
|
|
|
|
const questionTypeMap = {
|
|
|
|
|
'单选': 'select',
|
|
|
|
|
'多选': 'multi',
|
2020-10-20 16:48:28 +08:00
|
|
|
|
'判断': 'judge',
|
|
|
|
|
'填空': 'fill',
|
|
|
|
|
'问答': 'answer'
|
2020-09-22 16:45:03 +08:00
|
|
|
|
};
|
|
|
|
|
if (file) {
|
2020-10-27 10:43:55 +08:00
|
|
|
|
try {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
const that = this;
|
|
|
|
|
const reader = new FileReader();
|
|
|
|
|
if (reader) {
|
|
|
|
|
reader.onload = function (e) {
|
|
|
|
|
let wb;
|
|
|
|
|
const data = e.target.result;
|
|
|
|
|
if (that.rABS) {
|
|
|
|
|
wb = XLSX.read(btoa(that.fixdata(data)), { // 手动转化
|
|
|
|
|
type: 'base64'
|
2020-09-22 16:45:03 +08:00
|
|
|
|
});
|
2020-10-27 10:43:55 +08:00
|
|
|
|
} else {
|
|
|
|
|
wb = XLSX.read(data, {
|
|
|
|
|
type: 'binary'
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
const questionList = [];
|
|
|
|
|
if (wb && wb.Sheets) {
|
|
|
|
|
for (const index in wb.Sheets) {
|
|
|
|
|
const dataList = convertSheetToList(wb.Sheets[index], true);
|
|
|
|
|
let questionTypeIndex;
|
|
|
|
|
let topicIndex;
|
|
|
|
|
let option1Index;
|
|
|
|
|
let option2Index;
|
|
|
|
|
let option3Index;
|
|
|
|
|
let option4Index;
|
|
|
|
|
let answerIndex;
|
|
|
|
|
dataList.forEach((item, index) => {
|
|
|
|
|
if (item[0] === '题型') {
|
|
|
|
|
questionTypeIndex = index;
|
|
|
|
|
} else if (item[0] === '题目') {
|
|
|
|
|
topicIndex = index;
|
|
|
|
|
} else if ( item[0] === '选项' && item[1] === 'A') {
|
|
|
|
|
option1Index = index;
|
|
|
|
|
} else if (!item[0] && item[1] === 'B') {
|
|
|
|
|
option2Index = index;
|
|
|
|
|
} else if (!item[0] && item[1] === 'C') {
|
|
|
|
|
option3Index = index;
|
|
|
|
|
} else if (!item[0] && item[1] === 'D') {
|
|
|
|
|
option4Index = index;
|
|
|
|
|
} else if (item[0] === '答案') {
|
|
|
|
|
answerIndex = index;
|
2020-09-22 16:45:03 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2020-10-27 10:43:55 +08:00
|
|
|
|
if (questionTypeIndex || questionTypeIndex === 0) {
|
|
|
|
|
dataList[questionTypeIndex].forEach((item, index) => {
|
|
|
|
|
if (item && item !== '题型') {
|
|
|
|
|
const param = {
|
|
|
|
|
type: questionTypeMap[item],
|
|
|
|
|
topic: dataList[topicIndex][index],
|
|
|
|
|
optionList: []
|
|
|
|
|
};
|
|
|
|
|
if (param.type === 'fill') {
|
|
|
|
|
const answer = dataList[answerIndex][index];
|
|
|
|
|
const answerList = answer.split('&&');
|
|
|
|
|
answerList && answerList.forEach(item => {
|
|
|
|
|
param.optionList.push({content: item, correct: true});
|
|
|
|
|
});
|
|
|
|
|
} else if (param.type === 'answer') {
|
|
|
|
|
param.optionList.push({content: dataList[answerIndex][index]});
|
|
|
|
|
} else {
|
|
|
|
|
param.optionList.push({ content:dataList[option1Index][index] || '正确', correct: dataList[answerIndex][index].includes('A') || dataList[answerIndex][index] == '√' });
|
|
|
|
|
param.optionList.push({ content:dataList[option2Index][index] || '错误', correct: dataList[answerIndex][index].includes('B') || dataList[answerIndex][index] == '×' });
|
|
|
|
|
if (dataList[option3Index][index]) {
|
|
|
|
|
param.optionList.push({content:dataList[option3Index][index], correct: dataList[answerIndex][index].includes('C')});
|
|
|
|
|
}
|
|
|
|
|
if (dataList[option4Index][index]) {
|
|
|
|
|
param.optionList.push({content:dataList[option4Index][index], correct: dataList[answerIndex][index].includes('D')});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
questionList.push(param);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2020-09-22 16:45:03 +08:00
|
|
|
|
}
|
2020-10-27 10:43:55 +08:00
|
|
|
|
that.$store.dispatch('race/setPreTheoryData', questionList).then(() => {
|
|
|
|
|
that.$router.push({ path: `/system/preTheoryImport`});
|
|
|
|
|
}).catch((e) => {
|
|
|
|
|
that.$message.error('导入题库失败!');
|
|
|
|
|
});
|
|
|
|
|
// importQuestionBand(questionList, 'DRTS').then(resp => {
|
|
|
|
|
// this.$message.success('导入题库成功!');
|
|
|
|
|
// }).catch(()=>{
|
|
|
|
|
// this.$message.error('导入题库失败!');
|
|
|
|
|
// });
|
2020-09-22 16:45:03 +08:00
|
|
|
|
}
|
2020-10-27 10:43:55 +08:00
|
|
|
|
};
|
|
|
|
|
if (that.rABS) {
|
|
|
|
|
reader.readAsArrayBuffer(file);
|
|
|
|
|
} else {
|
|
|
|
|
reader.readAsBinaryString(file);
|
2020-09-22 16:45:03 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-27 10:43:55 +08:00
|
|
|
|
}, 200);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
this.$message.error('请根据下载模板导入题目!');
|
|
|
|
|
}
|
2020-09-22 16:45:03 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
importQuestionBank() {
|
|
|
|
|
const obj = document.getElementById('queryFormFilesInput');
|
|
|
|
|
if (!obj.files) return;
|
|
|
|
|
const f = obj.files[0];
|
|
|
|
|
this.handleImport(f);
|
2020-10-20 16:48:28 +08:00
|
|
|
|
},
|
|
|
|
|
questionsRuleManage() {
|
|
|
|
|
this.$router.push({ path: `/system/questionsRuleManage`});
|
2020-10-27 10:43:55 +08:00
|
|
|
|
},
|
|
|
|
|
exportTemplate() {
|
|
|
|
|
const wb = XLSX.utils.book_new();
|
|
|
|
|
const data1 = [{A: '序号', B: '题型', C:'题目', D:'选项', E: '', F: '', G: '', H: '答案'}];
|
|
|
|
|
const data2 = [{A: '', B: '', C:'', D:'A', E: 'B', F: 'C', G: 'D', H: ''}];
|
|
|
|
|
const data3 = [{A: '1', B: '判断', C:'题目一', D:'', E: '', F: '', G: '', H: '√'}];
|
|
|
|
|
const data4 = [{A: '2', B: '判断', C:'题目二', D:'', E: '', F: '', G: '', H: '×'}];
|
|
|
|
|
const data5 = [{A: '3', B: '单选', C:'题目三', D:'选项A', E: '选项B', F: '选项C', G: '选项D', H: 'A'}];
|
|
|
|
|
const data6 = [{A: '4', B: '多选', C:'题目四', D:'选项A', E: '选项B', F: '选项C', G: '选项D', H: 'ABCD'}];
|
|
|
|
|
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 ws = XLSX.utils.json_to_sheet(data, {skipHeader:true});
|
|
|
|
|
ws['!merges'] = [
|
|
|
|
|
{
|
|
|
|
|
s: {c: 3, r: 0},
|
|
|
|
|
e: {c: 6, 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: 7, r: 0},
|
|
|
|
|
e: {c: 7, r: 1}
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
ws['!cols'] = [
|
|
|
|
|
{width: 10},
|
|
|
|
|
{width: 10},
|
|
|
|
|
{width: 50},
|
|
|
|
|
{width: 15},
|
|
|
|
|
{width: 15},
|
|
|
|
|
{width: 15},
|
|
|
|
|
{width: 15},
|
|
|
|
|
{width: 15}
|
|
|
|
|
];
|
|
|
|
|
XLSX.utils.book_append_sheet(wb, ws, 'file');
|
|
|
|
|
XLSX.writeFile(wb, '题库模板' + '.xlsx');
|
2020-05-26 15:59:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|