From 8acd3a0310985fd37d8ebfcc096906eb2f7b47d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=96=AF=EF=BC=88xiaosi=EF=BC=89?= <1531733886@qq.com> Date: Wed, 25 Oct 2023 20:45:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(layouts):=20=E2=9C=A8=20sidebar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Sidebar text overflows to display abbreviations and displays tootips - Adjust the style to optimize the expansion and contraction animation --- .env | 0 package.json | 2 +- pnpm-lock.yaml | 10 +- src/components/SvgIcon/index.vue | 19 +- .../page-layouts/components/Sidebar/Item.vue | 55 +++- .../components/Sidebar/MinSidebar.vue | 1 + .../components/Sidebar/SidebarItem.vue | 95 ++++-- .../page-layouts/components/Sidebar/index.vue | 9 +- src/styles/sidebar.scss | 301 +++++------------- src/styles/var/site-bar.scss | 2 +- src/utils/plugin/element.ts | 5 + 11 files changed, 214 insertions(+), 285 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 00000000..e69de29b diff --git a/package.json b/package.json index 6509ae46..caf2b4fc 100644 --- a/package.json +++ b/package.json @@ -48,7 +48,7 @@ "dayjs": "^1.11.9", "docx-preview": "^0.1.18", "echarts": "^5.4.3", - "element-plus": "^2.3.12", + "element-plus": "^2.4.1", "es6-promise": "^4.2.8", "i18next": "^23.5.0", "intro.js": "^7.2.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ce16b40b..8cad1e2c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,4 +1,4 @@ -lockfileVersion: '6.1' +lockfileVersion: '6.0' settings: autoInstallPeers: true @@ -39,8 +39,8 @@ dependencies: specifier: ^5.4.3 version: 5.4.3 element-plus: - specifier: ^2.3.12 - version: 2.3.12(vue@3.3.4) + specifier: ^2.4.1 + version: 2.4.1(vue@3.3.4) es6-promise: specifier: ^4.2.8 version: 4.2.8 @@ -7597,10 +7597,10 @@ packages: integrity: sha512-shUVy6Eawp33dFBFIoYbIwLHrX0IZ857AlH9ug2o4rvbWmpaCUdBpQ5Zw39HRrfzAFm4APJE9V+E2A/WB0YqJw==, } - /element-plus@2.3.12(vue@3.3.4): + /element-plus@2.4.1(vue@3.3.4): resolution: { - integrity: sha512-fAWpbKCyt+l1dsqSNPOs/F/dBN4Wp5CGAyxbiS5zqDwI4q3QPM+LxLU2h3GUHMIBtMGCvmsG98j5HPMkTKkvcA==, + integrity: sha512-t7nl+vQlkBKVk1Ag6AufSDyFV8YIXxTFsaya4Nz/0tiRlcz65WPN4WMFeNURuFJleu1HLNtP4YyQKMuS7El8uA==, } peerDependencies: vue: ^3.2.0 diff --git a/src/components/SvgIcon/index.vue b/src/components/SvgIcon/index.vue index bdddac62..68a3c81f 100644 --- a/src/components/SvgIcon/index.vue +++ b/src/components/SvgIcon/index.vue @@ -26,7 +26,7 @@ diff --git a/src/layouts/page-layouts/components/Sidebar/MinSidebar.vue b/src/layouts/page-layouts/components/Sidebar/MinSidebar.vue index eeae3ebf..706fdb18 100644 --- a/src/layouts/page-layouts/components/Sidebar/MinSidebar.vue +++ b/src/layouts/page-layouts/components/Sidebar/MinSidebar.vue @@ -51,6 +51,7 @@ class-name="menu-item-svg" :icon="menusRoute.meta && menusRoute.meta.icon" :title="menusRoute.meta?.title" + mode="horizontal" /> diff --git a/src/layouts/page-layouts/components/Sidebar/SidebarItem.vue b/src/layouts/page-layouts/components/Sidebar/SidebarItem.vue index ba388a20..787cc07d 100644 --- a/src/layouts/page-layouts/components/Sidebar/SidebarItem.vue +++ b/src/layouts/page-layouts/components/Sidebar/SidebarItem.vue @@ -6,6 +6,7 @@ import Item from './Item.vue'; import AppLink from './Link.vue'; import type { AppRouteRecordRaw } from '@/router/type'; + import { translateI18n } from '@/hooks/web/useI18n'; const props = defineProps({ // route object @@ -21,21 +22,32 @@ type: String, default: '', }, + level: { + type: Number, + default: 0, + }, + collapse: { + type: Boolean, + default: false, + }, + mode: { + type: String as PropType<'vertical' | 'horizontal'>, + default: 'vertical', + }, }); - const onlyOneChild = ref({}); - const hasOneShowingChild = ( - children: Array = [], - parent: AppRouteRecordRaw, - ) => { - const showingChildren = children.filter((item: AppRouteRecordRaw) => { - if (item.meta?.hideSidebar) { - return false; - } else { - // Temp set(will be used if only has one showing child) - onlyOneChild.value = item; - return true; - } - }); + + const onlyOneChild = ref>({}); + const hasOneShowingChild = (parent: AppRouteRecordRaw) => { + const showingChildren = + parent.children?.filter((item: AppRouteRecordRaw) => { + if (item.meta?.hideSidebar) { + return false; + } else { + // Temp set(will be used if only has one showing child) + onlyOneChild.value = item; + return true; + } + }) ?? []; // When there is only one child router, the child router is displayed by default if (showingChildren.length === 1) { @@ -65,44 +77,63 @@
- +
- - diff --git a/src/layouts/page-layouts/components/Sidebar/index.vue b/src/layouts/page-layouts/components/Sidebar/index.vue index 89f76b20..12f48dcb 100644 --- a/src/layouts/page-layouts/components/Sidebar/index.vue +++ b/src/layouts/page-layouts/components/Sidebar/index.vue @@ -56,6 +56,10 @@ } return path; }); + + const collapse = computed(() => + appConfig.value.sidebarMode === 'horizontal' ? false : appConfig.value.collapseMenu, + );