@utogether/udp-core 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (239) hide show
  1. package/build/plugins.ts +13 -2
  2. package/dist/{403-JWjatlxJ.js → 403-D6H3sArg.js} +7 -6
  3. package/dist/{404-BcdMJfPb.js → 404-DTyfysQ2.js} +14 -13
  4. package/dist/{500-bsa3F_cc.js → 500-DKaVDaBm.js} +10 -9
  5. package/dist/{AuthorityInfo-CqItgNs5.js → AuthorityInfo-DQULR69Y.js} +1 -1
  6. package/dist/AuthorityInfo.vue_vue_type_style_index_0_lang-CzAnoTnO.js +100 -0
  7. package/dist/{AuthorityPanel-BaLMwMgW.js → AuthorityPanel-BeBNiwqc.js} +1 -1
  8. package/dist/{AuthorityPanel.vue_vue_type_style_index_0_lang-C_bkqLD9.js → AuthorityPanel.vue_vue_type_style_index_0_lang-CIYmnP9-.js} +6 -6
  9. package/dist/{Company-DVff9IA7.js → Company-BWFrR-Cq.js} +3 -3
  10. package/dist/{CompanyPanel-CNrdq4XE.js → CompanyPanel-Dh814lsw.js} +16 -16
  11. package/dist/{Department-CqcpfL4i.js → Department-DagPxerl.js} +10 -10
  12. package/dist/{DepartmentPanel-Bvti4LGu.js → DepartmentPanel-BVy2YGED.js} +108 -78
  13. package/dist/{DesignPanel-CjykspE1.js → DesignPanel-DKfjfj2S.js} +1 -1
  14. package/dist/{DesignPanel.vue_vue_type_style_index_0_lang-BK9EERdd.js → DesignPanel.vue_vue_type_style_index_0_lang-D-a8W08Y.js} +24 -26
  15. package/dist/DictView-CE5nEiKu.js +110 -0
  16. package/dist/InvOrganization-CZk_EbFZ.js +74 -0
  17. package/dist/Org-BO8jfnqN.js +39 -0
  18. package/dist/{Preview-Cm_7RhYU.js → Preview-DYJaP96f.js} +2 -2
  19. package/dist/{ReportDefine-CJVlQ--7.js → ReportDefine-DZXbs7iX.js} +1 -1
  20. package/dist/{ReportDesign-B0unlrkt.js → ReportDesign-CSdqOQ1D.js} +46 -46
  21. package/dist/{ReportQuery-BKuMCEvF.js → ReportQuery-_Vdt3CnA.js} +5 -5
  22. package/dist/{ReportQueryFrom-DAngMJLU.js → ReportQueryFrom-BWKddh9p.js} +1 -1
  23. package/dist/{ReportQueryFrom.vue_vue_type_style_index_0_lang-CPpwmztJ.js → ReportQueryFrom.vue_vue_type_style_index_0_lang-DbdGwioi.js} +6 -5
  24. package/dist/{ReportTemplate-8YH3L8Pv.js → ReportTemplate-DS-DGao8.js} +26 -26
  25. package/dist/{Role-MxI30-0W.js → Role-BM0kEu7y.js} +6 -6
  26. package/dist/{RoleAssign-BzUY_y_y.js → RoleAssign-Cp05HUWn.js} +9 -9
  27. package/dist/{RolePanel-DS_TErTn.js → RolePanel-DeuHpCdK.js} +1 -1
  28. package/dist/{RolePanel-CXdcvsR5.js → RolePanel-hXeshcCZ.js} +1 -1
  29. package/dist/{RolePanel.vue_vue_type_script_setup_true_lang-Ddl-A7Zh.js → RolePanel.vue_vue_type_script_setup_true_lang-Bf0pSCTN.js} +42 -36
  30. package/dist/RolePanel.vue_vue_type_script_setup_true_lang-CNyWCIJm.js +132 -0
  31. package/dist/{ScrollPanel.vue_vue_type_style_index_0_lang-DnchUgIF.js → ScrollPanel.vue_vue_type_style_index_0_lang-BiKe39xG.js} +20 -20
  32. package/dist/{Staff-D7tXo_Gn.js → Staff-DLltLFMl.js} +3 -3
  33. package/dist/{StaffInfo-Bk8BY8PO.js → StaffInfo-pfELaI_i.js} +1 -1
  34. package/dist/{StaffInfo.vue_vue_type_script_setup_true_lang-DqKwZi5f.js → StaffInfo.vue_vue_type_script_setup_true_lang-BKKdNggm.js} +13 -13
  35. package/dist/{StaffPanel-VtpGCTIq.js → StaffPanel-D3Pk28JN.js} +1 -1
  36. package/dist/StaffPanel.vue_vue_type_script_setup_true_lang-D9HLeyKe.js +143 -0
  37. package/dist/{SysUser-D0Q6OvD7.js → SysUser-BOh7ejz3.js} +2 -2
  38. package/dist/{SysUserPanel-1_vrsANQ.js → SysUserPanel-RElVo0BV.js} +1 -1
  39. package/dist/SysUserPanel.vue_vue_type_script_setup_true_lang-DoW0v5y9.js +341 -0
  40. package/dist/{SystemMenu-9PG3vESE.js → SystemMenu-DZneBqKO.js} +53 -51
  41. package/dist/{UserInfo-qgXUEGwi.js → UserInfo-D9qo_f_9.js} +1 -1
  42. package/dist/{UserInfo.vue_vue_type_style_index_0_lang-CN0C5rVk.js → UserInfo.vue_vue_type_style_index_0_lang-CY4dtMnZ.js} +35 -33
  43. package/dist/{childView-C7ZSA5fR.js → childView-CmlGxD9G.js} +1 -1
  44. package/dist/{childView-yV2QLwfA.js → childView-DStrPumM.js} +1 -1
  45. package/dist/{childView.vue_vue_type_style_index_0_lang-DdKxPGdh.js → childView.vue_vue_type_style_index_0_lang-B9k694be.js} +23 -24
  46. package/dist/childView.vue_vue_type_style_index_0_lang-Dtv1rrdP.js +177 -0
  47. package/dist/{code-rule-95K1jr-u.js → code-rule-CxzgQDH_.js} +42 -41
  48. package/dist/core.es.js +19 -10
  49. package/dist/{cron-task-DGrQwOHs.js → cron-task-kbyRTz97.js} +5 -5
  50. package/dist/flow-task-B07st2aD.js +10 -0
  51. package/dist/{frameView-7SmME93D.js → frameView-BawZlIge.js} +15 -14
  52. package/dist/img/l_img.svg +1 -1
  53. package/dist/img/minicolors.png +0 -0
  54. package/dist/img/v_img.svg +1 -1
  55. package/dist/index-nkstuOxE.js +5533 -0
  56. package/dist/{layoutView-C6WIVWGZ.js → layoutView-DVGqPJmA.js} +1776 -1764
  57. package/dist/{log-in-e7D5Ss1P.js → log-in-j2PZGLQH.js} +36 -29
  58. package/dist/log-out-DIJU-Vpf.js +130 -0
  59. package/dist/login-DvmHMcgD.js +251 -0
  60. package/dist/{login-log-CvVnyGi3.js → login-log-DJBGJVV0.js} +10 -8
  61. package/dist/{lov-view-DoF5LqFQ.js → lov-view-C-dIDLh8.js} +9 -9
  62. package/dist/{menuInfo-CNzGQwOD.js → menuInfo-D0mcKmrT.js} +1 -1
  63. package/dist/{menuInfo.vue_vue_type_style_index_0_lang-51SYxVc_.js → menuInfo.vue_vue_type_style_index_0_lang-CbwS7aGl.js} +144 -121
  64. package/dist/pda-app-BjvyTDkw.js +710 -0
  65. package/dist/redirect-BqegffKC.js +15 -0
  66. package/dist/{resource-gVFFMO9l.js → resource-BknIxaTQ.js} +17 -17
  67. package/dist/{su-welcome-BN_s_RX_.js → su-welcome-CwtvamZC.js} +137 -139
  68. package/dist/sys-config-CCKhGcCL.js +370 -0
  69. package/dist/udp-core.css +1 -9
  70. package/dist/utogether-MlnyYtNS.js +4 -0
  71. package/index.ts +19 -6
  72. package/package.json +18 -17
  73. package/src/App.vue +2 -7
  74. package/src/api/http.ts +1 -4
  75. package/src/api/index.ts +5 -3
  76. package/src/api/user.ts +2 -2
  77. package/src/components/SuCharts/src/UserInfo.vue +3 -3
  78. package/src/components/SuScrollTree/ScrollPanel.vue +4 -9
  79. package/src/components/udp/content/index.vue +88 -0
  80. package/src/components/udp/form/form.vue +109 -0
  81. package/src/components/udp/grid/index.vue +524 -0
  82. package/src/components/udp/index.ts +5 -4
  83. package/src/components/udp/ut-stamp-badge/index.vue +271 -0
  84. package/src/components/udp/utils.ts +408 -40
  85. package/src/directives/permission/index.ts +1 -1
  86. package/src/layout/components/lay-navbar/index.vue +9 -7
  87. package/src/layout/components/lay-panel/index.vue +3 -3
  88. package/src/layout/components/lay-search/index.vue +1 -1
  89. package/src/layout/components/lay-select-org/index.vue +4 -9
  90. package/src/layout/components/lay-setting/index.vue +503 -510
  91. package/src/layout/components/lay-sidebar/breadCrumb.vue +1 -1
  92. package/src/layout/components/lay-sidebar/horizontal.vue +8 -6
  93. package/src/layout/components/lay-sidebar/mixNav.vue +260 -258
  94. package/src/layout/components/lay-sidebar/sidebar-logo.vue +101 -98
  95. package/src/layout/components/lay-tag/index.vue +598 -625
  96. package/src/layout/hooks/useDataThemeChange.ts +1 -1
  97. package/src/layout/hooks/useNav.ts +176 -173
  98. package/src/layout/hooks/useTag.ts +227 -233
  99. package/src/layout/layoutView.vue +215 -215
  100. package/src/layout/types.ts +93 -92
  101. package/src/main.ts +115 -109
  102. package/src/plugins/i18n/en.ts +26 -13
  103. package/src/plugins/i18n/module/u-workflow.ts +1 -1
  104. package/src/plugins/i18n/zh.ts +363 -337
  105. package/src/plugins/vxe-table/index.ts +116 -46
  106. package/src/plugins/vxe-table/render.tsx +950 -817
  107. package/src/router/index.ts +187 -183
  108. package/src/router/modules/flow.ts +35 -0
  109. package/src/router/modules/home.ts +32 -32
  110. package/src/router/modules/remaining.ts +1 -26
  111. package/src/router/utils.ts +420 -377
  112. package/src/store/modules/app.ts +2 -4
  113. package/src/store/modules/epTheme.ts +48 -49
  114. package/src/store/modules/multiTags.ts +15 -14
  115. package/src/store/modules/permission.ts +25 -15
  116. package/src/store/modules/system.ts +1 -3
  117. package/src/style/button.scss +11 -4
  118. package/src/style/login.css +1 -1
  119. package/src/style/tailwind.css +1 -68
  120. package/src/style/vxetable.scss +103 -11
  121. package/src/utils/authority/index.ts +1 -1
  122. package/src/utils/dataFormat/index.ts +222 -223
  123. package/src/utils/index.ts +3 -1
  124. package/src/utils/lifecycle.ts +39 -20
  125. package/src/utils/propTypes.ts +1 -6
  126. package/src/utils/storage/index.ts +2 -2
  127. package/src/utils/{http → udp/http}/index.ts +27 -30
  128. package/src/utils/{http → udp/http}/types.d.ts +2 -6
  129. package/src/views/login/login-view.vue +6 -20
  130. package/src/views/organization/company/CompanyPanel.vue +2 -2
  131. package/src/views/organization/department/Department.vue +58 -58
  132. package/src/views/organization/department/DepartmentPanel.vue +303 -283
  133. package/src/views/organization/inv-org/InvOrganization.vue +23 -9
  134. package/src/views/organization/org/Org.vue +9 -5
  135. package/src/views/organization/staff/StaffInfo.vue +127 -133
  136. package/src/views/organization/staff/StaffPanel.vue +171 -145
  137. package/src/views/system/cron/cron-task.vue +2 -12
  138. package/src/views/system/menu/AuthorityPanel.vue +2 -2
  139. package/src/views/system/menu/SystemMenu.vue +185 -191
  140. package/src/views/system/menu/menuInfo.vue +39 -23
  141. package/src/views/system/role/AuthorityInfo.vue +19 -15
  142. package/src/views/system/role/Role.vue +1 -5
  143. package/src/views/system/role/RolePanel.vue +11 -2
  144. package/src/views/system/role/UserInfo.vue +11 -9
  145. package/src/views/system/role-assign/RoleAssign.vue +2 -2
  146. package/src/views/system/role-assign/RolePanel.vue +12 -9
  147. package/src/views/system/sys/sys-config.vue +70 -21
  148. package/src/views/system/sysUser/SysUserPanel.vue +347 -278
  149. package/src/views/uapp/pda/pda-app.vue +48 -16
  150. package/src/views/udev/coderule/code-rule.vue +132 -121
  151. package/src/views/udev/dict/DictView.vue +118 -106
  152. package/src/views/udev/dict/childView.vue +183 -222
  153. package/src/views/udev/lov/childView.vue +174 -180
  154. package/src/views/ufile/aggregation/File.vue +5 -5
  155. package/src/views/ufile/file/water-mark.vue +14 -14
  156. package/src/views/uhome/components/menu-favorite.vue +315 -331
  157. package/src/views/uhome/su-welcome.vue +319 -339
  158. package/src/views/ulogin/login.vue +325 -316
  159. package/src/views/upms/interface/log-in.vue +100 -106
  160. package/src/views/upms/interface/log-out.vue +104 -107
  161. package/src/views/upms/user/login-log.vue +54 -60
  162. package/src/views/urpt/design/DesignPanel.vue +16 -35
  163. package/src/views/urpt/design/Preview.vue +1 -0
  164. package/src/views/urpt/design/ReportDesign.vue +17 -23
  165. package/src/views/urpt/static-resource/resource.vue +3 -3
  166. package/src/views/urpt/template/ReportTemplate.vue +7 -7
  167. package/src/views/utask/flow-task.vue +18 -0
  168. package/types/global.d.ts +231 -236
  169. package/vite.config.ts +13 -2
  170. package/dist/AuthorityInfo.vue_vue_type_style_index_0_lang-32L40GY2.js +0 -102
  171. package/dist/DictView-q7kR9K--.js +0 -95
  172. package/dist/InvOrganization-DI45LqZV.js +0 -260
  173. package/dist/Org-CZju_ZiR.js +0 -35
  174. package/dist/RolePanel.vue_vue_type_script_setup_true_lang-DJKu6PXz.js +0 -126
  175. package/dist/StaffPanel.vue_vue_type_script_setup_true_lang-C3Ixs12y.js +0 -111
  176. package/dist/SysUserPanel.vue_vue_type_script_setup_true_lang-C5XEmxsV.js +0 -288
  177. package/dist/childView.vue_vue_type_style_index_0_lang-bkmucBUL.js +0 -187
  178. package/dist/core.umd.js +0 -173
  179. package/dist/index-OswH7SsT.js +0 -9937
  180. package/dist/log-out--RRncZhN.js +0 -120
  181. package/dist/login-BhCMeCLS.js +0 -251
  182. package/dist/pda-app-nn3llDUx.js +0 -2209
  183. package/dist/redirect-CmMplDV4.js +0 -15
  184. package/dist/sys-config-DGutV-VX.js +0 -277
  185. package/dist/utogether-wFDCI28t.js +0 -182
  186. package/src/assets/images/empty.png +0 -0
  187. package/src/assets/images/logo.png +0 -0
  188. package/src/components/ReCountTo/README.md +0 -2
  189. package/src/components/ReCountTo/index.ts +0 -18
  190. package/src/components/ReCountTo/src/normal/index.tsx +0 -165
  191. package/src/components/ReCountTo/src/normal/props.ts +0 -37
  192. package/src/components/ReCountTo/src/rebound/index.tsx +0 -67
  193. package/src/components/ReCountTo/src/rebound/props.ts +0 -14
  194. package/src/components/ReCountTo/src/rebound/rebound.css +0 -77
  195. package/src/components/ReCropper/index.ts +0 -14
  196. package/src/components/ReCropper/src/index.tsx +0 -141
  197. package/src/components/ReFlicker/index.css +0 -39
  198. package/src/components/ReFlicker/index.ts +0 -50
  199. package/src/components/ReFlop/index.ts +0 -14
  200. package/src/components/ReFlop/src/Filpper.tsx +0 -99
  201. package/src/components/ReFlop/src/filpper.css +0 -184
  202. package/src/components/ReFlop/src/index.vue +0 -126
  203. package/src/components/ReFlowChart/index.ts +0 -24
  204. package/src/components/ReFlowChart/src/Control.vue +0 -139
  205. package/src/components/ReFlowChart/src/DataDialog.vue +0 -12
  206. package/src/components/ReFlowChart/src/NodePanel.vue +0 -151
  207. package/src/components/ReFlowChart/src/adpterForTurbo.ts +0 -160
  208. package/src/components/ReFlowChart/src/assets/iconfont/iconfont.css +0 -49
  209. package/src/components/ReFlowChart/src/assets/iconfont/iconfont.eot +0 -0
  210. package/src/components/ReFlowChart/src/assets/iconfont/iconfont.js +0 -61
  211. package/src/components/ReFlowChart/src/assets/iconfont/iconfont.json +0 -58
  212. package/src/components/ReFlowChart/src/assets/iconfont/iconfont.svg +0 -47
  213. package/src/components/ReFlowChart/src/assets/iconfont/iconfont.ttf +0 -0
  214. package/src/components/ReFlowChart/src/assets/iconfont/iconfont.woff +0 -0
  215. package/src/components/ReFlowChart/src/assets/iconfont/iconfont.woff2 +0 -0
  216. package/src/components/ReFlowChart/src/config.ts +0 -62
  217. package/src/components/ReSplitPane/index.css +0 -49
  218. package/src/components/ReSplitPane/index.tsx +0 -119
  219. package/src/components/ReSplitPane/resizer.css +0 -45
  220. package/src/components/ReSplitPane/resizer.tsx +0 -30
  221. package/src/components/SuCommon/card/components/Card.vue +0 -148
  222. package/src/components/SuCommon/card/components/DialogForm.vue +0 -127
  223. package/src/components/SuCommon/card/index.vue +0 -142
  224. package/src/components/SuCommon/icon-select/index.vue +0 -241
  225. package/src/components/SuCommon/table/index.vue +0 -208
  226. package/src/components/SuCommon/utils/index.ts +0 -103
  227. package/src/components/SuCommon/utils/slot.tsx +0 -50
  228. package/src/components/udp/form-upload.vue +0 -132
  229. package/src/components/udp/modal-form.vue +0 -180
  230. package/src/utils/udp/useRender.ts +0 -420
  231. package/src/views/components/contextmenu/basic.vue +0 -74
  232. package/src/views/components/contextmenu/context-menu.vue +0 -40
  233. package/src/views/components/contextmenu/menuDynamic.vue +0 -99
  234. package/src/views/components/contextmenu/menuGroup.vue +0 -71
  235. package/src/views/components/count-to/index.vue +0 -43
  236. package/src/views/components/cropping/index.vue +0 -59
  237. package/src/views/components/cropping/picture.jpeg +0 -0
  238. package/src/views/components/split-pane/index.vue +0 -82
  239. package/src/views/components/video/index.vue +0 -57
