Merge branch 'master' of https://e.coding.net/ctcdevteam/cma_search
This commit is contained in:
commit
c8268bbc26
|
@ -330,6 +330,60 @@ 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: '/system',
|
||||
component: Layout,
|
||||
|
|
|
@ -0,0 +1,194 @@
|
|||
<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"
|
||||
highlight-current-row max-height="600">
|
||||
<el-table-column type="index" width="50"></el-table-column>
|
||||
<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>
|
||||
</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(['questioncat_update'])"></el-button>
|
||||
<el-button type="danger" size="small" @click="handleDelete(scope)" icon="el-icon-delete"
|
||||
:disabled="!checkPermission(['questioncat_delete'])"></el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
|
||||
@pagination="getList" />
|
||||
<el-dialog :visible.sync="dialogVisible" :title="dialogType === 'edit' ? '编辑分类' : '新增分类'">
|
||||
<el-form :model="questioncat" label-width="80px" label-position="right" :rules="rule1" ref="commonForm">
|
||||
<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>
|
||||
<el-button type="primary" @click="confirm('commonForm')">确认</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { getDictList } from "@/api/dict";
|
||||
import checkPermission from "@/utils/permission";
|
||||
import Pagination from "@/components/Pagination";
|
||||
|
||||
const defaultObj = {
|
||||
id: "",
|
||||
name: "",
|
||||
pid: ""
|
||||
};
|
||||
const listQuery = {
|
||||
page: 1,
|
||||
limit: 20
|
||||
};
|
||||
export default {
|
||||
components: { Pagination },
|
||||
data() {
|
||||
return {
|
||||
questioncat: defaultObj,
|
||||
search: "",
|
||||
total: 0,
|
||||
listQuery: listQuery,
|
||||
tableData: [],
|
||||
typeOptions: [],
|
||||
listLoading: false,
|
||||
dialogVisible: false,
|
||||
dialogType: "new",
|
||||
rule1: {
|
||||
name: [{ required: true, message: "请输入名称", trigger: "blur" }],
|
||||
type: [{ required: true, message: "请选择分类", trigger: "change" }]
|
||||
},
|
||||
typeData: [{
|
||||
value: '公共',
|
||||
label: '公共'
|
||||
}, {
|
||||
value: '专业',
|
||||
label: '专业'
|
||||
}],
|
||||
};
|
||||
},
|
||||
computed: {},
|
||||
created() {
|
||||
// this.getList();
|
||||
this.getTypeAll();
|
||||
},
|
||||
methods: {
|
||||
checkPermission,
|
||||
|
||||
getList(query = this.listQuery) {
|
||||
this.listLoading = true;
|
||||
getQuestioncatList(query).then(response => {
|
||||
this.tableData = response.data.results;
|
||||
this.total = response.data.count;
|
||||
this.listLoading = false;
|
||||
});
|
||||
},
|
||||
//领域类型
|
||||
getTypeAll() {
|
||||
getDictList({ type__code: "field_type" }).then((res) => {
|
||||
this.typeOptions = res.data;
|
||||
});
|
||||
},
|
||||
resetFilter() {
|
||||
this.search = ""
|
||||
this.listQuery = listQuery
|
||||
this.getList();
|
||||
},
|
||||
handleFilter() {
|
||||
this.getList();
|
||||
},
|
||||
handleAdd() {
|
||||
this.questioncat = Object.assign({}, defaultObj);
|
||||
this.dialogType = "new";
|
||||
this.dialogVisible = true;
|
||||
this.$nextTick(() => {
|
||||
this.$refs["commonForm"].clearValidate();
|
||||
});
|
||||
},
|
||||
handleEdit(scope) {
|
||||
this.questioncat = Object.assign({}, scope.row); // copy obj
|
||||
this.dialogType = "edit";
|
||||
this.dialogVisible = true;
|
||||
this.$nextTick(() => {
|
||||
this.$refs["commonForm"].clearValidate();
|
||||
});
|
||||
},
|
||||
handleDelete(scope) {
|
||||
this.$confirm("确认删除该分类吗?将丢失数据!", "警告", {
|
||||
confirmButtonText: "确认",
|
||||
cancelButtonText: "取消",
|
||||
type: "error"
|
||||
})
|
||||
.then(async () => {
|
||||
await deleteQuestioncat(scope.row.id);
|
||||
this.getList();
|
||||
this.$message({
|
||||
type: "success",
|
||||
message: "成功删除!"
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
// console.error(err);
|
||||
});
|
||||
},
|
||||
async confirm(form) {
|
||||
this.$refs[form].validate(valid => {
|
||||
if (valid) {
|
||||
const isEdit = this.dialogType === "edit";
|
||||
if (isEdit) {
|
||||
updateQuestioncat(this.questioncat.id, this.questioncat).then(
|
||||
() => {
|
||||
this.getList();
|
||||
this.dialogVisible = false;
|
||||
this.$message.success('成功')
|
||||
}
|
||||
);
|
||||
} else {
|
||||
createQuestioncat(this.questioncat).then(res => {
|
||||
this.getList();
|
||||
this.dialogVisible = false;
|
||||
this.$message.success('成功')
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
@ -0,0 +1,222 @@
|
|||
<template>
|
||||
<div class="app-container">
|
||||
<el-card style=" min-height: calc(100vh - 65px);">
|
||||
<el-form :model="Form" :rules="rules" ref="Form" label-width="100px" status-icon>
|
||||
<el-form-item label="题型" prop="type">
|
||||
<el-select v-model="Form.type" style="width: 400px">
|
||||
<el-option v-for="item in typeOptions" :key="item.key" :label="item.label" :value="item.value" />
|
||||
</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-form-item label="题干" prop="name">
|
||||
<el-input v-model="Form.name" height="100" width="800px" />
|
||||
</el-form-item>
|
||||
<el-form-item label="题干图片" prop="img">
|
||||
<el-upload
|
||||
class="avatar-uploader"
|
||||
:headers="upHeaders"
|
||||
:action="upUrl"
|
||||
accept="image/jpeg, image/gif, image/png, image/bmp"
|
||||
:show-file-list="false"
|
||||
:on-success="handleImgSuccess"
|
||||
:before-upload="beforeImgUpload">
|
||||
<img v-if="Form.img" :src="Form.img" style="width: 200px;height: 100px;display: block;" />
|
||||
|
||||
<el-button size="small" type="primary" v-else>点击上传</el-button>
|
||||
</el-upload>
|
||||
<el-button type="text" @click="delImg()" v-if="Form.img">删除</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item label="选项A" prop="optionA">
|
||||
<el-input v-model="Form.options.A" height="30" width="800px" :disabled="inputDisable" />
|
||||
</el-form-item>
|
||||
<el-form-item label="选项B" prop="optionB">
|
||||
<el-input v-model="Form.options.B" height="30" width="800px" :disabled="inputDisable" />
|
||||
</el-form-item>
|
||||
<el-form-item label="选项C" v-show="Form.type != '判断'">
|
||||
<el-input v-model="Form.options.C" height="30" width="800px" />
|
||||
</el-form-item>
|
||||
<el-form-item label="选项D" v-show="Form.type != '判断'">
|
||||
<el-input v-model="Form.options.D" height="30" width="800px" />
|
||||
</el-form-item>
|
||||
<el-form-item label="选项E" v-show="Form.type != '判断'">
|
||||
<el-input v-model="Form.options.E" height="30" width="800px" />
|
||||
</el-form-item>
|
||||
<el-form-item label="选项F" v-show="Form.type != '判断'">
|
||||
<el-input v-model="Form.options.F" height="30" width="800px" />
|
||||
</el-form-item>
|
||||
<el-form-item label="正确答案" v-if="Form.type == '多选'">
|
||||
<el-checkbox-group v-model="Form.right">
|
||||
<el-checkbox label="A"></el-checkbox>
|
||||
<el-checkbox label="B"></el-checkbox>
|
||||
<el-checkbox label="C"></el-checkbox>
|
||||
<el-checkbox label="D"></el-checkbox>
|
||||
<el-checkbox label="E"></el-checkbox>
|
||||
<el-checkbox label="F"></el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="正确答案" v-else-if="Form.type == '单选'">
|
||||
<el-radio-group v-model="Form.right">
|
||||
<el-radio label="A"></el-radio>
|
||||
<el-radio label="B"></el-radio>
|
||||
<el-radio label="C"></el-radio>
|
||||
<el-radio label="D"></el-radio>
|
||||
<el-radio label="E"></el-radio>
|
||||
<el-radio label="F"></el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="正确答案" v-else>
|
||||
<el-radio-group v-model="Form.right">
|
||||
<el-radio label="A"></el-radio>
|
||||
<el-radio label="B"></el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="解析">
|
||||
<el-input v-model="Form.resolution" style="width:600px" type="textarea" :rows=3></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="真题年份" prop="year">
|
||||
<el-input v-model="Form.year"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="submitForm('Form')" :loading="submitLoding">立即创建</el-button>
|
||||
<el-button @click="resetForm('Form')">重置</el-button>
|
||||
<el-button type="warning" @click="goBack()">返回</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
// import el-input from '@/components/Tinymce/index2'
|
||||
// import { createQuestion,getQuestioncatAll } from "@/api/question";
|
||||
import { genTree } from "@/utils";
|
||||
import { upUrl } from "@/api/file";
|
||||
import { getToken } from "@/utils/auth";
|
||||
export default {
|
||||
components: {},
|
||||
data() {
|
||||
return {
|
||||
upHeaders: { Authorization: "JWT " + getToken() },
|
||||
upUrl: upUrl(),
|
||||
Form: {
|
||||
name: "",
|
||||
type: "",
|
||||
img: null,
|
||||
questioncat: null,
|
||||
year: null,
|
||||
right: '',
|
||||
options: {
|
||||
A: '',
|
||||
B: ''
|
||||
}
|
||||
},
|
||||
catOptions: [],
|
||||
inputDisable: false,
|
||||
submitLoding: false,
|
||||
rules: {
|
||||
type: [
|
||||
{ required: true, message: "请选择", trigger: "blur" }
|
||||
],
|
||||
name: [
|
||||
{ required: true, message: "请输入", trigger: "blur" }
|
||||
],
|
||||
},
|
||||
typeOptions: [
|
||||
{ key: 1, label: "单选", value: "单选" },
|
||||
{ key: 2, label: "多选", value: "多选" },
|
||||
{ key: 3, label: "判断", value: "判断" }
|
||||
],
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
'Form.type': 'setOptions'
|
||||
},
|
||||
created() {
|
||||
this.getQuestioncatAll()
|
||||
},
|
||||
methods: {
|
||||
handleImgSuccess(res, file) {
|
||||
this.Form.img = res.data.path
|
||||
},
|
||||
beforeImgUpload(file) {
|
||||
const isLt2M = file.size / 1024 / 1024 < 0.6;
|
||||
if (!isLt2M) {
|
||||
this.$message.error("上传图片大小不能超过 600KB!");
|
||||
}
|
||||
return isLt2M;
|
||||
},
|
||||
submitForm(formName) {
|
||||
this.$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]
|
||||
}
|
||||
}
|
||||
createQuestion(this.Form).then(response => {
|
||||
this.submitLoding = false
|
||||
if (response.code >= 200) {
|
||||
this.$message({
|
||||
type: "success",
|
||||
message: "新建成功!"
|
||||
});
|
||||
this.goBack()
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
},
|
||||
resetForm(formName) {
|
||||
this.$refs[formName].resetFields();
|
||||
},
|
||||
goBack() {
|
||||
this.$router.go(-1)
|
||||
},
|
||||
getQuestioncatAll() {
|
||||
getQuestioncatAll().then(response => {
|
||||
this.catOptions = genTree(response.data);
|
||||
});
|
||||
},
|
||||
delImg() {
|
||||
this.Form.img = null
|
||||
},
|
||||
setOptions() {
|
||||
if (this.Form.type == '判断') {
|
||||
this.Form.options = {
|
||||
A: '对',
|
||||
B: '错'
|
||||
}
|
||||
this.inputDisable = true
|
||||
} else {
|
||||
this.Form.options = {
|
||||
A: '',
|
||||
B: ''
|
||||
}
|
||||
this.inputDisable = false
|
||||
}
|
||||
if (this.Form.type == '多选') {
|
||||
this.Form.right = []
|
||||
} else {
|
||||
this.Form.right = ''
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<style scoped>
|
||||
.app-container {
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
|
@ -0,0 +1,276 @@
|
|||
<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.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="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 style="margin-top:10px">
|
||||
<el-button type="primary" slot="reference" @click="handleAdd()">新增</el-button>
|
||||
<el-button @click="handleEnabled">启用</el-button>
|
||||
<el-popover placement="top" width="160" v-if="checkPermission(['question_import'])"
|
||||
v-model="popovervisible">
|
||||
<p>导入题目前,请下载模板并按格式录入.</p>
|
||||
<div style="text-align: left; margin: 0;">
|
||||
<el-link href="/media/muban/question.xlsx" target="_blank" @click="popovervisible = false"
|
||||
type="primary">下载模板</el-link>
|
||||
<el-upload :action="upUrl" :on-success="handleUploadSuccess" accept=".xlsx" :headers="upHeaders"
|
||||
:show-file-list="false">
|
||||
<el-button size="small" type="primary" @click="popovervisible = false">上传导入</el-button>
|
||||
</el-upload>
|
||||
</div>
|
||||
|
||||
<el-button slot="reference">Excel导入</el-button>
|
||||
</el-popover>
|
||||
<el-button type="primary" icon="el-icon-download" @click="exportQuestion">导出Excel</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<el-table :data="tableData" style="width: 100%;margin-top:10px;" border stripe fit v-loading="listLoading"
|
||||
highlight-current-row max-height="600" @sort-change="changeSort" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="55"></el-table-column>
|
||||
<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="所属题库">
|
||||
<template slot-scope="scope">{{ scope.row.questioncat_name }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="题型">
|
||||
<template slot-scope="scope">{{ scope.row.type }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="是否启用">
|
||||
<template slot-scope="scope">
|
||||
<el-tag v-if="scope.row.enabled" type="success">是</el-tag>
|
||||
<el-tag v-else type="danger">否</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="真题年份">
|
||||
<template slot-scope="scope">
|
||||
<span v-if="scope.row.year">{{ scope.row.year }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="创建日期" sortable='custom' prop="create_time">
|
||||
<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>
|
||||
<el-button type="primary" size="small" @click="handleEdit(scope)" icon="el-icon-edit"
|
||||
:disabled="!checkPermission(['question_edit'])"></el-button>
|
||||
<el-button type="danger" size="small" @click="handleDelete(scope)" icon="el-icon-delete"
|
||||
:disabled="!checkPermission(['question_delete'])"></el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
|
||||
@pagination="getList" />
|
||||
<el-dialog title="题目详情" :visible.sync="dialogVisible" width="30%">
|
||||
<div>{{ question.type }}</div>
|
||||
<div>{{ question.name }}</div>
|
||||
<ul id="repeat">
|
||||
<li v-for="(value, key) in question.options" v-bind:key="key">
|
||||
{{ key }}:
|
||||
<span>{{ value }}</span>
|
||||
</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>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// import {
|
||||
// getQuestioncatAll,
|
||||
// getQuestionList,
|
||||
// deleteQuestion,
|
||||
// importQuestion,
|
||||
// exportQuestion,
|
||||
// enableQuestions
|
||||
// } from "@/api/question";
|
||||
import { genTree, deepClone } from "@/utils";
|
||||
import checkPermission from "@/utils/permission";
|
||||
import Pagination from "@/components/Pagination";
|
||||
import { upUrl, upHeaders } from "@/api/file";
|
||||
import { getToken } from "@/utils/auth";
|
||||
|
||||
const defaultObj = {
|
||||
id: "",
|
||||
name: ""
|
||||
};
|
||||
const listQuery = {
|
||||
page: 1,
|
||||
limit: 20,
|
||||
search: ''
|
||||
};
|
||||
export default {
|
||||
components: { Pagination },
|
||||
data() {
|
||||
return {
|
||||
popovervisible: false,
|
||||
upUrl: upUrl(),
|
||||
upHeaders: upHeaders(),
|
||||
questioncat: {
|
||||
id: "",
|
||||
name: ""
|
||||
},
|
||||
total: 0,
|
||||
listQuery: listQuery,
|
||||
tableData: [],
|
||||
questioncatData: [],
|
||||
listLoading: false,
|
||||
dialogVisible: false,
|
||||
dialogType: "new",
|
||||
rule1: {
|
||||
name: [{ required: true, message: "请输入名称", trigger: "blur" }]
|
||||
},
|
||||
typeOptions: [
|
||||
{ key: 1, label: "单选", value: "单选" },
|
||||
{ key: 2, label: "多选", value: "多选" },
|
||||
{ key: 3, label: "判断", value: "判断" }
|
||||
],
|
||||
question: {},
|
||||
questioncatC: [],
|
||||
selects: [],
|
||||
};
|
||||
},
|
||||
computed: {},
|
||||
created() {
|
||||
// this.getList();
|
||||
// this.getQuestioncatAll();
|
||||
},
|
||||
methods: {
|
||||
checkPermission,
|
||||
handleUploadSuccess(res, file) {
|
||||
if (res.code == 200) {
|
||||
const loading = this.$loading({ text: "正在导入中..." })
|
||||
importQuestion(res.data).then(response => {
|
||||
loading.close()
|
||||
if (response.code == 200) {
|
||||
this.$message({
|
||||
message: '导入成功',
|
||||
type: 'success'
|
||||
});
|
||||
this.getList(listQuery)
|
||||
} else if (response.code == 206) {
|
||||
this.$message({
|
||||
message: '部分未成功' + response.data,
|
||||
type: 'success'
|
||||
});
|
||||
} else {
|
||||
this.$message.error(response.msg);
|
||||
}
|
||||
|
||||
});
|
||||
} else {
|
||||
this.$message.error("Excel上传失败!");
|
||||
}
|
||||
},
|
||||
getList() {
|
||||
this.listLoading = true;
|
||||
getQuestionList(this.listQuery).then(response => {
|
||||
this.tableData = response.data.results;
|
||||
this.total = response.data.count;
|
||||
this.listLoading = false;
|
||||
});
|
||||
},
|
||||
getQuestioncatAll() {
|
||||
getQuestioncatAll().then(response => {
|
||||
this.questioncatData = genTree(response.data);
|
||||
});
|
||||
},
|
||||
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.listQuery = listQuery
|
||||
this.getList();
|
||||
},
|
||||
handleSearch() {
|
||||
this.listQuery.page = 1
|
||||
this.getList();
|
||||
},
|
||||
handleAdd() {
|
||||
this.$router.push({ path: "/exam/questionCreate" })
|
||||
},
|
||||
handleDetail(scope) {
|
||||
this.dialogVisible = true
|
||||
this.question = scope.row
|
||||
},
|
||||
handleEdit(scope) {
|
||||
this.$router.push({ path: "/exam/questionUpdate", query: { id: scope.row.id } })
|
||||
},
|
||||
handleDelete(scope) {
|
||||
this.$confirm("确认删除该题目吗?将丢失数据!", "警告", {
|
||||
confirmButtonText: "确认",
|
||||
cancelButtonText: "取消",
|
||||
type: "error"
|
||||
})
|
||||
.then(async () => {
|
||||
await deleteQuestion(scope.row.id);
|
||||
this.getList();
|
||||
this.$message({
|
||||
type: "success",
|
||||
message: "成功删除!"
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
// console.error(err);
|
||||
});
|
||||
},
|
||||
exportQuestion() {
|
||||
const loading = this.$loading({
|
||||
text: '正在准备..'
|
||||
});
|
||||
exportQuestion(this.listQuery).then(response => {
|
||||
loading.close()
|
||||
window.open(response.data.path, "_blank");
|
||||
}).catch(e => { loading.close() });
|
||||
},
|
||||
changeSort(val) {
|
||||
if (val.order == "ascending") {
|
||||
this.listQuery.ordering = val.prop;
|
||||
} else {
|
||||
this.listQuery.ordering = "-" + val.prop;
|
||||
}
|
||||
|
||||
this.getList();
|
||||
},
|
||||
handleSelectionChange(val) {
|
||||
let selects = [];
|
||||
for (var i = 0; i < val.length; i++) {
|
||||
selects.push(val[i].id);
|
||||
}
|
||||
this.selects = selects;
|
||||
},
|
||||
handleEnabled() {
|
||||
if (this.selects.length) {
|
||||
enableQuestions({ ids: this.selects }).then(res => {
|
||||
this.$message.success("成功");
|
||||
this.getList();
|
||||
})
|
||||
} else {
|
||||
this.$message.warning("请先选择题目");
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
@ -0,0 +1,215 @@
|
|||
<template>
|
||||
<div class="app-container">
|
||||
<el-form :model="Form" :rules="rules" ref="Form" label-width="100px" status-icon>
|
||||
<el-form-item label="题型" prop="type">
|
||||
<el-select v-model="Form.type" style="width: 400px" :disabled="true">
|
||||
<el-option
|
||||
v-for="item in typeOptions"
|
||||
:key="item.key"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</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-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
|
||||
class="avatar-uploader"
|
||||
:headers="upHeaders"
|
||||
:action="upUrl"
|
||||
accept="image/jpeg, image/gif, image/png, image/bmp"
|
||||
:show-file-list="false"
|
||||
:on-success="handleImgSuccess"
|
||||
:before-upload="beforeImgUpload"
|
||||
>
|
||||
<img v-if="Form.img" :src="Form.img" style="width: 200px;height: 100px;display: block;"/>
|
||||
<el-button size="small" type="primary" v-else>点击上传</el-button>
|
||||
</el-upload>
|
||||
<el-button type="text" @click="delImg()" v-if="Form.img">删除</el-button>
|
||||
</el-form-item>
|
||||
<el-form-item label="选项A" prop="optionA">
|
||||
<el-input v-model="Form.options.A" height="30" width="800px" :disabled="inputDisable" />
|
||||
</el-form-item>
|
||||
<el-form-item label="选项B" prop="optionB">
|
||||
<el-input v-model="Form.options.B" height="30" width="800px" :disabled="inputDisable" />
|
||||
</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">
|
||||
<el-checkbox label="A"></el-checkbox>
|
||||
<el-checkbox label="B"></el-checkbox>
|
||||
<el-checkbox label="C"></el-checkbox>
|
||||
<el-checkbox label="D"></el-checkbox>
|
||||
<el-checkbox label="E"></el-checkbox>
|
||||
<el-checkbox label="F"></el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="正确答案" v-else-if="Form.type =='单选'">
|
||||
<el-radio-group v-model="Form.right">
|
||||
<el-radio label="A"></el-radio>
|
||||
<el-radio label="B"></el-radio>
|
||||
<el-radio label="C"></el-radio>
|
||||
<el-radio label="D"></el-radio>
|
||||
<el-radio label="E"></el-radio>
|
||||
<el-radio label="F"></el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="正确答案" v-else>
|
||||
<el-radio-group v-model="Form.right">
|
||||
<el-radio label="A"></el-radio>
|
||||
<el-radio label="B"></el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="解析">
|
||||
<el-input v-model="Form.resolution" style="width:600px" type="textarea" :rows="3"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="真题年份" prop="year">
|
||||
<el-input v-model="Form.year"></el-input>
|
||||
</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>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
// import el-input from '@/components/Tinymce/index2'
|
||||
// import { createQuestion,getQuestioncatAll, getQuestion, getQuestioncatList, updateQuestion } from "@/api/question";
|
||||
import { genTree } from "@/utils";
|
||||
import { upUrl } from "@/api/file";
|
||||
import { getToken } from "@/utils/auth";
|
||||
export default {
|
||||
components:{ },
|
||||
data() {
|
||||
return {
|
||||
upHeaders: { Authorization: "JWT " + getToken() },
|
||||
upUrl: upUrl(),
|
||||
Form: {
|
||||
id:0,
|
||||
name: "",
|
||||
img: null,
|
||||
type:"",
|
||||
questioncat:null,
|
||||
year:null,
|
||||
right:'',
|
||||
options:{
|
||||
A:'',
|
||||
B:''
|
||||
}
|
||||
},
|
||||
catOptions:[],
|
||||
inputDisable: false,
|
||||
submitLoding:false,
|
||||
rules: {
|
||||
type: [
|
||||
{ required: true, message: "请选择", trigger: "blur" }
|
||||
],
|
||||
name: [
|
||||
{ required: true, message: "请输入", trigger: "blur" }
|
||||
],
|
||||
},
|
||||
typeOptions: [
|
||||
{ key: 1, label: "单选", value: "单选" },
|
||||
{ key: 2, label: "多选", value: "多选"},
|
||||
{ key: 3, label: "判断", value: "判断" }
|
||||
],
|
||||
};
|
||||
},
|
||||
watch:{
|
||||
},
|
||||
created() {
|
||||
this.Form.id = this.$route.query.id //接收参数
|
||||
this.getQuestion();
|
||||
this.getQuestioncatAll()
|
||||
},
|
||||
methods: {
|
||||
handleImgSuccess(res, file) {
|
||||
this.Form.img = res.data.path
|
||||
},
|
||||
beforeImgUpload(file) {
|
||||
const isLt2M = file.size / 1024 / 1024 < 0.6;
|
||||
if (!isLt2M) {
|
||||
this.$message.error("上传图片大小不能超过 600KB!");
|
||||
}
|
||||
return isLt2M;
|
||||
},
|
||||
submitForm(formName) {
|
||||
this.$refs[formName].validate(valid => {
|
||||
if (valid) {
|
||||
this.submitLoding = true
|
||||
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 => {
|
||||
this.submitLoding = false
|
||||
if(response.code >= 200){
|
||||
this.$message({
|
||||
type: "success",
|
||||
message: "修改成功!"
|
||||
});
|
||||
this.goBack()
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
},
|
||||
getQuestion() {
|
||||
getQuestion(this.Form.id).then(response => {
|
||||
this.Form = response.data ;
|
||||
});
|
||||
},
|
||||
goBack() {
|
||||
this.$router.go(-1)
|
||||
},
|
||||
delImg() {
|
||||
this.Form.img = null
|
||||
},
|
||||
getQuestioncatAll() {
|
||||
getQuestioncatAll().then(response => {
|
||||
this.catOptions = genTree(response.data);
|
||||
});
|
||||
},
|
||||
}
|
||||
}
|
||||
</script>
|
Loading…
Reference in New Issue