优化题库列表

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,
groups?: string[],
tag?: string,
subtag?: string,
sub_tag?: string,
category?: string,
quality: number,
withNext: boolean
}

View File

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

View File

@ -5,7 +5,16 @@
<el-form-item label="关键字" prop="key">
<el-input v-model="filterForm.key" placeholder="关键字"/>
</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-button type="primary" @click="search">查询</el-button>
<el-button @click="resetFilterForm">重置</el-button>
@ -36,6 +45,13 @@
<span>{{ row.createtime | parseTime }}</span>
</template>
</el-table-column>
<el-table-column
label="分类"
>
<template slot-scope="{row}">
<span>{{ row.category }}</span>
</template>
</el-table-column>
<el-table-column
min-width="200px"
label="名称"
@ -66,9 +82,20 @@
</template>
</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
align="center"
width="180"
label="操作"
fixed="right"
>
<template slot-scope="scope">
<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 { parseTime } from '@/utils'
import { Form } from 'element-ui'
import { deleteQuestion, getQuestions, IQuestionData } from '@/api/question'
import {
deleteQuestion, getAllCategory,
getAllTags,
getQuestions,
IQuestionData
} from '@/api/question'
@Component({
name: 'QuestionList',
@ -143,14 +175,23 @@ export default class extends Vue {
private listQuery = {
page: 1,
limit: 20,
key: ''
key: '',
tag: '',
sub_tag: '',
groups: ''
}
private typeOptions: any[] = []
private tagSet: Set<string> = new Set()
private tagOptions: string[] = []
private filterForm = {
key: ''
key: '',
typeSelect: []
}
created() {
this.getList()
this.getRemoteTags()
this.getRemoteCategory()
}
@ -183,6 +224,12 @@ export default class extends Vue {
private filterData() {
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.getList()
}
@ -196,6 +243,30 @@ export default class extends Vue {
if (!data.records) return
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>