zhou zhou
4 小时以前 fec285d150b377d004e47f0973d298b92fe4c711
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getFirstMenuPath } from '@/utils'
import { HOME_PAGE_PATH } from '@/router'
const useMenuStore = defineStore('menuStore', () => {
  const homePath = ref(HOME_PAGE_PATH)
  const menuList = ref([])
  const menuWidth = ref('')
  const removeRouteFns = ref([])
  const setMenuList = (list) => {
    menuList.value = list
    setHomePath(HOME_PAGE_PATH || getFirstMenuPath(list))
  }
  const getHomePath = () => homePath.value
  const setHomePath = (path) => {
    homePath.value = path
  }
  const addRemoveRouteFns = (fns) => {
    removeRouteFns.value.push(...fns)
  }
  const removeAllDynamicRoutes = () => {
    removeRouteFns.value.forEach((fn) => fn())
    removeRouteFns.value = []
  }
  const clearRemoveRouteFns = () => {
    removeRouteFns.value = []
  }
  return {
    menuList,
    menuWidth,
    removeRouteFns,
    setMenuList,
    getHomePath,
    setHomePath,
    addRemoveRouteFns,
    removeAllDynamicRoutes,
    clearRemoveRouteFns
  }
})
export { useMenuStore }