af-mobile-client-vue3 1.4.62 → 1.4.64
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.
- package/certs/127.0.0.1+2-key.pem +28 -0
- package/certs/127.0.0.1+2.pem +27 -0
- package/mock/modules/prose.mock.ts.timestamp-1758877157774.mjs +53 -0
- package/mock/modules/user.mock.ts.timestamp-1758877157774.mjs +97 -0
- package/package.json +120 -120
- package/src/api/user/index.ts +45 -45
- package/src/components/core/ImageUploader/index.vue +510 -510
- package/src/components/data/XFormItem/index.vue +1 -0
- package/src/router/guards.ts +131 -131
- package/src/services/api/Login.ts +6 -6
- package/src/services/v3Api.ts +170 -170
- package/src/types/platform.ts +194 -194
- package/src/utils/platform-auth.ts +150 -150
- package/src/views/external/index.vue +158 -158
- package/src/views/loading/AuthLoading.vue +395 -395
- package/src/views/user/register/index.vue +958 -958
- package/vite.config.ts +122 -122
package/src/router/guards.ts
CHANGED
|
@@ -1,131 +1,131 @@
|
|
|
1
|
-
import type { RouteLocationNormalized } from 'vue-router'
|
|
2
|
-
import { useUserStore } from '@af-mobile-client-vue3/stores/modules/user'
|
|
3
|
-
import { UserType } from '@af-mobile-client-vue3/types/auth'
|
|
4
|
-
import { hasAuthority } from '@af-mobile-client-vue3/utils/authority-utils'
|
|
5
|
-
import { isExternalUser } from '@af-mobile-client-vue3/utils/platform-auth'
|
|
6
|
-
import { showToast } from 'vant'
|
|
7
|
-
|
|
8
|
-
// 不需要登录拦截的路由配置
|
|
9
|
-
const loginIgnore = {
|
|
10
|
-
names: ['404', '403', 'user-appointment', 'appointment-form', 'appointment-history', 'AuthLoading'], // 根据路由名称匹配
|
|
11
|
-
paths: ['/login', '/XReportFormIframeView', '/invoiceShow', '/register', '/loading'], // 根据路由fullPath匹配
|
|
12
|
-
/**
|
|
13
|
-
* 判断路由是否包含在该配置中
|
|
14
|
-
* @param route vue-router 的 route 对象
|
|
15
|
-
*/
|
|
16
|
-
includes(route) {
|
|
17
|
-
return this.names.includes(route.name) || this.paths.includes(route.path)
|
|
18
|
-
},
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* 登录守卫 - 支持外部用户微信授权
|
|
23
|
-
* @param to 目标路由
|
|
24
|
-
* @param from 来源路由
|
|
25
|
-
* @param next 导航函数
|
|
26
|
-
*/
|
|
27
|
-
function loginGuard(to: RouteLocationNormalized, from: RouteLocationNormalized, next: any) {
|
|
28
|
-
const userStore = useUserStore()
|
|
29
|
-
const token = userStore.getToken()
|
|
30
|
-
|
|
31
|
-
// 跳过不需要登录验证的路由
|
|
32
|
-
if (loginIgnore.includes(to)) {
|
|
33
|
-
next()
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// 已登录用户的处理
|
|
38
|
-
if (token && !to.query.appData && !(to.query.code && to.query.state)) {
|
|
39
|
-
// 如果已登录且访问登录页,重定向到首页
|
|
40
|
-
if (to.path === '/login') {
|
|
41
|
-
const defaultRoute = userStore.getDefaultRoute()
|
|
42
|
-
next({ path: defaultRoute })
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
next()
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// 未登录用户的处理
|
|
50
|
-
if (!token || to.query.appData || (to.query.code && to.query.state)) {
|
|
51
|
-
// 使用统一的检测函数判断用户类型
|
|
52
|
-
const externalResult = isExternalUser(to)
|
|
53
|
-
|
|
54
|
-
if (externalResult.isExternal) {
|
|
55
|
-
// 外部用户统一跳转到 loading 页面
|
|
56
|
-
const query: any = {
|
|
57
|
-
redirect: to.path,
|
|
58
|
-
}
|
|
59
|
-
Object.assign(query, to.query)
|
|
60
|
-
// 直接将认证参数传递到路由查询参数中
|
|
61
|
-
if (externalResult.authParams) {
|
|
62
|
-
Object.assign(query, externalResult.authParams)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
next({
|
|
66
|
-
path: '/loading',
|
|
67
|
-
query,
|
|
68
|
-
})
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// 内部用户跳转到登录页
|
|
73
|
-
showToast({
|
|
74
|
-
message: '登录状态已失效,请重新登录!',
|
|
75
|
-
position: 'bottom',
|
|
76
|
-
})
|
|
77
|
-
next({ path: '/login' })
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 权限守卫 - 支持外部用户权限检查
|
|
83
|
-
* @param to 目标路由
|
|
84
|
-
* @param from 来源路由
|
|
85
|
-
* @param next 导航函数
|
|
86
|
-
*/
|
|
87
|
-
function authorityGuard(to: RouteLocationNormalized, from: RouteLocationNormalized, next: any) {
|
|
88
|
-
const userStore = useUserStore()
|
|
89
|
-
const userType = userStore.getUserType()
|
|
90
|
-
const permissions = userStore.getPermissions()
|
|
91
|
-
const roles = userStore.getRoles()
|
|
92
|
-
|
|
93
|
-
// 跳过不需要权限验证的路由
|
|
94
|
-
if (loginIgnore.includes(to)) {
|
|
95
|
-
next()
|
|
96
|
-
return
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const meta = to.meta
|
|
100
|
-
|
|
101
|
-
// 如果路由不需要认证,直接通过
|
|
102
|
-
if (meta.requiresAuth === false) {
|
|
103
|
-
next()
|
|
104
|
-
return
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// 检查用户类型权限
|
|
108
|
-
const isExternalUser = userType === UserType.EXTERNAL
|
|
109
|
-
const allowExternalUser = meta.allowExternalUser ?? false
|
|
110
|
-
|
|
111
|
-
if (isExternalUser && !allowExternalUser) {
|
|
112
|
-
// 外部用户访问不被允许的页面,重定向到403页面
|
|
113
|
-
next({ path: '/403' })
|
|
114
|
-
return
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// 传统权限检查
|
|
118
|
-
if (!hasAuthority(to, permissions, roles)) {
|
|
119
|
-
// 没有权限,重定向到403页面
|
|
120
|
-
next({ path: '/403' })
|
|
121
|
-
return
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// 权限检查通过
|
|
125
|
-
next()
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export default {
|
|
129
|
-
beforeEach: [loginGuard, authorityGuard],
|
|
130
|
-
afterEach: [],
|
|
131
|
-
}
|
|
1
|
+
import type { RouteLocationNormalized } from 'vue-router'
|
|
2
|
+
import { useUserStore } from '@af-mobile-client-vue3/stores/modules/user'
|
|
3
|
+
import { UserType } from '@af-mobile-client-vue3/types/auth'
|
|
4
|
+
import { hasAuthority } from '@af-mobile-client-vue3/utils/authority-utils'
|
|
5
|
+
import { isExternalUser } from '@af-mobile-client-vue3/utils/platform-auth'
|
|
6
|
+
import { showToast } from 'vant'
|
|
7
|
+
|
|
8
|
+
// 不需要登录拦截的路由配置
|
|
9
|
+
const loginIgnore = {
|
|
10
|
+
names: ['404', '403', 'user-appointment', 'appointment-form', 'appointment-history', 'AuthLoading'], // 根据路由名称匹配
|
|
11
|
+
paths: ['/login', '/XReportFormIframeView', '/invoiceShow', '/register', '/loading'], // 根据路由fullPath匹配
|
|
12
|
+
/**
|
|
13
|
+
* 判断路由是否包含在该配置中
|
|
14
|
+
* @param route vue-router 的 route 对象
|
|
15
|
+
*/
|
|
16
|
+
includes(route) {
|
|
17
|
+
return this.names.includes(route.name) || this.paths.includes(route.path)
|
|
18
|
+
},
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 登录守卫 - 支持外部用户微信授权
|
|
23
|
+
* @param to 目标路由
|
|
24
|
+
* @param from 来源路由
|
|
25
|
+
* @param next 导航函数
|
|
26
|
+
*/
|
|
27
|
+
function loginGuard(to: RouteLocationNormalized, from: RouteLocationNormalized, next: any) {
|
|
28
|
+
const userStore = useUserStore()
|
|
29
|
+
const token = userStore.getToken()
|
|
30
|
+
|
|
31
|
+
// 跳过不需要登录验证的路由
|
|
32
|
+
if (loginIgnore.includes(to)) {
|
|
33
|
+
next()
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 已登录用户的处理
|
|
38
|
+
if (token && !to.query.appData && !(to.query.code && to.query.state)) {
|
|
39
|
+
// 如果已登录且访问登录页,重定向到首页
|
|
40
|
+
if (to.path === '/login') {
|
|
41
|
+
const defaultRoute = userStore.getDefaultRoute()
|
|
42
|
+
next({ path: defaultRoute })
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
next()
|
|
46
|
+
return
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// 未登录用户的处理
|
|
50
|
+
if (!token || to.query.appData || (to.query.code && to.query.state)) {
|
|
51
|
+
// 使用统一的检测函数判断用户类型
|
|
52
|
+
const externalResult = isExternalUser(to)
|
|
53
|
+
|
|
54
|
+
if (externalResult.isExternal) {
|
|
55
|
+
// 外部用户统一跳转到 loading 页面
|
|
56
|
+
const query: any = {
|
|
57
|
+
redirect: to.path,
|
|
58
|
+
}
|
|
59
|
+
Object.assign(query, to.query)
|
|
60
|
+
// 直接将认证参数传递到路由查询参数中
|
|
61
|
+
if (externalResult.authParams) {
|
|
62
|
+
Object.assign(query, externalResult.authParams)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
next({
|
|
66
|
+
path: '/loading',
|
|
67
|
+
query,
|
|
68
|
+
})
|
|
69
|
+
return
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// 内部用户跳转到登录页
|
|
73
|
+
showToast({
|
|
74
|
+
message: '登录状态已失效,请重新登录!',
|
|
75
|
+
position: 'bottom',
|
|
76
|
+
})
|
|
77
|
+
next({ path: '/login' })
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 权限守卫 - 支持外部用户权限检查
|
|
83
|
+
* @param to 目标路由
|
|
84
|
+
* @param from 来源路由
|
|
85
|
+
* @param next 导航函数
|
|
86
|
+
*/
|
|
87
|
+
function authorityGuard(to: RouteLocationNormalized, from: RouteLocationNormalized, next: any) {
|
|
88
|
+
const userStore = useUserStore()
|
|
89
|
+
const userType = userStore.getUserType()
|
|
90
|
+
const permissions = userStore.getPermissions()
|
|
91
|
+
const roles = userStore.getRoles()
|
|
92
|
+
|
|
93
|
+
// 跳过不需要权限验证的路由
|
|
94
|
+
if (loginIgnore.includes(to)) {
|
|
95
|
+
next()
|
|
96
|
+
return
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
const meta = to.meta
|
|
100
|
+
|
|
101
|
+
// 如果路由不需要认证,直接通过
|
|
102
|
+
if (meta.requiresAuth === false) {
|
|
103
|
+
next()
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// 检查用户类型权限
|
|
108
|
+
const isExternalUser = userType === UserType.EXTERNAL
|
|
109
|
+
const allowExternalUser = meta.allowExternalUser ?? false
|
|
110
|
+
|
|
111
|
+
if (isExternalUser && !allowExternalUser) {
|
|
112
|
+
// 外部用户访问不被允许的页面,重定向到403页面
|
|
113
|
+
next({ path: '/403' })
|
|
114
|
+
return
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 传统权限检查
|
|
118
|
+
if (!hasAuthority(to, permissions, roles)) {
|
|
119
|
+
// 没有权限,重定向到403页面
|
|
120
|
+
next({ path: '/403' })
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// 权限检查通过
|
|
125
|
+
next()
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export default {
|
|
129
|
+
beforeEach: [loginGuard, authorityGuard],
|
|
130
|
+
afterEach: [],
|
|
131
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
const loginApi = {
|
|
2
|
-
Login: '/af-auth/login',
|
|
3
|
-
Logout: '/af-auth/logout',
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export { loginApi }
|
|
1
|
+
const loginApi = {
|
|
2
|
+
Login: '/af-auth/login',
|
|
3
|
+
Logout: '/af-auth/logout',
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export { loginApi }
|
package/src/services/v3Api.ts
CHANGED
|
@@ -1,170 +1,170 @@
|
|
|
1
|
-
import { runLogic } from '@af-mobile-client-vue3/services/api/common'
|
|
2
|
-
import { METHOD, request } from '@af-mobile-client-vue3/utils/http/index'
|
|
3
|
-
|
|
4
|
-
function getLeafNodes(nodes) {
|
|
5
|
-
// console.log(nodes)
|
|
6
|
-
// 确保 nodes 是数组
|
|
7
|
-
const nodeArray = Array.isArray(nodes) ? nodes : [nodes]
|
|
8
|
-
return nodeArray.reduce((leaves, node) => {
|
|
9
|
-
if (node.children && node.children.length) {
|
|
10
|
-
// 递归处理子节点并合并结果
|
|
11
|
-
leaves.push(...getLeafNodes(node.children))
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
// 当前节点是叶子节点时,直接加入结果
|
|
15
|
-
leaves.push(node)
|
|
16
|
-
}
|
|
17
|
-
return leaves
|
|
18
|
-
}, [])
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function getLeafNodesByCondition(type, nodes, parent = null) {
|
|
22
|
-
// console.log('nodes------',nodes)
|
|
23
|
-
// 确保 nodes 是数组
|
|
24
|
-
const nodeArray = Array.isArray(nodes) ? nodes : [nodes]
|
|
25
|
-
|
|
26
|
-
return nodeArray.reduce((leaves, node) => {
|
|
27
|
-
const isValidNode = node.resourcetype === type && node.name !== '组织机构'
|
|
28
|
-
const updatedParent = node.name === '组织机构' ? null : node.name
|
|
29
|
-
|
|
30
|
-
if (node.children && node.children.length) {
|
|
31
|
-
// 当前节点符合条件时,加入叶子节点列表
|
|
32
|
-
if (isValidNode && node.resourcetype === 'organization') {
|
|
33
|
-
leaves.push({
|
|
34
|
-
...node,
|
|
35
|
-
name: parent ? `${node.name}` : node.name,
|
|
36
|
-
children: [],
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
if (isValidNode && node.resourcetype === 'department') {
|
|
40
|
-
leaves.push({
|
|
41
|
-
...node,
|
|
42
|
-
name: parent ? `${node.name}-${parent}` : node.name,
|
|
43
|
-
children: [],
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
// 递归处理子节点
|
|
47
|
-
leaves.push(...getLeafNodesByCondition(type, node.children, updatedParent))
|
|
48
|
-
}
|
|
49
|
-
else if (isValidNode) {
|
|
50
|
-
// 无子节点但符合条件时,直接加入叶子节点列表
|
|
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
|
-
})
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
return leaves
|
|
66
|
-
}, [])
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
function transformData(inputData) {
|
|
70
|
-
if (!inputData || !Array.isArray(inputData))
|
|
71
|
-
return []
|
|
72
|
-
|
|
73
|
-
function transform(node) {
|
|
74
|
-
if (!node || typeof node !== 'object')
|
|
75
|
-
return {}
|
|
76
|
-
|
|
77
|
-
let children = []
|
|
78
|
-
if (node.children) {
|
|
79
|
-
if (Array.isArray(node.children)) {
|
|
80
|
-
children = node.children.map(transform)
|
|
81
|
-
}
|
|
82
|
-
else if (typeof node.children === 'object') {
|
|
83
|
-
// 检查是否是空标记
|
|
84
|
-
if (node.children.empty === true) {
|
|
85
|
-
children = []
|
|
86
|
-
}
|
|
87
|
-
else if (node.children.id || node.children.name) {
|
|
88
|
-
// 如果是单个节点对象
|
|
89
|
-
children = [transform(node.children)]
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return {
|
|
95
|
-
label: node.name || '',
|
|
96
|
-
value: node.id ?? null,
|
|
97
|
-
f_organization_id: node.f_organization_id,
|
|
98
|
-
f_department_id: node.f_department_id,
|
|
99
|
-
parentid: node.parentid || node.parentId || node.parent_id || null,
|
|
100
|
-
orgid: node.orgid,
|
|
101
|
-
children,
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return inputData.map(transform)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
function getResData(params, toCallback) {
|
|
109
|
-
const data = { userId: params.userid, roleName: params.roleName, filter: params.filter, filterType: params.filterType }
|
|
110
|
-
if (params.source === '获取分公司') {
|
|
111
|
-
runLogic('getOrgBySearch', data, 'af-system').then(res => toCallback(res))
|
|
112
|
-
}
|
|
113
|
-
else if (params.source === '获取部门') {
|
|
114
|
-
runLogic('getDepBySearch', data, 'af-system').then(res => toCallback(res))
|
|
115
|
-
}
|
|
116
|
-
else if (params.source === '获取人员') {
|
|
117
|
-
runLogic('getUserBySearch', data, 'af-system').then(res => toCallback(res))
|
|
118
|
-
}
|
|
119
|
-
else if (params.source === '根据角色获取人员') {
|
|
120
|
-
runLogic('getUserBySearchRole', data, 'af-system').then(res => toCallback(res))
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
return search(params).then(res => toCallback(res))
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
export async function searchToOption(params, callback) {
|
|
128
|
-
function toCallback(res) {
|
|
129
|
-
if (res.length) {
|
|
130
|
-
if (res[0].children && res[0].children.length) {
|
|
131
|
-
if (res[0].children[0].children) {
|
|
132
|
-
callback(transformData(res[0].children[0].children))
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
callback(transformData(res[0].children))
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
else {
|
|
139
|
-
callback(res[0].children)
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
callback(res)
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
await getResData(params, toCallback)
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export async function searchToListOption(params, callback) {
|
|
151
|
-
function toCallback(res) {
|
|
152
|
-
if (params.source.includes('人员')) {
|
|
153
|
-
// console.log('ren---------',res)
|
|
154
|
-
callback(transformData(getLeafNodes(res)))
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
const type = params.source.includes('公司') ? 'organization' : 'department'
|
|
158
|
-
// console.log('bumenpgonngsi',res)
|
|
159
|
-
callback(transformData(getLeafNodesByCondition(type, res)))
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
await getResData(params, toCallback)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export async function search(params) {
|
|
167
|
-
return request('/rs/search', METHOD.POST, params, params.config)
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export default { searchToOption, search }
|
|
1
|
+
import { runLogic } from '@af-mobile-client-vue3/services/api/common'
|
|
2
|
+
import { METHOD, request } from '@af-mobile-client-vue3/utils/http/index'
|
|
3
|
+
|
|
4
|
+
function getLeafNodes(nodes) {
|
|
5
|
+
// console.log(nodes)
|
|
6
|
+
// 确保 nodes 是数组
|
|
7
|
+
const nodeArray = Array.isArray(nodes) ? nodes : [nodes]
|
|
8
|
+
return nodeArray.reduce((leaves, node) => {
|
|
9
|
+
if (node.children && node.children.length) {
|
|
10
|
+
// 递归处理子节点并合并结果
|
|
11
|
+
leaves.push(...getLeafNodes(node.children))
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
// 当前节点是叶子节点时,直接加入结果
|
|
15
|
+
leaves.push(node)
|
|
16
|
+
}
|
|
17
|
+
return leaves
|
|
18
|
+
}, [])
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getLeafNodesByCondition(type, nodes, parent = null) {
|
|
22
|
+
// console.log('nodes------',nodes)
|
|
23
|
+
// 确保 nodes 是数组
|
|
24
|
+
const nodeArray = Array.isArray(nodes) ? nodes : [nodes]
|
|
25
|
+
|
|
26
|
+
return nodeArray.reduce((leaves, node) => {
|
|
27
|
+
const isValidNode = node.resourcetype === type && node.name !== '组织机构'
|
|
28
|
+
const updatedParent = node.name === '组织机构' ? null : node.name
|
|
29
|
+
|
|
30
|
+
if (node.children && node.children.length) {
|
|
31
|
+
// 当前节点符合条件时,加入叶子节点列表
|
|
32
|
+
if (isValidNode && node.resourcetype === 'organization') {
|
|
33
|
+
leaves.push({
|
|
34
|
+
...node,
|
|
35
|
+
name: parent ? `${node.name}` : node.name,
|
|
36
|
+
children: [],
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
if (isValidNode && node.resourcetype === 'department') {
|
|
40
|
+
leaves.push({
|
|
41
|
+
...node,
|
|
42
|
+
name: parent ? `${node.name}-${parent}` : node.name,
|
|
43
|
+
children: [],
|
|
44
|
+
})
|
|
45
|
+
}
|
|
46
|
+
// 递归处理子节点
|
|
47
|
+
leaves.push(...getLeafNodesByCondition(type, node.children, updatedParent))
|
|
48
|
+
}
|
|
49
|
+
else if (isValidNode) {
|
|
50
|
+
// 无子节点但符合条件时,直接加入叶子节点列表
|
|
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
|
+
})
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return leaves
|
|
66
|
+
}, [])
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function transformData(inputData) {
|
|
70
|
+
if (!inputData || !Array.isArray(inputData))
|
|
71
|
+
return []
|
|
72
|
+
|
|
73
|
+
function transform(node) {
|
|
74
|
+
if (!node || typeof node !== 'object')
|
|
75
|
+
return {}
|
|
76
|
+
|
|
77
|
+
let children = []
|
|
78
|
+
if (node.children) {
|
|
79
|
+
if (Array.isArray(node.children)) {
|
|
80
|
+
children = node.children.map(transform)
|
|
81
|
+
}
|
|
82
|
+
else if (typeof node.children === 'object') {
|
|
83
|
+
// 检查是否是空标记
|
|
84
|
+
if (node.children.empty === true) {
|
|
85
|
+
children = []
|
|
86
|
+
}
|
|
87
|
+
else if (node.children.id || node.children.name) {
|
|
88
|
+
// 如果是单个节点对象
|
|
89
|
+
children = [transform(node.children)]
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
label: node.name || '',
|
|
96
|
+
value: node.id ?? null,
|
|
97
|
+
f_organization_id: node.f_organization_id,
|
|
98
|
+
f_department_id: node.f_department_id,
|
|
99
|
+
parentid: node.parentid || node.parentId || node.parent_id || null,
|
|
100
|
+
orgid: node.orgid,
|
|
101
|
+
children,
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return inputData.map(transform)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function getResData(params, toCallback) {
|
|
109
|
+
const data = { userId: params.userid, roleName: params.roleName, filter: params.filter, filterType: params.filterType }
|
|
110
|
+
if (params.source === '获取分公司') {
|
|
111
|
+
runLogic('getOrgBySearch', data, 'af-system').then(res => toCallback(res))
|
|
112
|
+
}
|
|
113
|
+
else if (params.source === '获取部门') {
|
|
114
|
+
runLogic('getDepBySearch', data, 'af-system').then(res => toCallback(res))
|
|
115
|
+
}
|
|
116
|
+
else if (params.source === '获取人员') {
|
|
117
|
+
runLogic('getUserBySearch', data, 'af-system').then(res => toCallback(res))
|
|
118
|
+
}
|
|
119
|
+
else if (params.source === '根据角色获取人员') {
|
|
120
|
+
runLogic('getUserBySearchRole', data, 'af-system').then(res => toCallback(res))
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
return search(params).then(res => toCallback(res))
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export async function searchToOption(params, callback) {
|
|
128
|
+
function toCallback(res) {
|
|
129
|
+
if (res.length) {
|
|
130
|
+
if (res[0].children && res[0].children.length) {
|
|
131
|
+
if (res[0].children[0].children) {
|
|
132
|
+
callback(transformData(res[0].children[0].children))
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
callback(transformData(res[0].children))
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
callback(res[0].children)
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
callback(res)
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
await getResData(params, toCallback)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export async function searchToListOption(params, callback) {
|
|
151
|
+
function toCallback(res) {
|
|
152
|
+
if (params.source.includes('人员')) {
|
|
153
|
+
// console.log('ren---------',res)
|
|
154
|
+
callback(transformData(getLeafNodes(res)))
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
157
|
+
const type = params.source.includes('公司') ? 'organization' : 'department'
|
|
158
|
+
// console.log('bumenpgonngsi',res)
|
|
159
|
+
callback(transformData(getLeafNodesByCondition(type, res)))
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
await getResData(params, toCallback)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export async function search(params) {
|
|
167
|
+
return request('/rs/search', METHOD.POST, params, params.config)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export default { searchToOption, search }
|