af-mobile-client-vue3 1.0.95 → 1.0.96

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 (113) hide show
  1. package/.env +6 -6
  2. package/.env.development +4 -4
  3. package/.env.envoiceShow +6 -6
  4. package/.env.production +6 -6
  5. package/.husky/commit-msg +1 -1
  6. package/.husky/pre-commit +1 -1
  7. package/.vscode/settings.json +61 -61
  8. package/build/vite/index.ts +91 -91
  9. package/eslint.config.js +9 -1
  10. package/mock/modules/user.mock.ts +152 -152
  11. package/package.json +1 -1
  12. package/public/favicon.svg +4 -4
  13. package/public/safari-pinned-tab.svg +32 -32
  14. package/scripts/verifyCommit.js +19 -19
  15. package/src/App.vue +43 -43
  16. package/src/api/user/index.ts +40 -40
  17. package/src/bootstrap.ts +18 -18
  18. package/src/components/core/App/MicroAppView.vue +3 -3
  19. package/src/components/core/NavBar/index.vue +12 -12
  20. package/src/components/core/SvgIcon/index.vue +1 -1
  21. package/src/components/core/Tabbar/index.vue +38 -38
  22. package/src/components/core/Uploader/index.vue +1 -1
  23. package/src/components/core/XGridDropOption/index.vue +151 -151
  24. package/src/components/core/XMultiSelect/index.vue +183 -183
  25. package/src/components/data/XCellDetail/index.vue +106 -106
  26. package/src/components/data/XCellList/XCellList.md +28 -28
  27. package/src/components/data/XCellList/index.vue +50 -11
  28. package/src/components/data/XCellListFilter/QrScanner/index.vue +1 -1
  29. package/src/components/data/XCellListFilter/VpnRecognition/index.vue +3 -3
  30. package/src/components/data/XCellListFilter/index.vue +160 -62
  31. package/src/components/data/XForm/index.vue +2 -2
  32. package/src/components/data/XFormGroup/index.vue +3 -3
  33. package/src/components/data/XFormItem/index.vue +25 -26
  34. package/src/components/data/XOlMap/demo.vue +209 -0
  35. package/src/components/data/XOlMap/index.vue +644 -0
  36. package/src/components/data/XReportForm/XReportFormJsonRender.vue +220 -220
  37. package/src/components/data/XReportForm/index.vue +1079 -1079
  38. package/src/components/data/XReportGrid/XAddReport/XAddReport.vue +4 -7
  39. package/src/components/data/XReportGrid/XAddReport/index.md +3 -7
  40. package/src/components/data/XReportGrid/XAddReport/index.ts +2 -2
  41. package/src/components/data/XReportGrid/XReport.vue +25 -38
  42. package/src/components/data/XReportGrid/XReportDesign.vue +46 -46
  43. package/src/components/data/XReportGrid/XReportDrawer/XReportDrawer.vue +3 -3
  44. package/src/components/data/XReportGrid/XReportDrawer/index.ts +2 -2
  45. package/src/components/data/XReportGrid/XReportJsonRender.vue +20 -7
  46. package/src/components/data/XReportGrid/XReportTrGroup.vue +4 -4
  47. package/src/components/data/XReportGrid/index.md +4 -6
  48. package/src/components/data/XSignature/index.vue +285 -285
  49. package/src/components/data/XTag/index.vue +10 -10
  50. package/src/components/layout/NormalDataLayout/index.vue +70 -70
  51. package/src/components/layout/TabBarLayout/index.vue +40 -40
  52. package/src/components.d.ts +53 -53
  53. package/src/env.d.ts +16 -16
  54. package/src/font-style/font.css +3 -3
  55. package/src/hooks/useCommon.ts +9 -9
  56. package/src/layout/GridView/index.vue +1 -1
  57. package/src/layout/PageLayout.vue +4 -4
  58. package/src/layout/SingleLayout.vue +2 -2
  59. package/src/locales/en-US.json +25 -25
  60. package/src/locales/zh-CN.json +25 -25
  61. package/src/plugins/AppData.ts +38 -38
  62. package/src/plugins/index.ts +1 -1
  63. package/src/router/guards.ts +59 -59
  64. package/src/router/index.ts +61 -60
  65. package/src/router/invoiceRoutes.ts +33 -33
  66. package/src/router/routes.ts +20 -14
  67. package/src/services/api/common.ts +109 -109
  68. package/src/services/api/manage.ts +8 -8
  69. package/src/services/restTools.ts +52 -52
  70. package/src/services/v3Api.ts +46 -35
  71. package/src/stores/modules/cachedView.ts +1 -1
  72. package/src/stores/modules/setting.ts +52 -52
  73. package/src/stores/modules/user.ts +5 -5
  74. package/src/stores/mutation-type.ts +7 -7
  75. package/src/styles/app.less +6 -1
  76. package/src/utils/Storage.ts +1 -1
  77. package/src/utils/authority-utils.ts +84 -84
  78. package/src/utils/crypto.ts +39 -39
  79. package/src/utils/http/index.ts +6 -6
  80. package/src/utils/i18n.ts +41 -41
  81. package/src/utils/indexedDB.ts +180 -180
  82. package/src/utils/mobileUtil.ts +26 -26
  83. package/src/utils/routerUtil.ts +271 -271
  84. package/src/utils/runEvalFunction.ts +13 -13
  85. package/src/utils/validate.ts +1 -1
  86. package/src/utils/wechatUtil.ts +9 -9
  87. package/src/views/chat/index.vue +1 -1
  88. package/src/views/common/LoadError.vue +64 -64
  89. package/src/views/common/NotFound.vue +68 -68
  90. package/src/views/component/EvaluateRecordView/index.vue +40 -40
  91. package/src/views/component/XCellDetailView/index.vue +217 -216
  92. package/src/views/component/XCellListView/index.vue +1 -1
  93. package/src/views/component/XFormAppraiseView/index.vue +4 -4
  94. package/src/views/component/XFormGroupView/index.vue +1 -1
  95. package/src/views/component/XFormView/index.vue +6 -7
  96. package/src/views/component/XReportFormIframeView/index.vue +47 -47
  97. package/src/views/component/XReportFormView/index.vue +13 -13
  98. package/src/views/component/XReportGridView/index.vue +2 -3
  99. package/src/views/component/XSignatureView/index.vue +50 -50
  100. package/src/views/component/index.vue +4 -4
  101. package/src/views/component/menu.vue +117 -117
  102. package/src/views/component/notice.vue +46 -46
  103. package/src/views/component/topNav.vue +36 -36
  104. package/src/views/invoiceShow/index.vue +61 -62
  105. package/src/views/user/login/ForgetPasswordForm.vue +94 -93
  106. package/src/views/user/login/LoginForm.vue +8 -7
  107. package/src/views/user/login/LoginTitle.vue +68 -68
  108. package/src/views/user/login/index.vue +22 -22
  109. package/src/views/user/my/index.vue +230 -230
  110. package/src/vue-router.d.ts +9 -9
  111. package/tsconfig.json +43 -43
  112. package/uno.config.ts +1 -1
  113. package/vite.config.ts +123 -123
