feat: 问卷列表新增排序功能 (#54)

This commit is contained in:
Realabiha 2024-01-23 21:49:39 +08:00 committed by GitHub
parent 4031266ce8
commit 45f3816209
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 105 additions and 22 deletions

View File

@ -1,11 +1,12 @@
import axios from './base'; import axios from './base';
export const getSurveyList = (curPage, filter) => { export const getSurveyList = (curPage, filter, order) => {
return axios.get('/surveyManage/list', { return axios.get('/surveyManage/list', {
params: { params: {
pageSize: 10, pageSize: 10,
curPage, curPage,
filter, filter,
order
}, },
}); });
}; };

View File

@ -4,12 +4,23 @@
<div class="select"> <div class="select">
<text-select <text-select
v-for="item in Object.keys(selectOptionsDict)" v-for="item in Object.keys(selectOptionsDict)"
:key="item"
:effect-fun="onSelectChange" :effect-fun="onSelectChange"
:effect-key="item" :effect-key="item"
:options="selectOptionsDict[item]" :options="selectOptionsDict[item]"
/> />
</div> </div>
<div class="search"> <div class="search">
<text-button
v-for="item in Object.keys(buttonOptionsDict)"
:key="item"
:effect-fun="onButtonChange"
:effect-key="item"
:option="buttonOptionsDict[item]"
:icon="buttonOptionsDict[item].icons.find(iconItem => iconItem.effectValue === buttonValueMap[item]).name"
size="mini"
type="text"
></text-button>
<text-search <text-search
placeholder="请输入问卷标题" placeholder="请输入问卷标题"
:value="searchVal" :value="searchVal"
@ -102,7 +113,8 @@ import State from './state';
import ToolBar from './toolBar'; import ToolBar from './toolBar';
import TextSearch from './textSearch' import TextSearch from './textSearch'
import TextSelect from './textSelect' import TextSelect from './textSelect'
import { fieldConfig, thead, noListDataConfig, noSearchDataConfig, selectOptionsDict } from '../config'; import TextButton from './textButton'
import { fieldConfig, thead, noListDataConfig, noSearchDataConfig, selectOptionsDict, buttonOptionsDict } from '../config';
import { CODE_MAP } from '@/management/api/base'; import { CODE_MAP } from '@/management/api/base';
import { QOP_MAP } from '@/management/utils/constant'; import { QOP_MAP } from '@/management/utils/constant';
import { getSurveyList, deleteSurvey } from '@/management/api/survey'; import { getSurveyList, deleteSurvey } from '@/management/api/survey';
@ -127,6 +139,11 @@ export default {
selectValueMap: { selectValueMap: {
questionType: '', questionType: '',
'curStatus.status': '' 'curStatus.status': ''
},
buttonOptionsDict,
buttonValueMap: {
'curStatus.date': '',
createDate: -1
} }
}; };
}, },
@ -168,6 +185,16 @@ export default {
] ]
} }
] ]
},
order(){
const formatOrder = Object.entries(this.buttonValueMap)
.filter(([, effectValue]) => effectValue)
.reduce((prev, item) => {
const [effectKey, effectValue] = item
prev.push({field: effectKey, value: effectValue})
return prev
}, [])
return JSON.stringify(formatOrder)
} }
}, },
created() { created() {
@ -180,7 +207,8 @@ export default {
const filter = JSON.stringify(this.filter.filter(item => { const filter = JSON.stringify(this.filter.filter(item => {
return item.condition[0].field === 'title' || item.condition[0].value return item.condition[0].field === 'title' || item.condition[0].value
})) }))
const res = await getSurveyList(this.currentPage, filter);
const res = await getSurveyList(this.currentPage, filter, this.order);
this.loading = false; this.loading = false;
if (res.code === CODE_MAP.SUCCESS) { if (res.code === CODE_MAP.SUCCESS) {
this.total = res.data.count; this.total = res.data.count;
@ -289,6 +317,14 @@ export default {
this.selectValueMap[selectKey] = selectValue this.selectValueMap[selectKey] = selectValue
this.currentPage = 1 this.currentPage = 1
this.init() this.init()
},
onButtonChange(effectValue, effectKey){
this.buttonValueMap = {
'curStatus.date': '',
createDate: ''
}
this.buttonValueMap[effectKey] = effectValue
this.init()
} }
}, },
components: { components: {
@ -298,6 +334,7 @@ export default {
ToolBar, ToolBar,
TextSearch, TextSearch,
TextSelect, TextSelect,
TextButton,
State, State,
}, },
}; };

View File

@ -1,7 +1,9 @@
<template> <template>
<div class="text-button-root" @click="onClick"> <div class="text-button-root" @click="onClick">
<el-button type="text" :icon="currentOption.icon" size="mini"> <el-button
<slot>{{ currentOption.label }}</slot> v-bind="{...$attrs}"
>
<slot>{{ option.label }}</slot>
</el-button> </el-button>
</div> </div>
</template> </template>
@ -10,13 +12,12 @@ export default{
name: 'TextButton', name: 'TextButton',
data(){ data(){
return { return {
optionIndex: 0, iconIndex: 0
optionValue: ''
} }
}, },
props: { props: {
options: { option: {
type: Array, type: Object,
required: true required: true
}, },
effectFun: { effectFun: {
@ -27,31 +28,35 @@ export default{
} }
}, },
computed: { computed: {
optionsLength(){ toggleOptionIcons(){
return this.options.length return this.option.icons.slice(1)
}, },
currentOption(){ iconsLength(){
return this.options[this.optionIndex % this.optionsLength] return this.toggleOptionIcons.length
},
currentIconItem(){
let finalIconIndex = this.iconIndex % this.iconsLength
return this.toggleOptionIcons[finalIconIndex]
} }
}, },
watch: {
currentOption(newOption){
typeof this.effectFun === 'function' && this.effectFun(newOption, this.effectKey)
}
},
methods: { methods: {
onClick(){ onClick(){
if(this.optionIndex > this.optionsLength){ this.iconIndex++
this.optionIndex = 0 if(this.iconIndex >= this.iconsLength){
return this.iconIndex = 0
} }
this.optionIndex++ typeof this.effectFun === 'function' && this.effectFun(this.currentIconItem.effectValue, this.effectKey)
} }
}, },
created(){
this.iconIndex = this.toggleOptionIcons.findIndex(iconItem => iconItem.isDefaultValue)
}
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.el-button{ .el-button{
margin-right: 20px; margin-right: 20px;
font-size: 14px;
color: #4a4c5b;
} }
</style> </style>

View File

@ -134,4 +134,44 @@ export const selectOptionsDict = Object.freeze({
'curStatus.status': curStatusSelect 'curStatus.status': curStatusSelect
}) })
export const buttonOptionsDict = Object.freeze({
'curStatus.date': {
label: '更新时间',
icons: [
{
name: 'el-icon-sort',
effectValue: '',
isDefaultValue: true
},
{
name: 'el-icon-sort-up',
effectValue: 1
},
{
name: 'el-icon-sort-down',
effectValue: -1,
},
]
},
createDate: {
label: '创建时间',
icons: [
{
name: 'el-icon-sort',
effectValue: '',
},
{
name: 'el-icon-sort-up',
effectValue: 1
},
{
name: 'el-icon-sort-down',
effectValue: -1,
isDefaultValue: true
},
]
}
})