auth.ts 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import { defineStore } from "pinia";
  2. import { AuthState, CommonMenuItem } from "@/stores/interface";
  3. // import { getAuthButtonListApi, getAuthMenuListApi } from "@/api/modules/login";
  4. import {
  5. getFlatMenuList,
  6. getShowMenuList,
  7. getAllBreadcrumbList,
  8. getQuickEnterFuncTree,
  9. getQuickEnterFuncTreeRouter
  10. } from "@/utils";
  11. import { menuRouter } from "@/routers/modules/menuRouter";
  12. import { baseRouter } from "@/routers/modules/baseRouter";
  13. import { salePriceRouter } from "@/routers/modules/salePriceRouter";
  14. import { mattressQtuoteRouter } from "@/routers/modules/mattressQtuoteRouter";
  15. import { bednetQtuoteRouter } from "@/routers/modules/bednetQtuoteRouter";
  16. import { semifinprodQuoteRouter } from "@/routers/modules/selmifinprodRouter";
  17. import { erpApiRouter } from "@/routers/modules/erpApiRouter";
  18. import { useUserStore } from "@/stores/modules/user";
  19. import { concat } from "lodash-es";
  20. import { isArray } from "@/utils/is";
  21. import { useLayoutLocalStore } from "@/stores/modules/layoutLocal";
  22. export const useAuthStore = defineStore({
  23. id: "geeker-auth",
  24. state: (): AuthState => ({
  25. // 按钮权限列表
  26. authButtonList: [],
  27. // 菜单权限列表
  28. authMenuList: [],
  29. // 当前页面的 router name,用来做按钮权限筛选
  30. routeName: "",
  31. // 系统选项
  32. optionList: [],
  33. commonMenu: []
  34. }),
  35. getters: {
  36. // // 按钮权限列表
  37. authButtonListGet: state => state.authButtonList,
  38. authOptionListGet: state => state.optionList,
  39. // 菜单权限列表 ==> 这里的菜单没有经过任何处理
  40. authMenuListGet: state => state.authMenuList,
  41. // 菜单权限列表 ==> 左侧菜单栏渲染,需要剔除 isHide == true
  42. showMenuListGet: state => getShowMenuList(state.authMenuList),
  43. // 菜单权限列表 ==> 扁平化之后的一维数组菜单,主要用来添加动态路由
  44. flatMenuListGet: state => getFlatMenuList(state.authMenuList),
  45. // 递归处理后的所有面包屑导航列表
  46. breadcrumbListGet: state => getAllBreadcrumbList(state.authMenuList),
  47. // 首页常用功能树
  48. quickEnterFuncTreeGet: state => getQuickEnterFuncTree(state.authMenuList),
  49. // 首页常用功能树路由
  50. quickEnterFuncTreeRouter: state => getQuickEnterFuncTreeRouter(state.authMenuList)
  51. },
  52. actions: {
  53. /**
  54. * @description 按钮权限列表
  55. */
  56. async getAuthButtonList() {
  57. const userStore = useUserStore();
  58. // const { data } = await getAuthButtonListApi();
  59. // this.authButtonList = data;
  60. this.authButtonList = userStore.userInfo.rsltFunids ?? [];
  61. },
  62. /**
  63. * @description 按钮权限列表
  64. */
  65. async getAuthOptionList() {
  66. const userStore = useUserStore();
  67. // const { data } = await getAuthButtonListApi();
  68. // this.authButtonList = data;
  69. this.optionList = userStore.userInfo?.optionList ?? [];
  70. },
  71. /**
  72. * @description 获取菜单列表
  73. */
  74. async getAuthMenuList() {
  75. // const { data } = await getAuthMenuListApi();
  76. // console.log("getAuthMenuList data :>> ", data);
  77. // this.authMenuList = data;
  78. this.authMenuList = concat(
  79. menuRouter,
  80. baseRouter,
  81. salePriceRouter,
  82. mattressQtuoteRouter,
  83. bednetQtuoteRouter,
  84. semifinprodQuoteRouter,
  85. erpApiRouter
  86. );
  87. console.log("getAuthMenuList authMenuList :>> ", this.authMenuList);
  88. },
  89. // Set RouteName
  90. async setRouteName(name: string) {
  91. this.routeName = name;
  92. },
  93. // // Set GlobalState
  94. // setGlobalState(...args: ObjToKeyValArray<any>) {
  95. // // setGlobalState(...args: ObjToKeyValArray<GlobalState>) {
  96. // args && this.$patch({ [args[0]]: args[1] });
  97. // }
  98. setCommonMenu(data: string | any) {
  99. if (isArray(data)) {
  100. this.commonMenu = data;
  101. } else {
  102. let index = this.commonMenu.findIndex((item: any) => item.funid == data);
  103. if (index == -1) {
  104. this.commonMenu.push({ funid: data });
  105. } else {
  106. this.commonMenu.splice(index, 1);
  107. }
  108. }
  109. },
  110. getQuickEnterFunc(layout: any) {
  111. let initParam: any = {};
  112. for (const key in layout) {
  113. if (isArray(layout[key])) {
  114. let arr = layout[key];
  115. for (let i = 0; i < arr.length; i++) {
  116. console.log("arr[i] :>> ", arr[i]);
  117. if (arr[i].id == "QuickEnter") {
  118. initParam = arr[i]?.initParam ?? {};
  119. break;
  120. }
  121. }
  122. }
  123. }
  124. return initParam;
  125. },
  126. async getHomeLayout() {
  127. const layoutLocalStore = useLayoutLocalStore();
  128. let layout = await layoutLocalStore.getDwLayout("web_home_layout");
  129. console.log("111 layout :>> ", layout);
  130. let localLayout = {};
  131. if (layout?.hasOwnProperty("itemvalue") && layout.itemvalue) {
  132. layout.itemvalue = layout.itemvalue.replace(/'/g, '"');
  133. localLayout = JSON.parse(layout.itemvalue);
  134. }
  135. console.log("localLayout :>> ", localLayout);
  136. let params = this.getQuickEnterFunc(localLayout);
  137. console.log("getHomeLayout params :>> ", params);
  138. this.setCommonMenu(params.fnlist);
  139. // console.log("cloneDeep(defaultLayout) :>> ", cloneDeep(defaultLayout));
  140. // if (JSON.stringify(localLayout) != "{}") {
  141. // localLayout = Object.assign(cloneDeep(defaultLayout), localLayout);
  142. // } else {
  143. // localLayout = cloneDeep(defaultLayout);
  144. // }
  145. // console.log("after localLayout :>> ", localLayout);
  146. // dwLayout.value = LayoutSettingRef.value?.setDefaultFunc(localLayout);
  147. // console.log("onMounted 111 dwLayout.value :>> ", dwLayout.value);
  148. // for (const key in dwLayout.value) {
  149. // if (isArray(dwLayout.value[key])) {
  150. // let arr = dwLayout.value[key];
  151. // for (let i = 0; i < arr.length; i++) {
  152. // console.log("arr[i] :>> ", arr[i]);
  153. // if (arr[i].hasOwnProperty("initParam")) {
  154. // initParam[arr[i].id] = arr[i].initParam;
  155. // }
  156. // }
  157. // }
  158. // }
  159. }
  160. }
  161. });