xto-fronted 0.4.99 → 0.4.100

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xto-fronted",
3
- "version": "0.4.99",
3
+ "version": "0.4.100",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "description": "XTO 前端应用框架",
@@ -36,13 +36,32 @@ const displayMenuList = computed(() => props.menuList.length > 0 ? props.menuLis
36
36
  const isCollapsed = computed(() => appStore.isCollapsed)
37
37
  const activeMenu = computed(() => route.path)
38
38
 
39
- // 菜单展开状态持久化
39
+ // 获取菜单的唯一标识(优先使用 menuId,其次 menuCode,最后 menuUrl)
40
+ const getMenuKey = (menu: any): string => {
41
+ return menu.menuId || menu.menuCode || menu.menuUrl || ''
42
+ }
43
+
44
+ // 菜单展开状态持久化(基于当前菜单列表的标识)
40
45
  const OPENED_MENUS_KEY = 'sidebar_opened_menus'
41
- const openedMenus = ref<string[]>(local.get<string[]>(OPENED_MENUS_KEY) || [])
46
+ const MENU_LIST_KEY = 'sidebar_menu_list_key'
47
+
48
+ // 获取当前菜单列表的唯一标识
49
+ const getCurrentMenuListKey = (): string => {
50
+ return displayMenuList.value.map(getMenuKey).join(',')
51
+ }
52
+
53
+ // 初始化展开状态:只有当菜单列表相同时才恢复之前的展开状态
54
+ const savedMenuListKey = local.get<string>(MENU_LIST_KEY) || ''
55
+ const currentKey = getCurrentMenuListKey()
56
+ const initialOpenedMenus = savedMenuListKey === currentKey
57
+ ? (local.get<string[]>(OPENED_MENUS_KEY) || [])
58
+ : []
59
+ const openedMenus = ref<string[]>(initialOpenedMenus)
42
60
 
43
61
  // 监听变化并持久化
44
62
  watch(openedMenus, (val) => {
45
63
  local.set(OPENED_MENUS_KEY, val)
64
+ local.set(MENU_LIST_KEY, getCurrentMenuListKey())
46
65
  }, { deep: true })
47
66
 
48
67
  // 递归查找当前路由对应的父菜单路径
@@ -81,8 +100,9 @@ watch(displayMenuList, (newList, oldList) => {
81
100
  if (newList !== oldList) {
82
101
  openedMenus.value = []
83
102
  local.set(OPENED_MENUS_KEY, [])
103
+ local.set(MENU_LIST_KEY, getCurrentMenuListKey())
84
104
  }
85
- })
105
+ }, { immediate: false })
86
106
 
87
107
  // 菜单主题相关
88
108
  const menuBgColor = computed(() => appStore.isDark ? '#1d1e1f' : '#fff')