menu.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. path: '/kmplatform/openplatform',
  11. name: 'openplatform',
  12. title: "开放平台",
  13. children: []
  14. }])
  15. // const routeList = ref([{
  16. // path: '/kmplatform/home',
  17. // name: 'kmplatform-home',
  18. // title: "主页",
  19. // children: []
  20. // },
  21. // {
  22. // path: '/kmplatform/knowledgebase',
  23. // name: 'knowledgebase',
  24. // title: "知识库",
  25. // children: []
  26. // },
  27. // {
  28. // path: '/kmplatform/kgbuilder',
  29. // name: 'kgbuilder',
  30. // title: "知识图谱构建",
  31. // children: []
  32. // },
  33. // {
  34. // path: '/kmplatform/openplatform',
  35. // name: 'openplatform',
  36. // title: "开放平台",
  37. // children: []
  38. // },
  39. // {
  40. // path: '/kmplatform/kgpermission',
  41. // name: 'kgpermission',
  42. // title: "系统权限",
  43. // children: []
  44. // }
  45. // ])
  46. const operationPermissions = computed(() => {
  47. let permissions = {}
  48. function traverseTree(node) {
  49. // 如果当前节点有子节点,递归遍历每个子节点
  50. if (node.children && node.children.length > 0) {
  51. node.children.forEach(child => {
  52. permissions[child.menu_route] = true
  53. // console.log(child.name); // 处理子节点
  54. traverseTree(child); // 递归遍历子节点的子节点
  55. });
  56. }
  57. }
  58. routeList.value.forEach(node => {
  59. traverseTree(node);
  60. });
  61. return permissions
  62. })
  63. const updateRouteList = (newRoutes) => {
  64. routeList.value = newRoutes; // 更新路由列表
  65. };
  66. function isOP(code) {
  67. return operationPermissions.value[code] ? true : false;
  68. }
  69. return { routeList, updateRouteList, operationPermissions, isOP }
  70. })