@@ -1,377 +1,420 @@
1
- import type { RouteRecordRaw, RouteComponent } from 'vue-router';
2
- import { isProxy, toRaw, defineAsyncComponent } from 'vue';
3
- import { useTimeoutFn } from '@vueuse/core';
4
- import { storageLocal, buildHierarchyTree, dbstorage } from '@utogether/utils';
5
- import { clone } from 'xe-utils';
6
- import { router, getViews } from './index';
7
- import { getConfig } from '../config';
8
- import { geti18n } from '../plugins/i18n';
9
- import { routerArrays } from '../layout/types';
10
- import { usePermissionStoreHook } from '../store/modules/permission';
11
- import { useSystemStoreHook } from '../store/modules/system';
12
- import { useMultiTagsStoreHook } from '../store/modules/multiTags';
13
- import { getServiceApi } from '../api';
14
- import createComponent from './createComponent';
15
-
16
- const Layout = () => import('../layout/layoutView.vue');
17
- const IFrame = () => import('../layout/frameView.vue');
18
-
19
- // 动态路由
20
- import { initDict, initSystemInfo, getAsyncRoutes } from '../api/user';
21
- // https://cn.vitejs.dev/guide/features.html#glob-import
22
- // const modulesRoutes = import.meta.glob('/src/views/**/*.{vue,tsx}');
23
-
24
- // 菜单类型
25
- enum MenuCategoty {
26
- Menu = '5', // 菜单
27
- Lowcode = '10' // 低代码
28
- }
29
-
30
- /** 按照路由中meta下的rank等级升序来排序路由 */
31
- function ascending(arr: any[]) {
32
- arr.forEach(v => {
33
- if (v?.meta?.rank === null) v.meta.rank = undefined;
34
- if (v?.meta?.rank === 0) {
35
- if (v.name !== 'home' && v.path !== '/') {
36
- console.warn('rank only the home page can be 0');
37
- }
38
- }
39
- });
40
- return arr.sort((a: { meta: { rank: number } }, b: { meta: { rank: number } }) => {
41
- return a?.meta?.rank - b?.meta?.rank;
42
- });
43
- }
44
-
45
- /** 过滤meta中showLink为false的菜单 */
46
- function filterTree(data: RouteComponent[]) {
47
- const newTree = clone(data, true).filter(
48
- (v: { meta: { showLink: boolean } }) => v && v.meta?.showLink !== false
49
- );
50
- newTree.forEach((v: { children }) => v.children && (v.children = filterTree(v.children)));
51
- return newTree;
52
- }
53
-
54
- /** 通过指定 `key` 获取父级路径集合,默认 `key` 为 `path` */
55
- function getParentPaths(value: string, routes: RouteRecordRaw[], key = 'path') {
56
- // 深度遍历查找
57
- function dfs(routes: RouteRecordRaw[], value: string, parents: string[]) {
58
- for (let i = 0; i < routes.length; i++) {
59
- const item = routes[i];
60
- // 找到path则返回父级path
61
- // if (item[key] === value) {
62
- // return parents.length ? parents : routes[0];
63
- // }
64
- if (item[key] === value) return parents;
65
- // children不存在或为空则不递归
66
- if (!item.children || !item.children.length) continue;
67
- // 往下查找时将当前path入栈
68
- parents.push(item.path);
69
- // @ts-ignore
70
- if (dfs(item.children, value, parents).length) return parents;
71
- // 深度遍历查找未找到时当前path 出栈
72
- parents.pop();
73
- }
74
- // 未找到时返回空数组
75
- return [];
76
- }
77
-
78
- return dfs(routes, value, []);
79
- }
80
-
81
- /** 查找对应 `path` 的路由信息 */
82
- function findRouteByPath(path: string, routes: RouteRecordRaw[]) {
83
- let res = routes.find((item: { path: string }) => item.path == path);
84
- if (res) {
85
- return isProxy(res) ? toRaw(res) : res;
86
- } else {
87
- for (let i = 0; i < routes.length; i++) {
88
- if (routes[i].children instanceof Array && routes[i].children.length > 0) {
89
- res = findRouteByPath(path, routes[i].children);
90
- if (res) {
91
- return isProxy(res) ? toRaw(res) : res;
92
- }
93
- }
94
- }
95
- return null;
96
- }
97
- }
98
- function addPathMatch() {
99
- if (!router.hasRoute('pathMatch')) {
100
- router.addRoute({
101
- path: '/:pathMatch(.*)',
102
- name: 'pathMatch',
103
- redirect: '/error/404'
104
- });
105
- }
106
- }
107
-
108
- /**
109
- * @description: 添加审批动态路由
110
- * @param {*} syncRoutes 异步获取的路由表数据
111
- * @param {*} routes 格式化后的路由表数据
112
- * @return {*} 格式化后的路由表数据
113
- */
114
- // function addWorkflowRouter(syncRoutes, routes) {
115
- // const flowIdx = syncRoutes.findIndex(f => f.menuCode === 'Workflow');
116
- // const isExit = flowIdx !== -1 && syncRoutes[flowIdx].children?.some(s => s.name === 'workflowApprove');
117
- // if (!isExit) {
118
- // flowIdx !== -1 && routes[flowIdx].children?.push(workflowRouter);
119
- // }
120
- // return routes;
121
- // }
122
- // 菜单国家化
123
- function setMenui18n() {
124
- const i18n = geti18n();
125
- i18n.global?.mergeLocaleMessage('zh', menuI18n.zh);
126
- i18n.global?.mergeLocaleMessage('en', menuI18n.en);
127
- storageLocal.setItem('menu_zh', menuI18n.zh);
128
- storageLocal.setItem('menu_en', menuI18n.en);
129
- }
130
-
131
- function handleAsyncRoutes(routesList) {
132
- if (routesList?.length) {
133
- const idx = routesList.findIndex(f => f.menuCode === 'SysHome');
134
- if (idx !== -1) {
135
- // 仪表盘报表
136
- const dashboardTabs = [];
137
- const homeMenus = [];
138
- routesList[idx].children.forEach(child => {
139
- if (child.menuCategory !== '1') {
140
- dashboardTabs.push(child);
141
- } else {
142
- homeMenus.push(child);
143
- }
144
- });
145
- routesList[idx].children = homeMenus;
146
- useSystemStoreHook().setHomeMenus(dashboardTabs);
147
- }
148
- const routes = clone(addAsyncRoutes(routesList), true);
149
-
150
- // routes = addWorkflowRouter(routesList, routes);
151
- setMenui18n();
152
- formatFlatteningRoutes(routes).map((v: RouteRecordRaw) => {
153
- // 菜单国际化
154
- // 防止重复添加路由
155
- const { options } = router;
156
- if (options.routes[0].children.findIndex(value => value.path === v.path) !== -1) {
157
- return;
158
- } else {
159
- // 切记将路由push到routes后还需要使用addRoute,这样路由才能正常跳转
160
- router.options.routes[0].children.push(v);
161
- // 最终路由进行升序
162
- ascending(router.options.routes[0].children);
163
- if (!router.hasRoute(v?.name)) router.addRoute(v);
164
- }
165
- });
166
- }
167
- usePermissionStoreHook().changeSetting(routesList);
168
- if (!useMultiTagsStoreHook().getMultiTagsCache) {
169
- useMultiTagsStoreHook().handleTags('equal', [
170
- ...routerArrays,
171
- ...usePermissionStoreHook().flatteningRoutes.filter(v => v?.meta?.fixedTag)
172
- ]);
173
- }
174
- addPathMatch();
175
- }
176
-
177
- /** 初始化路由(`new Promise` 写法防止在异步请求中造成无限循环)*/
178
- async function initRouter(userName) {
179
- let asyncRouteList = [];
180
- const key = `U-${userName}-ROUTES`;
181
- // 开启动态路由缓存本地
182
- if (getConfig().CachingAsyncRoutes) {
183
- await dbstorage.getItem(key).then(data => (asyncRouteList = data));
184
- }
185
- initDict().then(res => useSystemStoreHook().setDict(res));
186
- await initSystemInfo().then(async (res: IRecord) => {
187
- useSystemStoreHook().setSystemInfo(res);
188
- await getServiceApi()
189
- .get('/uums/cusOrganization', { pageSize: 100, pageNum: 1, orgId: res.orgId })
190
- .then((res: IResponseData) => useSystemStoreHook().setInvOrgList(res?.list || []));
191
- });
192
- if (asyncRouteList?.length) {
193
- return new Promise(resolve => {
194
- handleAsyncRoutes(asyncRouteList);
195
- // 缓存最新的路由
196
- getAsyncRoutes({ userName }).then((data: any) => {
197
- dbstorage.setItem(key, data);
198
- });
199
- resolve(router);
200
- });
201
- } else {
202
- return new Promise(resolve => {
203
- getAsyncRoutes({ userName }).then((data: any) => {
204
- handleAsyncRoutes(clone(data, true));
205
- dbstorage.setItem(key, data);
206
- resolve(router);
207
- });
208
- });
209
- }
210
- }
211
-
212
- /**
213
- * 将多级嵌套路由处理成一维数组
214
- * @param routesList 传入路由
215
- * @returns 返回处理后的一维路由
216
- */
217
- function formatFlatteningRoutes(routesList: RouteRecordRaw[]) {
218
- if (routesList.length === 0) return routesList;
219
- let hierarchyList = buildHierarchyTree(routesList);
220
- for (let i = 0; i < hierarchyList.length; i++) {
221
- if (hierarchyList[i].children) {
222
- hierarchyList = hierarchyList
223
- .slice(0, i + 1)
224
- .concat(hierarchyList[i].children, hierarchyList.slice(i + 1));
225
- }
226
- }
227
- return hierarchyList;
228
- }
229
-
230
- /**
231
- * 一维数组处理成多级嵌套数组(三级及以上的路由全部拍成二级,keep-alive 只支持到二级缓存)
232
- * @param routesList 处理后的一维路由菜单数组
233
- * @returns 返回将一维数组重新处理成规定路由的格式
234
- */
235
- function formatTwoStageRoutes(routesList: RouteRecordRaw[]) {
236
- if (routesList.length === 0) return routesList;
237
- const newRoutesList: RouteRecordRaw[] = [];
238
- routesList.forEach((v: RouteRecordRaw) => {
239
- if (v.path === '/') {
240
- newRoutesList.push({
241
- component: v.component,
242
- name: v.name,
243
- path: v.path,
244
- redirect: v.redirect,
245
- meta: v.meta,
246
- children: []
247
- });
248
- } else {
249
- newRoutesList[0].children.push({ ...v });
250
- }
251
- });
252
- return newRoutesList;
253
- }
254
-
255
- /** 处理缓存路由(添加、删除、刷新) */
256
- function handleAliveRoute({ name }: ToRouteType, mode?: string) {
257
- switch (mode) {
258
- case 'add':
259
- usePermissionStoreHook().cacheOperate({ mode: 'add', name });
260
- break;
261
- case 'delete':
262
- usePermissionStoreHook().cacheOperate({ mode: 'delete', name });
263
- break;
264
- case 'refresh':
265
- usePermissionStoreHook().cacheOperate({ mode: 'refresh', name });
266
- break;
267
- default:
268
- usePermissionStoreHook().cacheOperate({ mode: 'delete', name });
269
- useTimeoutFn(() => {
270
- usePermissionStoreHook().cacheOperate({ mode: 'add', name });
271
- }, 100);
272
- }
273
- }
274
-
275
- /** 过滤后端传来的动态路由 重新生成规范路由 */
276
- const menuI18n = {
277
- zh: {},
278
- en: {}
279
- };
280
- const addAsyncRoutes = (arrRoutes: Array<any>) => {
281
- const modulesRoutes = getViews();
282
-
283
- if (!arrRoutes || !arrRoutes.length) return;
284
- const modulesRoutesKeys = Object.keys(modulesRoutes);
285
- for (let i = 0; i < arrRoutes.length; i++) {
286
- const v = arrRoutes[i];
287
-
288
- if (v?.children && v.children.length && !v.redirect) {
289
- // 父级的redirect属性取值:如果子级存在且父级的redirect属性不存在,默认取第一个子级的path;如果子级存在且父级的redirect属性存在,取存在的redirect属性,会覆盖默认值
290
- v.redirect = v.children[0].path;
291
- }
292
- const { icon, permissionCode, extraIcon, frameSrc } = v;
293
- v.meta = { keepAlive: true, rank: v.sort, title: `${v.i18nField}` };
294
- Object.assign(v.meta, { icon, permissionCode, extraIcon, frameSrc });
295
- menuI18n.zh[v.i18nField] = v.menuName || v.menuNameEn;
296
- menuI18n.en[v.i18nField] = v.menuNameEn || v.menuName;
297
- v.name = v.menuCode || v.name;
298
- v.path = v.menuPath || v.path;
299
- if (!v.parentId) {
300
- v.component = Layout;
301
- } else if (v.meta?.frameSrc) {
302
- v.component = IFrame;
303
- } else if (v.menuCategory === MenuCategoty.Lowcode) {
304
- // 低开路由处理
305
- const index = modulesRoutesKeys.findIndex(ev => ev.includes('lowcode-contain'));
306
- v.component = createComponent(
307
- v.name,
308
- defineAsyncComponent(() => import(/* @vite-ignore */ modulesRoutesKeys[index]))
309
- );
310
- // 将模块类型赋值到meta中
311
- Object.assign(v.meta, { moduleType: v.moduleType });
312
- } else if (v.menuCategory !== MenuCategoty.Menu) {
313
- const index = modulesRoutesKeys.findIndex(ev => ev.includes(v.path));
314
- v.component = modulesRoutes[modulesRoutesKeys[index]];
315
- }
316
- if (v?.children && v.children.length) {
317
- addAsyncRoutes(v.children);
318
- } else {
319
- delete v.children;
320
- }
321
- }
322
- return arrRoutes;
323
- };
324
-
325
- // 是否有权限
326
- function hasPermissions(value: Array<string>): boolean {
327
- if (value && value instanceof Array && value.length > 0) {
328
- const roles = usePermissionStoreHook().buttonAuth;
329
- const permissionRoles = value;
330
-
331
- const hasPermission = roles.some(role => {
332
- return permissionRoles.includes(role);
333
- });
334
-
335
- if (!hasPermission) {
336
- return false;
337
- }
338
- return true;
339
- } else {
340
- return false;
341
- }
342
- }
343
- // 删除当前路由
344
- function delCurrentRoute(current: any, toNext = true) {
345
- const startIndex: number = useMultiTagsStoreHook().multiTags.findIndex(tag => {
346
- if (current.query) {
347
- if (current.path === tag.path) {
348
- return current.query === tag.query;
349
- }
350
- } else {
351
- return current.path === tag.path;
352
- }
353
- });
354
- useMultiTagsStoreHook().handleTags('splice', '', { startIndex, length: 1 });
355
- handleAliveRoute(current.matched, 'delete');
356
- if (toNext) {
357
- const newRoute = useMultiTagsStoreHook().handleTags('slice');
358
- router.push({
359
- path: newRoute[0].path,
360
- query: newRoute[0].query
361
- });
362
- }
363
- }
364
-
365
- export {
366
- ascending,
367
- filterTree,
368
- initRouter,
369
- hasPermissions,
370
- addAsyncRoutes,
371
- getParentPaths,
372
- findRouteByPath,
373
- handleAliveRoute,
374
- formatTwoStageRoutes,
375
- formatFlatteningRoutes,
376
- delCurrentRoute
377
- };
1
+ /*
2
+ * @Author: levi7754 levi7754@163.com
3
+ * @Date: 2024-08-01 21:42:39
4
+ * @LastEditors: levi7754 levi7754@163.com
5
+ * @LastEditTime: 2025-12-02 18:21:41
6
+ * @FilePath: \udp-front\packages\udp-core\src\router\utils.ts
7
+ * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
8
+ */
9
+ import type { RouteRecordRaw, RouteComponent } from 'vue-router';
10
+ import { isProxy, toRaw, defineAsyncComponent } from 'vue';
11
+ import { useTimeoutFn } from '@vueuse/core';
12
+ import { storageLocal, buildHierarchyTree, dbstorage } from '@utogether/utils';
13
+ import { clone } from 'xe-utils';
14
+ import { router, getViews } from './index';
15
+ import { getConfig } from '../config';
16
+ import { geti18n } from '../plugins/i18n';
17
+ import { routerArrays } from '../layout/types';
18
+ import { usePermissionStoreHook } from '../store/modules/permission';
19
+ import { useSystemStoreHook } from '../store/modules/system';
20
+ import { useMultiTagsStoreHook } from '../store/modules/multiTags';
21
+ import { getServiceApi } from '../api';
22
+ import createComponent from './createComponent';
23
+
24
+ const Layout = () => import('../layout/layoutView.vue');
25
+ const IFrame = () => import('../layout/frameView.vue');
26
+
27
+ // 动态路由
28
+ import { initDict, initSystemInfo, getAsyncRoutes } from '../api/user';
29
+ // https://cn.vitejs.dev/guide/features.html#glob-import
30
+ // const modulesRoutes = import.meta.glob('/src/views/**/*.{vue,tsx}');
31
+
32
+ // 菜单类型
33
+ enum MenuCategoty {
34
+ Menu = '5', // 菜单
35
+ Lowcode = '10' // 低代码
36
+ }
37
+
38
+ /** 按照路由中meta下的rank等级升序来排序路由 */
39
+ function ascending(arr: any[]) {
40
+ arr.forEach(v => {
41
+ if (v?.meta?.rank === null) v.meta.rank = undefined;
42
+ if (v?.meta?.rank === 0) {
43
+ if (v.name !== 'home' && v.path !== '/') {
44
+ console.warn('rank only the home page can be 0');
45
+ }
46
+ }
47
+ });
48
+ return arr.sort((a: { meta: { rank: number } }, b: { meta: { rank: number } }) => {
49
+ return a?.meta?.rank - b?.meta?.rank;
50
+ });
51
+ }
52
+
53
+ /** 过滤meta中showLink为false的菜单 */
54
+ function filterTree(data: RouteComponent[]) {
55
+ const newTree = clone(data, true).filter((v: { meta: { showLink: boolean } }) => v && v.meta?.showLink !== false);
56
+ newTree.forEach((v: { children }) => v.children && (v.children = filterTree(v.children)));
57
+ return newTree;
58
+ }
59
+
60
+ /** 通过指定 `key` 获取父级路径集合,默认 `key` 为 `path` */
61
+ function getParentPaths(value: string, routes: RouteRecordRaw[], key = 'path') {
62
+ // 深度遍历查找
63
+ function dfs(routes: RouteRecordRaw[], value: string, parents: string[]) {
64
+ for (let i = 0; i < routes.length; i++) {
65
+ const item = routes[i];
66
+ // 找到path则返回父级path
67
+ // if (item[key] === value) {
68
+ // return parents.length ? parents : routes[0];
69
+ // }
70
+ if (item[key] === value) return parents;
71
+ // children不存在或为空则不递归
72
+ if (!item.children || !item.children.length) continue;
73
+ // 往下查找时将当前path入栈
74
+ parents.push(item.path);
75
+ // @ts-ignore
76
+ if (dfs(item.children, value, parents).length) return parents;
77
+ // 深度遍历查找未找到时当前path 出栈
78
+ parents.pop();
79
+ }
80
+ // 未找到时返回空数组
81
+ return [];
82
+ }
83
+
84
+ return dfs(routes, value, []);
85
+ }
86
+
87
+ /** 查找对应 `path` 的路由信息 */
88
+ function findRouteByPath(path: string, routes: RouteRecordRaw[]) {
89
+ let res = routes.find((item: { path: string }) => item.path == path);
90
+ if (res) {
91
+ return isProxy(res) ? toRaw(res) : res;
92
+ } else {
93
+ for (let i = 0; i < routes.length; i++) {
94
+ if (routes[i].children instanceof Array && routes[i].children.length > 0) {
95
+ res = findRouteByPath(path, routes[i].children);
96
+ if (res) {
97
+ return isProxy(res) ? toRaw(res) : res;
98
+ }
99
+ }
100
+ }
101
+ return null;
102
+ }
103
+ }
104
+ function addPathMatch() {
105
+ if (!router.hasRoute('pathMatch')) {
106
+ router.addRoute({
107
+ path: '/:pathMatch(.*)',
108
+ name: 'pathMatch',
109
+ redirect: '/error/404'
110
+ });
111
+ }
112
+ }
113
+
114
+ /**
115
+ * @description: 添加审批动态路由
116
+ * @param {*} syncRoutes 异步获取的路由表数据
117
+ * @param {*} routes 格式化后的路由表数据
118
+ * @return {*} 格式化后的路由表数据
119
+ */
120
+ // function addWorkflowRouter(syncRoutes, routes) {
121
+ // const flowIdx = syncRoutes.findIndex(f => f.menuCode === 'Workflow');
122
+ // const isExit = flowIdx !== -1 && syncRoutes[flowIdx].children?.some(s => s.name === 'workflowApprove');
123
+ // if (!isExit) {
124
+ // flowIdx !== -1 && routes[flowIdx].children?.push(workflowRouter);
125
+ // }
126
+ // return routes;
127
+ // }
128
+ // 菜单国家化
129
+ function setMenui18n() {
130
+ const i18n = geti18n();
131
+ i18n.global?.mergeLocaleMessage('zh', menuI18n.zh);
132
+ i18n.global?.mergeLocaleMessage('en', menuI18n.en);
133
+ storageLocal.setItem('menu_zh', menuI18n.zh);
134
+ storageLocal.setItem('menu_en', menuI18n.en);
135
+ }
136
+
137
+ function handleAsyncRoutes(routesList) {
138
+ if (routesList?.length) {
139
+ const idx = routesList.findIndex(f => f.menuCode === 'SysHome');
140
+ if (idx !== -1) {
141
+ // 仪表盘报表
142
+ const dashboardTabs = [];
143
+ const homeMenus = [];
144
+ routesList[idx].children.forEach(child => {
145
+ if (child.menuCategory !== '1') {
146
+ dashboardTabs.push(child);
147
+ } else {
148
+ homeMenus.push(child);
149
+ }
150
+ });
151
+ routesList[idx].children = homeMenus;
152
+ useSystemStoreHook().setHomeMenus(dashboardTabs);
153
+ }
154
+ const routes = clone(addAsyncRoutes(routesList), true);
155
+
156
+ // routes = addWorkflowRouter(routesList, routes);
157
+ setMenui18n();
158
+ formatFlatteningRoutes(routes).map((v: RouteRecordRaw) => {
159
+ // 菜单国际化
160
+ // 防止重复添加路由
161
+ const { options } = router;
162
+ if (options.routes[0].children.findIndex(value => value.path === v.path) !== -1) {
163
+ return;
164
+ } else {
165
+ // 切记将路由push到routes后还需要使用addRoute,这样路由才能正常跳转
166
+ router.options.routes[0].children.push(v);
167
+ // 最终路由进行升序
168
+ ascending(router.options.routes[0].children);
169
+ if (!router.hasRoute(v?.name)) router.addRoute(v);
170
+ }
171
+ });
172
+ }
173
+ usePermissionStoreHook().changeSetting(routesList);
174
+ if (!useMultiTagsStoreHook().getMultiTagsCache) {
175
+ useMultiTagsStoreHook().handleTags('equal', [
176
+ ...routerArrays,
177
+ ...usePermissionStoreHook().flatteningRoutes.filter(v => v?.meta?.fixedTag)
178
+ ]);
179
+ }
180
+ addPathMatch();
181
+ }
182
+
183
+ /** 初始化路由(`new Promise` 写法防止在异步请求中造成无限循环)*/
184
+ async function initRouter(userName) {
185
+ let asyncRouteList = [];
186
+ const key = `U-${userName}-ROUTES`;
187
+ // 开启动态路由缓存本地
188
+ if (getConfig().CachingAsyncRoutes) {
189
+ await dbstorage.getItem(key).then(data => (asyncRouteList = data));
190
+ }
191
+ initDict().then(res => useSystemStoreHook().setDict(res));
192
+ await initSystemInfo().then(async (res: IRecord) => {
193
+ useSystemStoreHook().setSystemInfo(res);
194
+ await getServiceApi()
195
+ .get('/uums/cusOrganization', { pageSize: 100, pageNum: 1, orgId: res.orgId })
196
+ .then((res: IResponseData) => useSystemStoreHook().setInvOrgList(res?.list || []));
197
+ });
198
+ if (asyncRouteList?.length) {
199
+ return new Promise(resolve => {
200
+ handleAsyncRoutes(asyncRouteList);
201
+ // 缓存最新的路由
202
+ getAsyncRoutes({ userName }).then((data: any) => {
203
+ dbstorage.setItem(key, data);
204
+ });
205
+ resolve(router);
206
+ });
207
+ } else {
208
+ return new Promise(resolve => {
209
+ getAsyncRoutes({ userName }).then((data: any) => {
210
+ handleAsyncRoutes(clone(data, true));
211
+ dbstorage.setItem(key, data);
212
+ resolve(router);
213
+ });
214
+ });
215
+ }
216
+ }
217
+
218
+ /**
219
+ * 将多级嵌套路由处理成一维数组
220
+ * @param routesList 传入路由
221
+ * @returns 返回处理后的一维路由
222
+ */
223
+ function formatFlatteningRoutes(routesList: RouteRecordRaw[]) {
224
+ if (routesList.length === 0) return routesList;
225
+ let hierarchyList = buildHierarchyTree(routesList);
226
+ for (let i = 0; i < hierarchyList.length; i++) {
227
+ if (hierarchyList[i].children) {
228
+ hierarchyList = hierarchyList.slice(0, i + 1).concat(hierarchyList[i].children, hierarchyList.slice(i + 1));
229
+ }
230
+ }
231
+ return hierarchyList;
232
+ }
233
+
234
+ /**
235
+ * 一维数组处理成多级嵌套数组(三级及以上的路由全部拍成二级,keep-alive 只支持到二级缓存)
236
+ * @param routesList 处理后的一维路由菜单数组
237
+ * @returns 返回将一维数组重新处理成规定路由的格式
238
+ */
239
+ function formatTwoStageRoutes(routesList: RouteRecordRaw[]) {
240
+ if (routesList.length === 0) return routesList;
241
+ const newRoutesList: RouteRecordRaw[] = [];
242
+ routesList.forEach((v: RouteRecordRaw) => {
243
+ if (v.path === '/') {
244
+ newRoutesList.push({
245
+ component: v.component,
246
+ name: v.name,
247
+ path: v.path,
248
+ redirect: v.redirect,
249
+ meta: v.meta,
250
+ children: []
251
+ });
252
+ } else {
253
+ newRoutesList[0].children.push({ ...v });
254
+ }
255
+ });
256
+ return newRoutesList;
257
+ }
258
+
259
+ /** 处理缓存路由(添加、删除、刷新) */
260
+ function handleAliveRoute({ name }: ToRouteType, mode?: string) {
261
+ switch (mode) {
262
+ case 'add':
263
+ usePermissionStoreHook().cacheOperate({ mode: 'add', name });
264
+ break;
265
+ case 'delete':
266
+ usePermissionStoreHook().cacheOperate({ mode: 'delete', name });
267
+ break;
268
+ case 'refresh':
269
+ usePermissionStoreHook().cacheOperate({ mode: 'refresh', name });
270
+ break;
271
+ default:
272
+ usePermissionStoreHook().cacheOperate({ mode: 'delete', name });
273
+ useTimeoutFn(() => {
274
+ usePermissionStoreHook().cacheOperate({ mode: 'add', name });
275
+ }, 100);
276
+ }
277
+ }
278
+
279
+ /** 过滤后端传来的动态路由 重新生成规范路由 */
280
+ const menuI18n = {
281
+ zh: {},
282
+ en: {}
283
+ };
284
+
285
+ const processMenus = [];
286
+
287
+ const addAsyncRoutes = (arrRoutes: Array<any>) => {
288
+ const modulesRoutes = getViews();
289
+
290
+ if (!arrRoutes || !arrRoutes.length) return;
291
+ const modulesRoutesKeys = Object.keys(modulesRoutes);
292
+ for (let i = 0; i < arrRoutes.length; i++) {
293
+ const v = arrRoutes[i];
294
+
295
+ if (v?.children && v.children.length && !v.redirect) {
296
+ // 父级的redirect属性取值:如果子级存在且父级的redirect属性不存在,默认取第一个子级的path;如果子级存在且父级的redirect属性存在,取存在的redirect属性,会覆盖默认值
297
+ v.redirect = v.children[0].path;
298
+ }
299
+ const { icon, permissionCode, extraIcon, frameSrc } = v;
300
+ // 流程菜单保存
301
+ v.isApprovalPage === 'Y' && processMenus.push(v);
302
+
303
+ v.meta = {
304
+ keepAlive: true,
305
+ rank: v.sort,
306
+ title: `${v.i18nField}`,
307
+ // 审批流设计页面和审批页面的code写死,只需配置页面即可(保底方式)
308
+ // showLink: !['UDPFlowTask'].includes(v.menuCode) ? null : false
309
+ showLink: v.showLink !== 'N'
310
+ };
311
+ v.hiddenTag = null;
312
+ Object.assign(v.meta, { icon, permissionCode, extraIcon, frameSrc });
313
+ menuI18n.zh[v.i18nField] = v.menuName || v.menuNameEn;
314
+ menuI18n.en[v.i18nField] = v.menuNameEn || v.menuName;
315
+ v.name = v.menuCode || v.name;
316
+ v.path = v.menuPath || v.path;
317
+ if (!v.parentId) {
318
+ v.component = Layout;
319
+ } else if (v.meta?.frameSrc) {
320
+ v.component = IFrame;
321
+ } else if (v.menuCategory === MenuCategoty.Lowcode) {
322
+ // 低开路由处理
323
+ const index = modulesRoutesKeys.findIndex(ev => ev.includes('lowcode-contain'));
324
+ v.component = createComponent(
325
+ v.name,
326
+ defineAsyncComponent(() => import(/* @vite-ignore */ modulesRoutesKeys[index]))
327
+ );
328
+ // 将模块类型赋值到meta中
329
+ Object.assign(v.meta, { moduleType: v.moduleType });
330
+ } else if (v.menuCategory !== MenuCategoty.Menu) {
331
+ const index = modulesRoutesKeys.findIndex(ev => ev.includes(v.path));
332
+ v.component = modulesRoutes[modulesRoutesKeys[index]];
333
+ }
334
+ if (v?.children && v.children.length) {
335
+ addAsyncRoutes(v.children);
336
+ } else {
337
+ delete v.children;
338
+ }
339
+ }
340
+ return arrRoutes;
341
+ };
342
+
343
+ // 是否有权限
344
+ function hasPermissions(value: Array<string>): boolean {
345
+ if (value && value instanceof Array && value.length > 0) {
346
+ const roles = usePermissionStoreHook().buttonAuth;
347
+ const permissionRoles = value;
348
+
349
+ const hasPermission = roles.some(role => {
350
+ return permissionRoles.includes(role);
351
+ });
352
+
353
+ if (!hasPermission) {
354
+ return false;
355
+ }
356
+ return true;
357
+ } else {
358
+ return false;
359
+ }
360
+ }
361
+ // 删除当前路由
362
+ function delCurrentRoute(current: any, toNext = true) {
363
+ const startIndex: number = useMultiTagsStoreHook().multiTags.findIndex(tag => {
364
+ if (current.query) {
365
+ if (current.path === tag.path) {
366
+ return current.query === tag.query;
367
+ }
368
+ } else {
369
+ return current.path === tag.path;
370
+ }
371
+ });
372
+ useMultiTagsStoreHook().handleTags('splice', '', { startIndex, length: 1 });
373
+ handleAliveRoute(current.matched, 'delete');
374
+ if (toNext) {
375
+ const newRoute = useMultiTagsStoreHook().handleTags('slice');
376
+ router.push({
377
+ path: newRoute[0].path,
378
+ query: newRoute[0].query
379
+ });
380
+ }
381
+ }
382
+
383
+ function handleTopMenu(route) {
384
+ if (route?.children && route.children.length > 1) {
385
+ if (route.redirect) {
386
+ return route.children.filter(cur => cur.path === route.redirect)[0];
387
+ } else {
388
+ return route.children[0];
389
+ }
390
+ } else {
391
+ return route;
392
+ }
393
+ }
394
+
395
+ /** 获取所有菜单中的第一个菜单(顶级菜单)*/
396
+ function getTopMenu(tag = false) {
397
+ const topMenu = handleTopMenu(usePermissionStoreHook().wholeMenus[0]?.children[0]);
398
+ tag && useMultiTagsStoreHook().handleTags('push', topMenu);
399
+ return topMenu;
400
+ }
401
+
402
+ function getProcessMenu() {
403
+ return processMenus;
404
+ }
405
+
406
+ export {
407
+ ascending,
408
+ filterTree,
409
+ initRouter,
410
+ getTopMenu,
411
+ getProcessMenu,
412
+ hasPermissions,
413
+ addAsyncRoutes,
414
+ getParentPaths,
415
+ findRouteByPath,
416
+ handleAliveRoute,
417
+ formatTwoStageRoutes,
418
+ formatFlatteningRoutes,
419
+ delCurrentRoute
420
+ };