From c2029d0fd8af2ef2d20958b632a577ab313263d1 Mon Sep 17 00:00:00 2001
From: chuan_wuhao <443547225@qq.com>
Date: Thu, 24 Nov 2022 16:18:13 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=B7=AF=E7=94=B1=E5=8F=98?=
=?UTF-8?q?=E5=8C=96=E4=B8=8D=E8=A7=A6=E5=8F=91=E8=8F=9C=E5=8D=95=E7=8A=B6?=
=?UTF-8?q?=E6=80=81=E6=9B=B4=E6=96=B0=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
dist/production-dist/index.html | 2 +-
src/store/modules/menu.ts | 32 ++++++++++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/dist/production-dist/index.html b/dist/production-dist/index.html
index 90b16f38..ebf26c1f 100644
--- a/dist/production-dist/index.html
+++ b/dist/production-dist/index.html
@@ -5,7 +5,7 @@
ray template
-
+
diff --git a/src/store/modules/menu.ts b/src/store/modules/menu.ts
index a1b10365..5560d93e 100644
--- a/src/store/modules/menu.ts
+++ b/src/store/modules/menu.ts
@@ -7,6 +7,7 @@ import type { RouteRecordRaw } from 'vue-router'
export const useMenu = defineStore('menu', () => {
const router = useRouter()
+ const route = useRoute()
const { t } = useI18n()
const cacheMenuKey =
@@ -47,6 +48,30 @@ export const useMenu = defineStore('menu', () => {
setCache('menuKey', key)
}
+ /**
+ *
+ * @param path 路由地址
+ *
+ * 监听路由地址变化更新菜单状态
+ */
+ const updateMenuKeyWhenRouteUpdate = (path: string) => {
+ const matchMenuItem = (options: MenuOption[]) => {
+ for (const i of options) {
+ if (i?.children?.length) {
+ matchMenuItem(i.children)
+ }
+
+ if (path === i.path) {
+ menuModelValueChange(i.path, i)
+
+ break
+ }
+ }
+ }
+
+ matchMenuItem(menuState.options)
+ }
+
/**
*
* 获取菜单列表
@@ -108,6 +133,13 @@ export const useMenu = defineStore('menu', () => {
const spliceMenTagOptions = (idx: number) =>
menuState.menuTagOptions.splice(idx, 1)
+ watch(
+ () => route.fullPath,
+ (newData) => {
+ updateMenuKeyWhenRouteUpdate(newData)
+ },
+ )
+
return {
...toRefs(menuState),
menuModelValueChange,