yuang-framework-ui-common 1.0.66 → 1.0.67
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/lib/hooks/uims/uimsApplication.ts +133 -35
- package/package.json +1 -1
@@ -1,36 +1,134 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
import { http } from '../../../lib/config/httpConfig';
|
2
|
+
import { application } from '../../../lib/config/applicationConfig';
|
3
|
+
|
3
4
|
// import { toTree } from 'yuang-framework-ui-pc/es';
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
//
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
5
|
+
|
6
|
+
/**
|
7
|
+
* 查询Uims应用树数据,先查询所有满足条件的数据,再转树结构
|
8
|
+
*/
|
9
|
+
const queryUimsApplicationTreeData = ({ applicationName }) => {
|
10
|
+
return new Promise((resolve, reject) => {
|
11
|
+
const data = { parentId: '0', name: applicationName };
|
12
|
+
// prettier-ignore
|
13
|
+
http.post(`${application.gatewayServerBaseUrl}/uims-api/admin/uims-application/selectPage`, data).then(res=>{
|
14
|
+
const listData = [
|
15
|
+
{
|
16
|
+
id: '0',
|
17
|
+
name: '全部应用',
|
18
|
+
isHasChildren: true,
|
19
|
+
isLeaf: false,
|
20
|
+
levelNum: 0,
|
21
|
+
parentId: ''
|
22
|
+
},
|
23
|
+
...res.data.data.records
|
24
|
+
];
|
25
|
+
const treeData = toTree({
|
26
|
+
data: listData,
|
27
|
+
idField: 'id',
|
28
|
+
parentIdField: 'parentId'
|
29
|
+
});
|
30
|
+
resolve({ treeData });
|
31
|
+
}).catch(() => {
|
32
|
+
reject();
|
33
|
+
});
|
34
|
+
});
|
35
|
+
};
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
/**
|
40
|
+
* toTree 方法参数
|
41
|
+
* 临时添加
|
42
|
+
*/
|
43
|
+
export interface ToTreeOption<T> {
|
44
|
+
/** 数据 */
|
45
|
+
data?: T[] | null;
|
46
|
+
/** id 字段名称 */
|
47
|
+
idField?: string | null;
|
48
|
+
/** parentId 字段名称 */
|
49
|
+
parentIdField?: string | null;
|
50
|
+
/** 生成的 children 字段名称 */
|
51
|
+
childrenField?: string | null;
|
52
|
+
/** 最顶级的 parentId 值 */
|
53
|
+
parentId?: number | string | (number | string)[] | null;
|
54
|
+
/** 是否添加包含所有父级 id 的字段 */
|
55
|
+
addParentIds?: boolean | null;
|
56
|
+
/** 包含所有父级 id 字段的名称 */
|
57
|
+
parentIdsField?: string | null;
|
58
|
+
/** 所有父级的 id */
|
59
|
+
parentIds?: (number | string)[] | null;
|
60
|
+
}
|
61
|
+
|
62
|
+
/**
|
63
|
+
* parentId 形式数据转 children 形式
|
64
|
+
* 临时添加
|
65
|
+
* @param option ToTreeOption
|
66
|
+
*/
|
67
|
+
export function toTree<T>(option: ToTreeOption<T>): T[] {
|
68
|
+
const data = option.data;
|
69
|
+
const idField = option.idField || 'id';
|
70
|
+
const parentIdField = option.parentIdField || 'parentId';
|
71
|
+
const childrenField = option.childrenField || 'children';
|
72
|
+
const parentIdIsNull = option.parentId == null;
|
73
|
+
const parentId = parentIdIsNull ? [] : option.parentId;
|
74
|
+
const parentIdIsArray = Array.isArray(parentId);
|
75
|
+
const addParentIds = option.addParentIds;
|
76
|
+
const parentIdsField = option.parentIdsField || 'parentIds';
|
77
|
+
const parentIds = option.parentIds ?? [];
|
78
|
+
|
79
|
+
if (data == null) {
|
80
|
+
return [];
|
81
|
+
}
|
82
|
+
|
83
|
+
if (parentIdIsNull) {
|
84
|
+
data.forEach((d) => {
|
85
|
+
if (
|
86
|
+
!data.some((t) => d[parentIdField] == t[idField]) &&
|
87
|
+
!(parentId as unknown[]).includes(d[parentIdField])
|
88
|
+
) {
|
89
|
+
(parentId as unknown[]).push(d[parentIdField]);
|
90
|
+
}
|
91
|
+
});
|
92
|
+
}
|
93
|
+
|
94
|
+
const result: T[] = [];
|
95
|
+
data.forEach((d) => {
|
96
|
+
if (d[idField] == d[parentIdField]) {
|
97
|
+
const error = {
|
98
|
+
[idField]: d[idField],
|
99
|
+
[parentIdField]: d[parentIdField],
|
100
|
+
data: d
|
101
|
+
};
|
102
|
+
console.error('data error:', error);
|
103
|
+
throw new Error('data error');
|
104
|
+
}
|
105
|
+
if (
|
106
|
+
parentIdIsArray
|
107
|
+
? parentId.includes(d[parentIdField])
|
108
|
+
: d[parentIdField] == parentId
|
109
|
+
) {
|
110
|
+
const t = { ...d };
|
111
|
+
const children = toTree({
|
112
|
+
data,
|
113
|
+
idField,
|
114
|
+
parentIdField,
|
115
|
+
childrenField,
|
116
|
+
parentId: d[idField],
|
117
|
+
addParentIds,
|
118
|
+
parentIdsField,
|
119
|
+
parentIds: [...parentIds, d[idField]]
|
120
|
+
});
|
121
|
+
if (children.length > 0) {
|
122
|
+
t[childrenField] = children;
|
123
|
+
}
|
124
|
+
if (addParentIds) {
|
125
|
+
t[parentIdsField] = parentIds;
|
126
|
+
}
|
127
|
+
result.push(t);
|
128
|
+
}
|
129
|
+
});
|
130
|
+
return result;
|
131
|
+
}
|
132
|
+
|
133
|
+
|
134
|
+
export { queryUimsApplicationTreeData };
|