@@ -1,52 +1,52 @@
1
- import { http } from '@af-mobile-client-vue3/utils/http'
2
- import type { BasicResponseModel } from '@af-mobile-client-vue3/api/user'
3
-
4
- /**
5
- * GET请求
6
- * @param url 请求地址
7
- * @param params 路径参数
8
- */
9
- export function get(url: string, params?: any) {
10
- return http.request<BasicResponseModel>({
11
- url,
12
- method: 'GET',
13
- params,
14
- })
15
- }
16
-
17
- /**
18
- * POST请求
19
- * @param url 请求地址
20
- * @param data 请求参数
21
- */
22
- export function post(url: string, data: any) {
23
- return http.request<BasicResponseModel>({
24
- url,
25
- method: 'POST',
26
- data,
27
- })
28
- }
29
-
30
- export function postWithConfig(url: string, data: any, config: any) {
31
- return http.request<BasicResponseModel>({
32
- url,
33
- method: 'POST',
34
- data,
35
- headers: { ...config },
36
- })
37
- }
38
-
39
- /**
40
- * DELETE请求
41
- * @param url 请求地址
42
- * @param data 查询参数
43
- * @param config 额外的配置项(如自定义头信息等)
44
- */
45
- export function del(url: string, data?: any, config?: any) {
46
- return http.request<BasicResponseModel>({
47
- url,
48
- method: 'DELETE',
49
- data,
50
- ...config,
51
- })
52
- }
1
+ import type { BasicResponseModel } from '@af-mobile-client-vue3/api/user'
2
+ import { http } from '@af-mobile-client-vue3/utils/http'
3
+
4
+ /**
5
+ * GET请求
6
+ * @param url 请求地址
7
+ * @param params 路径参数
8
+ */
9
+ export function get(url: string, params?: any) {
10
+ return http.request<BasicResponseModel>({
11
+ url,
12
+ method: 'GET',
13
+ params,
14
+ })
15
+ }
16
+
17
+ /**
18
+ * POST请求
19
+ * @param url 请求地址
20
+ * @param data 请求参数
21
+ */
22
+ export function post(url: string, data: any) {
23
+ return http.request<BasicResponseModel>({
24
+ url,
25
+ method: 'POST',
26
+ data,
27
+ })
28
+ }
29
+
30
+ export function postWithConfig(url: string, data: any, config: any) {
31
+ return http.request<BasicResponseModel>({
32
+ url,
33
+ method: 'POST',
34
+ data,
35
+ headers: { ...config },
36
+ })
37
+ }
38
+
39
+ /**
40
+ * DELETE请求
41
+ * @param url 请求地址
42
+ * @param data 查询参数
43
+ * @param config 额外的配置项(如自定义头信息等)
44
+ */
45
+ export function del(url: string, data?: any, config?: any) {
46
+ return http.request<BasicResponseModel>({
47
+ url,
48
+ method: 'DELETE',
49
+ data,
50
+ ...config,
51
+ })
52
+ }
@@ -1,15 +1,16 @@
1
- import { METHOD, request } from '@af-mobile-client-vue3/utils/http/index'
2
1
  import { runLogic } from '@af-mobile-client-vue3/services/api/common'
