Skip to content

Commit 933f9f1

Browse files
committed
refactor: sort list change
1 parent 9beb4f8 commit 933f9f1

File tree

3 files changed

+85
-14
lines changed

3 files changed

+85
-14
lines changed

frontend/src/i18n/en.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
"password_reset_successful": "Password reset successful"
3333
},
3434
"dashboard": {
35+
"sort_column": "Sort field",
36+
"sort_type": "Sort type",
37+
"time": "Time",
38+
"sort_asc": "Ascending",
39+
"sort_desc": "Descending",
3540
"name_repeat": "Name Repeat",
3641
"rich_text_tips": "Double-click to enter text content",
3742
"exit_preview": "Exit preview",
@@ -487,4 +492,4 @@
487492
"back_community": "Restore to Community Edition",
488493
"confirm_tips": "Are you sure to restore to Community Edition?"
489494
}
490-
}
495+
}

frontend/src/i18n/zh-CN.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
"password_reset_successful": "重置密码成功"
3535
},
3636
"dashboard": {
37+
"sort_column": "排序字段",
38+
"sort_type": "排序方式",
39+
"time": "时间",
40+
"sort_asc": "升序",
41+
"sort_desc": "降序",
3742
"name_repeat": "仪表板名称已被使用",
3843
"rich_text_tips": "双击输入文本内容",
3944
"exit_preview": "退出预览",
@@ -499,4 +504,4 @@
499504
"back_community": "还原至社区版",
500505
"confirm_tips": "确定还原至社区版?"
501506
}
502-
}
507+
}

frontend/src/views/dashboard/common/ResourceTree.vue

Lines changed: 73 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ const expandedArray = ref([])
5757
const resourceListTree = ref()
5858
const returnMounted = ref(false)
5959
const state = reactive({
60-
curSortType: 'time_desc',
60+
curSortType: 'name_asc',
61+
curSortTypePrefix: 'name',
62+
curSortTypeSuffix: '_asc',
6163
resourceTree: [] as SQTreeNode[],
6264
originResourceTree: [] as SQTreeNode[],
6365
sortType: [],
@@ -134,6 +136,7 @@ const getTree = async () => {
134136
dashboardApi.list_resource(params).then((res: SQTreeNode[]) => {
135137
state.originResourceTree = res || []
136138
state.resourceTree = _.cloneDeep(state.originResourceTree)
139+
handleSortTypeChange('name_asc')
137140
afterTreeInit()
138141
})
139142
}
@@ -246,16 +249,41 @@ const baseInfoChangeFinish = () => {
246249
getTree()
247250
}
248251
249-
const handleSortTypeChange = (sortType: string) => {
250-
state.resourceTree = treeSort(state.originResourceTree, sortType)
251-
state.curSortType = sortType
252+
const handleSortTypeChange = (menuSortType: string) => {
253+
state.curSortTypePrefix = ['name', 'time'].includes(menuSortType)
254+
? menuSortType
255+
: state.curSortTypePrefix
256+
state.curSortTypeSuffix = ['_asc', '_desc'].includes(menuSortType)
257+
? menuSortType
258+
: state.curSortTypeSuffix
259+
const curMenuSortType = state.curSortTypePrefix + state.curSortTypeSuffix
260+
state.resourceTree = treeSort(state.originResourceTree, curMenuSortType)
261+
state.curSortType = curMenuSortType
252262
wsCache.set('TreeSort-dashboard', state.curSortType)
253263
}
254264
255-
// const sortTypeChange = (sortType: string) => {
256-
// state.resourceTree = treeSort(state.originResourceTree, sortType)
257-
// state.curSortType = sortType
258-
// }
265+
const sortColumnList = [
266+
{
267+
name: t('dashboard.time'),
268+
value: 'time',
269+
},
270+
{
271+
name: t('dashboard.name'),
272+
value: 'name',
273+
divided: true,
274+
},
275+
]
276+
277+
const sortTypeList = [
278+
{
279+
name: t('dashboard.sort_asc'),
280+
value: '_asc',
281+
},
282+
{
283+
name: t('dashboard.sort_desc'),
284+
value: '_desc',
285+
},
286+
]
259287
260288
const sortList = [
261289
{
@@ -322,7 +350,12 @@ defineExpose({
322350
</el-icon>
323351
</template>
324352
</el-input>
325-
<el-dropdown trigger="click" @command="handleSortTypeChange">
353+
<el-dropdown
354+
popper-class="tree-sort-menu-custom"
355+
trigger="click"
356+
placement="bottom-end"
357+
@command="handleSortTypeChange"
358+
>
326359
<el-icon class="filter-icon-span">
327360
<el-tooltip :offset="16" effect="dark" :content="sortTypeTip" placement="top">
328361
<Icon v-if="state.curSortType.includes('asc')" name="dv-sort-asc" class="opt-icon"
@@ -336,17 +369,28 @@ defineExpose({
336369
</el-tooltip>
337370
</el-icon>
338371
<template #dropdown>
339-
<el-dropdown-menu style="width: 246px">
340-
<template v-for="ele in sortList" :key="ele.value">
372+
<el-dropdown-menu style="width: 120px">
373+
<span class="sort_menu">{{ t('dashboard.sort_column') }}</span>
374+
<template v-for="ele in sortColumnList" :key="ele.value">
341375
<el-dropdown-item
342376
class="ed-select-dropdown__item"
343-
:class="ele.value === state.curSortType && 'selected'"
377+
:class="state.curSortType.includes(ele.value) && 'selected'"
344378
:command="ele.value"
345379
>
346380
{{ ele.name }}
347381
</el-dropdown-item>
348382
<li v-if="ele.divided" class="ed-dropdown-menu__item--divided"></li>
349383
</template>
384+
<span class="sort_menu">{{ t('dashboard.sort_type') }}</span>
385+
<template v-for="ele in sortTypeList" :key="ele.value">
386+
<el-dropdown-item
387+
class="ed-select-dropdown__item"
388+
:class="state.curSortType.includes(ele.value) && 'selected'"
389+
:command="ele.value"
390+
>
391+
{{ ele.name }}
392+
</el-dropdown-item>
393+
</template>
350394
</el-dropdown-menu>
351395
</template>
352396
</el-dropdown>
@@ -555,6 +599,17 @@ defineExpose({
555599
</style>
556600

557601
<style lang="less">
602+
.tree-sort-menu-custom {
603+
padding: 0 4px !important;
604+
li {
605+
border-radius: 4px;
606+
padding: 0 8px !important;
607+
&:hover {
608+
// color: var(--primary-color);
609+
background-color: rgba(31, 35, 41, 0.1) !important;
610+
}
611+
}
612+
}
558613
.menu-outer-dv_popper {
559614
min-width: 140px;
560615
margin-top: -2px !important;
@@ -586,4 +641,10 @@ defineExpose({
586641
.color-dataV-disabled {
587642
background: #bbbfc4 !important;
588643
}
644+
645+
.sort_menu {
646+
color: rgba(143, 149, 158, 1);
647+
font-size: 14px;
648+
margin-left: 12px;
649+
}
589650
</style>

0 commit comments

Comments
 (0)