From 8f39df8404bb60acf700b57de310e02f52c565a7 Mon Sep 17 00:00:00 2001 From: wuyuxi <980025512@qq.com> Date: Tue, 7 May 2024 23:21:05 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E9=9D=A2=E5=8C=85=E5=B1=91):=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E4=BE=A7=E8=BE=B9=E6=A0=8F=E9=9D=A2=E5=8C=85=E5=B1=91?= =?UTF-8?q?=E5=AF=BC=E8=88=AA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/AsideView.vue | 118 ++++++++++++++++++++++++------- src/layout/BreadCrumb.vue | 30 ++++++++ src/layout/LayOut.vue | 4 +- src/router/index.ts | 80 ++++++++++++++++----- src/views/admin/FormAdvanced.vue | 28 ++++++++ 5 files changed, 217 insertions(+), 43 deletions(-) create mode 100644 src/layout/BreadCrumb.vue create mode 100644 src/views/admin/FormAdvanced.vue diff --git a/src/layout/AsideView.vue b/src/layout/AsideView.vue index c9a90c4..f34344b 100644 --- a/src/layout/AsideView.vue +++ b/src/layout/AsideView.vue @@ -8,6 +8,8 @@ import { useCollapseStore } from '@/stores/collapse' interface IItemBase { title: string key: string + children?: IItemBase[] + index?: string } interface ISubMenuItem extends Partial { @@ -16,7 +18,7 @@ interface ISubMenuItem extends Partial { icon?: ComponentPublicInstance } -interface IMenuItem extends IItemBase { +interface IMenuItem extends Omit { icon?: ComponentPublicInstance children?: ISubMenuItem[] disabled?: boolean @@ -27,7 +29,8 @@ const defaultItems: IMenuItem[] = [ { title: 'DashBoard', icon: rawComponent(Histogram), - key: 'index' + key: 'index', + index: '/admin' }, { title: '组件', @@ -37,30 +40,35 @@ const defaultItems: IMenuItem[] = [ { groupTitle: '列表', children: [ - { title: '普通列表', key: 'base-table' }, + { title: '普通列表', key: 'base-table', index: '/admin/base-table' }, { title: '高级列表', - key: 'advanced-table' + key: 'advanced-table', + index: '/admin/advanced-table' } ] }, { groupTitle: '表单', children: [ - { title: '普通表单', key: 'base-form' }, + { title: '普通表单', key: 'base-form', index: '/admin/base-form' }, { title: '高级表单', - key: 'advanced-form' + key: 'advanced-form', + children: [ + { + title: '文件上传', + key: 'file-upload', + index: '/admin/advanced-form/file-upload' + }, + { + title: '图片裁剪', + key: 'img-crop', + index: '/admin/advanced-form/img-crop' + } + ] } ] - }, - { - title: '文件上传', - key: 'file-upload' - }, - { - title: '图片裁剪', - key: 'img-crop' } ] }, @@ -71,23 +79,65 @@ const defaultItems: IMenuItem[] = [ children: [ { title: '水印', - key: 'watermark' + key: 'watermark', + index: '/admin/watermark' }, { title: '音乐播放器', - key: 'player' + key: 'player', + index: '/admin/player' } ] }, { title: '其他功能', icon: rawComponent(Setting), - key: 'other-func' + key: 'other-func', + index: '/admin/other-func' } ] const menuItems = reactive(defaultItems) +const flattenTree = (root) => { + const flattened = [] + const stack = [root] + while (stack.length > 0) { + const node = stack.pop() + if (!Array.isArray(node)) { + flattened.push(node) + } + for (let i = node.length - 1; i >= 0; i--) { + if (node[i]?.index) { + stack.push(node[i]) + } + if (node[i]?.children?.length) { + stack.push(node[i]?.children) + } + } + } + return flattened +} + const route = useRoute() +const activeIndex = computed(() => { + const current = route.path + const flattenMenus = flattenTree(defaultItems) + const flattenMenuPaths = flattenMenus.map((v) => v.index) + + let matchedPath = current + if (!flattenMenuPaths.includes(current)) { + const matched = [...route.matched] + while (matched.length > 0) { + const node = matched.pop() + if (flattenMenuPaths.includes(node.path)) { + matchedPath = node.path + break + } + } + } + return matchedPath +}) + const store = useCollapseStore() const showCollapse = computed(() => store.status === 'collapse') const isCollapse = computed(() => store.status === 'collapse' && store.collapse) @@ -106,7 +156,7 @@ const toggleCollapse = () => { height="100%" > { - {{ submenu.title }} + {{ submenu.title }} - + - + @@ -152,7 +222,7 @@ const toggleCollapse = () => { - + diff --git a/src/layout/BreadCrumb.vue b/src/layout/BreadCrumb.vue new file mode 100644 index 0000000..ec88ccf --- /dev/null +++ b/src/layout/BreadCrumb.vue @@ -0,0 +1,30 @@ + + + + + diff --git a/src/layout/LayOut.vue b/src/layout/LayOut.vue index 321de49..1aa7d4c 100644 --- a/src/layout/LayOut.vue +++ b/src/layout/LayOut.vue @@ -1,15 +1,16 @@ + + + +