This commit is contained in:
shijing 2022-11-11 17:05:38 +08:00
parent 4d4b62c42a
commit b3b9a986fa
14 changed files with 1684 additions and 176 deletions

213
client/src/api/exam.js Normal file
View File

@ -0,0 +1,213 @@
import request from '@/utils/request'
//获取题目类型
export function getQuestioncatList(query) {
return request({
url: '/exam/questioncat/',
method: 'get',
params: query
})
}
//新增题目类型
export function createQuestioncat(data) {
return request({
url: `/exam/questioncat/`,
method: 'post',
data
})
}
//编辑题目类型
export function updateQuestioncat(id, data) {
return request({
url: `/exam/questioncat/${id}/`,
method: 'put',
data
})
}
//删除题目类型
export function deleteQuestioncat(id) {
return request({
url: `/exam/questioncat/${id}/`,
method: 'delete'
})
}
//题目列表
export function getQuestionList(query) {
return request({
url: '/exam/question/',
method: 'get',
params: query
})
}
//题目详情
export function getQuestionDetail(id) {
return request({
url: `/exam/question/${id}/`,
method: 'get'
})
}
//新增题目
export function createQuestion(data) {
return request({
url: `/exam/question/`,
method: 'post',
data
})
}
//编辑题目
export function updateQuestion(id, data) {
return request({
url: `/exam/question/${id}/`,
method: 'put',
data
})
}
//删除题目
export function deleteQuestion(id) {
return request({
url: `/exam/question/${id}/`,
method: 'delete'
})
}
//导入题目
export function importQuestion(data) {
return request({
url: `/exam/question/import/`,
method: 'post',
data
})
}
//导出题目
export function exportQuestion(data) {
return request({
url: `/exam/question/export/`,
method: 'get',
params: query
})
}
//启用题目
export function enableQuestions(data) {
return request({
url: `/exam/question/enable/`,
method: 'post',
data
})
}
//试卷增删改查
//获取试卷
export function getPaperList(query) {
return request({
url: '/exam/paper/',
method: 'get',
params: query
})
}
//试卷详情
export function getPaperDetail(id) {
return request({
url: `/exam/paper/${id}/`,
method: 'get'
})
}
//新增试卷
export function createPaper(data) {
return request({
url: `/exam/paper/`,
method: 'post',
data
})
}
//编辑试卷
export function updatePaper(id, data) {
return request({
url: `/exam/paper/${id}/`,
method: 'put',
data
})
}
//删除试卷
export function deletePaper(id) {
return request({
url: `/exam/paper/${id}/`,
method: 'delete'
})
}
//考试增删改查
//获取考试列表
export function getExamList(query) {
return request({
url: '/exam/exam/',
method: 'get',
params: query
})
}
//考试详情
export function getExamDetail(id) {
return request({
url: `/exam/exam/${id}/`,
method: 'get'
})
}
//新增考试
export function createExam(data) {
return request({
url: `/exam/exam/`,
method: 'post',
data
})
}
//编辑考试
export function updateExam(id, data) {
return request({
url: `/exam/exam/${id}/`,
method: 'put',
data
})
}
//删除考试
export function deleteExam(id) {
return request({
url: `/exam/exam/${id}/`,
method: 'delete'
})
}
//考试记录增删改查
//考试记录列表和详情
export function getExamRecordList(query) {
return request({
url: '/exam/examrecord/',
method: 'get',
params: query
})
}
//考试记录
export function getExamRecordDetail(id) {
return request({
url: `/exam/examrecord/${id}/`,
method: 'get'
})
}
//新增考试记录
export function createExamRecord(data) {
return request({
url: `/exam/examrecord/`,
method: 'post',
data
})
}
//编辑考试记录
export function updateExamRecord(id, data) {
return request({
url: `/exam/examrecord/${id}/`,
method: 'put',
data
})
}
//删除考试记录
export function deleteExamRecord(id) {
return request({
url: `/exam/examrecord/${id}/`,
method: 'delete'
})
}

View File