2
+ import { METHOD, request } from '@af-mobile-client-vue3/utils/http/index'
3
3
 
4
- function getLeafNodes (nodes) {
5
- // console.log(nodes)
4
+ function getLeafNodes(nodes) {
5
+ // console.log(nodes)
6
6
  // 确保 nodes 是数组
7
7
  const nodeArray = Array.isArray(nodes) ? nodes : [nodes]
8
8
  return nodeArray.reduce((leaves, node) => {
9
9
  if (node.children && node.children.length) {
10
10
  // 递归处理子节点并合并结果
11
11
  leaves.push(...getLeafNodes(node.children))
12
- } else {
12
+ }
13
+ else {
13
14
  // 当前节点是叶子节点时,直接加入结果
14
15
  leaves.push(node)
15
16
  }
@@ -17,7 +18,7 @@ function getLeafNodes (nodes) {
17
18
  }, [])
18
19
  }
19
20
 
20
- function getLeafNodesByCondition (type, nodes, parent = null) {
21
+ function getLeafNodesByCondition(type, nodes, parent = null) {
21
22
  // console.log('nodes------',nodes)
22
23
  // 确保 nodes 是数组
23
24
  const nodeArray = Array.isArray(nodes) ? nodes : [nodes]
@@ -44,27 +45,29 @@ function getLeafNodesByCondition (type, nodes, parent = null) {
44
45
  }
45
46
  // 递归处理子节点
46
47
  leaves.push(...getLeafNodesByCondition(type, node.children, updatedParent))
47
- } else if (isValidNode) {
48
+ }
49
+ else if (isValidNode) {
48
50
  // 无子节点但符合条件时,直接加入叶子节点列表
49
- if (node.resourcetype === 'organization'){
50
- leaves.push({
51
- ...node,
52
- name: parent ? `${node.name}-${parent}` : node.name,
53
- })
54
- }else if (node.resourcetype === 'department' && !nodeArray.includes(node.name)) {
55
- // console.log('数组',nodeArray.includes(node.name))
56
- leaves.push({
57
- ...node,
58
- name: parent ? `${node.name}-${parent}` : node.name,
59
- })
60
- }
51
+ if (node.resourcetype === 'organization') {
52
+ leaves.push({
53
+ ...node,
54
+ name: parent ? `${node.name}-${parent}` : node.name,
55
+ })
56
+ }
57
+ else if (node.resourcetype === 'department' && !nodeArray.includes(node.name)) {
58
+ // console.log('数组',nodeArray.includes(node.name))
59
+ leaves.push({
60
+ ...node,
61
+ name: parent ? `${node.name}-${parent}` : node.name,
62
+ })
61
63
  }
64
+ }
62
65
  return leaves
63
66
  }, [])
64
67
  }
