rt-sim-training-client/src/views/competitionManage/generatePaper.vue

226 lines
8.8 KiB
Vue
Raw Normal View History

2020-05-26 17:33:19 +08:00
<template>
<div style="width: 100%;height: 100%;">
<div style="margin-top: 10px;position: absolute; right: 50px;">
2020-05-27 11:25:39 +08:00
<el-button size="small" type="primary" @click="exportPaper">导出试题</el-button>
2020-05-26 17:33:19 +08:00
<el-button size="small" type="primary" @click="goBack">返回</el-button>
</div>
2020-05-26 18:43:59 +08:00
<el-card style="width: 45%;margin-left: 50px;margin-top: 60px;display: inline-block;height: calc(100% - 100px);">
2020-05-26 17:33:19 +08:00
<div slot="header">
<span>理论试题列表</span>
2020-05-26 18:43:59 +08:00
<el-button style="float: right; padding: 3px 0" type="text" @click="addTheoryQuestion">添加试题</el-button>
<el-button style="float: right; padding: 3px 0;margin-right: 5px" type="text" @click="theoryReview">预览</el-button>
2020-05-26 17:33:19 +08:00
</div>
<el-table
2020-05-26 18:43:59 +08:00
:data="theoryQuestionList"
2020-05-26 17:33:19 +08:00
style="width: 100%"
2020-05-27 13:51:27 +08:00
height="100%"
2020-05-27 16:36:55 +08:00
:summary-method="getSummaries"
2020-05-27 17:27:50 +08:00
:show-summary="showSummary"
2020-05-27 15:31:47 +08:00
:row-style="handleRowStyle"
2020-05-26 17:33:19 +08:00
>
2020-05-27 17:27:50 +08:00
<el-table-column prop="type" label="类型" width="100">
2020-05-26 17:33:19 +08:00
<template slot-scope="scope">
2020-05-27 17:27:50 +08:00
<el-tag type="primary" disable-transitions>{{ QuestionTypeMap[scope.row.type] }}</el-tag>
2020-05-26 17:33:19 +08:00
</template>
</el-table-column>
<el-table-column prop="topic" label="题目" show-overflow-tooltip="">
2020-05-27 16:36:55 +08:00
<template slot-scope="scope">
<span v-html="scope.row.topic" />
</template>
</el-table-column>
2020-05-27 17:27:50 +08:00
<el-table-column prop="score" label="分值" width="100">
2020-05-27 10:33:26 +08:00
<template slot-scope="scope">
<span v-if="!scope.row.editScope" @click="editScope(scope.row)">{{ scope.row.score }}</span>
<i v-if="!scope.row.editScope" class="el-icon-edit" @click="editScope(scope.row)" />
2020-05-27 15:31:47 +08:00
<el-input-number v-if="scope.row.editScope" v-model="scope.row.score" v-focus="scope.row.editFocus" :controls="noControls" :min="0" size="mini" style="width: 90px" @blur="editScopeBlur(scope.row)" />
2020-05-27 10:33:26 +08:00
</template>
</el-table-column>
2020-05-27 11:28:29 +08:00
<el-table-column prop="operate" label="操作" width="100">
2020-05-26 17:33:19 +08:00
<template slot-scope="scope">
2020-05-27 15:38:40 +08:00
<el-button type="warning" size="mini" @click="removeTheoryQuestion(scope.row)">移出</el-button>
2020-05-26 17:33:19 +08:00
</template>
</el-table-column>
</el-table>
</el-card>
2020-05-26 18:43:59 +08:00
<el-card style="width: 45%;margin-left: calc(10% - 100px);margin-top: 60px;display: inline-block;height: calc(100% - 100px);">
2020-05-26 17:33:19 +08:00
<div slot="header">
<span>实操试题列表</span>
2020-05-27 11:07:04 +08:00
<el-button style="float: right; padding: 3px 0" type="text" @click="addOperateQuestion">添加试题</el-button>
2020-05-26 18:43:59 +08:00
<el-button style="float: right; padding: 3px 0;margin-right: 5px" type="text" @click="operateReview">预览</el-button>
2020-05-26 17:33:19 +08:00
</div>
<el-table
2020-05-27 10:33:26 +08:00
:data="operateQuestionList"
2020-05-26 17:33:19 +08:00
style="width: 100%"
2020-05-27 13:51:27 +08:00
height="100%"
2020-05-27 15:31:47 +08:00
:row-style="handleRowStyle"
2020-05-27 16:36:55 +08:00
:summary-method="getSummaries"
2020-05-27 17:27:50 +08:00
:show-summary="showSummary"
2020-05-26 17:33:19 +08:00
>
2020-05-27 17:27:50 +08:00
<el-table-column prop="name" label="实操名称" />
<el-table-column prop="creatorName" label="创建人" />
2020-05-27 10:33:26 +08:00
<el-table-column prop="score" label="分值">
<template slot-scope="scope">
2020-05-27 11:25:39 +08:00
<span v-if="!scope.row.editScope" @click="editScope(scope.row)">{{ scope.row.score }}</span>
<i v-if="!scope.row.editScope" class="el-icon-edit" @click="editScope(scope.row)" />
2020-05-27 15:31:47 +08:00
<el-input-number v-if="scope.row.editScope" v-model="scope.row.score" v-focus="scope.row.editFocus" :controls="noControls" :min="0" size="mini" @blur="editScopeBlur(scope.row)" />
2020-05-27 10:33:26 +08:00
</template>
</el-table-column>
2020-05-26 17:33:19 +08:00
<el-table-column prop="operate" label="操作">
<template slot-scope="scope">
2020-05-27 15:38:40 +08:00
<el-button type="warning" size="mini" @click="removeOperateQuestion(scope.row)">移出</el-button>
2020-05-26 17:33:19 +08:00
</template>
</el-table-column>
</el-table>
</el-card>
2020-05-27 13:51:27 +08:00
<set-exam-time ref="setExamTime" :theory-question-list="theoryQuestionList" :operate-question-list="operateQuestionList" />
2020-05-27 10:33:26 +08:00
<theory-review ref="theoryReview" :theory-question-list="theoryQuestionList" />
<theory-question ref="theoryQuestion" :theory-index-list="theoryIndexList" @addQuestion="addTheoryQuestionList" @removeQuestion="removeTheoryQuestion" />
2020-05-27 11:07:04 +08:00
<operate-question ref="operateQuestion" :operate-index-list="operateIndexList" @addQuestion="addOperateQuestionList" @removeQuestion="removeOperateQuestion" />
2020-05-26 17:33:19 +08:00
</div>
</template>
<script>
2020-05-26 18:43:59 +08:00
import TheoryReview from './theoryReview';
import TheoryQuestion from './theoryQuestion';
2020-05-27 11:07:04 +08:00
import OperateQuestion from './operateQuestion';
2020-05-27 11:25:39 +08:00
import SetExamTime from './setExamTime';
2020-05-26 17:33:19 +08:00
export default {
name: 'GeneratPaper',
2020-05-26 18:43:59 +08:00
components: {
2020-05-27 11:25:39 +08:00
SetExamTime,
2020-05-26 18:43:59 +08:00
TheoryReview,
2020-05-27 11:07:04 +08:00
TheoryQuestion,
OperateQuestion
2020-05-26 18:43:59 +08:00
},
2020-05-26 17:33:19 +08:00
data() {
return {
QuestionTypeMap: {
select: '选择题',
judge: '判断题'
2020-05-26 18:43:59 +08:00
},
2020-05-27 17:27:50 +08:00
showSummary: true,
2020-05-27 15:31:47 +08:00
noControls: false,
2020-05-27 10:33:26 +08:00
theoryQuestionList: [], // 理论试卷试题列表
operateQuestionList: [], // 实操试卷试题列表
theoryIndexList: [], // 理论试卷试题索引列表
operateIndexList: []// 实操试卷试题索引列表
2020-05-26 17:33:19 +08:00
};
},
2020-05-26 17:35:55 +08:00
methods: {
2020-05-27 10:33:26 +08:00
removeOperateQuestion(row) {
const index = this.operateIndexList.indexOf(row.id);
this.operateIndexList.splice(index, 1);
this.operateQuestionList.splice(index, 1);
},
removeTheoryQuestion(row) {
const index = this.theoryIndexList.indexOf(row.id);
this.theoryIndexList.splice(index, 1);
this.theoryQuestionList.splice(index, 1);
},
addTheoryQuestionList(row) {
2020-05-27 16:36:55 +08:00
if (this.theoryQuestionList.length) {
this.theoryIndexList.push(row.id);
this.theoryQuestionList.push(row);
} else {
this.theoryIndexList = [row.id];
this.theoryQuestionList = [row];
}
2020-05-27 10:33:26 +08:00
},
addOperateQuestionList(row) {
2020-05-27 16:36:55 +08:00
if (this.operateQuestionList.length) {
this.operateIndexList.push(row.id);
this.operateQuestionList.push(row);
} else {
this.operateIndexList = [row.id];
this.operateQuestionList = [row];
}
2020-05-27 10:33:26 +08:00
},
2020-05-26 18:43:59 +08:00
addTheoryQuestion() {
this.$refs.theoryQuestion.doShow();
},
2020-05-27 11:07:04 +08:00
addOperateQuestion() {
this.$refs.operateQuestion.doShow();
},
2020-05-26 17:33:19 +08:00
goBack() {
this.$router.go(-1);
2020-05-26 18:43:59 +08:00
},
theoryReview() {
this.$refs.theoryReview.doShow();
},
operateReview() {
2020-05-27 10:33:26 +08:00
},
editScope(row) {
this.$set(row, 'editScope', true);
this.$nextTick(() => {
2020-05-27 11:25:39 +08:00
this.$set(row, 'editFocus', true);
2020-05-27 10:33:26 +08:00
});
},
editScopeBlur(row) {
this.$set(row, 'editScope', false);
2020-05-27 11:25:39 +08:00
this.$set(row, 'editFocus', true);
2020-05-27 15:31:47 +08:00
if (row.score > 0) {
this.$set(row, 'isError', false);
}
2020-05-27 17:27:50 +08:00
this.showSummary = false;
this.$nextTick(() => {
this.getSummaries({data: this.theoryQuestionList});
});
2020-05-27 15:31:47 +08:00
},
handleRowStyle({row, rowIndex}) {
2020-05-27 15:38:40 +08:00
return row.isError ? {background: '#F00'} : {background: '#FFF'};
2020-05-27 11:25:39 +08:00
},
2020-05-27 16:36:55 +08:00
getSummaries(param) {
2020-05-27 17:27:50 +08:00
const { data } = param;
2020-05-27 16:36:55 +08:00
const sums = [];
2020-05-27 17:27:50 +08:00
sums[0] = '总分';
const values = data.map(item => Number(item.score));
if (!values.every(value => isNaN(value))) {
sums[2] = values.reduce((prev, curr) => {
const value = Number(curr);
if (!isNaN(value)) {
return prev + curr;
} else {
return prev;
}
}, 0);
sums[2] += ' 分';
}
this.showSummary = true;
2020-05-27 16:36:55 +08:00
return sums;
},
2020-05-27 11:25:39 +08:00
exportPaper() {
2020-05-27 15:31:47 +08:00
let flag = false;
this.theoryQuestionList.forEach((item) => {
if (item.score <= 0) {
flag = true;
this.$set(item, 'isError', true);
}
});
this.operateQuestionList.forEach((item) => {
if (item.score <= 0) {
flag = true;
this.$set(item, 'isError', true);
}
});
if (flag) {
this.$message.error('试题分分值不得为0');
} else {
this.$refs.setExamTime.doShow();
}
2020-05-26 17:33:19 +08:00
}
}
};
</script>
<style scoped>
2020-05-27 13:51:27 +08:00
/deep/
.el-card__body{
2020-05-27 17:27:50 +08:00
height: calc(100% - 47px);
}
/deep/
.el-table__body-wrapper {
height: calc(100% - 97px) !important;
2020-05-27 13:51:27 +08:00
}
2020-05-26 17:33:19 +08:00
</style>