@utogether/udp-core 1.0.1-beta.9 → 1.0.2

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 (168) hide show
  1. package/build/plugins.ts +37 -39
  2. package/dist/{403-BOzKHdlm.js → 403-B1rIjAAu.js} +6 -6
  3. package/dist/{404-uwgt4Nll.js → 404-mBqc2y4t.js} +4 -4
  4. package/dist/{500-4HBf6V9m.js → 500-BoI45Zdh.js} +2 -2
  5. package/dist/{AuthorityInfo-DvbIh1vT.js → AuthorityInfo-B08NBIIn.js} +1 -1
  6. package/dist/{AuthorityInfo.vue_vue_type_style_index_0_lang-BlCPvwXU.js → AuthorityInfo.vue_vue_type_style_index_0_lang-BLP1SaiH.js} +3 -3
  7. package/dist/{Company-D7Q9BFmr.js → Company-JGGyWEWH.js} +3 -3
  8. package/dist/{CompanyPanel-C0-PJlrt.js → CompanyPanel-BQ_cCmDx.js} +7 -7
  9. package/dist/{Department-h2hlXACv.js → Department-z2iO6hwM.js} +10 -10
  10. package/dist/{DepartmentPanel-B6hDEQpG.js → DepartmentPanel-BtQe7zwU.js} +108 -78
  11. package/dist/{DesignPanel-cS58-1v9.js → DesignPanel-7mhtVWas.js} +1 -1
  12. package/dist/{DesignPanel.vue_vue_type_style_index_0_lang-LdvLC8VU.js → DesignPanel.vue_vue_type_style_index_0_lang-4EsHemj_.js} +6 -6
  13. package/dist/{DictView-T3TmpBa8.js → DictView-CjchV2Yk.js} +15 -16
  14. package/dist/InvOrganization-Pn1O_XP0.js +74 -0
  15. package/dist/{Org-CnCBDGKF.js → Org-BqytV_vi.js} +1 -1
  16. package/dist/{Preview-BaktKXB1.js → Preview-CLpUUMay.js} +2 -2
  17. package/dist/{ReportDefine-5Rb0PO9A.js → ReportDefine-Cz1KtEUF.js} +1 -1
  18. package/dist/{ReportDesign-DYdkVREA.js → ReportDesign-BaORYud4.js} +13 -13
  19. package/dist/{ReportQuery-BwhzIXMt.js → ReportQuery-CPCPXiXz.js} +1 -1
  20. package/dist/{ReportQueryFrom-PHtWwlOe.js → ReportQueryFrom-C_AcrfkJ.js} +1 -1
  21. package/dist/{ReportQueryFrom.vue_vue_type_style_index_0_lang-BE5yZNPM.js → ReportQueryFrom.vue_vue_type_style_index_0_lang-Bm67ejay.js} +1 -1
  22. package/dist/{ReportTemplate-DaadVXIi.js → ReportTemplate-CFiNMz79.js} +11 -11
  23. package/dist/{Role-Dtg3nAmG.js → Role-B-XDoJd5.js} +3 -3
  24. package/dist/{RoleAssign-DEGtLssH.js → RoleAssign-BolW8YVs.js} +8 -8
  25. package/dist/{RolePanel-DpUzfE_o.js → RolePanel-2kfs5tw9.js} +1 -1
  26. package/dist/{RolePanel-CT7BTPmy.js → RolePanel-HilSuYns.js} +1 -1
  27. package/dist/{RolePanel.vue_vue_type_script_setup_true_lang-Xyo0YEI0.js → RolePanel.vue_vue_type_script_setup_true_lang-CE4gApUY.js} +7 -7
  28. package/dist/{RolePanel.vue_vue_type_script_setup_true_lang-Dg2A6DJu.js → RolePanel.vue_vue_type_script_setup_true_lang-DPzgfAyV.js} +13 -13
  29. package/dist/{ScrollPanel.vue_vue_type_style_index_0_lang-CyutzDZS.js → ScrollPanel.vue_vue_type_style_index_0_lang-CCTH4RkH.js} +4 -4
  30. package/dist/{Staff-_NlAGkrh.js → Staff-BTk3whFC.js} +3 -3
  31. package/dist/{StaffInfo-DVgUvVgd.js → StaffInfo-d3AuSzlA.js} +1 -1
  32. package/dist/{StaffInfo.vue_vue_type_script_setup_true_lang-C8hmlFgX.js → StaffInfo.vue_vue_type_script_setup_true_lang-eOL4VlfE.js} +5 -5
  33. package/dist/{StaffPanel-DKNZE3IE.js → StaffPanel-DV-D4jjz.js} +1 -1
  34. package/dist/StaffPanel.vue_vue_type_script_setup_true_lang-4sFq3CEo.js +135 -0
  35. package/dist/{SysUser-kQUf7XKz.js → SysUser-BnjYytws.js} +2 -2
  36. package/dist/{SysUserPanel-C191uX3U.js → SysUserPanel-CBoyD-Qi.js} +1 -1
  37. package/dist/SysUserPanel.vue_vue_type_script_setup_true_lang-PrTlTZR-.js +341 -0
  38. package/dist/{SystemMenu-DwuSvHnj.js → SystemMenu-kYB_ZaUt.js} +36 -36
  39. package/dist/{UserInfo-DIsInFld.js → UserInfo-4dx97VBL.js} +1 -1
  40. package/dist/{UserInfo.vue_vue_type_style_index_0_lang-CnvGdbej.js → UserInfo.vue_vue_type_style_index_0_lang-BpbC_ZDm.js} +10 -10
  41. package/dist/{childView-3Bs2UBEw.js → childView-CHPNfTEb.js} +1 -1
  42. package/dist/{childView-BawyULD7.js → childView-CKA_JgVZ.js} +1 -1
  43. package/dist/{childView.vue_vue_type_style_index_0_lang-YpWF-p2F.js → childView.vue_vue_type_style_index_0_lang-Bym2fQRd.js} +7 -7
  44. package/dist/childView.vue_vue_type_style_index_0_lang-W7bCtXeu.js +177 -0
  45. package/dist/{code-rule-DVaYcn8S.js → code-rule-CbxuZg0-.js} +40 -38
  46. package/dist/core.es.js +18 -12
  47. package/dist/{cron-task-xuzP-BpE.js → cron-task-nTOpqQYf.js} +7 -7
  48. package/dist/flow-task-B07st2aD.js +10 -0
  49. package/dist/{frameView-Cudt06qS.js → frameView-Z1tPUyCh.js} +1 -1
  50. package/dist/index-C3q8HoJM.js +4650 -0
  51. package/dist/{layoutView-BlFTV2jX.js → layoutView--MGA9zUB.js} +1766 -1760
  52. package/dist/{log-in-e7D5Ss1P.js → log-in-CSYJDA6m.js} +36 -29
  53. package/dist/log-out-DiwGCg7p.js +130 -0
  54. package/dist/login-C6Y0ajDp.js +251 -0
  55. package/dist/{login-log-kqKzKTto.js → login-log-C0V-_l3F.js} +5 -3
  56. package/dist/{lov-view-B2HaxyMs.js → lov-view-Cmv7wZZ9.js} +6 -6
  57. package/dist/{menuInfo-BxCTJ1VW.js → menuInfo-UeutJpOa.js} +1 -1
  58. package/dist/{menuInfo.vue_vue_type_style_index_0_lang-CLOPNeUW.js → menuInfo.vue_vue_type_style_index_0_lang-CWX4Mu67.js} +118 -98
  59. package/dist/{pda-app-DPsAFNiw.js → pda-app-B6w99SJo.js} +10 -10
  60. package/dist/{resource-Dibb7t8u.js → resource-BybJvUv0.js} +4 -4
  61. package/dist/{su-welcome-DejR0KkM.js → su-welcome-C1bmxHoY.js} +119 -121
  62. package/dist/sys-config-BnmIDnCj.js +370 -0
  63. package/dist/udp-core.css +1 -9
  64. package/dist/utogether-MlnyYtNS.js +4 -0
  65. package/index.ts +49 -40
  66. package/package.json +18 -18
  67. package/src/App.vue +65 -65
  68. package/src/api/http.ts +1 -4
  69. package/src/api/index.ts +4 -2
  70. package/src/api/user.ts +2 -2
  71. package/src/components/SuCharts/src/UserInfo.vue +78 -78
  72. package/src/components/SuScrollTree/ScrollPanel.vue +1 -6
  73. package/src/components/udp/content/index.vue +88 -0
  74. package/src/components/udp/{form.vue → form/form.vue} +13 -16
  75. package/src/components/udp/{grid.vue → grid/index.vue} +56 -27
  76. package/src/components/udp/index.ts +4 -9
  77. package/src/components/udp/ut-stamp-badge/index.vue +271 -0
  78. package/src/components/udp/utils.ts +66 -105
  79. package/src/layout/components/lay-navbar/index.vue +8 -6
  80. package/src/layout/components/lay-panel/index.vue +150 -150
  81. package/src/layout/components/lay-search/index.vue +25 -25
  82. package/src/layout/components/lay-select-org/index.vue +4 -9
  83. package/src/layout/components/lay-setting/index.vue +503 -510
  84. package/src/layout/components/lay-sidebar/horizontal.vue +8 -6
  85. package/src/layout/components/lay-sidebar/mixNav.vue +260 -258
  86. package/src/layout/components/lay-sidebar/sidebar-logo.vue +101 -98
  87. package/src/layout/components/lay-tag/index.vue +24 -51
  88. package/src/layout/hooks/useDataThemeChange.ts +1 -1
  89. package/src/layout/hooks/useNav.ts +176 -173
  90. package/src/layout/hooks/useTag.ts +227 -233
  91. package/src/layout/types.ts +93 -92
  92. package/src/main.ts +115 -119
  93. package/src/plugins/i18n/en.ts +302 -302
  94. package/src/plugins/i18n/module/u-workflow.ts +1 -1
  95. package/src/plugins/i18n/zh.ts +21 -6
  96. package/src/plugins/vxe-table/index.ts +116 -53
  97. package/src/plugins/vxe-table/render.tsx +945 -956
  98. package/src/router/index.ts +17 -17
  99. package/src/router/modules/flow.ts +35 -0
  100. package/src/router/modules/home.ts +32 -32
  101. package/src/router/modules/remaining.ts +58 -58
  102. package/src/router/utils.ts +420 -377
  103. package/src/store/modules/app.ts +2 -4
  104. package/src/store/modules/epTheme.ts +48 -49
  105. package/src/store/modules/multiTags.ts +15 -14
  106. package/src/store/modules/permission.ts +25 -15
  107. package/src/store/modules/system.ts +1 -3
  108. package/src/style/button.scss +85 -85
  109. package/src/style/login.css +1 -1
  110. package/src/style/vxetable.scss +61 -2
  111. package/src/utils/dataFormat/index.ts +223 -223
  112. package/src/utils/index.ts +3 -1
  113. package/src/utils/lifecycle.ts +39 -20
  114. package/src/utils/propTypes.ts +1 -6
  115. package/src/utils/storage/index.ts +2 -2
  116. package/src/utils/udp/http/index.ts +24 -11
  117. package/src/utils/udp/http/types.d.ts +3 -10
  118. package/src/views/login/login-view.vue +4 -18
  119. package/src/views/organization/company/CompanyPanel.vue +259 -259
  120. package/src/views/organization/department/Department.vue +58 -58
  121. package/src/views/organization/department/DepartmentPanel.vue +303 -283
  122. package/src/views/organization/inv-org/InvOrganization.vue +22 -7
  123. package/src/views/organization/staff/StaffInfo.vue +127 -133
  124. package/src/views/organization/staff/StaffPanel.vue +162 -145
  125. package/src/views/system/cron/cron-task.vue +2 -12
  126. package/src/views/system/menu/SystemMenu.vue +185 -183
  127. package/src/views/system/menu/menuInfo.vue +384 -363
  128. package/src/views/system/role/UserInfo.vue +195 -195
  129. package/src/views/system/role-assign/RoleAssign.vue +57 -57
  130. package/src/views/system/role-assign/RolePanel.vue +139 -139
  131. package/src/views/system/sys/sys-config.vue +69 -20
  132. package/src/views/system/sysUser/SysUserPanel.vue +97 -28
  133. package/src/views/uapp/pda/pda-app.vue +208 -208
  134. package/src/views/udev/coderule/code-rule.vue +132 -121
  135. package/src/views/udev/dict/DictView.vue +2 -2
  136. package/src/views/udev/dict/childView.vue +183 -222
  137. package/src/views/udev/lov/childView.vue +1 -7
  138. package/src/views/udev/lov/lov-view.vue +91 -91
  139. package/src/views/uhome/components/menu-favorite.vue +314 -331
  140. package/src/views/uhome/su-welcome.vue +319 -339
  141. package/src/views/ulogin/login.vue +325 -321
  142. package/src/views/upms/interface/log-in.vue +100 -106
  143. package/src/views/upms/interface/log-out.vue +104 -107
  144. package/src/views/upms/user/login-log.vue +54 -60
  145. package/src/views/urpt/design/DesignPanel.vue +507 -507
  146. package/src/views/urpt/design/Preview.vue +1 -0
  147. package/src/views/urpt/design/ReportDesign.vue +2 -4
  148. package/src/views/utask/flow-task.vue +18 -0
  149. package/types/global.d.ts +231 -236
  150. package/dist/InvOrganization-BVuOhzbt.js +0 -66
  151. package/dist/StaffPanel.vue_vue_type_script_setup_true_lang-BOOO6Cek.js +0 -111
  152. package/dist/SysUserPanel.vue_vue_type_script_setup_true_lang-SwNbAEvW.js +0 -294
  153. package/dist/childView.vue_vue_type_style_index_0_lang-DWIFCX3X.js +0 -187
  154. package/dist/index-CKnq5xIa.js +0 -2623
  155. package/dist/log-out--RRncZhN.js +0 -120
  156. package/dist/login-CpKykfdf.js +0 -253
  157. package/dist/sys-config-DiySRWns.js +0 -277
  158. package/dist/utogether-Dct_14Zk.js +0 -182
  159. package/src/components/udp/count-down.vue +0 -536
  160. package/src/components/udp/flip-down/FlipCard/flip-card.vue +0 -251
  161. package/src/components/udp/flip-down/FlipCard/interfaces.ts +0 -4
  162. package/src/components/udp/flip-down/FlipClock/flip-clock.vue +0 -113
  163. package/src/components/udp/form-upload.vue +0 -482
  164. package/src/components/udp/lov.vue +0 -388
  165. package/src/components/udp/modal-form.vue +0 -189
  166. package/src/components/udp/modal-grid.vue +0 -288
  167. package/src/components/udp/upload.vue +0 -423
  168. package/src/utils/udp/useRender.ts +0 -431
@@ -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
+ };