优化题库列表

This commit is contained in:
zhl 2021-04-23 15:52:06 +08:00
parent 1ee2fe9060
commit 3aaed5fd06
3 changed files with 85 additions and 11 deletions

View File

@ -9,7 +9,8 @@ export interface IQuestionData {
a4?: string, a4?: string,
groups?: string[], groups?: string[],
tag?: string, tag?: string,
subtag?: string, sub_tag?: string,
category?: string,
quality: number, quality: number,
withNext: boolean withNext: boolean
} }

View File

@ -13,12 +13,12 @@
<el-col :span="24"> <el-col :span="24">
<el-form-item <el-form-item
style="margin-bottom: 40px;" style="margin-bottom: 40px;"
prop="title" prop="question"
> >
<material-input <material-input
v-model="postForm.question" v-model="postForm.question"
:maxlength="100" :maxlength="100"
name="name" name="question"
required required
> >
题目 题目
@ -31,11 +31,12 @@
<el-form-item <el-form-item
style="margin-bottom: 40px;" style="margin-bottom: 40px;"
label="答案:" label="答案:"
prop="a1"
> >
<el-input <el-input
v-model="postForm.a1" v-model="postForm.a1"
:rows="1"
placeholder="输入答案" placeholder="输入答案"
name="a1"
required required
/> />
</el-form-item> </el-form-item>
@ -221,7 +222,8 @@ export default class extends Vue {
private postForm = Object.assign({}, defaultQuestionData) private postForm = Object.assign({}, defaultQuestionData)
private loading = false private loading = false
private rules = { private rules = {
title: [{ validator: this.validateRequire }], question: [{ validator: this.validateRequire }],
a1: [{ validator: this.validateRequire }],
} }
private typeOptions: any[] = [] private typeOptions: any[] = []
private typeSelect: string[] = [] private typeSelect: string[] = []
@ -256,7 +258,7 @@ export default class extends Vue {
try { try {
const { data } = await getQuestion(id, { /* Your params here */ }) const { data } = await getQuestion(id, { /* Your params here */ })
this.postForm = data this.postForm = data
this.typeSelect = [this.postForm.tag || '', this.postForm.subtag || ''] this.typeSelect = [this.postForm.tag || '', this.postForm.sub_tag || '']
// Just for test // Just for test
const title = this.lang === 'zh' ? '编辑题目' : 'Edit Question' const title = this.lang === 'zh' ? '编辑题目' : 'Edit Question'
// Set tagsview title // Set tagsview title
@ -282,7 +284,7 @@ export default class extends Vue {
private typechange(val: string[]) { private typechange(val: string[]) {
this.postForm.tag = this.typeSelect[0] this.postForm.tag = this.typeSelect[0]
this.postForm.subtag = this.typeSelect[1] this.postForm.sub_tag = this.typeSelect[1]
} }
private async tagChange(tags: string[]) { private async tagChange(tags: string[]) {

View File

@ -5,7 +5,16 @@
<el-form-item label="关键字" prop="key"> <el-form-item label="关键字" prop="key">
<el-input v-model="filterForm.key" placeholder="关键字"/> <el-input v-model="filterForm.key" placeholder="关键字"/>
</el-form-item> </el-form-item>
<el-form-item label="分类" prop="key">
<el-cascader
:options="typeOptions"
v-model="filterForm.typeSelect"
filterable
clearable
size="medium"
>
</el-cascader>
</el-form-item>
<el-form-item> <el-form-item>
<el-button type="primary" @click="search">查询</el-button> <el-button type="primary" @click="search">查询</el-button>
<el-button @click="resetFilterForm">重置</el-button> <el-button @click="resetFilterForm">重置</el-button>
@ -36,6 +45,13 @@
<span>{{ row.createtime | parseTime }}</span> <span>{{ row.createtime | parseTime }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column
label="分类"
>
<template slot-scope="{row}">
<span>{{ row.category }}</span>
</template>
</el-table-column>
<el-table-column <el-table-column
min-width="200px" min-width="200px"
label="名称" label="名称"
@ -66,9 +82,20 @@
</template> </template>
</el-table-column> </el-table-column>
<el-table-column
label="Tags"
>
<template slot-scope="{row}">
<el-tag v-for="item in row.groups">{{ item }}</el-tag>
</template>
</el-table-column>
<el-table-column <el-table-column
align="center" align="center"
width="180"
label="操作" label="操作"
fixed="right"
> >
<template slot-scope="scope"> <template slot-scope="scope">
<router-link :to="'/question/edit/'+scope.row._id"> <router-link :to="'/question/edit/'+scope.row._id">
@ -109,7 +136,12 @@ import Pagination from '@/components/Pagination/index.vue'
import { deleteShop, getShops } from '@/api/shop' import { deleteShop, getShops } from '@/api/shop'
import { parseTime } from '@/utils' import { parseTime } from '@/utils'
import { Form } from 'element-ui' import { Form } from 'element-ui'
import { deleteQuestion, getQuestions, IQuestionData } from '@/api/question' import {
deleteQuestion, getAllCategory,
getAllTags,
getQuestions,
IQuestionData
} from '@/api/question'
@Component({ @Component({
name: 'QuestionList', name: 'QuestionList',
@ -143,14 +175,23 @@ export default class extends Vue {
private listQuery = { private listQuery = {
page: 1, page: 1,
limit: 20, limit: 20,
key: '' key: '',
tag: '',
sub_tag: '',
groups: ''
} }
private typeOptions: any[] = []
private tagSet: Set<string> = new Set()
private tagOptions: string[] = []
private filterForm = { private filterForm = {
key: '' key: '',
typeSelect: []
} }
created() { created() {
this.getList() this.getList()
this.getRemoteTags()
this.getRemoteCategory()
} }
@ -183,6 +224,12 @@ export default class extends Vue {
private filterData() { private filterData() {
this.listQuery.key = this.filterForm.key this.listQuery.key = this.filterForm.key
if (this.filterForm.typeSelect.length > 0) {
this.listQuery.tag = this.filterForm.typeSelect[0]
}
if (this.filterForm.typeSelect.length > 1) {
this.listQuery.sub_tag = this.filterForm.typeSelect[1]
}
this.listQuery.page = 1 this.listQuery.page = 1
this.getList() this.getList()
} }
@ -196,6 +243,30 @@ export default class extends Vue {
if (!data.records) return if (!data.records) return
this.allDepts = data.records this.allDepts = data.records
} }
private async getRemoteTags() {
let { data } = await getAllTags()
console.log(data)
this.tagSet = new Set(data)
this.tagOptions = data
}
private async getRemoteCategory() {
let {data} = await getAllCategory()
for (let cat of data) {
let subArr = []
for (let s of cat.children) {
subArr.push({
value: s._id,
label: s.name
})
}
this.typeOptions.push({
value: cat._id,
label: cat.name,
children: subArr
})
}
}
} }
</script> </script>