From a59759e6546aa2dc382de0dbb7b01207678efcb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E8=8F=9C=20Cai?= Date: Mon, 9 Sep 2024 18:01:36 +0800 Subject: [PATCH 1/4] =?UTF-8?q?fix:=20=E5=A4=9A=E7=BA=A7=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E4=B8=8B=EF=BC=8C=E4=B8=8D=E8=83=BD=E6=AD=A3=E7=A1=AE=E5=B1=95?= =?UTF-8?q?=E5=BC=80=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/components/SideNav.vue | 33 +++++++++++++++++++++--------- src/router/modules/homepage.ts | 26 ++++++++++++++++++++++- 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/layouts/components/SideNav.vue b/src/layouts/components/SideNav.vue index fbe24c51..90a195d7 100644 --- a/src/layouts/components/SideNav.vue +++ b/src/layouts/components/SideNav.vue @@ -27,7 +27,7 @@ import { difference, remove, union } from 'lodash'; import { MenuValue } from 'tdesign-vue-next'; import type { PropType } from 'vue'; -import { computed, onMounted, ref, watch } from 'vue'; +import { computed, onMounted, onUnmounted, ref, watch } from 'vue'; import { useRouter } from 'vue-router'; import AssetLogoFull from '@/assets/assets-logo-full.svg?component'; @@ -80,12 +80,24 @@ const active = computed(() => getActive()); const expanded = ref([]); +const getExpanded = () => { + const path = getActive(); + const parts = path.split('/'); + const result = []; + let currentPath = ''; + + for (let i = 1; i < parts.length - 1; i++) { + currentPath += `/${parts[i]}`; + result.push(currentPath); + } + + expanded.value = menuAutoCollapsed.value ? result : union(result, expanded.value); +}; + watch( () => active.value, () => { - const path = getActive(); - const parentPath = path.substring(0, path.lastIndexOf('/')); - expanded.value = menuAutoCollapsed.value ? [parentPath] : union([parentPath], expanded.value); + getExpanded(); }, ); @@ -148,13 +160,14 @@ const autoCollapsed = () => { }; onMounted(() => { - const path = getActive(); - const parentPath = path.substring(0, path.lastIndexOf('/')); - expanded.value = union([parentPath], expanded.value); + getExpanded(); autoCollapsed(); - window.onresize = () => { - autoCollapsed(); - }; + + window.addEventListener('resize', autoCollapsed); +}); + +onUnmounted(() => { + window.removeEventListener('resize', autoCollapsed); }); const goHome = () => { diff --git a/src/router/modules/homepage.ts b/src/router/modules/homepage.ts index 883738a2..3bd3b499 100644 --- a/src/router/modules/homepage.ts +++ b/src/router/modules/homepage.ts @@ -21,13 +21,37 @@ export default [ { path: 'base', name: 'DashboardBase', - component: () => import('@/pages/dashboard/base/index.vue'), + // component: () => import('@/pages/dashboard/base/index.vue'), meta: { title: { zh_CN: '概览仪表盘', en_US: 'Overview', }, }, + children: [ + { + path: 'base-1', + name: 'DashboardBase-1', + component: () => import('@/pages/dashboard/base/index.vue'), + meta: { + title: { + zh_CN: '概览仪表盘-1', + en_US: 'Overview-1', + }, + }, + }, + { + path: 'detail-1', + name: 'DashboardDetail-1', + component: () => import('@/pages/dashboard/detail/index.vue'), + meta: { + title: { + zh_CN: '统计报表-1', + en_US: 'Dashboard Detail-1', + }, + }, + }, + ], }, { path: 'detail', From 2b6c8dc577abea596ee35b8659bf68c5a2f5c944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E8=8F=9C=20Cai?= Date: Mon, 9 Sep 2024 23:57:14 +0800 Subject: [PATCH 2/4] =?UTF-8?q?chore:=20=E5=88=87=E6=8D=A2=E8=B7=AF?= =?UTF-8?q?=E7=94=B1demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/modules/homepage.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/router/modules/homepage.ts b/src/router/modules/homepage.ts index 3bd3b499..e06b4369 100644 --- a/src/router/modules/homepage.ts +++ b/src/router/modules/homepage.ts @@ -19,8 +19,8 @@ export default [ }, children: [ { - path: 'base', - name: 'DashboardBase', + path: 'base-1', + name: 'DashboardBase-1', // component: () => import('@/pages/dashboard/base/index.vue'), meta: { title: { @@ -30,8 +30,8 @@ export default [ }, children: [ { - path: 'base-1', - name: 'DashboardBase-1', + path: 'base', + name: 'DashboardBase', component: () => import('@/pages/dashboard/base/index.vue'), meta: { title: { From d43577d083c5f21481022b134f0211fc09056b58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E8=8F=9C=20Cai?= Date: Tue, 10 Sep 2024 00:06:41 +0800 Subject: [PATCH 3/4] =?UTF-8?q?chore:=20=E4=BF=AE=E6=94=B9demo=E8=B7=AF?= =?UTF-8?q?=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/modules/homepage.ts | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/router/modules/homepage.ts b/src/router/modules/homepage.ts index e06b4369..cc00b169 100644 --- a/src/router/modules/homepage.ts +++ b/src/router/modules/homepage.ts @@ -19,19 +19,30 @@ export default [ }, children: [ { - path: 'base-1', - name: 'DashboardBase-1', - // component: () => import('@/pages/dashboard/base/index.vue'), + path: 'base', + name: 'DashboardBase', + component: () => import('@/pages/dashboard/base/index.vue'), meta: { title: { zh_CN: '概览仪表盘', en_US: 'Overview', }, }, + }, + { + path: 'detail', + name: 'DashboardDetail', + // component: () => import('@/pages/dashboard/detail/index.vue'), + meta: { + title: { + zh_CN: '统计报表', + en_US: 'Dashboard Detail', + }, + }, children: [ { - path: 'base', - name: 'DashboardBase', + path: 'base-1', + name: 'DashboardBase-1', component: () => import('@/pages/dashboard/base/index.vue'), meta: { title: { @@ -53,17 +64,6 @@ export default [ }, ], }, - { - path: 'detail', - name: 'DashboardDetail', - component: () => import('@/pages/dashboard/detail/index.vue'), - meta: { - title: { - zh_CN: '统计报表', - en_US: 'Dashboard Detail', - }, - }, - }, ], }, ]; From 61e6e27bc1e060c05d09268c9fa639e8d63e6cac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=BF=E8=8F=9C=20Cai?= Date: Mon, 4 Nov 2024 14:20:18 +0800 Subject: [PATCH 4/4] =?UTF-8?q?chore:=20=E4=BC=98=E5=8C=96=E7=A4=BA?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/components/SideNav.vue | 10 ++-------- src/router/modules/homepage.ts | 28 ++++++++-------------------- 2 files changed, 10 insertions(+), 28 deletions(-) diff --git a/src/layouts/components/SideNav.vue b/src/layouts/components/SideNav.vue index 90a195d7..420a7f24 100644 --- a/src/layouts/components/SideNav.vue +++ b/src/layouts/components/SideNav.vue @@ -82,14 +82,8 @@ const expanded = ref([]); const getExpanded = () => { const path = getActive(); - const parts = path.split('/'); - const result = []; - let currentPath = ''; - - for (let i = 1; i < parts.length - 1; i++) { - currentPath += `/${parts[i]}`; - result.push(currentPath); - } + const parts = path.split('/').slice(1); + const result = parts.map((_, index) => `/${parts.slice(0, index + 1).join('/')}`); expanded.value = menuAutoCollapsed.value ? result : union(result, expanded.value); }; diff --git a/src/router/modules/homepage.ts b/src/router/modules/homepage.ts index cc00b169..20dbf259 100644 --- a/src/router/modules/homepage.ts +++ b/src/router/modules/homepage.ts @@ -30,35 +30,23 @@ export default [ }, }, { - path: 'detail', - name: 'DashboardDetail', - // component: () => import('@/pages/dashboard/detail/index.vue'), + path: 'dashboard', + name: 'Dashboard', meta: { title: { - zh_CN: '统计报表', - en_US: 'Dashboard Detail', + zh_CN: '报表', + en_US: 'Dashboard', }, }, children: [ { - path: 'base-1', - name: 'DashboardBase-1', - component: () => import('@/pages/dashboard/base/index.vue'), - meta: { - title: { - zh_CN: '概览仪表盘-1', - en_US: 'Overview-1', - }, - }, - }, - { - path: 'detail-1', - name: 'DashboardDetail-1', + path: 'detail', + name: 'Detail', component: () => import('@/pages/dashboard/detail/index.vue'), meta: { title: { - zh_CN: '统计报表-1', - en_US: 'Dashboard Detail-1', + zh_CN: '统计报表', + en_US: 'Dashboard Detail', }, }, },