@utogether/udp-core 2.0.0-beta.26 → 2.0.0-beta.28

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 (183) hide show
  1. package/dist/403-CyoOD-Ik.js +65 -0
  2. package/dist/404-Ch_OHTw0.js +65 -0
  3. package/dist/500-Cf9am7HK.js +67 -0
  4. package/dist/AuthorityInfo-BJ427cqG.js +4 -0
  5. package/dist/AuthorityInfo.vue_vue_type_style_index_0_lang-D9y7AwbB.js +99 -0
  6. package/dist/AuthorityPanel-lVnZ5bce.js +4 -0
  7. package/dist/AuthorityPanel.vue_vue_type_style_index_0_lang-nsfhDlvV.js +113 -0
  8. package/dist/Company-qo-lKPkv.js +25 -0
  9. package/dist/CompanyPanel-DkKWAKvY.js +204 -0
  10. package/dist/DataSet-iBHzs75s.js +147 -0
  11. package/dist/Department-CHUQByKX.js +25 -0
  12. package/dist/DepartmentPanel-C742dfOO.js +248 -0
  13. package/dist/DesignPanel-D9oE5R7m.js +4 -0
  14. package/dist/DesignPanel.vue_vue_type_style_index_0_lang-hYldVEbo.js +1097 -0
  15. package/dist/DictView-CrFXprP9.js +110 -0
  16. package/dist/InvOrganization-Cz8SzIgs.js +73 -0
  17. package/dist/Org-Bzt6yKox.js +38 -0
  18. package/dist/Preview-jonigfMQ.js +48 -0
  19. package/dist/ReportDefine-BpiM5Ovq.js +10 -0
  20. package/dist/ReportDesign-fp09cXJ7.js +164 -0
  21. package/dist/ReportQuery-52ZP1PYP.js +74 -0
  22. package/dist/ReportQueryFrom-DSYavJb1.js +4 -0
  23. package/dist/ReportQueryFrom.vue_vue_type_style_index_0_lang-DBGYEp0u.js +177 -0
  24. package/dist/ReportTemplate-CA_UW0eD.js +161 -0
  25. package/dist/Role-DqOt8Bk0.js +25 -0
  26. package/dist/RoleAssign-BdxhefhQ.js +26 -0
  27. package/dist/RolePanel-2gZ3H0ET.js +4 -0
  28. package/dist/RolePanel-BsNd0svJ.js +4 -0
  29. package/dist/RolePanel.vue_vue_type_script_setup_true_lang-DLOwgF99.js +152 -0
  30. package/dist/RolePanel.vue_vue_type_script_setup_true_lang-DmzD9kab.js +131 -0
  31. package/dist/ScrollPanel.vue_vue_type_style_index_0_lang-B9ptUMeI.js +99 -0
  32. package/dist/Staff-D3L8fEoY.js +26 -0
  33. package/dist/StaffInfo-DYRw6ZYJ.js +4 -0
  34. package/dist/StaffInfo.vue_vue_type_script_setup_true_lang-xqEOQnMs.js +107 -0
  35. package/dist/StaffPanel-DkrNH6Px.js +4 -0
  36. package/dist/StaffPanel.vue_vue_type_script_setup_true_lang-BPBMnliy.js +152 -0
  37. package/dist/SysUser-Bl1-cIpJ.js +15 -0
  38. package/dist/SysUserPanel-yxNLaBwt.js +4 -0
  39. package/dist/SysUserPanel.vue_vue_type_script_setup_true_lang-BDcsgSl5.js +352 -0
  40. package/dist/SystemMenu-C4_Arn12.js +155 -0
  41. package/dist/UserInfo-QcNwJCUR.js +4 -0
  42. package/dist/UserInfo.vue_vue_type_style_index_0_lang-DLIeUphX.js +159 -0
  43. package/dist/childView-B23DEO2u.js +4 -0
  44. package/dist/childView-saDZQv9x.js +4 -0
  45. package/dist/childView.vue_vue_type_style_index_0_lang-RsKR6CAC.js +182 -0
  46. package/dist/childView.vue_vue_type_style_index_0_lang-ZFEfavUY.js +142 -0
  47. package/dist/code-rule-2_Ihx_by.js +147 -0
  48. package/dist/core.es.js +26 -6
  49. package/dist/cron-task-BFOPJQIk.js +134 -0
  50. package/dist/flow-task-PoDnE_kE.js +10 -0
  51. package/dist/frameView-f7Ya0Knj.js +43 -0
  52. package/dist/index-BpdTDaTk.js +3213 -0
  53. package/dist/layout-home-v3DPJ7rB.js +231 -0
  54. package/dist/layoutView-DZHoQDH1.js +3190 -0
  55. package/dist/log-in-BPAMJTwH.js +115 -0
  56. package/dist/log-out-DZACF0jg.js +129 -0
  57. package/dist/login-B8cwozax.js +216 -0
  58. package/dist/login-log-CVvRgZSu.js +70 -0
  59. package/dist/lov-view-Ba7Y7xy0.js +98 -0
  60. package/dist/menuInfo-BpRKFYK8.js +4 -0
  61. package/dist/menuInfo.vue_vue_type_style_index_0_lang-DJ5sUC6m.js +359 -0
  62. package/dist/pda-app-C0jJecrL.js +706 -0
  63. package/dist/redirect-DTz8GSnv.js +15 -0
  64. package/dist/resource-BG22Cw4P.js +97 -0
  65. package/dist/su-welcome-DaxhbrC6.js +879 -0
  66. package/dist/sys-config-CG2fMtak.js +384 -0
  67. package/dist/udp-core.css +1 -2
  68. package/dist/useNav-_u2UAQWk.js +84 -0
  69. package/dist/utogether-MlnyYtNS.js +4 -0
  70. package/dist/wecom-push-B75FLee5.js +70 -0
  71. package/index.ts +54 -50
  72. package/package.json +21 -21
  73. package/src/App.vue +79 -78
  74. package/src/api/http.ts +10 -4
  75. package/src/api/index.ts +51 -51
  76. package/src/api/user.ts +64 -64
  77. package/src/components/SuQrcode/src/index.tsx +231 -236
  78. package/src/components/udp/content/index.vue +93 -93
  79. package/src/components/udp/form-upload/form-upload.vue +496 -496
  80. package/src/components/udp/grid/index.vue +643 -544
  81. package/src/components/udp/index.ts +2 -1
  82. package/src/components/udp/modal-form/index.vue +326 -0
  83. package/src/components/udp/utils.ts +420 -420
  84. package/src/layout/components/lay-navbar/index.vue +240 -240
  85. package/src/layout/components/lay-panel/index.vue +2 -6
  86. package/src/layout/components/lay-search/components/SearchModal.vue +185 -181
  87. package/src/layout/components/lay-sidebar/mixNav.vue +261 -261
  88. package/src/layout/components/lay-sidebar/sidebarItem.vue +199 -195
  89. package/src/layout/components/lay-sidebar/vertical.vue +92 -92
  90. package/src/layout/layoutView.vue +1 -0
  91. package/src/main.ts +111 -109
  92. package/src/plugins/i18n/zh.ts +5 -1
  93. package/src/plugins/vxe-table/index.ts +116 -116
  94. package/src/router/index.ts +5 -34
  95. package/src/router/utils.ts +434 -430
  96. package/src/store/modules/permission.ts +1 -1
  97. package/src/store/modules/system.ts +193 -186
  98. package/src/style/print-lock.css +380 -375
  99. package/src/style/suprint.css +990 -985
  100. package/src/style/vxetable.scss +372 -364
  101. package/src/utils/authority/index.ts +19 -2
  102. package/src/utils/dataFormat/index.ts +309 -222
  103. package/src/utils/udp/http/index.ts +126 -67
  104. package/src/utils/udp/http/types.d.ts +15 -14
  105. package/src/views/login/login-view.vue +4 -21
  106. package/src/views/organization/department/DepartmentPanel.vue +3 -4
  107. package/src/views/system/sys/sys-config.vue +344 -344
  108. package/src/views/uhome/components/home-todo.vue +191 -178
  109. package/src/views/uhome/dynamic-card.vue +31 -31
  110. package/src/views/uhome/su-welcome.vue +310 -310
  111. package/src/views/ulogin/login.vue +292 -296
  112. package/src/views/urpt/design/DesignPanel.vue +538 -507
  113. package/src/views/urpt/design/print-data.ts +39 -59
  114. package/tsconfig.json +2 -3
  115. package/types/global.d.ts +234 -234
  116. package/vite.config.ts +2 -1
  117. package/dist/403-D6Wb3JJh.js +0 -72
  118. package/dist/404-B_HNbPNV.js +0 -72
  119. package/dist/500-BMemTTy1.js +0 -77
  120. package/dist/AuthorityInfo-6wHxwiFM.js +0 -91
  121. package/dist/AuthorityPanel-OqF_DvXA.js +0 -98
  122. package/dist/Company-BLXSfow0.js +0 -21
  123. package/dist/CompanyPanel-B4kRZ5Cg.js +0 -199
  124. package/dist/DataSet-CuGZcKC-.js +0 -141
  125. package/dist/Department-oFhsa7cd.js +0 -21
  126. package/dist/DepartmentPanel-B1UGpu-r.js +0 -242
  127. package/dist/DepartmentPanel-BL58AdoT.js +0 -2
  128. package/dist/DesignPanel-DmkFVw1N.js +0 -1196
  129. package/dist/DictView-CC5yMzOq.js +0 -100
  130. package/dist/File-WJXjGYxr.js +0 -89
  131. package/dist/InvOrganization-BwMmD8Ua.js +0 -76
  132. package/dist/Org-HgnOWubi.js +0 -76
  133. package/dist/Preview-CAzWxLmP.js +0 -45
  134. package/dist/ReIcon-DecitXmg.js +0 -413
  135. package/dist/ReportDefine-BgLM-Rjk.js +0 -10
  136. package/dist/ReportDesign-DwchGG2P.js +0 -158
  137. package/dist/ReportQuery-D5jaRJEn.js +0 -101
  138. package/dist/ReportQueryFrom-CNlmtYey.js +0 -198
  139. package/dist/ReportTemplate-CNcTmccs.js +0 -162
  140. package/dist/Role-Be8WfdCA.js +0 -21
  141. package/dist/RoleAssign-CtehGAUf.js +0 -22
  142. package/dist/RolePanel-CAwITg_q.js +0 -131
  143. package/dist/RolePanel-SN0FGFZ7.js +0 -176
  144. package/dist/ScrollPanel-DW30pGz1.js +0 -88
  145. package/dist/Staff-V2YsNKcj.js +0 -22
  146. package/dist/StaffInfo-CKRPW0r4.js +0 -149
  147. package/dist/StaffPanel-BxcgMg7u.js +0 -143
  148. package/dist/SysUser-Dxyj5w5m.js +0 -12
  149. package/dist/SysUserPanel-DI6CWcZo.js +0 -365
  150. package/dist/SystemMenu-BBHREM8T.js +0 -154
  151. package/dist/UserInfo-BMVQ0xwE.js +0 -194
  152. package/dist/_plugin-vue_export-helper-C6QCLu9I.js +0 -8
  153. package/dist/api-BFNxcxSN.js +0 -30
  154. package/dist/authority-BJFEUdrh.js +0 -20
  155. package/dist/await-to-js.es5-DkWYmPXW.js +0 -10
  156. package/dist/childView-BBjPEraB.js +0 -184
  157. package/dist/childView-DNqG2UVm.js +0 -181
  158. package/dist/code-rule-QFrhqFrW.js +0 -151
  159. package/dist/contant-Q77dU_V3.js +0 -4
  160. package/dist/cron-task-BpUDKEAU.js +0 -131
  161. package/dist/flow-task-DAc2NrDU.js +0 -11
  162. package/dist/frameView-Di0zJZUR.js +0 -39
  163. package/dist/layout-home-BVp7vYLR.js +0 -239
  164. package/dist/layoutView-B6Mx2ERA.js +0 -2662
  165. package/dist/log-in-BrNB0mLz.js +0 -117
  166. package/dist/log-out-dYfqvzy6.js +0 -111
  167. package/dist/login-D_Hjy3Jd.js +0 -231
  168. package/dist/login-log-CJak-ANA.js +0 -79
  169. package/dist/lov-view-DM5Nm5tW.js +0 -95
  170. package/dist/menuInfo-BlOY1KZW.js +0 -346
  171. package/dist/mitt-CQgI7DYU.js +0 -27
  172. package/dist/pda-app-CA7YI37u.js +0 -589
  173. package/dist/redirect-N0k4tImU.js +0 -16
  174. package/dist/resource-CfQTHFcs.js +0 -94
  175. package/dist/su-welcome-DVD3S_du.js +0 -799
  176. package/dist/sys-config-Ddb3vBpK.js +0 -316
  177. package/dist/system-Cm3lyBas.js +0 -1528
  178. package/dist/udp-core-DaQd5CF1.js +0 -2028
  179. package/dist/useDataThemeChange-DJ4K3VGp.js +0 -226
  180. package/dist/useNav-BhOJIdrJ.js +0 -106
  181. package/dist/utogether-l7JXs4Lv.js +0 -4
  182. package/dist/water-mark-WDQZ9YqB.js +0 -119
  183. package/dist/wecom-push-kWkAVRCj.js +0 -77
