routers.js 1.2 KB

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