first commit
This commit is contained in:
@@ -0,0 +1,486 @@
|
||||
<!--#
|
||||
layout("/layouts/platform.html"){
|
||||
#-->
|
||||
<!-- 在线答题-题库管理 -->
|
||||
<style>
|
||||
.el-divider {
|
||||
background-color: #409EFF;
|
||||
}
|
||||
|
||||
.el-divider__text {
|
||||
color: #409EFF;
|
||||
}
|
||||
|
||||
.inputParent input {
|
||||
border: none;
|
||||
border-bottom: 1px solid rgb(220, 223, 230);
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.issueList > .el-table__header-wrapper {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.issueList .el-table__expanded-cell {
|
||||
background-color: rgb(250, 250, 250) !important;
|
||||
}
|
||||
|
||||
</style>
|
||||
<div id="app" v-cloak>
|
||||
<el-row class="transition-row">
|
||||
<transition name="el-zoom-in-center">
|
||||
<div v-show="v=='index'" class="transition-item">
|
||||
<el-row class="header navbar bg-white shadow">
|
||||
<div class="btn-group tool-button mt5">
|
||||
<el-input placeholder="请输入内容" v-model="pageForm.searchKeyword">
|
||||
<template slot="prepend">题目</template>
|
||||
</el-input>
|
||||
</div>
|
||||
|
||||
<div class="btn-group tool-button mt5">
|
||||
<el-select v-model="pageForm.type" clearable
|
||||
placeholder="题型">
|
||||
<el-option
|
||||
v-for="item in typeOptions"
|
||||
:label="item.name"
|
||||
:value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</div>
|
||||
|
||||
<div class="btn-group tool-button mt5">
|
||||
<el-button icon="el-icon-search" @click="doSearch"
|
||||
style="background-color:#409eff;color: white;"></el-button>
|
||||
</div>
|
||||
|
||||
<div class="pull-right offscreen-right mt5">
|
||||
<el-button size="medium" type="primary" plain @click="openAdd"><i class="ti-plus"></i>新建题目
|
||||
</el-button>
|
||||
</div>
|
||||
</el-row>
|
||||
<el-row class="el-table-container">
|
||||
<el-table :data="tableData" size="medium" header-align="center" align="center" style="width: 100%">
|
||||
<el-table-column
|
||||
label="序号" type="index" header-align="center" align="center">
|
||||
<template scope="scope">
|
||||
<span>{{scope.$index+(pageForm.pageNumber - 1) * pageForm.pageSize + 1}} </span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="name" show-overflow-tooltip label="题目" header-align="center"
|
||||
align="center"></el-table-column>
|
||||
<el-table-column prop="type" label="题型" header-align="center" align="center">
|
||||
<template scope="scope">
|
||||
<span v-if="scope.row.type==1">单选</span>
|
||||
<span v-if="scope.row.type==2">多选</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="create_time" label="创建时间" header-align="center"
|
||||
align="center"></el-table-column>
|
||||
<el-table-column label="操作" header-align="center" align="center" width="200px">
|
||||
<template scope="scope">
|
||||
<el-button size="small" @click="openView(scope.row.id)">查看</el-button>
|
||||
<el-button size="small" type="primary"
|
||||
@click="openEdit(scope.row.id)" plain>编辑
|
||||
</el-button>
|
||||
<el-button size="small" type="danger"
|
||||
@click="doDelete(scope.row.id)" plain>删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-row>
|
||||
<el-row class="el-pagination-container">
|
||||
<el-pagination
|
||||
@size-change="pageSizeChange"
|
||||
@current-change="pageNumberChange"
|
||||
:current-page="pageForm.pageNumber"
|
||||
:page-sizes="[10, 20, 30, 50]"
|
||||
:page-size="pageForm.pageSize"
|
||||
layout="total, sizes, prev, pager, next, jumper"
|
||||
:total="pageForm.totalCount">
|
||||
</el-pagination>
|
||||
</el-row>
|
||||
</div>
|
||||
</transition>
|
||||
|
||||
<transition name="el-zoom-in-center">
|
||||
<div v-show="v=='add'||v=='edit'" class="transition-item">
|
||||
<el-card class="box-card v-box" shadow="never">
|
||||
<div slot="header" class="clearfix">
|
||||
<el-button icon="el-icon-back" type="text" @click="v='index'"
|
||||
style="font-size: 18px">返回
|
||||
</el-button>
|
||||
<div class="pull-right offscreen-right mt5">
|
||||
<el-button size="medium" type="primary" plain @click="operation">确 定</el-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="padding: 0 5%; height:calc(100vh - 150px);overflow-y: scroll">
|
||||
<el-form :model="formData" ref="addForm" label-position="right" :rules="formRules" size="small"
|
||||
label-width="80px">
|
||||
<el-form-item prop="name" label="题目名称">
|
||||
<el-input size="medium" type="textarea" placeholder="请输入题目名称"
|
||||
v-model="formData.name"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="type" label="题目类型">
|
||||
<el-radio-group v-model="formData.type">
|
||||
<el-radio :label="1">单选</el-radio>
|
||||
<el-radio :label="2">多选</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="22">
|
||||
<el-divider content-position="left" class="dia">
|
||||
<span style="color: #3ea1ec;">题目选项</span>
|
||||
</el-divider>
|
||||
</el-col>
|
||||
<el-col :span="2" style="text-align: right">
|
||||
<el-button @click="formData.answer.push({option_txt:''})"
|
||||
style="margin-top: 10px"
|
||||
icon="el-icon-plus"
|
||||
type="warning" size="mini"></el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-checkbox-group v-model="checkVal">
|
||||
<el-table :data="formData.answer" header-align="center"
|
||||
style="width: 100%">
|
||||
<el-table-column type="index" label="序号"></el-table-column>
|
||||
<el-table-column prop="option_txt" label="选项" header-align="center"
|
||||
align="center">
|
||||
<template slot-scope="scope">
|
||||
<el-input placeholder="请输入选项名" maxlength="100"
|
||||
v-model="scope.row.option_txt"></el-input>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="is_yes" label="正确答案" header-align="center" width="100px"
|
||||
align="center">
|
||||
<template slot-scope="scope">
|
||||
|
||||
<el-radio v-model="is_yes" :label="scope.$index+1"
|
||||
v-if="formData.type==1">
|
||||
</el-radio>
|
||||
|
||||
<el-checkbox :label="scope.$index+1"
|
||||
v-if="formData.type==2">
|
||||
</el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" header-align="center" width="150px" align="center">
|
||||
<template slot-scope="scope">
|
||||
<el-button icon="el-icon-delete" type="danger"
|
||||
@click="delOptionX(scope)"></el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-checkbox-group>
|
||||
</el-row>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</transition>
|
||||
|
||||
<transition name="el-zoom-in-center">
|
||||
<div v-show="v=='view'" class="transition-item">
|
||||
<el-card class="box-card v-box" shadow="never">
|
||||
<div slot="header" class="clearfix">
|
||||
<el-button icon="el-icon-back" type="text" @click="v='index'"
|
||||
style="font-size: 18px">返回
|
||||
</el-button>
|
||||
</div>
|
||||
|
||||
<div style="padding: 0 5%; height:calc(100vh - 150px);overflow-y: scroll">
|
||||
<el-form :model="viewData" ref="addForm" label-position="right" size="small"
|
||||
label-width="80px">
|
||||
<el-form-item prop="name" label="题目名称">
|
||||
<el-input readonly size="medium" type="textarea"
|
||||
v-model="viewData.name"
|
||||
></el-input>
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item prop="type" label="题目类型">
|
||||
<el-radio-group v-model="viewData.type">
|
||||
<el-radio disabled :label="1">单选</el-radio>
|
||||
<el-radio disabled :label="2">多选</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
|
||||
<el-row>
|
||||
<el-col :span="22">
|
||||
<el-divider content-position="left" class="dia">
|
||||
<span style="color: #3ea1ec;">题目选项</span>
|
||||
</el-divider>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
<el-checkbox-group v-model="checkVal">
|
||||
<el-table :data="viewData.answer" header-align="center"
|
||||
style="width: 100%">
|
||||
<el-table-column type="index" label="序号"></el-table-column>
|
||||
<el-table-column prop="option_txt" label="选项" header-align="center"
|
||||
align="center">
|
||||
<template slot-scope="scope">
|
||||
<el-input readonly maxlength="100"
|
||||
v-model="scope.row.option_txt"></el-input>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column readonly prop="is_yes" label="正确答案" header-align="center"
|
||||
width="100px"
|
||||
align="center">
|
||||
<template slot-scope="scope">
|
||||
|
||||
<el-radio disabled v-model="is_yes" :label="scope.$index+1"
|
||||
v-if="viewData.type==1">
|
||||
</el-radio>
|
||||
|
||||
<el-checkbox disabled :label="scope.$index+1"
|
||||
v-if="viewData.type==2">
|
||||
</el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-checkbox-group>
|
||||
</el-row>
|
||||
</div>
|
||||
</el-card>
|
||||
</div>
|
||||
</transition>
|
||||
</el-row>
|
||||
|
||||
</div>
|
||||
<script>
|
||||
const vue = new Vue({
|
||||
el: '#app',
|
||||
data() {
|
||||
return {
|
||||
pageForm: {
|
||||
searchName: "name",
|
||||
searchKeyword: "",
|
||||
pageNumber: 1,
|
||||
pageSize: 10,
|
||||
totalCount: 0,
|
||||
pageOrderName: "",
|
||||
pageOrderBy: "",
|
||||
type: ""
|
||||
},
|
||||
viewData: {},
|
||||
formData: {type: 1, answer: [{}, {}, {}, {}]},
|
||||
checkVal: [],
|
||||
is_yes: '',
|
||||
tableData: [],
|
||||
delOption: [],
|
||||
v: 'index',
|
||||
formRules: {
|
||||
name: [{required: true, message: '必填', trigger: ['blur', 'change']}],
|
||||
type: [{required: true, message: '必填', trigger: ['blur', 'change']}],
|
||||
option_txt: [{required: true, message: '必填', trigger: ['blur', 'change']}],
|
||||
},
|
||||
typeOptions: [{id: 1, name: "单选题"}, {id: 2, name: "多选题"}]
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
delOptionX(scope) {
|
||||
this.delOption = []
|
||||
if (scope.row.id) {
|
||||
this.delOption.push(scope.row.id)
|
||||
}
|
||||
if (this.formData.type == 1 && scope.$index == this.is_yes - 1) {
|
||||
this.is_yes = ''
|
||||
}
|
||||
if (this.formData.type == 2) {
|
||||
this.checkVal.splice(this.checkVal.indexOf(scope.$index + 1), 1)
|
||||
}
|
||||
this.formData.answer.splice(scope.$index, 1)
|
||||
},
|
||||
openView(id) {
|
||||
$.get("/platform/hd/zxdt/subject/findOne", {id: id}, (res) => {
|
||||
const {code, data, msg} = res
|
||||
if (code == 0) {
|
||||
this.viewData = data
|
||||
if (data.type == 2) {
|
||||
data.answer.forEach((val, idx) => {
|
||||
if (val.is_yes) {
|
||||
this.checkVal.push(idx + 1)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
data.answer.forEach((val, idx) => {
|
||||
if (val.is_yes) {
|
||||
this.is_yes = idx + 1
|
||||
}
|
||||
})
|
||||
}
|
||||
this.v = 'view'
|
||||
} else {
|
||||
this.$message.error(msg)
|
||||
}
|
||||
})
|
||||
},
|
||||
doDelete(id) {
|
||||
let that = this
|
||||
this.$confirm('确定要删除吗', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
callback(a, b) {
|
||||
if ("confirm" == a) {//确认后再执行
|
||||
$.get(base + "/platform/hd/zxdt/subject/delete", {id: id}).then(res => {
|
||||
if (res.code == 0) {
|
||||
that.$message.success(res.msg);
|
||||
that.pageData();
|
||||
} else {
|
||||
that.$message.warning(res.msg);
|
||||
}
|
||||
}).catch(err => {
|
||||
that.$message.error(err.msg);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
openAdd() {
|
||||
this.formData = {type: 1, answer: [{}, {}, {}, {}]}
|
||||
this.is_yes = ''
|
||||
this.checkVal = []
|
||||
this.v = 'add'
|
||||
},
|
||||
openEdit(id) {
|
||||
$.get("/platform/hd/zxdt/subject/findOne", {id: id}, (res) => {
|
||||
const {code, data, msg} = res
|
||||
if (code == 0) {
|
||||
this.formData = data
|
||||
if (data.type == 2) {
|
||||
data.answer.forEach((val, idx) => {
|
||||
if (val.is_yes) {
|
||||
this.checkVal.push(idx + 1)
|
||||
}
|
||||
})
|
||||
} else {
|
||||
data.answer.forEach((val, idx) => {
|
||||
if (val.is_yes) {
|
||||
this.is_yes = idx + 1
|
||||
}
|
||||
})
|
||||
}
|
||||
this.v = "edit"
|
||||
} else {
|
||||
this.$message.error(msg)
|
||||
}
|
||||
})
|
||||
},
|
||||
operation() {
|
||||
let url
|
||||
if (this.formData.answer.length < 0) {
|
||||
this.$message.warning('请至少添加一个选项!');
|
||||
return
|
||||
}
|
||||
|
||||
for (let i = 0; i < this.formData.answer.length; i++) {
|
||||
if (!this.formData.answer[i].option_txt) {
|
||||
this.$message.warning('第 ' + (i + 1) + " 个选项的名字未填写!");
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (this.formData.type == '2') {
|
||||
if (this.checkVal.length < 1) {
|
||||
this.$message.warning('请至少选择一个选项为正确答案!');
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if (!this.is_yes) {
|
||||
this.$message.warning('请至少选择一个选项为正确答案!');
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (this.v == 'edit') {
|
||||
url = "/platform/hd/zxdt/subject/doEdit"
|
||||
} else if (this.v == 'add') {
|
||||
url = "/platform/hd/zxdt/subject/doAdd"
|
||||
}
|
||||
|
||||
const loading = this.$loading({
|
||||
lock: true,
|
||||
text: '数据提交中...',
|
||||
spinner: 'el-icon-loading',
|
||||
background: 'rgba(0, 0, 0, 0.7)'
|
||||
});
|
||||
|
||||
this.$refs["addForm"].validate((valid) => {
|
||||
if (valid) {
|
||||
this.formData.answer.forEach((value) => {
|
||||
value.is_yes = false
|
||||
})
|
||||
if (this.formData.type == "2") {
|
||||
this.checkVal.forEach((v) => {
|
||||
this.formData.answer[parseInt([v]) - 1].is_yes = true
|
||||
})
|
||||
} else {
|
||||
this.formData.answer[parseInt([this.is_yes]) - 1].is_yes = true
|
||||
}
|
||||
|
||||
$.post(base + url, {
|
||||
subject: JSON.stringify(this.formData),
|
||||
delOption: JSON.stringify(this.delOption)
|
||||
}, (data) => {
|
||||
if (data.code == 0) {
|
||||
this.v = 'index'
|
||||
this.pageData()
|
||||
this.$message.success(data.msg)
|
||||
} else {
|
||||
this.$message.error(data.msg);
|
||||
}
|
||||
loading.close()
|
||||
}, "json");
|
||||
}
|
||||
})
|
||||
},
|
||||
doSearch() {
|
||||
this.pageForm.pageNumber = 1;
|
||||
this.pageData();
|
||||
},
|
||||
pageOrder(column) {//按字段排序
|
||||
this.pageForm.pageOrderName = column.prop;
|
||||
this.pageForm.pageOrderBy = column.order;
|
||||
this.pageData();
|
||||
},
|
||||
pageNumberChange(val) {//页码更新操作
|
||||
this.pageForm.pageNumber = val;
|
||||
this.pageData();
|
||||
},
|
||||
pageSizeChange(val) {//分页大小更新操作
|
||||
this.pageForm.pageSize = val;
|
||||
this.pageData();
|
||||
},
|
||||
pageData() {//加载分页数据
|
||||
sublime.showLoadingbar();
|
||||
$.post(base + "/platform/hd/zxdt/subject/pageData", this.pageForm, (res) => {
|
||||
const {code, msg, data} = res
|
||||
if (code == 0) {
|
||||
this.tableData = data.list;
|
||||
this.pageForm.totalCount = data.totalCount;
|
||||
sublime.closeLoadingbar();
|
||||
} else {
|
||||
this.$message.error(msg);
|
||||
}
|
||||
}, "json");
|
||||
}
|
||||
,
|
||||
},
|
||||
created() {
|
||||
this.pageData();
|
||||
},
|
||||
})
|
||||
</script>
|
||||
|
||||
<!--#
|
||||
}
|
||||
#-->
|
||||
Reference in New Issue
Block a user