@@ -1,430 +1,434 @@
1
- /*
2
- * @Author: levi7754 levi7754@163.com
3
- * @Date: 2024-08-01 21:42:39
4
- * @LastEditors: levi7754 levi7754@163.com
5
- * @LastEditTime: 2026-04-16 09:56:45
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, cookies } 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 { kTOKEN } from '../contant';
19
- import { usePermissionStoreHook } from '../store/modules/permission';
20
- import { useSystemStoreHook } from '../store/modules/system';
21
- import { useMultiTagsStoreHook } from '../store/modules/multiTags';
22
- import { getServiceApi } from '../api';
23
- import createComponent from './createComponent';
24
-
25
- const Layout = () => import('../layout/layoutView.vue');
26
- const IFrame = () => import('../layout/frameView.vue');
27
-
28
- // 动态路由
29
- import { initSystemInfo, getAsyncRoutes } from '../api/user';
30
- // https://cn.vitejs.dev/guide/features.html#glob-import
31
- // const modulesRoutes = import.meta.glob('/src/views/**/*.{vue,tsx}');
32
-
33
- // 菜单类型
34
- enum MenuCategoty {
35
- Link = '3', // 外链
36
- Menu = '5', // 菜单
37
- Lowcode = '10' // 低代码
38
- }
39
-
40
- /** 按照路由中meta下的rank等级升序来排序路由 */
41
- function ascending(arr: any[]) {
42
- arr.forEach(v => {
43
- if (v?.meta?.rank === null) v.meta.rank = undefined;
44
- if (v?.meta?.rank === 0) {
45
- if (v.name !== 'home' && v.path !== '/') {
46
- console.warn('rank only the home page can be 0');
47
- }
48
- }
49
- });
50
- return arr.sort((a: { meta: { rank: number } }, b: { meta: { rank: number } }) => {
51
- return a?.meta?.rank - b?.meta?.rank;
52
- });
53
- }
54
-
55
- /** 过滤meta中showLink为false的菜单 */
56
- function filterTree(data: RouteComponent[]) {
57
- const newTree = clone(data, true).filter((v: { meta: { showLink: boolean } }) => v && v.meta?.showLink !== false);
58
- newTree.forEach((v: { children }) => v.children && (v.children = filterTree(v.children)));
59
- return newTree;
60
- }
61
-
62
- /** 通过指定 `key` 获取父级路径集合,默认 `key` 为 `path` */
63
- function getParentPaths(value: string, routes: RouteRecordRaw[], key = 'path') {
64
- // 深度遍历查找
65
- function dfs(routes: RouteRecordRaw[], value: string, parents: string[]) {
66
- for (let i = 0; i < routes.length; i++) {
67
- const item = routes[i];
68
- // 找到path则返回父级path
69
- // if (item[key] === value) {
70
- // return parents.length ? parents : routes[0];
71
- // }
72
- if (item[key] === value) return parents;
73
- // children不存在或为空则不递归
74
- if (!item.children || !item.children.length) continue;
75
- // 往下查找时将当前path入栈
76
- parents.push(item.path);
77
- // @ts-ignore
78
- if (dfs(item.children, value, parents).length) return parents;
79
- // 深度遍历查找未找到时当前path 出栈
80
- parents.pop();
81
- }
82
- // 未找到时返回空数组
83
- return [];
84
- }
85
-
86
- return dfs(routes, value, []);
87
- }
88
-
89
- /** 查找对应 `path` 的路由信息 */
90
- function findRouteByPath(path: string, routes: RouteRecordRaw[]) {
91
- let res = routes.find((item: { path: string }) => item.path == path);
92
- if (res) {
93
- return isProxy(res) ? toRaw(res) : res;
94
- } else {
95
- for (let i = 0; i < routes.length; i++) {
96
- if (routes[i].children instanceof Array && routes[i].children.length > 0) {
97
- res = findRouteByPath(path, routes[i].children);
98
- if (res) {
99
- return isProxy(res) ? toRaw(res) : res;
100
- }
101
- }
102
- }
103
- return null;
104
- }
105
- }
106
- function addPathMatch() {
107
- if (!router.hasRoute('pathMatch')) {
108
- router.addRoute({
109
- path: '/:pathMatch(.*)',
110
- name: 'pathMatch',
111
- redirect: '/error/404'
112
- });
113
- }
114
- }
115
-
116
- /**
117
- * @description: 添加审批动态路由
118
- * @param {*} syncRoutes 异步获取的路由表数据
119
- * @param {*} routes 格式化后的路由表数据
120
- * @return {*} 格式化后的路由表数据
121
- */
122
- // function addWorkflowRouter(syncRoutes, routes) {
123
- // const flowIdx = syncRoutes.findIndex(f => f.menuCode === 'Workflow');
124
- // const isExit = flowIdx !== -1 && syncRoutes[flowIdx].children?.some(s => s.name === 'workflowApprove');
125
- // if (!isExit) {
126
- // flowIdx !== -1 && routes[flowIdx].children?.push(workflowRouter);
127
- // }
128
- // return routes;
129
- // }
130
- // 菜单国家化
131
- function setMenui18n() {
132
- const i18n = geti18n();
133
- i18n.global?.mergeLocaleMessage('zh', menuI18n.zh);
134
- i18n.global?.mergeLocaleMessage('en', menuI18n.en);
135
- storageLocal.setItem('menu_zh', menuI18n.zh);
136
- storageLocal.setItem('menu_en', menuI18n.en);
137
- }
138
-
139
- function handleAsyncRoutes(routesList) {
140
- if (routesList?.length) {
141
- const idx = routesList.findIndex(f => f.menuCode === 'SysHome');
142
- if (idx !== -1) {
143
- // 仪表盘报表
144
- const dashboardTabs = [];
145
- const homeMenus = [];
146
- routesList[idx].children.forEach(child => {
147
- if (child.menuCategory !== '1') {
148
- dashboardTabs.push(child);
149
- } else {
150
- homeMenus.push(child);
151
- }
152
- });
153
- routesList[idx].children = homeMenus;
154
- useSystemStoreHook().setHomeMenus(dashboardTabs);
155
- }
156
- const routes = clone(addAsyncRoutes(routesList), true);
157
-
158
- // routes = addWorkflowRouter(routesList, routes);
159
- setMenui18n();
160
- formatFlatteningRoutes(routes).map((v: RouteRecordRaw) => {
161
- // 菜单国际化
162
- // 防止重复添加路由
163
- const { options } = router;
164
- if (options.routes[0].children.findIndex(value => value.path === v.path) !== -1) {
165
- return;
166
- } else {
167
- // 切记将路由push到routes后还需要使用addRoute,这样路由才能正常跳转
168
- router.options.routes[0].children.push(v);
169
- // 最终路由进行升序
170
- ascending(router.options.routes[0].children);
171
- if (!router.hasRoute(v?.name)) router.addRoute(v);
172
- }
173
- });
174
- }
175
- usePermissionStoreHook().changeSetting(routesList);
176
- if (!useMultiTagsStoreHook().getMultiTagsCache) {
177
- useMultiTagsStoreHook().handleTags('equal', [
178
- ...routerArrays,
179
- ...usePermissionStoreHook().flatteningRoutes.filter(v => v?.meta?.fixedTag)
180
- ]);
181
- }
182
- addPathMatch();
183
- }
184
-
185
- /** 初始化路由(`new Promise` 写法防止在异步请求中造成无限循环)*/
186
- async function initRouter(userName) {
187
- let asyncRouteList = [];
188
- const key = `U-${userName}-ROUTES`;
189
- // 开启动态路由缓存本地
190
- if (getConfig().CachingAsyncRoutes) {
191
- await dbstorage.getItem(key).then(data => (asyncRouteList = data));
192
- }
193
- await initSystemInfo().then(async (res: IRecord) => {
194
- useSystemStoreHook().setSystemInfo(res);
195
- await getServiceApi()
196
- .get('/uums/cusOrganization', { pageSize: 100, pageNum: 1, orgId: res.orgId })
197
- .then((res: IResponseData) => useSystemStoreHook().setInvOrgList(res?.list || []));
198
- });
199
- if (asyncRouteList?.length) {
200
- return new Promise(resolve => {
201
- handleAsyncRoutes(asyncRouteList);
202
- // 缓存最新的路由
203
- getAsyncRoutes({ userName }).then((data: any) => {
204
- dbstorage.setItem(key, data);
205
- });
206
- resolve(router);
207
- });
208
- } else {
209
- return new Promise(resolve => {
210
- getAsyncRoutes({ userName }).then((data: any) => {
211
- handleAsyncRoutes(clone(data, true));
212
- dbstorage.setItem(key, data);
213
- resolve(router);
214
- });
215
- });
216
- }
217
- }
218
-
219
- /**
220
- * 将多级嵌套路由处理成一维数组
221
- * @param routesList 传入路由
222
- * @returns 返回处理后的一维路由
223
- */
224
- function formatFlatteningRoutes(routesList: RouteRecordRaw[]) {
225
- if (routesList.length === 0) return routesList;
226
- let hierarchyList = buildHierarchyTree(routesList);
227
- for (let i = 0; i < hierarchyList.length; i++) {
228
- if (hierarchyList[i].children) {
229
- hierarchyList = hierarchyList.slice(0, i + 1).concat(hierarchyList[i].children, hierarchyList.slice(i + 1));
230
- }
231
- }
232
- return hierarchyList;
233
- }
234
-
235
- /**
236
- * 一维数组处理成多级嵌套数组(三级及以上的路由全部拍成二级,keep-alive 只支持到二级缓存)
237
- * @param routesList 处理后的一维路由菜单数组
238
- * @returns 返回将一维数组重新处理成规定路由的格式
239
- */
240
- function formatTwoStageRoutes(routesList: RouteRecordRaw[]) {
241
- if (routesList.length === 0) return routesList;
242
- const newRoutesList: RouteRecordRaw[] = [];
243
- routesList.forEach((v: RouteRecordRaw) => {
244
- if (v.path === '/') {
245
- newRoutesList.push({
246
- component: v.component,
247
- name: v.name,
248
- path: v.path,
249
- redirect: v.redirect,
250
- meta: v.meta,
251
- children: []
252
- });
253
- } else {
254
- newRoutesList[0].children.push({ ...v });
255
- }
256
- });
257
- return newRoutesList;
258
- }
259
-
260
- /** 处理缓存路由(添加、删除、刷新) */
261
- function handleAliveRoute({ name }: ToRouteType, mode?: string) {
262
- switch (mode) {
263
- case 'add':
264
- usePermissionStoreHook().cacheOperate({ mode: 'add', name });
265
- break;
266
- case 'delete':
267
- usePermissionStoreHook().cacheOperate({ mode: 'delete', name });
268
- break;
269
- case 'refresh':
270
- usePermissionStoreHook().cacheOperate({ mode: 'refresh', name });
271
- break;
272
- default:
273
- usePermissionStoreHook().cacheOperate({ mode: 'delete', name });
274
- useTimeoutFn(() => {
275
- usePermissionStoreHook().cacheOperate({ mode: 'add', name });
276
- }, 100);
277
- }
278
- }
279
-
280
- /** 过滤后端传来的动态路由 重新生成规范路由 */
281
- const menuI18n = {
282
- zh: {},
283
- en: {}
284
- };
285
-
286
- const processMenus = [];
287
-
288
- const addAsyncRoutes = (arrRoutes: Array<any>) => {
289
- const modulesRoutes = getViews();
290
-
291
- if (!arrRoutes || !arrRoutes.length) return;
292
- const modulesRoutesKeys = Object.keys(modulesRoutes);
293
- for (let i = 0; i < arrRoutes.length; i++) {
294
- const v = arrRoutes[i];
295
-
296
- if (v?.children && v.children.length && !v.redirect) {
297
- // 父级的redirect属性取值:如果子级存在且父级的redirect属性不存在,默认取第一个子级的path;如果子级存在且父级的redirect属性存在,取存在的redirect属性,会覆盖默认值
298
- v.redirect = v.children[0].path;
299
- }
300
- const { icon, permissionCode, extraIcon, frameSrc } = v;
301
- // 流程菜单保存
302
- v.isApprovalPage === 'Y' && processMenus.push(v);
303
-
304
- v.meta = {
305
- keepAlive: true,
306
- rank: v.sort,
307
- title: `${v.i18nField}`,
308
- // 审批流设计页面和审批页面的code写死,只需配置页面即可(保底方式)
309
- // showLink: !['UDPFlowTask'].includes(v.menuCode) ? null : false
310
- showLink: v.showLink !== 'N'
311
- };
312
- v.hiddenTag = null;
313
- Object.assign(v.meta, { icon, permissionCode, extraIcon, frameSrc });
314
- menuI18n.zh[v.i18nField] = v.menuName || v.menuNameEn;
315
- menuI18n.en[v.i18nField] = v.menuNameEn || v.menuName;
316
- v.name = v.menuCode || v.name;
317
- v.path = v.menuPath || v.path;
318
- if (!v.parentId) {
319
- v.component = Layout;
320
- } else if (v.meta?.frameSrc) {
321
- v.component = IFrame;
322
- } else if (v.menuCategory === MenuCategoty.Lowcode) {
323
- // 低开路由处理
324
- const index = modulesRoutesKeys.findIndex(ev => ev.includes('lowcode-contain'));
325
- v.component = createComponent(
326
- v.name,
327
- defineAsyncComponent(() => import(/* @vite-ignore */ modulesRoutesKeys[index]))
328
- );
329
- // 将模块类型赋值到meta中
330
- Object.assign(v.meta, { moduleType: v.moduleType });
331
- } else if (v.menuCategory !== MenuCategoty.Menu) {
332
- const index = modulesRoutesKeys.findIndex(ev => ev.includes(v.path));
333
- v.component = modulesRoutes[modulesRoutesKeys[index]];
334
- // 外链添加token
335
- if (v.menuCategory === MenuCategoty.Link && v.name.includes('${access_token}')) {
336
- let name = v.name;
337
- const token = JSON.parse(cookies.get(kTOKEN));
338
- name = v.name.replace('${access_token}', token.accessToken);
339
- name = v.name.includes('${refresh_token}') ? name.replace('${refresh_token}', token.refreshToken) : name;
340
- name = v.name.includes('${expires_in}') ? name.replace('${expires_in}', token.expires) : name;
341
- v.name = name;
342
- }
343
- }
344
- if (v?.children && v.children.length) {
345
- addAsyncRoutes(v.children);
346
- } else {
347
- delete v.children;
348
- }
349
- }
350
- return arrRoutes;
351
- };
352
-
353
- // 是否有权限
354
- function hasPermissions(value: Array<string>): boolean {
355
- if (value && value instanceof Array && value.length > 0) {
356
- const roles = usePermissionStoreHook().buttonAuth;
357
- const permissionRoles = value;
358
-
359
- const hasPermission = roles.some(role => {
360
- return permissionRoles.includes(role);
361
- });
362
-
363
- if (!hasPermission) {
364
- return false;
365
- }
366
- return true;
367
- } else {
368
- return false;
369
- }
370
- }
371
- // 删除当前路由
372
- function delCurrentRoute(current: any, toNext = true) {
373
- const startIndex: number = useMultiTagsStoreHook().multiTags.findIndex(tag => {
374
- if (current.query) {
375
- if (current.path === tag.path) {
376
- return current.query === tag.query;
377
- }
378
- } else {
379
- return current.path === tag.path;
380
- }
381
- });
382
- useMultiTagsStoreHook().handleTags('splice', '', { startIndex, length: 1 });
383
- handleAliveRoute(current.matched, 'delete');
384
- if (toNext) {
385
- const newRoute = useMultiTagsStoreHook().handleTags('slice');
386
- router.push({
387
- path: newRoute[0].path,
388
- query: newRoute[0].query
389
- });
390
- }
391
- }
392
-
393
- function handleTopMenu(route) {
394
- if (route?.children && route.children.length > 1) {
395
- if (route.redirect) {
396
- return route.children.filter(cur => cur.path === route.redirect)[0];
397
- } else {
398
- return route.children[0];
399
- }
400
- } else {
401
- return route;
402
- }
403
- }
404
-
405
- /** 获取所有菜单中的第一个菜单(顶级菜单)*/
406
- function getTopMenu(tag = false) {
407
- const topMenu = handleTopMenu(usePermissionStoreHook().wholeMenus[0]?.children[0]);
408
- tag && useMultiTagsStoreHook().handleTags('push', topMenu);
409
- return topMenu;
410
- }
411
-
412
- function getProcessMenu() {
413
- return processMenus;
414
- }
415
-
416
- export {
417
- ascending,
418
- filterTree,
419
- initRouter,
420
- getTopMenu,
421
- getProcessMenu,
422
- hasPermissions,
423
- addAsyncRoutes,
424
- getParentPaths,
425
- findRouteByPath,
426
- handleAliveRoute,
427
- formatTwoStageRoutes,
428
- formatFlatteningRoutes,
429
- delCurrentRoute
430
- };
1
+ /*
2
+ * @Author: levi7754 levi7754@163.com
3
+ * @Date: 2024-08-01 21:42:39
4
+ * @LastEditors: levi7754 levi7754@163.com
5
+ * @LastEditTime: 2026-09-09 11:33:05
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, cookies } 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 { kTOKEN } from '../contant';
19
+ import { usePermissionStoreHook } from '../store/modules/permission';
20
+ import { useSystemStoreHook } from '../store/modules/system';
21
+ import { useMultiTagsStoreHook } from '../store/modules/multiTags';
22
+ import { getServiceApi } from '../api';
23
+ import createComponent from './createComponent';
24
+
25
+ const Layout = () => import('../layout/layoutView.vue');
26
+ const IFrame = () => import('../layout/frameView.vue');
27
+
28
+ // 动态路由
29
+ import { initSystemInfo, getAsyncRoutes } from '../api/user';
30
+ // https://cn.vitejs.dev/guide/features.html#glob-import
31
+ // const modulesRoutes = import.meta.glob('/src/views/**/*.{vue,tsx}');
32
+
33
+ // 菜单类型
34
+ enum MenuCategoty {
35
+ Link = '3', // 外链
36
+ Menu = '5', // 菜单
37
+ Lowcode = '10' // 低代码
38
+ }
39
+
40
+ /** 按照路由中meta下的rank等级升序来排序路由 */
41
+ function ascending(arr: any[]) {
42
+ arr.forEach(v => {
43
+ if (v?.meta?.rank === null) v.meta.rank = undefined;
44
+ if (v?.meta?.rank === 0) {
45
+ if (v.name !== 'home' && v.path !== '/') {
46
+ console.warn('rank only the home page can be 0');
47
+ }
48
+ }
49
+ });
50
+ return arr.sort((a: { meta: { rank: number } }, b: { meta: { rank: number } }) => {
51
+ return a?.meta?.rank - b?.meta?.rank;
52
+ });
53
+ }
54
+
55
+ /** 过滤meta中showLink为false的菜单 */
56
+ function filterTree(data: RouteComponent[]) {
57
+ const newTree = clone(data, true).filter((v: { meta: { showLink: boolean } }) => v && v.meta?.showLink !== false);
58
+ newTree.forEach((v: { children }) => v.children && (v.children = filterTree(v.children)));
59
+ return newTree;
60
+ }
61
+
62
+ /** 通过指定 `key` 获取父级路径集合,默认 `key` 为 `path` */
63
+ function getParentPaths(value: string, routes: RouteRecordRaw[], key = 'path') {
64
+ // 深度遍历查找
65
+ function dfs(routes: RouteRecordRaw[], value: string, parents: string[]) {
66
+ for (let i = 0; i < routes.length; i++) {
67
+ const item = routes[i];
68
+ // 找到path则返回父级path
69
+ // if (item[key] === value) {
70
+ // return parents.length ? parents : routes[0];
71
+ // }
72
+ if (item[key] === value) return parents;
73
+ // children不存在或为空则不递归
74
+ if (!item.children || !item.children.length) continue;
75
+ // 往下查找时将当前path入栈
76
+ parents.push(item.path);
77
+ // @ts-ignore
78
+ if (dfs(item.children, value, parents).length) return parents;
79
+ // 深度遍历查找未找到时当前path 出栈
80
+ parents.pop();
81
+ }
82
+ // 未找到时返回空数组
83
+ return [];
84
+ }
85
+
86
+ return dfs(routes, value, []);
87
+ }
88
+
89
+ /** 查找对应 `path` 的路由信息 */
90
+ function findRouteByPath(path: string, routes: RouteRecordRaw[]) {
91
+ let res = routes.find((item: { path: string }) => item.path == path);
92
+ if (res) {
93
+ return isProxy(res) ? toRaw(res) : res;
94
+ } else {
95
+ for (let i = 0; i < routes.length; i++) {
96
+ if (routes[i].children instanceof Array && routes[i].children.length > 0) {
97
+ res = findRouteByPath(path, routes[i].children);
98
+ if (res) {
99
+ return isProxy(res) ? toRaw(res) : res;
100
+ }
101
+ }
102
+ }
103
+ return null;
104
+ }
105
+ }
106
+ function addPathMatch() {
107
+ if (!router.hasRoute('pathMatch')) {
108
+ router.addRoute({
109
+ path: '/:pathMatch(.*)',
110
+ name: 'pathMatch',
111
+ redirect: '/error/404'
112
+ });
113
+ }
114
+ }
115
+
116
+ /**
117
+ * @description: 添加审批动态路由
118
+ * @param {*} syncRoutes 异步获取的路由表数据
119
+ * @param {*} routes 格式化后的路由表数据
120
+ * @return {*} 格式化后的路由表数据
121
+ */
122
+ // function addWorkflowRouter(syncRoutes, routes) {
123
+ // const flowIdx = syncRoutes.findIndex(f => f.menuCode === 'Workflow');
124
+ // const isExit = flowIdx !== -1 && syncRoutes[flowIdx].children?.some(s => s.name === 'workflowApprove');
125
+ // if (!isExit) {
126
+ // flowIdx !== -1 && routes[flowIdx].children?.push(workflowRouter);
127
+ // }
128
+ // return routes;
129
+ // }
130
+ // 菜单国家化
131
+ function setMenui18n() {
132
+ const i18n = geti18n();
133
+ i18n.global?.mergeLocaleMessage('zh', menuI18n.zh);
134
+ i18n.global?.mergeLocaleMessage('en', menuI18n.en);
135
+ storageLocal.setItem('menu_zh', menuI18n.zh);
136
+ storageLocal.setItem('menu_en', menuI18n.en);
137
+ }
138
+
139
+ function handleAsyncRoutes(routesList) {
140
+ if (routesList?.length) {
141
+ const idx = routesList.findIndex(f => f.menuCode === 'SysHome');
142
+ if (idx !== -1) {
143
+ // 仪表盘报表
144
+ const dashboardTabs = [];
145
+ const homeMenus = [];
146
+ routesList[idx].children.forEach(child => {
147
+ if (child.menuCategory !== '1') {
148
+ dashboardTabs.push(child);
149
+ } else {
150
+ homeMenus.push(child);
151
+ }
152
+ });
153
+ routesList[idx].children = homeMenus;
154
+ useSystemStoreHook().setHomeMenus(dashboardTabs);
155
+ }
156
+ const routes = clone(addAsyncRoutes(routesList), true);
157
+
158
+ // routes = addWorkflowRouter(routesList, routes);
159
+ setMenui18n();
160
+ formatFlatteningRoutes(routes).map((v: RouteRecordRaw) => {
161
+ // 菜单国际化
162
+ // 防止重复添加路由
163
+ const { options } = router;
164
+ if (options.routes[0].children.findIndex(value => value.path === v.path) !== -1) {
165
+ return;
166
+ } else {
167
+ // 切记将路由push到routes后还需要使用addRoute,这样路由才能正常跳转
168
+ router.options.routes[0].children.push(v);
169
+ // 最终路由进行升序
170
+ ascending(router.options.routes[0].children);
171
+ if (!router.hasRoute(v?.name)) router.addRoute(v);
172
+ }
173
+ });
174
+ }
175
+ usePermissionStoreHook().changeSetting(routesList);
176
+ if (!useMultiTagsStoreHook().getMultiTagsCache) {
177
+ useMultiTagsStoreHook().handleTags('equal', [
178
+ ...routerArrays,
179
+ ...usePermissionStoreHook().flatteningRoutes.filter(v => v?.meta?.fixedTag)
180
+ ]);
181
+ }
182
+ addPathMatch();
183
+ }
184
+
185
+ /** 初始化路由(`new Promise` 写法防止在异步请求中造成无限循环)*/
186
+ async function initRouter(userName) {
187
+ let asyncRouteList = [];
188
+ const key = `U-${userName}-ROUTES`;
189
+ console.log('initRouter');
190
+ // 开启动态路由缓存本地
191
+ if (getConfig().CachingAsyncRoutes) {
192
+ await dbstorage.getItem(key).then(data => (asyncRouteList = data));
193
+ }
194
+ await initSystemInfo().then(async (res: IRecord) => {
195
+ useSystemStoreHook().setSystemInfo(res);
196
+ await getServiceApi()
197
+ .get('/uums/cusOrganization', { pageSize: 100, pageNum: 1, orgId: res.orgId })
198
+ .then((res: IResponseData) => useSystemStoreHook().setInvOrgList(res?.list || []));
199
+ });
200
+ if (asyncRouteList?.length) {
201
+ return new Promise(resolve => {
202
+ handleAsyncRoutes(asyncRouteList);
203
+ // 缓存最新的路由
204
+ getAsyncRoutes({ userName }).then((data: any) => {
205
+ dbstorage.setItem(key, data);
206
+ });
207
+ resolve(router);
208
+ });
209
+ } else {
210
+ return new Promise(resolve => {
211
+ getAsyncRoutes({ userName }).then((data: any) => {
212
+ handleAsyncRoutes(clone(data, true));
213
+ dbstorage.setItem(key, data);
214
+ resolve(router);
215
+ });
216
+ });
217
+ }
218
+ }
219
+
220
+ /**
221
+ * 将多级嵌套路由处理成一维数组
222
+ * @param routesList 传入路由
223
+ * @returns 返回处理后的一维路由
224
+ */
225
+ function formatFlatteningRoutes(routesList: RouteRecordRaw[]) {
226
+ if (routesList.length === 0) return routesList;
227
+ let hierarchyList = buildHierarchyTree(routesList);
228
+ for (let i = 0; i < hierarchyList.length; i++) {
229
+ if (hierarchyList[i].children) {
230
+ hierarchyList = hierarchyList.slice(0, i + 1).concat(hierarchyList[i].children, hierarchyList.slice(i + 1));
231
+ }
232
+ }
233
+ return hierarchyList;
234
+ }
235
+
236
+ /**
237
+ * 一维数组处理成多级嵌套数组(三级及以上的路由全部拍成二级,keep-alive 只支持到二级缓存)
238
+ * @param routesList 处理后的一维路由菜单数组
239
+ * @returns 返回将一维数组重新处理成规定路由的格式
240
+ */
241
+ function formatTwoStageRoutes(routesList: RouteRecordRaw[]) {
242
+ if (routesList.length === 0) return routesList;
243
+ const newRoutesList: RouteRecordRaw[] = [];
244
+ routesList.forEach((v: RouteRecordRaw) => {
245
+ if (v.path === '/') {
246
+ newRoutesList.push({
247
+ component: v.component,
248
+ name: v.name,
249
+ path: v.path,
250
+ redirect: v.redirect,
251
+ meta: v.meta,
252
+ children: []
253
+ });
254
+ } else {
255
+ newRoutesList[0].children.push({ ...v });
256
+ }
257
+ });
258
+ return newRoutesList;
259
+ }
260
+
261
+ /** 处理缓存路由(添加、删除、刷新) */
262
+ function handleAliveRoute({ name }: ToRouteType, mode?: string) {
263
+ switch (mode) {
264
+ case 'add':
265
+ usePermissionStoreHook().cacheOperate({ mode: 'add', name });
266
+ break;
267
+ case 'delete':
268
+ usePermissionStoreHook().cacheOperate({ mode: 'delete', name });
269
+ break;
270
+ case 'refresh':
271
+ usePermissionStoreHook().cacheOperate({ mode: 'refresh', name });
272
+ break;
273
+ default:
274
+ usePermissionStoreHook().cacheOperate({ mode: 'delete', name });
275
+ useTimeoutFn(() => {
276
+ usePermissionStoreHook().cacheOperate({ mode: 'add', name });
277
+ }, 100);
278
+ }
279
+ }
280
+
281
+ /** 过滤后端传来的动态路由 重新生成规范路由 */
282
+ const menuI18n = {
283
+ zh: {},
284
+ en: {}
285
+ };
286
+
287
+ const processMenus = [];
288
+
289
+ const addAsyncRoutes = (arrRoutes: Array<any>) => {
290
+ const modulesRoutes = getViews();
291
+
292
+ if (!arrRoutes || !arrRoutes.length) return;
293
+ const modulesRoutesKeys = Object.keys(modulesRoutes);
294
+ for (let i = 0; i < arrRoutes.length; i++) {
295
+ const v = arrRoutes[i];
296
+
297
+ if (v?.children && v.children.length && !v.redirect) {
298
+ // 父级的redirect属性取值:如果子级存在且父级的redirect属性不存在,默认取第一个子级的path;如果子级存在且父级的redirect属性存在,取存在的redirect属性,会覆盖默认值
299
+ v.redirect = v.children[0].path;
300
+ }
301
+ const { icon, permissionCode, extraIcon, frameSrc } = v;
302
+ // 流程菜单保存
303
+ v.isApprovalPage === 'Y' && processMenus.push(v);
304
+
305
+ v.meta = {
306
+ keepAlive: true,
307
+ rank: v.sort,
308
+ title: `${v.i18nField}`,
309
+ // 审批流设计页面和审批页面的code写死,只需配置页面即可(保底方式)
310
+ // showLink: !['UDPFlowTask'].includes(v.menuCode) ? null : false
311
+ showLink: v.showLink !== 'N'
312
+ };
313
+ v.hiddenTag = null;
314
+ Object.assign(v.meta, { icon, permissionCode, extraIcon, frameSrc });
315
+ menuI18n.zh[v.i18nField] = v.menuName || v.menuNameEn;
316
+ menuI18n.en[v.i18nField] = v.menuNameEn || v.menuName;
317
+ v.name = v.menuCode || v.name;
318
+ v.path = v.menuPath || v.path;
319
+ if (!v.parentId) {
320
+ v.component = Layout;
321
+ } else if (v.meta?.frameSrc) {
322
+ v.component = IFrame;
323
+ } else if (v.menuCategory === MenuCategoty.Lowcode) {
324
+ // 低开路由处理
325
+ const index = modulesRoutesKeys.findIndex(ev => ev.includes('lowcode-contain'));
326
+ v.component = createComponent(
327
+ v.name,
328
+ defineAsyncComponent(() => import(/* @vite-ignore */ modulesRoutesKeys[index]))
329
+ );
330
+ // 将模块类型赋值到meta
331
+ Object.assign(v.meta, { moduleType: v.moduleType });
332
+ } else if (v.menuCategory !== MenuCategoty.Menu) {
333
+ const index = modulesRoutesKeys.findIndex(ev => ev.includes(v.path));
334
+ v.component = modulesRoutes[modulesRoutesKeys[index]];
335
+ if (v.menuName.includes('电梯类别对应类型')) {
336
+ console.log('v', v);
337
+ }
338
+ // 外链添加token
339
+ if (v.menuCategory === MenuCategoty.Link && v.name.includes('${access_token}')) {
340
+ let name = v.name;
341
+ const token = JSON.parse(cookies.get(kTOKEN));
342
+ name = v.name.replace('${access_token}', token.accessToken);
343
+ name = v.name.includes('${refresh_token}') ? name.replace('${refresh_token}', token.refreshToken) : name;
344
+ name = v.name.includes('${expires_in}') ? name.replace('${expires_in}', token.expires) : name;
345
+ v.name = name;
346
+ }
347
+ }
348
+ if (v?.children && v.children.length) {
349
+ addAsyncRoutes(v.children);
350
+ } else {
351
+ delete v.children;
352
+ }
353
+ }
354
+ return arrRoutes;
355
+ };
356
+
357
+ // 是否有权限
358
+ function hasPermissions(value: Array<string>): boolean {
359
+ if (value && value instanceof Array && value.length > 0) {
360
+ const roles = usePermissionStoreHook().buttonAuth;
361
+ const permissionRoles = value;
362
+
363
+ const hasPermission = roles.some(role => {
364
+ return permissionRoles.includes(role);
365
+ });
366
+
367
+ if (!hasPermission) {
368
+ return false;
369
+ }
370
+ return true;
371
+ } else {
372
+ return false;
373
+ }
374
+ }
375
+ // 删除当前路由
376
+ function delCurrentRoute(current: any, toNext = true) {
377
+ const startIndex: number = useMultiTagsStoreHook().multiTags.findIndex(tag => {
378
+ if (current.query) {
379
+ if (current.path === tag.path) {
380
+ return current.query === tag.query;
381
+ }
382
+ } else {
383
+ return current.path === tag.path;
384
+ }
385
+ });
386
+ useMultiTagsStoreHook().handleTags('splice', '', { startIndex, length: 1 });
387
+ handleAliveRoute(current.matched, 'delete');
388
+ if (toNext) {
389
+ const newRoute = useMultiTagsStoreHook().handleTags('slice');
390
+ router.push({
391
+ path: newRoute[0].path,
392
+ query: newRoute[0].query
393
+ });
394
+ }
395
+ }
396
+
397
+ function handleTopMenu(route) {
398
+ if (route?.children && route.children.length > 1) {
399
+ if (route.redirect) {
400
+ return route.children.filter(cur => cur.path === route.redirect)[0];
401
+ } else {
402
+ return route.children[0];
403
+ }
404
+ } else {
405
+ return route;
406
+ }
407
+ }
408
+
409
+ /** 获取所有菜单中的第一个菜单(顶级菜单)*/
410
+ function getTopMenu(tag = false) {
411
+ const topMenu = handleTopMenu(usePermissionStoreHook().wholeMenus[0]?.children[0]);
412
+ tag && useMultiTagsStoreHook().handleTags('push', topMenu);
413
+ return topMenu;
414
+ }
415
+
416
+ function getProcessMenu() {
417
+ return processMenus;
418
+ }
419
+
420
+ export {
421
+ ascending,
422
+ filterTree,
423
+ initRouter,
424
+ getTopMenu,
425
+ getProcessMenu,
426
+ hasPermissions,
427
+ addAsyncRoutes,
428
+ getParentPaths,
429
+ findRouteByPath,
430
+ handleAliveRoute,
431
+ formatTwoStageRoutes,
432
+ formatFlatteningRoutes,
433
+ delCurrentRoute
434
+ };