From 933f9f1d59d56d87962269a9c469f02ae872348c Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Wed, 23 Jul 2025 16:31:51 +0800 Subject: [PATCH 1/2] refactor: sort list change --- frontend/src/i18n/en.json | 7 +- frontend/src/i18n/zh-CN.json | 7 +- .../views/dashboard/common/ResourceTree.vue | 85 ++++++++++++++++--- 3 files changed, 85 insertions(+), 14 deletions(-) diff --git a/frontend/src/i18n/en.json b/frontend/src/i18n/en.json index d52b35d3..e8426871 100644 --- a/frontend/src/i18n/en.json +++ b/frontend/src/i18n/en.json @@ -32,6 +32,11 @@ "password_reset_successful": "Password reset successful" }, "dashboard": { + "sort_column": "Sort field", + "sort_type": "Sort type", + "time": "Time", + "sort_asc": "Ascending", + "sort_desc": "Descending", "name_repeat": "Name Repeat", "rich_text_tips": "Double-click to enter text content", "exit_preview": "Exit preview", @@ -487,4 +492,4 @@ "back_community": "Restore to Community Edition", "confirm_tips": "Are you sure to restore to Community Edition?" } -} \ No newline at end of file +} diff --git a/frontend/src/i18n/zh-CN.json b/frontend/src/i18n/zh-CN.json index d1579fa2..5449abe1 100644 --- a/frontend/src/i18n/zh-CN.json +++ b/frontend/src/i18n/zh-CN.json @@ -34,6 +34,11 @@ "password_reset_successful": "重置密码成功" }, "dashboard": { + "sort_column": "排序字段", + "sort_type": "排序方式", + "time": "时间", + "sort_asc": "升序", + "sort_desc": "降序", "name_repeat": "仪表板名称已被使用", "rich_text_tips": "双击输入文本内容", "exit_preview": "退出预览", @@ -499,4 +504,4 @@ "back_community": "还原至社区版", "confirm_tips": "确定还原至社区版?" } -} \ No newline at end of file +} diff --git a/frontend/src/views/dashboard/common/ResourceTree.vue b/frontend/src/views/dashboard/common/ResourceTree.vue index c21678a5..e9fa88c4 100644 --- a/frontend/src/views/dashboard/common/ResourceTree.vue +++ b/frontend/src/views/dashboard/common/ResourceTree.vue @@ -57,7 +57,9 @@ const expandedArray = ref([]) const resourceListTree = ref() const returnMounted = ref(false) const state = reactive({ - curSortType: 'time_desc', + curSortType: 'name_asc', + curSortTypePrefix: 'name', + curSortTypeSuffix: '_asc', resourceTree: [] as SQTreeNode[], originResourceTree: [] as SQTreeNode[], sortType: [], @@ -134,6 +136,7 @@ const getTree = async () => { dashboardApi.list_resource(params).then((res: SQTreeNode[]) => { state.originResourceTree = res || [] state.resourceTree = _.cloneDeep(state.originResourceTree) + handleSortTypeChange('name_asc') afterTreeInit() }) } @@ -246,16 +249,41 @@ const baseInfoChangeFinish = () => { getTree() } -const handleSortTypeChange = (sortType: string) => { - state.resourceTree = treeSort(state.originResourceTree, sortType) - state.curSortType = sortType +const handleSortTypeChange = (menuSortType: string) => { + state.curSortTypePrefix = ['name', 'time'].includes(menuSortType) + ? menuSortType + : state.curSortTypePrefix + state.curSortTypeSuffix = ['_asc', '_desc'].includes(menuSortType) + ? menuSortType + : state.curSortTypeSuffix + const curMenuSortType = state.curSortTypePrefix + state.curSortTypeSuffix + state.resourceTree = treeSort(state.originResourceTree, curMenuSortType) + state.curSortType = curMenuSortType wsCache.set('TreeSort-dashboard', state.curSortType) } -// const sortTypeChange = (sortType: string) => { -// state.resourceTree = treeSort(state.originResourceTree, sortType) -// state.curSortType = sortType -// } +const sortColumnList = [ + { + name: t('dashboard.time'), + value: 'time', + }, + { + name: t('dashboard.name'), + value: 'name', + divided: true, + }, +] + +const sortTypeList = [ + { + name: t('dashboard.sort_asc'), + value: '_asc', + }, + { + name: t('dashboard.sort_desc'), + value: '_desc', + }, +] const sortList = [ { @@ -322,7 +350,12 @@ defineExpose({ - +