Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: 问卷列表新增排序功能 #54

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion web/src/management/api/survey.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import axios from './base';

export const getSurveyList = (curPage, filter) => {
export const getSurveyList = (curPage, filter, order) => {
return axios.get('/surveyManage/list', {
params: {
pageSize: 10,
curPage,
filter,
order
},
});
};
Expand Down
41 changes: 39 additions & 2 deletions web/src/management/pages/list/components/baseList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,23 @@
<div class="select">
<text-select
v-for="item in Object.keys(selectOptionsDict)"
:key="item"
:effect-fun="onSelectChange"
:effect-key="item"
:options="selectOptionsDict[item]"
/>
</div>
<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
placeholder="请输入问卷标题"
:value="searchVal"
Expand Down Expand Up @@ -102,7 +113,8 @@ import State from './state';
import ToolBar from './toolBar';
import TextSearch from './textSearch'
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 { QOP_MAP } from '@/management/utils/constant';
import { getSurveyList, deleteSurvey } from '@/management/api/survey';
Expand All @@ -127,6 +139,11 @@ export default {
selectValueMap: {
questionType: '',
'curStatus.status': ''
},
buttonOptionsDict,
buttonValueMap: {
'curStatus.date': '',
createDate: -1
}
};
},
Expand Down Expand Up @@ -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() {
Expand All @@ -180,7 +207,8 @@ export default {
const filter = JSON.stringify(this.filter.filter(item => {
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;
if (res.code === CODE_MAP.SUCCESS) {
this.total = res.data.count;
Expand Down Expand Up @@ -289,6 +317,14 @@ export default {
this.selectValueMap[selectKey] = selectValue
this.currentPage = 1
this.init()
},
onButtonChange(effectValue, effectKey){
this.buttonValueMap = {
'curStatus.date': '',
createDate: ''
}
this.buttonValueMap[effectKey] = effectValue
this.init()
}
},
components: {
Expand All @@ -298,6 +334,7 @@ export default {
ToolBar,
TextSearch,
TextSelect,
TextButton,
State,
},
};
Expand Down
43 changes: 24 additions & 19 deletions web/src/management/pages/list/components/textButton.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<template>
<div class="text-button-root" @click="onClick">
<el-button type="text" :icon="currentOption.icon" size="mini">
<slot>{{ currentOption.label }}</slot>
<el-button
v-bind="{...$attrs}"
>
<slot>{{ option.label }}</slot>
</el-button>
</div>
</template>
Expand All @@ -10,13 +12,12 @@ export default{
name: 'TextButton',
data(){
return {
optionIndex: 0,
optionValue: ''
iconIndex: 0
}
},
props: {
options: {
type: Array,
option: {
type: Object,
required: true
},
effectFun: {
Expand All @@ -27,31 +28,35 @@ export default{
}
},
computed: {
optionsLength(){
return this.options.length
toggleOptionIcons(){
return this.option.icons.slice(1)
},
currentOption(){
return this.options[this.optionIndex % this.optionsLength]
iconsLength(){
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: {
onClick(){
if(this.optionIndex > this.optionsLength){
this.optionIndex = 0
return
this.iconIndex++
if(this.iconIndex >= this.iconsLength){
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>
<style lang="scss" scoped>
.el-button{
margin-right: 20px;
font-size: 14px;
color: #4a4c5b;
}
</style>
40 changes: 40 additions & 0 deletions web/src/management/pages/list/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,44 @@ export const selectOptionsDict = Object.freeze({
'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
},
]
}
})