@ -330,60 +330,74 @@ export const asyncRoutes = [
},
]
},
// {
// path: '/exam',
// component: Layout,
// redirect: '/exam/questions',
// name: 'exam',
// meta: { title: '考试', icon: 'PT', perms: ['pt_view'] },
// alwaysShow: true,
// children: [
// {
// path: 'classify',
// name: '科目分类',
// component: () => import('@/views/exam/classify.vue'),
// meta: { title: '科目分类', perms: ['pt_view'] }
// },
// {
// path: 'questions',
// name: '题目列表',
// component: () => import('@/views/exam/questions.vue'),
// meta: { title: '题目列表', perms: ['pt_view'] }
// },
// {
// path: 'questionCreate',
// name: '新增题目',
// component: () => import('@/views/exam/questioncreate.vue'),
// meta: { title: '新增题目', perms: ['pt_view'] },
// hidden: true
// },
// {
// path: 'questionUpdate/:id',
// name: '编辑题目',
// component: () => import('@/views/exam/questionupdate.vue'),
// meta: { title: '编辑题目', perms: ['pt_view'] },
// hidden: true
// },
// {
// path: 'testPaper',
// name: '模考考试',
// component: () => import('@/views/exam/testPaper.vue'),
// meta: { title: '模考考试', perms: ['pt_view'] }
// },
// {
// path: 'examPaper',
// name: '正式考试',
// component: () => import('@/views/exam/examPaper.vue'),
// meta: { title: '正式考试', perms: ['pt_view'] }
// },
// {
// path: 'examPublish',
// name: '考试发布',
// component: () => import('@/views/exam/examPublish.vue'),
// meta: { title: '考试发布', perms: ['pt_view'] }
// },
// ]
// },
{
path: '/exam',
component: Layout,
redirect: '/exam/questions',
name: 'exam',
meta: { title: '考试', icon: 'PT', perms: ['pt_view'] },
alwaysShow: true,
children: [
{
path: 'classify',
name: '题目分类',
component: () => import('@/views/exam/classify.vue'),
meta: { title: '题目分类', perms: ['pt_view'] }
},
{
path: 'questions',
name: '题目列表',
component: () => import('@/views/exam/questions.vue'),
meta: { title: '题目列表', perms: ['pt_view'] }
},
{
path: 'questionCreate',
name: '新增题目',
component: () => import('@/views/exam/questioncreate.vue'),
meta: { title: '新增题目'},
hidden: true
},
{
path: 'questionUpdate',
name: '编辑题目',
component: () => import('@/views/exam/questionupdate.vue'),
meta: { title: '编辑题目'},
hidden: true
},
{
path: 'testPaper',
name: '考试试卷',
component: () => import('@/views/exam/testPaper.vue'),
meta: { title: '考试试卷', perms: ['pt_view'] }
},
{
path: 'paperCreate',
name: '新建试卷',
component: () => import('@/views/exam/testPaperCreate.vue'),
meta: { title: '新建试卷'},
hidden: true
},
{
path: 'paperUpdate',
name: '编辑试卷',
component: () => import('@/views/exam/testPaperUpdate.vue'),
meta: { title: '编辑试卷'},
hidden: true
},
{
path: 'index',
name: '考试',
component: () => import('@/views/exam/index.vue'),
meta: { title: '考试', perms: ['pt_view'] }
},
{
path: 'record',
name: '考试记录',
component: () => import('@/views/exam/examRecord.vue'),
meta: { title: '考试记录', perms: ['pt_view'] }
},
]
},
{
path: '/system',
component: Layout,

View File

@ -1,10 +1,6 @@
<template>
<div class="app-container">
<div style="margin-top:10px">
<el-select v-model="listQuery.pid" placeholder="所属领域" clearable style="width: 200px" class="filter-item"
@change="handleFilter">
<el-option v-for="item in typeOptions" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
<el-button type="primary" @click="handleAdd" icon="el-icon-plus">新增</el-button>
</div>
<el-table :data="tableData" style="width: 100%;margin-top:10px;" border fit v-loading="listLoading"
@ -13,11 +9,6 @@
<el-table-column align="center" label="名称">
<template slot-scope="scope">{{ scope.row.name }}</template>
</el-table-column>
<el-table-column align="center" label="所属领域">
<template slot-scope="scope">
<el-tag>{{ scope.row.subject_name }}</el-tag>
</template>
</el-table-column>
<el-table-column label="创建日期">
<template slot-scope="scope">
<span>{{ scope.row.create_time }}</span>
@ -39,18 +30,6 @@
<el-form-item label="名称" prop="name">
<el-input v-model="questioncat.name" placeholder="名称" />
</el-form-item>
<el-form-item label="类型" prop="type">
<el-select v-model="questioncat.type" placeholder="请选择" style="width:100%">
<el-option v-for="item in typeData" :key="item.value" :label="item.label" :value="item.value">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="所属领域" prop="field">
<el-select v-model="questioncat.field" placeholder="请选择" style="width:100%">
<el-option v-for="item in typeOptions" :key="item.id" :label="item.name" :value="item.id">
</el-option>
</el-select>
</el-form-item>
</el-form>
<div style="text-align:right;">
<el-button type="danger" @click="dialogVisible = false">取消</el-button>
@ -61,14 +40,13 @@
</template>
<script>
import { getDictList } from "@/api/dict";
import { getQuestioncatList,createQuestioncat,updateQuestioncat,deleteQuestioncat } from "@/api//exam";
import checkPermission from "@/utils/permission";
import Pagination from "@/components/Pagination";
const defaultObj = {
id: "",
name: "",
pid: ""
};
const listQuery = {
page: 1,
@ -100,10 +78,8 @@ export default {
}],
};
},
computed: {},
created() {
// this.getList();
this.getTypeAll();
mounted(){
this.getList();
},
methods: {
checkPermission,
@ -116,12 +92,7 @@ export default {
this.listLoading = false;
});
},
//领域类型
getTypeAll() {
getDictList({ type__code: "field_type" }).then((res) => {
this.typeOptions = res.data;
});
},
resetFilter() {
this.search = ""
this.listQuery = listQuery
@ -165,22 +136,23 @@ export default {
});
},
async confirm(form) {
this.$refs[form].validate(valid => {
let that = this;
that.$refs[form].validate(valid => {
if (valid) {
const isEdit = this.dialogType === "edit";
let isEdit = that.dialogType === "edit";
if (isEdit) {
updateQuestioncat(this.questioncat.id, this.questioncat).then(
updateQuestioncat(that.questioncat.id, that.questioncat).then(
() => {
this.getList();
this.dialogVisible = false;
this.$message.success('成功')
that.getList();
that.dialogVisible = false;
that.$message.success('成功')
}
);
} else {
createQuestioncat(this.questioncat).then(res => {
this.getList();
this.dialogVisible = false;
this.$message.success('成功')
createQuestioncat(that.questioncat).then(res => {
that.getList();
that.dialogVisible = false;
that.$message.success('成功')
});
}
} else {

View File

@ -0,0 +1,274 @@
<template>
<div class="app-container">
<div style="margin-top:10px">
<el-select
v-model="listQuery.is_pass"
placeholder="是否通过"
clearable
style="width: 200px"
class="filter-item"
@change="handleFilter"
>
<el-option
v-for="item in passOptions"
:key="item.key"
:label="item.label"
:value="item.value"
/>
</el-select>
<el-date-picker
v-model="value"
type="daterange"
align="right"
unlink-panels
range-separator=""
start-placeholder="开始日期"
end-placeholder="结束日期"
:picker-options="pickerOptions">
</el-date-picker>
<el-input
v-model="listQuery.search"
placeholder="输入用户名或用户单位名搜索"
style="width: 200px;"
class="filter-item"
@keyup.enter.native="handleFilter"
/>
<el-button
class="filter-item"
type="primary"
icon="el-icon-refresh-left"
@click="resetFilter"
>刷新重置</el-button>
<el-button type="primary" icon="el-icon-download" @click="exportTest" >导出Excel</el-button>
<div style="margin-top:10px">
</div>
</div>
<el-table
:data="tableData.results"
style="width: 100%;margin-top:10px;"
border
stripe
fit
v-loading="listLoading"
highlight-current-row
max-height="600"
@sort-change="changeSort"
>
<el-table-column type="index" width="50"></el-table-column>
<el-table-column align="left" label="类型">
<template slot-scope="scope">{{ scope.row.type }}</template>
</el-table-column>
<el-table-column align="left" label="用户">
<template slot-scope="scope" v-if="scope.row.consumer_detail">{{ scope.row.consumer_detail.name }}</template>
</el-table-column>
<el-table-column align="left" label="单位">
<template slot-scope="scope" v-if="scope.row.consumer_detail">{{ scope.row.consumer_detail.company_name }}</template>
</el-table-column>
<el-table-column align="left" label="工作类别">
<template slot-scope="scope">{{ scope.row.workscope_name }}</template>
</el-table-column>
<el-table-column align="left" label="得分" sortable='custom' prop="score">
<template slot-scope="scope">{{ scope.row.score }}</template>
</el-table-column>
<el-table-column align="left" label="耗时(时分秒)" sortable='custom' prop="took">
<template slot-scope="scope">{{ scope.row.took_format }}</template>
</el-table-column>
<el-table-column align="left" label="答题时间">
<template slot-scope="scope">{{ scope.row.start_time }}</template>
</el-table-column>
<el-table-column align="center" label="操作" fixed="right">
<template slot-scope="scope">
<el-button
v-if="scope.row.type=='正式考试'"
type="primary"
size="small"
@click="handleExport(scope)"
>生成Word</el-button>
<el-button
v-if="scope.row.type=='正式考试'"
type="warning"
size="small"
@click="handleExport2(scope)"
>重新生成</el-button>
<el-button
v-if="scope.row.type=='正式考试'"
type="danger"
size="small"
@click="handleDelete(scope)"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="tableData.count>0"
:total="tableData.count"
:page.sync="listQuery.page"
:limit.sync="listQuery.limit"
@pagination="getList"
/>
</div>
</template>
<script>
import { getExamRecordList, exportTest, exportwTest, deleteExamRecord,issue } from "@/api/exam";
import checkPermission from "@/utils/permission";
import Pagination from "@/components/Pagination";
const listQuery = {
page: 1,
limit: 20,
type:'正式考试',
search:''
};
export default {
components: { Pagination },
data() {
return {
listQuery: Object.assign({}, listQuery),
tableData: {
count:0,
results:[],
},
listLoading: true,
typeOptions: [
{ key: "自助模考", label: "自助模考", value: "自助模考" },
{ key: "押卷模考", label: "押卷模考", value: "押卷模考"},
{ key: "正式考试", label: "正式考试", value: "正式考试"},
],
passOptions: [
{ key: true, label: "通过", value: true },
{ key: false, label: "未通过", value: false},
],
pickerOptions: {
shortcuts: [{
text: '最近一天',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近一周',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近一个月',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
picker.$emit('pick', [start, end]);
}
}, {
text: '最近三个月',
onClick(picker) {
const end = new Date();
const start = new Date();
start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
picker.$emit('pick', [start, end]);
}
}]
},
value: '',
};
},
computed: {},
watch:{
value:'setTimeRange',
},
created() {
this.getQuery();
},
methods: {
checkPermission,
getQuery() {
if(this.$route.params.exam){
this.listQuery.exam = this.$route.params.exam;
this.getList()
}else{
this.getList()
}
},
getList() {
this.listLoading = true;
getExamRecordList(this.listQuery).then(response => {
this.tableData = response.data;
this.listLoading = false;
});
},
handleFilter() {
this.listQuery.page = 1;
this.getList();
},
resetFilter() {
this.listQuery = {
page: 1,
limit: 20,
type:'正式考试',
search:'',
};
this.value = []
this.getList();
},
handleExport(scope) {
const loading = this.$loading({text: '正在生成word...',});
exportwTest(scope.row.id).then(res=>{
loading.close()
window.open(res.data.path, "_blank");
}).catch(e=>{loading.close()})
},
handleDelete(scope){
this.$confirm("确认删除该考试记录吗?将丢失数据!", "警告", {
confirmButtonText: "确认",
cancelButtonText: "取消",
type: "error"
})
.then(async () => {
await deleteExamtest(scope.row.id);
this.getList()
this.$message({
type: "success",
message: "成功删除!"
});
})
.catch(err => {
console.error(err);
});
},
handleExport2(scope) {
const loading = this.$loading({text: '正在重新生成word...',});
exportwTest(scope.row.id, {anew:true}).then(res=>{
loading.close()
window.open(res.data.path, "_blank");
}).catch(e=>{loading.close()})
},
exportTest() {
const loading = this.$loading();
exportTest(this.listQuery).then(response => {
loading.close()
window.open(response.data.path, "_blank");
});
},
setTimeRange(){
this.listQuery.start = this.value[0],
this.listQuery.end = this.value[1],
this.getList()
},
changeSort (val) {
if(val.order == 'ascending'){
this.listQuery.ordering = val.prop
}else{
this.listQuery.ordering = '-' + val.prop
}
this.getList()
},
}
};
</script>

View File

@ -0,0 +1,282 @@
<template>
<div class="app-container">
<div style="margin-top:10px">
<el-input
v-model="listQuery.search"
placeholder="输入考试名称进行搜索"
style="width: 300px;"
class="filter-item"
@keyup.enter.native="handleFilter"
/>
<el-button type="primary" @click="handleAdd" icon="el-icon-plus" v-if ="checkPermission(['exam_create'])">新增</el-button>
<el-button
class="filter-item"
type="primary"
icon="el-icon-refresh-left"
@click="resetFilter"
>刷新重置</el-button>
</div>
<el-table
:data="tableData.results"
style="width: 100%;margin-top:10px;"
border
fit
v-loading="listLoading"
highlight-current-row
max-height="600"
row-key="id"
default-expand-all
>
<el-table-column label="考试名称">
<template slot-scope="scope">{{ scope.row.name }}</template>
</el-table-column>
<el-table-column label="考试试卷">
<template slot-scope="scope">
{{scope.row.paper_.name }}
<!-- <text v-if="scope.row.paper_">{{scope.row.paper_.name }}</text> -->
</template>
</el-table-column>
<el-table-column label="考试地点">
<template slot-scope="scope">{{ scope.row.place }}</template>
</el-table-column>
<el-table-column label="参考机会">
<template slot-scope="scope">{{ scope.row.chance }}</template>
</el-table-column>
<el-table-column label="开启时间">
<template slot-scope="scope">{{ scope.row.open_time }}</template>
</el-table-column>
<el-table-column label="关闭时间">
<template slot-scope="scope">{{ scope.row.close_time }}</template>
</el-table-column>
<el-table-column label="创建人">
<template slot-scope="scope">
<span>{{ scope.row.create_admin_username }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="操作" fixed="right">
<template slot-scope="scope">
<el-button
type="primary"
size="small"
@click="handleView(scope)"
:disabled="!checkPermission(['exam_view'])"
>详情</el-button>
<el-button
size="small"
@click="handleEdit(scope)"
:disabled="!checkPermission(['exam_update'])"
>编辑</el-button>
<el-button
type="danger"
size="small"
@click="handleDelete(scope)"
:disabled="!checkPermission(['exam_delete'])"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="tableData.count>0"
:total="tableData.count"
:page.sync="listQuery.page"
:limit.sync="listQuery.limit"
@pagination="getList"
/>
<el-dialog :visible.sync="dialogVisible" :title="dialogType==='edit'?'编辑考试':'新增考试'" >
<el-form :model="exam" label-width="120px" :rules="rule1" ref="examForm">
<el-form-item label="名称" prop="name">
<el-input v-model="exam.name" placeholder="名称" />
</el-form-item>
<el-form-item label="考试地点" prop="place">
<el-input v-model="exam.place" placeholder="考试地点" />
</el-form-item>
<el-form-item label="参考机会" prop="chance">
<el-input-number v-model="exam.chance" placeholder="参考机会" :min="1"/>
</el-form-item>
<el-form-item label="开启时间" prop="open_time">
<el-date-picker
v-model="exam.open_time"
type="datetime"
placeholder="开启时间"
style="width:100%">
</el-date-picker>
</el-form-item>
<el-form-item label="关闭时间" prop="close_time">
<el-date-picker
v-model="exam.close_time"
type="datetime"
placeholder="关闭时间"
style="width:100%"
></el-date-picker>
</el-form-item>
<el-form-item label="监考人姓名" prop="proctor_name" label-width="120px">
<el-input v-model="exam.proctor_name" placeholder="监考人姓名" />
</el-form-item>
<el-form-item label="监考人电话" prop="proctor_phone" label-width="120px">
<el-input v-model="exam.proctor_phone" placeholder="监考人联系方式" />
</el-form-item>
<el-form-item label="选定试卷" prop="paper" >
<el-select v-model="exam.paper" placeholder="可指定试卷" style="width:100%" clearable>
<el-option
v-for="item in paperOptions"
:key="item.id"
:label="item.name"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
</el-form>
<div style="text-align:right;">
<el-button type="danger" @click="dialogVisible=false">取消</el-button>
<el-button type="primary" @click="confirmexam('examForm')">确认</el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { getPaperList,getExamList, createExam, updateExam,deleteExam} from "@/api/exam";
import checkPermission from "@/utils/permission";
import Pagination from "@/components/Pagination"
const defaultexam = {
id: "",
name: "",
place: "",
open_time: null,
close_time: null,
proctor_name:'',
proctor_phone:'',
chance:3,
paper:''
};
const listQuery = {
page: 1,
limit: 20,
search: ""
}
export default {
components: { Pagination },
data() {
return {
selects:[],
exam: {
id: "",
name: "",
},
listQuery:listQuery,
tableData: {count:0},
listLoading: true,
dialogVisible: false,
dialogType: "new",
workscopeOptions:[],
paperOptions:[],
rule1: {
name: [{ required: true, message: "请输入", trigger: "blur" }],
place: [{ required: true, message: "请输入", trigger: "change" }],
workscope: [{ required: true, message: "请选择", trigger: "change" }],
open_time: [{ required: true, message: "请选择", trigger: "change" }],
close_time: [{ required: true, message: "请选择", trigger: "change" }],
proctor_name: [{ required: true, message: "请输入", trigger: "change" }],
proctor_phone: [{ required: true, message: "请输入", trigger: "change" }],
chance: [{ required: true, message: "请输入", trigger: "change" }]
},
};
},
computed: {},
mounted() {
this.getPaperOptions();
this.getList();
},
methods: {
checkPermission,
getPaperOptions(){
getPaperList({page:0}).then(res=>{
debugger;
console.log(res)
this.paperOptions = res.data
})
},
getList() {
this.listLoading = true;
debugger;
getExamList(this.listQuery).then(response => {
this.tableData = response.data
this.listLoading = false;
});
},
resetFilter() {
this.listQuery = {
page: 1,
limit: 20,
search: ""
};
this.getList();
},
handleFilter() {
this.listQuery.page = 1;
this.getList();
},
handleAdd() {
this.exam = Object.assign({}, defaultexam);
this.dialogType = "new";
this.dialogVisible = true;
this.$nextTick(() => {
this.$refs["examForm"].clearValidate();
});
},
handleEdit(scope) {
this.exam = Object.assign({}, scope.row); // copy obj
this.dialogType = "edit";
this.dialogVisible = true;
this.$nextTick(() => {
this.$refs["examForm"].clearValidate();
});
},
handleDelete(scope) {
this.$confirm("确认删除该考试吗?将丢失数据!", "警告", {
confirmButtonText: "确认",
cancelButtonText: "取消",
type: "error"
})
.then(async () => {
await deleteExam(scope.row.id);
this.getList()
this.$message({
type: "success",
message: "成功删除!"
});
})
.catch(err => {
// console.error(err);
});
},
handleView(scope){
this.$router.push({ path: "/exam/record", query: { exam: scope.row.id } })
},
async confirmexam(form) {
this.$refs[form].validate(valid => {
if (valid) {
const isEdit = this.dialogType === "edit";
if (isEdit) {
updateExam(this.exam.id, this.exam).then(() => {
this.getList();
this.dialogVisible = false;
this.$message.success('成功')
});
} else {
createExam(this.exam).then(res => {
this.getList();
this.dialogVisible = false;
this.$message.success('成功')
});
}
} else {
return false;
}
});
},
}
};
</script>

View File

@ -0,0 +1,220 @@
<template>
<el-dialog title="选取试题" :visible.sync="chooseVisible_" width="80%" >
<div style="margin-top:10px">
<el-select v-model="questioncatC" placeholder="分类" clearable style="width: 200px" class="filter-item" @change="handleFilter">
<el-option v-for="item in questioncatData" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
<el-select
v-model="listQuery.type"
placeholder="题型"
clearable
style="width: 120px"
class="filter-item"
@change="handleFilter"
>
<el-option
v-for="item in typeOptions"
:key="item.key"
:label="item.label"
:value="item.value"
/>
</el-select>
<el-input
v-model="search"
placeholder="输入题干进行搜索"
style="width: 200px;"
class="filter-item"
@keyup.enter.native="handleSearch"
/>
<el-button
class="filter-item"
type="primary"
icon="el-icon-search"
@click="handleSearch"
>搜索</el-button>
<el-button
class="filter-item"
type="primary"
icon="el-icon-refresh-left"
@click="resetFilter"
>刷新重置</el-button>
</div>
<div style="margin-top:10px">
</div>
<el-table
:data="tableData.results"
style="width: 100%;margin-top:10px;"
border
stripe
fit
v-loading="listLoading"
highlight-current-row
max-height="400"
ref="table"
>
<el-table-column
type="selection"
width="55">
</el-table-column>
<el-table-column align="left" label="题干">
<template slot-scope="scope">{{ scope.row.name }}</template>
</el-table-column>
<el-table-column align="left" label="所属题库">
<template slot-scope="scope">{{ scope.row.questioncat_name }}</template>
</el-table-column>
<el-table-column align="left" label="题型">
<template slot-scope="scope">{{ scope.row.type }}</template>
</el-table-column>
<el-table-column align="left" label="难易度">
<template slot-scope="scope">{{ scope.row.level }}</template>
</el-table-column>
<el-table-column label="创建日期">
<template slot-scope="scope">
<span>{{ scope.row.create_time }}</span>
</template>
</el-table-column>
<el-table-column align="center" label="操作">
<template slot-scope="scope">
<el-button
type="primary"
size="small"
@click="handleDetail(scope)"
icon="el-icon-more"
></el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="tableData.count>0"
:total="tableData.count"
:page.sync="listQuery.page"
:limit.sync="listQuery.limit"
@pagination="getList"
/>
<el-dialog
title="题目详情"
:visible.sync="dialogVisible"
width="30%"
append-to-body>
<div>{{question.type}}</div>
<div>{{question.name}}</div>
<ul id="repeat">
<li v-for="(value,key,index) in question.options">
{{ key }}:{{value}}
</li>
</ul>
<div>正确答案{{question.right}}</div>
<div>{{question.resolution}}</div>
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="dialogVisible = false"> </el-button>
</span>
</el-dialog>
<div style="text-align:left;">
<el-button type="primary" @click="choseQuestions('table')">选中</el-button>
</div>
</el-dialog>
</template>
<script>
import {
getQuestioncatList,
getQuestionList,
} from "@/api/exam";
import Pagination from "@/components/Pagination";
const listQuery = {
page: 1,
limit: 20,
search:''
};
export default {
name:'Questionchoose',
components: { Pagination },
props: {
chooseVisible: Boolean,
},
data() {
return {
questioncat: {
id: "",
name: ""
},
listQuery: listQuery,
search:"",
tableData: {
count:0,
results:[]
},
questioncatData:[],
listLoading: true,
dialogVisible: false,
typeOptions: [
{ key: 1, label: "单选", value: "单选" },
{ key: 2, label: "多选", value: "多选"},
{ key: 3, label: "判断", value: "判断" }
],
question:{},
questioncatC:[]
};
},
computed: {
chooseVisible_: {
get() {
return this.chooseVisible;
},
set(val) {
this.$emit('closeDg',val);
}
}
},
created() {
this.getList();
this.getQuestioncatAll();
},
methods: {
getList(query = this.listQuery) {
this.listLoading = true;
getQuestionList(query).then(response => {
if(response.data.results){
this.tableData = response.data
}
this.listLoading = false;
});
},
getQuestioncatAll() {
getQuestioncatList().then(response => {
this.questioncatData = response.data.results;
});
},
handleFilter() {
if(this.questioncatC.length) {
this.listQuery.questioncat = this.questioncatC[this.questioncatC.length-1]
}else{
this.listQuery.questioncat = ''
}
this.listQuery.page = 1;
this.getList();
},
resetFilter() {
this.search = ""
this.listQuery = listQuery
this.getList();
},
handleSearch() {
this.getList({ search: this.search });
},
handleDetail(scope) {
this.dialogVisible = true
this.question = scope.row
},
choseQuestions(table) {
const _selectData = this.$refs.table.selection
this.$emit('choseQ',_selectData);
this.$emit('closeDg',false);
this.$refs.table.clearSelection();
}
}
};
</script>

View File

@ -8,8 +8,9 @@
</el-select>
</el-form-item>
<el-form-item label="分类" prop="type">
<el-cascader v-model="Form.questioncat" :options="catOptions" :show-all-levels="false" clearable
style="width: 400px"></el-cascader>
<el-select v-model="Form.questioncat" placeholder="分类" clearable style="width: 200px" class="filter-item">
<el-option v-for="item in catOptions" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item label="题干" prop="name">
<el-input v-model="Form.name" height="100" width="800px" />
@ -89,9 +90,7 @@
</div>
</template>
<script>
// import el-input from '@/components/Tinymce/index2'
// import { createQuestion,getQuestioncatAll } from "@/api/question";
import { genTree } from "@/utils";
import { createQuestion,getQuestioncatList } from "@/api/exam";
import { upUrl } from "@/api/file";
import { getToken } from "@/utils/auth";
export default {
@ -148,30 +147,26 @@ export default {
return isLt2M;
},
submitForm(formName) {
this.$refs[formName].validate(valid => {
let that =this;
that.$refs[formName].validate(valid => {
if (valid) {
this.submitLoding = true
this.Form.questioncat = this.Form.questioncat.pop()
// this.Form.name = this.Form.name.replace('<p>','').replace('</p>','')
// for(let key in this.Form.options){
// this.Form.options[key] = this.Form.options[key].replace('<p>','').replace('</p>','')
// }
for (let key in this.Form.options) {
if (!this.Form.options[key]) {
delete this.Form.options[key]
that.submitLoding = true
for (let key in that.Form.options) {
if (!that.Form.options[key]) {
delete that.Form.options[key]
}
}
createQuestion(this.Form).then(response => {
this.submitLoding = false
debugger;
console.log(that.Form)
createQuestion(that.Form).then(response => {
that.submitLoding = false
if (response.code >= 200) {
this.$message({
that.$message({
type: "success",
message: "新建成功!"
});
this.goBack()
that.goBack()
}
});
} else {
return false;
@ -185,8 +180,8 @@ export default {
this.$router.go(-1)
},
getQuestioncatAll() {
getQuestioncatAll().then(response => {
this.catOptions = genTree(response.data);
getQuestioncatList().then(response => {
this.catOptions = response.data.results;
});
},
delImg() {

View File

@ -1,8 +1,11 @@
<template>
<div class="app-container">
<div style="margin-top:10px">
<el-cascader v-model="questioncatC" :options="questioncatData" clearable style="width: 200px"
:props="{ checkStrictly: true, emitPath: false }" @change="handleFilter"></el-cascader>
<el-select v-model="listQuery.questioncat" placeholder="题目分类" clearable style="width: 200px" class="filter-item"
@change="handleFilter">
<el-option v-for="item in questioncatData" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
<el-select v-model="listQuery.type" placeholder="题型" clearable style="width: 120px" class="filter-item"
@change="handleFilter">
<el-option v-for="item in typeOptions" :key="item.key" :label="item.label" :value="item.value" />
@ -38,7 +41,7 @@
<el-table-column label="题干" sortable="custom" prop="name" width="400px">
<template slot-scope="scope">{{ scope.row.name }}</template>
</el-table-column>
<el-table-column label="所属题库">
<el-table-column label="所属分类">
<template slot-scope="scope">{{ scope.row.questioncat_name }}</template>
</el-table-column>
<el-table-column label="题型">
@ -63,8 +66,7 @@
<el-table-column align="center" label="操作">
<template slot-scope="scope">
<el-button type="primary" size="small" @click="handleDetail(scope)" icon="el-icon-more"></el-button>
<el-button type="primary" size="small" @click="handleEdit(scope)" icon="el-icon-edit"
:disabled="!checkPermission(['question_edit'])"></el-button>
<el-button type="primary" size="small" @click="handleEdit(scope)" icon="el-icon-edit"></el-button>
<el-button type="danger" size="small" @click="handleDelete(scope)" icon="el-icon-delete"
:disabled="!checkPermission(['question_delete'])"></el-button>
</template>
@ -91,19 +93,17 @@
</template>
<script>
// import {
// getQuestioncatAll,
// getQuestionList,
// deleteQuestion,
// importQuestion,
// exportQuestion,
// enableQuestions
// } from "@/api/question";
import { genTree, deepClone } from "@/utils";
import {
getQuestioncatList,
getQuestionList,
deleteQuestion,
importQuestion,
exportQuestion,
enableQuestions,
} from "@/api/exam";
import checkPermission from "@/utils/permission";
import Pagination from "@/components/Pagination";
import { upUrl, upHeaders } from "@/api/file";
import { getToken } from "@/utils/auth";
const defaultObj = {
id: "",
@ -112,7 +112,8 @@ const defaultObj = {
const listQuery = {
page: 1,
limit: 20,
search: ''
search: '',
questioncat:''
};
export default {
components: { Pagination },
@ -141,14 +142,13 @@ export default {
{ key: 3, label: "判断", value: "判断" }
],
question: {},
questioncatC: [],
selects: [],
};
},
computed: {},
created() {
// this.getList();
// this.getQuestioncatAll();
this.getList();
this.getQuestioncatList();
},
methods: {
checkPermission,
@ -185,17 +185,12 @@ export default {
this.listLoading = false;
});
},
getQuestioncatAll() {
getQuestioncatAll().then(response => {
this.questioncatData = genTree(response.data);
getQuestioncatList() {
getQuestioncatList().then(response => {
this.questioncatData = response.data.results;
});
},
handleFilter() {
if (this.questioncatC.length) {
this.listQuery.questioncat = this.questioncatC[this.questioncatC.length - 1]
} else {
this.listQuery.questioncat = ''
}
this.listQuery.page = 1;
this.getList();
},
@ -208,7 +203,7 @@ export default {
this.getList();
},
handleAdd() {
this.$router.push({ path: "/exam/questionCreate" })
this.$router.push({ path: "/exam/questionCreate"})
},
handleDetail(scope) {
this.dialogVisible = true
@ -250,7 +245,6 @@ export default {
} else {
this.listQuery.ordering = "-" + val.prop;
}
this.getList();
},
handleSelectionChange(val) {

View File

@ -12,17 +12,12 @@
</el-select>
</el-form-item>
<el-form-item label="分类" prop="type">
<el-cascader
v-model="Form.questioncat"
:options="catOptions"
:show-all-levels="false"
clearable
style="width: 400px"
></el-cascader>
</el-form-item>
<el-select v-model="Form.questioncat" placeholder="分类" clearable style="width: 200px" class="filter-item">
<el-option v-for="item in catOptions" :key="item.id" :label="item.name" :value="item.id" />
</el-select>
</el-form-item>
<el-form-item label="题干" prop="name">
<el-input v-model="Form.name" height="100" width="800px" />
<!-- <el-input v-model="Form.name" style="width:600px" type="textarea" :rows=3></el-input> -->
</el-form-item>
<el-form-item label="题干图片" prop="img" >
<el-upload
@ -47,19 +42,15 @@
</el-form-item>
<el-form-item label="选项C" v-show="Form.type!='判断'">
<el-input v-model="Form.options.C" height="30" width="800px" />
<!-- <el-input v-model="Form.options.C" style="width:600px"></el-input> -->
</el-form-item>
<el-form-item label="选项D" v-show="Form.type!='判断'">
<el-input v-model="Form.options.D" height="30" width="800px" />
<!-- <el-input v-model="Form.options.D" style="width:600px"></el-input> -->
</el-form-item>
<el-form-item label="选项E" v-show="Form.type!='判断'">
<el-input v-model="Form.options.E" height="30" width="800px" />
<!-- <el-input v-model="Form.options.E" style="width:600px"></el-input> -->
</el-form-item>
<el-form-item label="选项F" v-show="Form.type!='判断'">
<el-input v-model="Form.options.F" height="30" width="800px" />
<!-- <el-input v-model="Form.options.F" style="width:600px"></el-input> -->
</el-form-item>
<el-form-item label="正确答案" v-if="Form.type =='多选'">
<el-checkbox-group v-model="Form.right">
@ -101,9 +92,7 @@
</div>
</template>
<script>
// import el-input from '@/components/Tinymce/index2'
// import { createQuestion,getQuestioncatAll, getQuestion, getQuestioncatList, updateQuestion } from "@/api/question";
import { genTree } from "@/utils";
import { getQuestionDetail,updateQuestion,getQuestioncatList } from "@/api/exam";
import { upUrl } from "@/api/file";
import { getToken } from "@/utils/auth";
export default {
@ -113,7 +102,7 @@ export default {
upHeaders: { Authorization: "JWT " + getToken() },
upUrl: upUrl(),
Form: {
id:0,
id:null,
name: "",
img: null,
type:"",
@ -168,16 +157,12 @@ export default {
if(this.Form.questioncat instanceof Array){
this.Form.questioncat = this.Form.questioncat.pop()
}
// this.Form.name = this.Form.name.replace('<p>','<span>').replace('</p>','</span>')
// for(let key in this.Form.options){
// this.Form.options[key] = this.Form.options[key].replace('<p>','<span>').replace('</p>','</span>')
// }
for(let key in this.Form.options){
if(!this.Form.options[key]){
delete this.Form.options[key]
}
}
updateQuestion(this.Form.id, this.Form).then(response => {
updateQuestion(this.Form.id, this.Form).then(response => {
this.submitLoding = false
if(response.code >= 200){
this.$message({
@ -186,8 +171,6 @@ export default {
});
this.goBack()
}
});
} else {
return false;
@ -195,7 +178,7 @@ export default {
});
},
getQuestion() {
getQuestion(this.Form.id).then(response => {
getQuestionDetail(this.Form.id).then(response => {
this.Form = response.data ;
});
},
@ -206,8 +189,8 @@ export default {
this.Form.img = null
},
getQuestioncatAll() {
getQuestioncatAll().then(response => {
this.catOptions = genTree(response.data);
getQuestioncatList().then(response => {
this.catOptions = response.data.results;
});
},
}

View File

@ -0,0 +1,167 @@
<template>
<div class="app-container">
<div style="margin-top:10px">
<el-input
v-model="listQuery.search"
placeholder="名称"
style="width: 200px;"
class="filter-item"
@keyup.enter.native="handleSearch"
/>
<el-button class="filter-item" type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
<el-button
class="filter-item"
type="primary"
icon="el-icon-refresh-left"
@click="resetFilter"
>刷新重置</el-button>
</div>
<div style="margin-top:10px">
<el-button type="primary" @click="handleAdd" icon="el-icon-plus">新增</el-button>
</div>
<el-table
:data="tableData.results"
style="width: 100%;margin-top:10px;"
border
stripe
fit
v-loading="listLoading"
highlight-current-row
max-height="600"
>
<el-table-column type="index" width="50"></el-table-column>
<el-table-column align="left" label="名称">
<template slot-scope="scope">{{ scope.row.name }}</template>
</el-table-column>
<!-- <el-table-column align="left" label="工作类别">
<template slot-scope="scope">{{ scope.row.workscope_name }}</template>
</el-table-column> -->
<el-table-column align="left" label="总分">
<template slot-scope="scope">{{ scope.row.total_score }}</template>
</el-table-column>
<el-table-column align="left" label="通过分">
<template slot-scope="scope">{{ scope.row.pass_score }}</template>
</el-table-column>
<el-table-column align="left" label="限时(分钟)">
<template slot-scope="scope">{{ scope.row.limit }}</template>
</el-table-column>
<el-table-column align="center" label="操作">
<template slot-scope="scope">
<el-button
type="primary"
size="small"
@click="handleEdit(scope)"
icon="el-icon-edit"
:disabled="!checkPermission(['paper_update'])"
></el-button>
<el-button
type="warning"
size="small"
@click="handleClone(scope)"
:disabled="!checkPermission(['paper_clone'])"
>克隆</el-button>
<el-button
type="danger"
size="small"
@click="handleDelete(scope)"
icon="el-icon-delete"
:disabled="!checkPermission(['paper_delete'])"
></el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="tableData.count>0"
:total="tableData.count"
:page.sync="listQuery.page"
:limit.sync="listQuery.limit"
@pagination="getList"
/>
</div>
</template>
<script>
import { getPaperList, deletePaper, clonePaper } from "@/api/exam";
import checkPermission from "@/utils/permission";
import Pagination from "@/components/Pagination";
const listQuery = {
page: 1,
limit: 20,
search:''
};
export default {
components: { Pagination },
data() {
return {
listQuery: Object.assign({}, listQuery),
tableData: {
count:0,
results:[],
},
listLoading: true,
};
},
computed: {},
created() {
this.getList();
},
methods: {
checkPermission,
getList(query = this.listQuery) {
this.listLoading = true;
getPaperList(query).then(response => {
if(response.data.results){
this.tableData = response.data;
}
this.listLoading = false;
});
},
resetFilter() {
this.listQuery = {
page: 1,
limit: 20,
search:''
};
this.getList();
},
handleSearch() {
this.listQuery.page = 1;
this.getList();
},
handleAdd() {
this.$router.push({path:"/exam/paperCreate"})
},
handleEdit(scope) {
this.$router.push({path:"/exam/paperUpdate",query:{id:scope.row.id}})
},
handleClone(scope) {
const loading = this.$loading({
text: '克隆中..',
});
clonePaper(scope.row.id).then(res=>{
this.getList()
loading.close()
}).catch(e=>{loading.close()})
},
handleDelete(scope) {
this.$confirm('确认删除?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
deletePaper(scope.row.id).then(response => {
this.$message({
type: 'success',
message: '删除成功!'
});
this.getList()
});
}).catch(() => {
});
},
}
};
</script>

View File

@ -0,0 +1,191 @@
<template>
<div class="app-container">
<el-row>
<el-col :span="8">
<h3>基本信息</h3>
<el-form :model="Form" :rules="rules" ref="Form" label-width="100px" status-icon>
<el-form-item label="名称" prop="name">
<el-input v-model="Form.name" style="width:80%"></el-input>
</el-form-item>
<el-form-item label="时间限制" prop="limit">
<el-input-number v-model="Form.limit" :min="0"></el-input-number>分钟
</el-form-item>
<el-form-item label="试卷信息">
<div>
单选题
<span style="color:darkred;font-weight:bold">{{Form.danxuan_count}} </span>
每道
<el-input-number v-model="Form.danxuan_score" :min="0" @change="calScore"></el-input-number>
</div>
<div>
多选题
<span style="color:darkred;font-weight:bold">{{Form.duoxuan_count}} </span>
每道
<el-input-number v-model="Form.duoxuan_score" :min="0" @change="calScore"></el-input-number>
</div>
<div>
判断题
<span style="color:darkred;font-weight:bold">{{Form.panduan_count}} </span>
每道
<el-input-number v-model="Form.panduan_score" :min="0" @change="calScore"></el-input-number>
</div>
<div>
总分
<span style="color:darkred;font-weight:bold">{{Form.total_score}}</span>
</div>
</el-form-item>
<el-form-item label="及格分数" prop="pass_score">
<el-input-number v-model="Form.pass_score" :min="0"></el-input-number>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm('Form')" :loading="submitLoding">保存</el-button>
<el-button type="warning" @click="goBack()">返回</el-button>
</el-form-item>
</el-form>
</el-col>
<el-col :span="16">
<h3>选题信息</h3>
<el-button type="primary" @click="handleChoose" icon="el-icon-plus">选择试题</el-button>
<div v-for="(item, index) in questions">
<h4>
<el-button
type="danger"
size="small"
@click="handleDelete(index)"
icon="el-icon-delete"
></el-button>
{{ index+1 }} -
<el-tag>{{item.type}}</el-tag>
{{ item.name }}
<span>(正确答案:{{item.right}})</span>
</h4>
<div v-for="(value, name) in item.options">{{ name }}: {{ value }}</div>
</div>
</el-col>
</el-row>
<Questionchoose v-bind:chooseVisible="chooseVisible" @closeDg="closeDg" @choseQ="choseQ"></Questionchoose>
</div>
</template>
<script>
import { getQuestioncatList, createPaper } from "@/api/exam";
import Questionchoose from "@/views/exam/questionChoose";
export default {
components: { Questionchoose },
data() {
return {
questions: [],
Form: {
name: "",
// workscope: null,
limit: 60,
total_score: 0,
pass_score: 60,
questions_: [],
danxuan_score: 2,
danxuan_count: 0,
duoxuan_score: 4,
duoxuan_count: 0,
panduan_score: 2,
panduan_count: 0
},
submitLoding: false,
rules: {
name: [
{ required: true, message: "名称不能为空", trigger: "blur" }
],
limit: [
{ required: true, message: "时间限制不能为空" },
{ type: "number", message: "时间限制必须是数字" }
],
pass_score: [
{ required: true, message: "及格分数不能为空" },
{ type: "number", message: "及格分数必须是数字" }
]
},
workscopeData: [],
chooseVisible: false
};
},
watch: {
questions: "calScore"
},
created() {
this.getQuestioncat();
},
methods: {
getQuestioncat() {
getQuestioncatList().then(response => {
this.workscopeData = response.data.results;
});
},
submitForm(formName) {
this.$refs[formName].validate(valid => {
if (valid) {
this.submitLoding = true;
createPaper(this.Form).then(response => {
this.submitLoding = false;
this.$message({
type: "success",
message: "编辑成功!"
});
this.goBack();
}).catch(res=>{
this.submitLoding = false;
});
} else {
return false;
}
});
},
resetForm(formName) {
this.$refs[formName].resetFields();
},
goBack() {
this.$router.replace("/exam/testpaper/");
},
handleChoose() {
this.chooseVisible = true;
},
closeDg(val) {
this.chooseVisible = val;
},
choseQ(val) {
this.questions = this.questions.concat(val);
},
handleDelete(val) {
this.questions.splice(val, 1);
},
calScore() {
let danxuan_count = 0,
duoxuan_count = 0,
panduan_count = 0,
questions = [];
for (var i = 0, len = this.questions.length; i < len; i++) {
var total_score = 0
switch (this.questions[i].type) {
case "单选":
danxuan_count = danxuan_count + 1;
total_score = this.Form.danxuan_score
break;
case "多选":
duoxuan_count = duoxuan_count + 1;
total_score = this.Form.duoxuan_score
break;
case "判断":
panduan_count = panduan_count + 1;
total_score = this.Form.panduan_score
break;
}
questions.push({question:this.questions[i].id,total_score:total_score})
}
this.Form.danxuan_count = danxuan_count;
this.Form.duoxuan_count = duoxuan_count;
this.Form.panduan_count = panduan_count;
let form = this.Form;
let score = form.danxuan_count * form.danxuan_score + form.duoxuan_count * form.duoxuan_score + form.panduan_count * form.panduan_score;
this.Form.total_score = score;
this.Form.questions_ = questions;
}
}
};
</script>

View File

@ -0,0 +1,203 @@
<template>
<div class="app-container">
<el-row>
<el-col :span="8">
<h3>基本信息</h3>
<el-form :model="Form" :rules="rules" ref="Form" label-width="100px" status-icon>
<el-form-item label="名称" prop="name">
<el-input v-model="Form.name" style="width:80%"></el-input>
</el-form-item>
<el-form-item label="时间限制" prop="limit">
<el-input-number v-model="Form.limit" :min="0"></el-input-number>分钟
</el-form-item>
<el-form-item label="试卷信息">
<div>
单选题
<span style="color:darkred;font-weight:bold">{{Form.danxuan_count}} </span>
每道
<el-input-number v-model="Form.danxuan_score" :min="0"></el-input-number>
</div>
<div>
多选题
<span style="color:darkred;font-weight:bold">{{Form.duoxuan_count}} </span>
每道
<el-input-number v-model="Form.duoxuan_score" :min="0"></el-input-number>
</div>
<div>
判断题
<span style="color:darkred;font-weight:bold">{{Form.panduan_count}} </span>
每道
<el-input-number v-model="Form.panduan_score" :min="0"></el-input-number>
</div>
<div>
总分
<span style="color:darkred;font-weight:bold">{{Form.total_score}}</span>
</div>
</el-form-item>
<el-form-item label="及格分数" prop="pass_score">
<el-input-number v-model="Form.pass_score" :min="0"></el-input-number>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm('Form')" :loading="submitLoding">保存</el-button>
<el-button type="warning" @click="goBack()">返回</el-button>
</el-form-item>
</el-form>
</el-col>
<el-col :span="16">
<h3>选题信息</h3>
<el-button type="primary" @click="handleChoose" icon="el-icon-plus">选择试题</el-button>
<div v-for="(item, index) in questions">
<h4>
<el-button
type="danger"
size="small"
@click="handleDelete(index)"
icon="el-icon-delete"
></el-button>
{{ index+1 }} -
<el-tag>{{item.type}}</el-tag>
{{ item.name }}
<span>(正确答案:{{item.right}})</span>
</h4>
<div v-for="(value, name) in item.options">{{ name }}: {{ value }}</div>
</div>
</el-col>
</el-row>
<Questionchoose v-bind:chooseVisible="chooseVisible" @closeDg="closeDg" @choseQ="choseQ"></Questionchoose>
</div>
</template>
<script>
import { getQuestioncatList, updatePaper,getPaperDetail } from "@/api/exam";
import { genTree } from "@/utils";
import Questionchoose from "@/views/exam/questionChoose";
export default {
components: { Questionchoose },
data() {
return {
questions: [],
Form: {
name: "",
limit: 60,
total_score: 0,
pass_score: 60,
questions_: [],
danxuan_score: 2,
danxuan_count: 0,
duoxuan_score: 4,
duoxuan_count: 0,
panduan_score: 2,
panduan_count: 0
},
submitLoding: false,
rules: {
name: [
{ required: true, message: "名称不能为空", trigger: "blur" }
// { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
],
limit: [
{ required: true, message: "时间限制不能为空" },
{ type: "number", message: "时间限制必须是数字" }
],
pass_score: [
{ required: true, message: "及格分数不能为空" },
{ type: "number", message: "及格分数必须是数字" }
]
},
workscopeData: [],
chooseVisible: false
};
},
watch: {
questions: "calScore"
},
created() {
this.getQuestioncat();
this.Form.id = this.$route.query.id //接收参数
this.getPaperDetail();
},
methods: {
getQuestioncat() {
getQuestioncatList().then(response => {
this.workscopeData = genTree(response.data);
});
},
getPaperDetail() {
let that = this;
getPaperDetail(this.Form.id).then(response => {
that.Form = response.data;
debugger;
that.questions = response.data.questions_;
});
},
submitForm(formName) {
this.$refs[formName].validate(valid => {
if (valid) {
this.submitLoding = true;
updatePaper(this.Form.id,this.Form).then(response => {
this.submitLoding = false;
this.$message({
type: "success",
message: "编辑成功!"
});
this.goBack();
}).catch(res=>{
this.submitLoding = false;
});
} else {
return false;
}
});
},
resetForm(formName) {
this.$refs[formName].resetFields();
},
goBack() {
this.$router.replace("/exam/testpaper/");
},
handleChoose() {
this.chooseVisible = true;
},
closeDg(val) {
this.chooseVisible = val;
},
choseQ(val) {
this.questions = this.questions.concat(val);
},
handleDelete(val) {
this.questions.splice(val, 1);
},
calScore() {
let that = this;
let danxuan_count = 0,
duoxuan_count = 0,
panduan_count = 0,
questions = [];
for (var i = 0, len = that.questions.length; i < len; i++) {
var total_score = 0
switch (that.questions[i].type) {
case "单选":
danxuan_count = danxuan_count + 1;
total_score = that.Form.danxuan_score;
break;
case "多选":
duoxuan_count = duoxuan_count + 1;
total_score = that.Form.duoxuan_score;
break;
case "判断":
panduan_count = panduan_count + 1;
total_score = that.Form.panduan_score;
break;
}
questions.push({question:that.questions[i].id,total_score:total_score})
}
that.Form.danxuan_count = danxuan_count;
that.Form.duoxuan_count = duoxuan_count;
that.Form.panduan_count = panduan_count;
let form = that.Form;
let score = form.danxuan_count * form.danxuan_score + form.duoxuan_count * form.duoxuan_score + form.panduan_count * form.panduan_score;
that.Form.total_score = score;
that.Form.questions_ = questions;
}
}
};
</script>