menu.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { ref, computed } from 'vue'
  2. import { defineStore } from 'pinia'
  3. import {
  4. deleteSessionVar,
  5. getSessionVar,
  6. saveSessionVar,
  7. } from "@/utils/session";
  8. export const useMenuStore = defineStore('menu', () => {
  9. let routeList = ref(getSessionVar("routeList") ? JSON.parse(getSessionVar("routeList")) : [])
  10. // const routeList = ref([{
  11. // path: '/kmplatform/home',
  12. // name: 'kmplatform-home',
  13. // title: "主页",
  14. // children: []
  15. // },
  16. // {
  17. // path: '/kmplatform/knowledgebase',
  18. // name: 'knowledgebase',
  19. // title: "知识库",
  20. // children: []
  21. // },
  22. // {
  23. // path: '/kmplatform/kgbuilder',
  24. // name: 'kgbuilder',
  25. // title: "知识图谱构建",
  26. // children: []
  27. // },
  28. // {
  29. // path: '/kmplatform/openplatform',
  30. // name: 'openplatform',
  31. // title: "开放平台",
  32. // children: []
  33. // },
  34. // {
  35. // path: '/kmplatform/kgpermission',
  36. // name: 'kgpermission',
  37. // title: "系统权限",
  38. // children: []
  39. // }
  40. // ])
  41. const operationPermissions = computed(() => {
  42. let permissions = {}
  43. routeList.value.forEach(i => {
  44. if (Array.isArray(i)) {
  45. i.children.forEach(j => {
  46. permissions[j.key] = true
  47. })
  48. }
  49. });
  50. return permissions
  51. })
  52. const updateRouteList = (newRoutes) => {
  53. routeList.value = newRoutes; // 更新路由列表
  54. };
  55. return { routeList, updateRouteList, operationPermissions }
  56. })