routers.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //import { getStore, setStore } from 'hc-vue3-ui'
  2. import { getStore, setStore } from '~src/utils/storage'
  3. import { deepClone, getArrValue, isNullES } from 'js-fast-way'
  4. //import testMenu from './modules/menu'
  5. //获取路由菜单
  6. export const getRouterData = async (toName) => {
  7. const routes = getArrValue(getStore('routes'))
  8. return routes.indexOf(toName) !== -1
  9. }
  10. //获取菜单数据
  11. export const getMenuData = async () => {
  12. let projectMenu = [], menu = getStore('projectMenu')
  13. const testMenu = getStore('menus')
  14. for (let i = 0; i < testMenu.length; i++) {
  15. if (testMenu[i].code === 'project') {
  16. projectMenu = await getProjectChildren(testMenu[i].children)
  17. break
  18. }
  19. }
  20. if (isNullES(menu) || menu.length <= 0) {
  21. setStore('projectMenu', projectMenu)
  22. }
  23. return testMenu
  24. }
  25. //获取项目管理菜单
  26. const getProjectChildren = async (arr) => {
  27. const children = getArrValue(arr)
  28. for (let i = 0; i < children.length; i++) {
  29. if (children[i].code === 'project-collect') {
  30. const childrens = children[i].children
  31. if (isNullES(childrens)) return []
  32. const newChildren = deepClone(childrens)
  33. delete children[i].children
  34. return getArrValue(newChildren)
  35. }
  36. }
  37. }