|
@@ -1,15 +1,68 @@
|
|
|
<template>
|
|
|
<div id="index">
|
|
|
- <list-frame title="作业题列表页" returns="/work/index" @query="search" :total="total" :filter="filFields" @add="toAdd">
|
|
|
+ <list-frame title="作业题列表页" returns="/work/index" @query="search" :needPag="false" :needFilter="false" @add="toAdd">
|
|
|
+ <el-row type="flex" justify="center" style="padding-bottom:1.875rem;">
|
|
|
+ <el-col :span="3">
|
|
|
+ <el-button type="primary" @click="submit" size="small">保存作业</el-button>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
<data-table :fields="fields" :data="list" :opera="opera" @edit="toEdit" @delete="toDelete"> </data-table>
|
|
|
</list-frame>
|
|
|
- <el-dialog title="选择题类型" :visible.sync="dialog" @close="toClose">
|
|
|
- <data-form v-loading="loading" :data="info" :fields="qFields" :rules="rules" @save="handleSave" :isNew="isNew">
|
|
|
- <template #radios>
|
|
|
- <el-radio v-for="(item, index) in radios" :key="index" :label="item.code">{{ item.name }}</el-radio>
|
|
|
- </template>
|
|
|
- </data-form>
|
|
|
+ <el-dialog title="作业题" :visible.sync="dialog" @close="toClose">
|
|
|
+ <el-form ref="infoForm" :model="info" :rules="rules" label-width="120px" size="small" @submit.native.prevent>
|
|
|
+ <el-form-item label="类型" :required="true" prop="type">
|
|
|
+ <el-radio-group v-model="info.type">
|
|
|
+ <el-radio v-for="(item, index) in radios" :key="index" :label="item.code">{{ item.name }}</el-radio>
|
|
|
+ </el-radio-group>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="题目" :required="true" prop="topic">
|
|
|
+ <el-input v-model="info.topic"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="选项" prop="option" v-if="info.type === '0' || info.type === '1'">
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="24" style="text-align:right;padding-bottom:10px">
|
|
|
+ <el-button type="primary" size="mini" @click="drawer = true">添加选项</el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="24">
|
|
|
+ <el-table :data="info.option" border stripe size="mini">
|
|
|
+ <el-table-column align="center" label="序号" prop="number"></el-table-column>
|
|
|
+ <el-table-column align="center" label="内容" prop="option_name"></el-table-column>
|
|
|
+ <el-table-column align="center" label="操作">
|
|
|
+ <template v-slot="{ row, $index }">
|
|
|
+ <el-tooltip effect="dark" content="编辑" placement="bottom">
|
|
|
+ <el-button type="text" size="mini" icon="el-icon-edit" @click="toOedit(row, $index)"></el-button>
|
|
|
+ </el-tooltip>
|
|
|
+ <el-tooltip effect="dark" content="删除" placement="bottom">
|
|
|
+ <el-button type="text" size="mini" icon="el-icon-delete" @click="toOdelete(row, $index)"></el-button>
|
|
|
+ </el-tooltip>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="答案" prop="answer" v-if="info.type === '0' || info.type === '1'">
|
|
|
+ <el-input v-model="info.answer"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item>
|
|
|
+ <el-row type="flex" justify="center">
|
|
|
+ <el-col :span="6">
|
|
|
+ <el-button type="primary" @click="handleSave">保 存</el-button>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="6">
|
|
|
+ <el-button @click="$refs.infoForm.resetFields()">重 置</el-button>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
</el-dialog>
|
|
|
+ <el-drawer :visible.sync="drawer" @close="toOclose" direction="rtl" :with-header="false">
|
|
|
+ <el-tabs style="padding:10px;">
|
|
|
+ <el-tab-pane label="选项">
|
|
|
+ <data-form :styles="{ padding: 0 }" :data="optionForm" :fields="oFields" :rules="oRules" @save="handleOsave" :isNew="oIsNew"></data-form>
|
|
|
+ </el-tab-pane>
|
|
|
+ </el-tabs>
|
|
|
+ </el-drawer>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
@@ -30,14 +83,17 @@ export default {
|
|
|
dataForm,
|
|
|
},
|
|
|
data: () => ({
|
|
|
+ loading: false,
|
|
|
+ isNew: true,
|
|
|
+ oIsNew: true,
|
|
|
dialog: false,
|
|
|
+ drawer: false,
|
|
|
opera: [
|
|
|
{
|
|
|
label: '编辑',
|
|
|
icon: 'el-icon-edit',
|
|
|
- method: 'add',
|
|
|
+ method: 'edit',
|
|
|
},
|
|
|
-
|
|
|
{
|
|
|
label: '删除',
|
|
|
icon: 'el-icon-delete',
|
|
@@ -46,20 +102,12 @@ export default {
|
|
|
],
|
|
|
|
|
|
fields: [
|
|
|
- { label: '题编号', prop: 'id' },
|
|
|
- { label: '题名称', prop: 'name' },
|
|
|
+ { label: '题名称', prop: 'topic' },
|
|
|
{
|
|
|
label: '问题类型',
|
|
|
prop: 'type',
|
|
|
format: item => {
|
|
|
- return item === '0' ? '单选' : item === '1' ? '多选' : item === '2' ? '问答' : '其他';
|
|
|
- },
|
|
|
- },
|
|
|
- {
|
|
|
- label: '状态',
|
|
|
- prop: 'state',
|
|
|
- format: item => {
|
|
|
- return item === '0' ? '弃用' : item === '1' ? '使用' : '其他';
|
|
|
+ return item === '0' ? '单选' : item === '1' ? '多选' : '简答';
|
|
|
},
|
|
|
},
|
|
|
],
|
|
@@ -86,14 +134,21 @@ export default {
|
|
|
],
|
|
|
},
|
|
|
],
|
|
|
- qFields: [
|
|
|
- { label: '类型', required: true, model: 'type', type: 'radio' },
|
|
|
- { label: '题目', required: true, model: 'topic' },
|
|
|
- { label: '选项', model: 'option', custom: true },
|
|
|
- { label: '答案', model: 'answer', custom: true },
|
|
|
+ rules: {
|
|
|
+ type: [{ required: true, message: '请选择类型' }],
|
|
|
+ topic: [{ required: true, message: '请输入题目' }],
|
|
|
+ },
|
|
|
+ oFields: [
|
|
|
+ { label: '序号', required: true, model: 'number' },
|
|
|
+ { label: '内容', required: true, model: 'option_name' },
|
|
|
],
|
|
|
+ oRules: {
|
|
|
+ number: [{ required: true, message: '请输入序号' }],
|
|
|
+ option_name: [{ required: true, message: '请输入内容' }],
|
|
|
+ },
|
|
|
list: [],
|
|
|
info: {},
|
|
|
+ optionForm: {},
|
|
|
radios: [
|
|
|
{ code: '0', name: '单选' },
|
|
|
{ code: '1', name: '多选' },
|
|
@@ -116,7 +171,7 @@ export default {
|
|
|
},
|
|
|
},
|
|
|
methods: {
|
|
|
- ...mapActions(['fetch']),
|
|
|
+ ...mapActions(['fetch', 'update']),
|
|
|
async search({ skip = 0, limit = 15, ...info } = {}) {
|
|
|
const res = await this.fetch(this.id);
|
|
|
if (this.$checkRes(res)) {
|
|
@@ -124,20 +179,79 @@ export default {
|
|
|
}
|
|
|
this.loading = false;
|
|
|
},
|
|
|
+ // 作业
|
|
|
toAdd() {
|
|
|
this.dialog = true;
|
|
|
+ this.isNew = true;
|
|
|
},
|
|
|
- toEdit(data) {
|
|
|
- console.log(`in toEdit`);
|
|
|
- console.log(data);
|
|
|
+ handleSave() {
|
|
|
+ this.$refs['infoForm'].validate(valid => {
|
|
|
+ if (valid) {
|
|
|
+ if (this.isNew) {
|
|
|
+ this.list.push(JSON.parse(JSON.stringify(this.info)));
|
|
|
+ } else {
|
|
|
+ let { index, ...data } = JSON.parse(JSON.stringify(this.info));
|
|
|
+ this.$set(this.list, index, data);
|
|
|
+ }
|
|
|
+ this.toClose();
|
|
|
+ } else {
|
|
|
+ console.warn('form validate error!!!');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ toEdit({ data, index }) {
|
|
|
+ data.index = index;
|
|
|
+ this.info = JSON.parse(JSON.stringify(data));
|
|
|
+ this.isNew = false;
|
|
|
+ this.dialog = true;
|
|
|
+ },
|
|
|
+ toDelete({ data, index }) {
|
|
|
+ this.list.splice(index, 1);
|
|
|
},
|
|
|
- toDelete(data) {},
|
|
|
toClose() {
|
|
|
this.dialog = false;
|
|
|
this.info = {};
|
|
|
+ this.$refs.infoForm.resetFields();
|
|
|
+ },
|
|
|
+ // 选项
|
|
|
+ toOclose() {
|
|
|
+ this.drawer = false;
|
|
|
+ this.oIsNew = true;
|
|
|
+ this.optionForm = {};
|
|
|
+ },
|
|
|
+ handleOsave({ isNew, data }) {
|
|
|
+ if (isNew) {
|
|
|
+ if (!_.isArray(this.info.option)) this.info.option = [];
|
|
|
+ this.info.option.push(data);
|
|
|
+ } else {
|
|
|
+ let { index, ...info } = data;
|
|
|
+ this.$set(this.info.option, index, info);
|
|
|
+ }
|
|
|
+ this.toOclose();
|
|
|
+ },
|
|
|
+ toOedit(row, index) {
|
|
|
+ let data = JSON.parse(JSON.stringify(row));
|
|
|
+ data.index = index;
|
|
|
+ this.optionForm = data;
|
|
|
+ this.drawer = true;
|
|
|
+ this.oIsNew = false;
|
|
|
+ },
|
|
|
+ toOdelete(row, index) {
|
|
|
+ this.info.option.splice(index, 1);
|
|
|
+ },
|
|
|
+ //作业
|
|
|
+ async submit() {
|
|
|
+ const res = await this.update({ id: this.id, question: JSON.parse(JSON.stringify(this.list)) });
|
|
|
+ if (this.$checkRes(res, '作业修改成功', '作业修改失败')) {
|
|
|
+ this.$router.push({ path: '/work/index' });
|
|
|
+ }
|
|
|
},
|
|
|
},
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
-<style lang="scss" scoped></style>
|
|
|
+<style lang="less" scoped>
|
|
|
+/deep/.el-tabs__header .is-top {
|
|
|
+ zoom: 1.1;
|
|
|
+}
|
|
|
+</style>
|