af-mobile-client-vue3 1.4.64 → 1.4.66

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.
@@ -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 }
@@ -210,6 +210,9 @@ export const useUserStore = defineStore('app-user', () => {
210
210
  }
211
211
  else {
212
212
  data = await login(params)
213
+ if (data.resources && data.resources.msg && data.resources.code && data.resources.code !== 200) {
214
+ return Promise.reject(new Error(data.resources.msg))
215
+ }
213
216
  // save token
214
217
  setToken(data.access_token)
215
218
  // 第三方教培系统鉴权兼容