65
68
 
66
- function transformData (inputData) {
67
- function transform (node) {
69
+ function transformData(inputData) {
70
+ function transform(node) {
68
71
  return {
69
72
  label: node.name,
70
73
  value: node.id,
@@ -72,41 +75,48 @@ function transformData (inputData) {
72
75
  f_department_id: node.f_department_id,
73
76
  parentid: node.parentid,
74
77
  orgid: node.orgid,
75
- children: node.children ? node.children.map(transform) : []
78
+ children: node.children ? node.children.map(transform) : [],
76
79
  }
77
80
  }
78
81
 
79
82
  return inputData.map(transform)
80
83
  }
81
84
 
82
- function getResData (params, toCallback) {
85
+ function getResData(params, toCallback) {
83
86
  const data = { userId: params.userid, roleName: params.roleName }
84
87
  if (params.source === '获取分公司') {
85
88
  runLogic('getOrgBySearch', data, 'af-system').then(res => toCallback(res))
86
- } else if (params.source === '获取部门') {
89
+ }
90
+ else if (params.source === '获取部门') {
87
91
  runLogic('getDepBySearch', data, 'af-system').then(res => toCallback(res))
88
- } else if (params.source === '获取人员') {
92
+ }
93
+ else if (params.source === '获取人员') {
89
94
  runLogic('getUserBySearch', data, 'af-system').then(res => toCallback(res))
90
- } else if (params.source === '根据角色获取人员') {
95
+ }
96
+ else if (params.source === '根据角色获取人员') {
91
97
  runLogic('getUserBySearchRole', data, 'af-system').then(res => toCallback(res))
92
- } else {
98
+ }
99
+ else {
93
100
  return search(params).then(res => toCallback(res))
94
101
  }
95
102
  }
96
103
 
97
- export async function searchToOption (params, callback) {
98
- function toCallback (res) {
104
+ export async function searchToOption(params, callback) {
105
+ function toCallback(res) {
99
106
  if (res.length) {
100
107
  if (res[0].children && res[0].children.length) {
101
108
  if (res[0].children[0].children) {
102
109
  callback(transformData(res[0].children[0].children))
103
- } else {
110
+ }
111
+ else {
104
112
  callback(transformData(res[0].children))
105
113
  }
106
- } else {
114
+ }
115
+ else {
107
116
  callback(res[0].children)
108
117
  }
109
- } else {
118
+ }
119
+ else {
110
120
  callback(res)
111
121
  }
112
122
  }
@@ -114,12 +124,13 @@ export async function searchToOption (params, callback) {
114
124
  await getResData(params, toCallback)
115
125
  }
116
126
 
117
- export async function searchToListOption (params, callback) {
118
- function toCallback (res) {
127
+ export async function searchToListOption(params, callback) {
128
+ function toCallback(res) {
119
129
  if (params.source.includes('人员')) {
120
130
  // console.log('ren---------',res)
121
131
  callback(transformData(getLeafNodes(res)))
122
- } else {
132
+ }
133
+ else {
123
134
  const type = params.source.includes('公司') ? 'organization' : 'department'
124
135
  // console.log('bumenpgonngsi',res)
125
136
  callback(transformData(getLeafNodesByCondition(type, res)))
@@ -129,7 +140,7 @@ export async function searchToListOption (params, callback) {
129
140
  await getResData(params, toCallback)
130
141
  }
131
142
 
132
- export async function search (params) {
143
+ export async function search(params) {
133
144
  return request('/rs/search', METHOD.POST, params, params.config)
134
145
  }
135
146
 
@@ -1,6 +1,6 @@
1
+ import type { toRouteType } from '@af-mobile-client-vue3/router'
1
2
  import { defineStore } from 'pinia'
2
3
  import { ref } from 'vue'
3
- import type { toRouteType } from '@af-mobile-client-vue3/router'
4
4
 
5
5
  const useCachedViewStore = defineStore('cached-view', () => {
6
6
  // 缓存页面 keepAlive
@@ -1,52 +1,52 @@
1
- import { defineStore } from 'pinia'
2
- import { ref } from 'vue'
3
- import { getConfigByNameAsync } from '@af-mobile-client-vue3/services/api/common'
4
- import { APP_WEB_CONFIG_KEY } from '@af-mobile-client-vue3/stores/mutation-type'
5
- import { createStorage } from '@af-mobile-client-vue3/utils/Storage'
6
-
7
- export interface WebConfig {
8
- systemName: string
9
- routerName: string
10
- systemDesc: string
11
- homePage: string
12
- defaultAvatarUrl: string
13
- wechatLogin: boolean
14
- }
15
-
16
- // 存放 webConfig 中的 setting 配置
17
- export const useSettingStore = defineStore('setting', () => {
18
- const setting = ref<WebConfig>(undefined)
19
- const setSetting = (newSetting: WebConfig) => {
20
- setting.value = newSetting
21
- }
22
- const getSetting = () => {
23
- return setting.value
24
- }
25
-
26
- const useStore = createStorage()
27
-
28
- const store = useSettingStore()
29
-
30
- const init = async () => {
31
- const catchWebConfig = useStore.get(APP_WEB_CONFIG_KEY)
32
- if (catchWebConfig) {
33
- setSetting(catchWebConfig)
34
- }
35
- else {
36
- const res = await getConfigByNameAsync('webMobileConfig')
37
- useStore.set(APP_WEB_CONFIG_KEY, res)
38
- const setting: WebConfig = res.setting
39
- if (setting)
40
- store.setSetting(setting)
41
- }
42
- }
43
-
44
- init().then(() => {})
45
-
46
- return {
47
- setSetting,
48
- getSetting,
49
- }
50
- })
51
-
52
- export default useSettingStore
1
+ import { getConfigByNameAsync } from '@af-mobile-client-vue3/services/api/common'
2
+ import { APP_WEB_CONFIG_KEY } from '@af-mobile-client-vue3/stores/mutation-type'
3
+ import { createStorage } from '@af-mobile-client-vue3/utils/Storage'
4
+ import { defineStore } from 'pinia'
5
+ import { ref } from 'vue'
6
+
7
+ export interface WebConfig {
8
+ systemName: string
9
+ routerName: string
10
+ systemDesc: string
11
+ homePage: string
12
+ defaultAvatarUrl: string
13
+ wechatLogin: boolean
14
+ }
15
+
16
+ // 存放 webConfig 中的 setting 配置
17
+ export const useSettingStore = defineStore('setting', () => {
18
+ const setting = ref<WebConfig>(undefined)
19
+ const setSetting = (newSetting: WebConfig) => {
20
+ setting.value = newSetting
21
+ }
22
+ const getSetting = () => {
23
+ return setting.value
24
+ }
25
+
26
+ const useStore = createStorage()
27
+
28
+ const store = useSettingStore()
29
+
30
+ const init = async () => {
31
+ const catchWebConfig = useStore.get(APP_WEB_CONFIG_KEY)
32
+ if (catchWebConfig) {
33
+ setSetting(catchWebConfig)
34
+ }
35
+ else {
36
+ const res = await getConfigByNameAsync('webMobileConfig')
37
+ useStore.set(APP_WEB_CONFIG_KEY, res)
38
+ const setting: WebConfig = res.setting
39
+ if (setting)
40
+ store.setSetting(setting)
41
+ }
42
+ }
43
+
44
+ init().then(() => {})
45
+
46
+ return {
47
+ setSetting,
48
+ getSetting,
49
+ }
50
+ })
51
+
52
+ export default useSettingStore
@@ -1,7 +1,6 @@
1
- import { defineStore } from 'pinia'
2
- import { ref } from 'vue'
3
1
  import type { RouteRecordRaw } from 'vue-router'
4
- import { createStorage } from '@af-mobile-client-vue3/utils/Storage'
2
+ import { doLogout, login, OALogin } from '@af-mobile-client-vue3/api/user'
3
+ import router from '@af-mobile-client-vue3/router/index'
5
4
  import {
6
5
  ACCESS_TOKEN,
7
6
  APP_LOGIN_KEY,
@@ -10,9 +9,10 @@ import {
10
9
  APP_ROUTES_KEY,
11
10
  CURRENT_USER,
12
11
  } from '@af-mobile-client-vue3/stores/mutation-type'
13
- import { OALogin, doLogout, login } from '@af-mobile-client-vue3/api/user'
14
12
  import crypto from '@af-mobile-client-vue3/utils/crypto'
15
- import router from '@af-mobile-client-vue3/router/index'
13
+ import { createStorage } from '@af-mobile-client-vue3/utils/Storage'
14
+ import { defineStore } from 'pinia'
15
+ import { ref } from 'vue'
16
16
 
17
17
  const Storage = createStorage({ storage: localStorage })
18
18
 
@@ -1,7 +1,7 @@
1
- export const CURRENT_USER = 'CURRENT-USER'
2
- export const ACCESS_TOKEN = 'Authorization'
3
- export const APP_LOGIN_KEY = 'admin.login'
4
- export const APP_PERMISSIONS_KEY = 'admin.permissions'
5
- export const APP_ROLES_KEY = 'admin.roles'
6
- export const APP_ROUTES_KEY = 'admin.routes'
7
- export const APP_WEB_CONFIG_KEY = 'admin.webconfig'
1
+ export const CURRENT_USER = 'CURRENT-USER'
2
+ export const ACCESS_TOKEN = 'Authorization'
3
+ export const APP_LOGIN_KEY = 'admin.login'
4
+ export const APP_PERMISSIONS_KEY = 'admin.permissions'
5
+ export const APP_ROLES_KEY = 'admin.roles'
6
+ export const APP_ROUTES_KEY = 'admin.routes'
7
+ export const APP_WEB_CONFIG_KEY = 'admin.webconfig'
@@ -4,6 +4,11 @@
4
4
  --base-interval-2: 28px;
5
5
  }
6
6
 
7
+ :root:root {
8
+ // 覆盖 primary 颜色
9
+ --van-blue: #2563EB;
10
+ }
11
+
7
12
  #system-app {
8
13
  min-height: 100vh;
9
14
  position: relative;
@@ -11,7 +16,7 @@
11
16
  }
12
17
 
13
18
  html {
14
- background: var(--van-white);
19
+ background: var(--van-gray-1);
15
20
  color-scheme: light;
16
21
  }
17
22
 
@@ -48,7 +48,7 @@ export function createStorage({ prefixKey = '', storage = localStorage } = {}) {
48
48
 
49
49
  this.remove(key)
50
50
  }
51
- catch (e) {
51
+ catch {
52
52
  return def
53
53
  }
54
54
  }
@@ -1,84 +1,84 @@
1
- /**
2
- * 判断是否有路由的权限
3
- * @param authority 路由权限配置
4
- * @param permissions 用户权限集合
5
- */
6
- function hasPermission(authority: any, permissions: any): boolean {
7
- let required: string = '*'
8
- if (typeof authority === 'string')
9
- required = authority
10
- else if (Array.isArray(authority))
11
- required = authority.toString()
12
- else if (typeof authority === 'object')
13
- required = authority.permission
14
-
15
- return required === '*' || hasAnyItem(required, permissions, (r, t) => !!(r === t || r === t.id))
16
- }
17
-
18
- /**
19
- * 判断是否有路由需要的角色
20
- * @param authority 路由权限配置
21
- * @param roles 用户角色集合
22
- */
23
- function hasRole(authority, roles) {
24
- let required
25
- if (typeof authority === 'object')
26
- required = authority.role
27
-
28
- return authority === '*' || hasAnyItem(required, roles, (r, t) => !!(r === t || r === t.id))
29
- }
30
-
31
- /**
32
- * 判断目标数组是否有所需元素
33
- * @param {string | string[]}required 所需元素,数组或单个元素
34
- * @param {string[] | object[]} source 目标数组
35
- * @param {Function} filter 匹配条件
36
- * (r: String, s: String|Object) => boolean
37
- */
38
- function hasAnyItem(required, source, filter): boolean {
39
- if (!required)
40
- return false
41
-
42
- const checkedList = Array.isArray(required) ? required : [required]
43
- return !!source.find(s => checkedList.find(r => filter(r, s)))
44
- }
45
-
46
- /**
47
- * 路由权限校验
48
- * @param route 路由
49
- * @param permissions 用户权限集合
50
- * @param roles 用户角色集合
51
- */
52
- function hasAuthority(route, permissions, roles) {
53
- // TODO 此处判断可能有问题
54
- if (!route.meta.pAuthorities)
55
- return true
56
-
57
- const authorities = [...route.meta.pAuthorities, route.meta.authority]
58
- for (const authority of authorities) {
59
- if (!hasPermission(authority, permissions) && !hasRole(authority, roles))
60
- return false
61
- }
62
- return true
63
- }
64
-
65
- /**
66
- * 根据权限配置过滤菜单数据
67
- * @param menuData
68
- * @param permissions
69
- * @param roles
70
- */
71
- function filterMenu(menuData, permissions, roles) {
72
- return menuData.filter((menu) => {
73
- if (menu.meta && menu.meta.invisible === undefined) {
74
- if (!hasAuthority(menu, permissions, roles))
75
- return false
76
- }
77
- if (menu.children && menu.children.length > 0)
78
- menu.children = filterMenu(menu.children, permissions, roles)
79
-
80
- return true
81
- })
82
- }
83
-
84
- export { filterMenu, hasAuthority }
1
+ /**
2
+ * 判断是否有路由的权限
3
+ * @param authority 路由权限配置
4
+ * @param permissions 用户权限集合
5
+ */
6
+ function hasPermission(authority: any, permissions: any): boolean {
7
+ let required: string = '*'
8
+ if (typeof authority === 'string')
9
+ required = authority
10
+ else if (Array.isArray(authority))
11
+ required = authority.toString()
12
+ else if (typeof authority === 'object')
13
+ required = authority.permission
14
+
15
+ return required === '*' || hasAnyItem(required, permissions, (r, t) => !!(r === t || r === t.id))
16
+ }
17
+
18
+ /**
19
+ * 判断是否有路由需要的角色
20
+ * @param authority 路由权限配置
21
+ * @param roles 用户角色集合
22
+ */
23
+ function hasRole(authority, roles) {
24
+ let required
25
+ if (typeof authority === 'object')
26
+ required = authority.role
27
+
28
+ return authority === '*' || hasAnyItem(required, roles, (r, t) => !!(r === t || r === t.id))
29
+ }
30
+
31
+ /**
32
+ * 判断目标数组是否有所需元素
33
+ * @param {string | string[]}required 所需元素,数组或单个元素
34
+ * @param {string[] | object[]} source 目标数组
35
+ * @param {Function} filter 匹配条件
36
+ * (r: String, s: String|Object) => boolean
37
+ */
38
+ function hasAnyItem(required, source, filter): boolean {
39
+ if (!required)
40
+ return false
41
+
42
+ const checkedList = Array.isArray(required) ? required : [required]
43
+ return !!source.find(s => checkedList.find(r => filter(r, s)))
44
+ }
45
+
46
+ /**
47
+ * 路由权限校验
48
+ * @param route 路由
49
+ * @param permissions 用户权限集合
50
+ * @param roles 用户角色集合
51
+ */
52
+ function hasAuthority(route, permissions, roles) {
53
+ // TODO 此处判断可能有问题
54
+ if (!route.meta.pAuthorities)
55
+ return true
56
+
57
+ const authorities = [...route.meta.pAuthorities, route.meta.authority]
58
+ for (const authority of authorities) {
59
+ if (!hasPermission(authority, permissions) && !hasRole(authority, roles))
60
+ return false
61
+ }
62
+ return true
63
+ }
64
+
65
+ /**
66
+ * 根据权限配置过滤菜单数据
67
+ * @param menuData
68
+ * @param permissions
69
+ * @param roles
70
+ */
71
+ function filterMenu(menuData, permissions, roles) {
72
+ return menuData.filter((menu) => {
73
+ if (menu.meta && menu.meta.invisible === undefined) {
74
+ if (!hasAuthority(menu, permissions, roles))
75
+ return false
76
+ }
77
+ if (menu.children && menu.children.length > 0)
78
+ menu.children = filterMenu(menu.children, permissions, roles)
79
+
80
+ return true
81
+ })
82
+ }
83
+
84
+ export { filterMenu, hasAuthority }