wui-components-v2 1.1.69 → 1.1.71

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 (117) hide show
  1. package/api/core/index.ts +74 -74
  2. package/api/feishu.ts +20 -20
  3. package/api/index.ts +4 -4
  4. package/api/login.ts +51 -51
  5. package/api/menu.ts +45 -45
  6. package/api/page.ts +114 -114
  7. package/api/sys.ts +12 -12
  8. package/api/tree.ts +28 -28
  9. package/components/action-popup/action-popup.vue +116 -116
  10. package/components/add-address-list/add-address-list.vue +187 -187
  11. package/components/add-address-page/add-address-page.vue +77 -77
  12. package/components/add-address-page/config.ts +297 -297
  13. package/components/audio-play/audio-play.vue +220 -220
  14. package/components/batch-upload-file/batch-upload-file.vue +75 -75
  15. package/components/card-botom-buttons/card-botom-buttons.vue +279 -279
  16. package/components/custom-date-picker/custom-date-picker.vue +106 -106
  17. package/components/custom-select-picker/custom-select-picker.vue +95 -95
  18. package/components/demo-block/demo-block.vue +63 -63
  19. package/components/demo-card/demo-card.vue +44 -44
  20. package/components/detail-popup/detail-popup.vue +99 -99
  21. package/components/evaluation-page/evaluation-page.vue +196 -196
  22. package/components/fold-card/fold-card.vue +171 -171
  23. package/components/form-control/form-control.vue +661 -661
  24. package/components/global-loading/GlobalLoading.md +366 -366
  25. package/components/global-loading/global-loading.vue +55 -55
  26. package/components/global-message/GlobalMessage.md +570 -570
  27. package/components/global-message/global-message.vue +68 -68
  28. package/components/global-toast/GlobalToast.md +261 -261
  29. package/components/global-toast/global-toast.vue +56 -56
  30. package/components/label-value/label-value.vue +144 -144
  31. package/components/label-value/open-value-more.vue +56 -56
  32. package/components/list-top-buttons/list-top-buttons.vue +19 -19
  33. package/components/loading/loading.vue +5 -5
  34. package/components/login-form/login-form.vue +126 -126
  35. package/components/login-form-box/login-form-box.vue +65 -65
  36. package/components/mulselect-picker/mulselect-picker.vue +86 -86
  37. package/components/phone-login-form/phone-login-form.vue +204 -204
  38. package/components/privacy-popup/privacy-popup.vue +191 -191
  39. package/components/product-card/product-card.vue +201 -201
  40. package/components/scan-input/scan-input.vue +406 -406
  41. package/components/search/search.vue +128 -128
  42. package/components/select-col-picker/select-col-picker.vue +168 -168
  43. package/components/tab-search/tab-search.vue +73 -73
  44. package/components/tree-select/components/TreeNode.vue +200 -200
  45. package/components/tree-select/components/index.vue +471 -471
  46. package/components/tree-select/components/tree-select.vue +56 -56
  47. package/components/tree-select/index.vue +93 -93
  48. package/components/user-choose/user-choose.vue +169 -151
  49. package/components/video-play/video-play.vue +56 -56
  50. package/components/wui-auto-update-component/wui-auto-update-component.vue +132 -132
  51. package/components/wui-default/wui-default.vue +49 -49
  52. package/components/wui-details-page/wui-details-page.vue +147 -147
  53. package/components/wui-edit-page/wui-edit-page-copy.vue +757 -757
  54. package/components/wui-edit-page/wui-edit-page.vue +793 -793
  55. package/components/wui-enume-select-control/wui-enume-select-control.vue +92 -92
  56. package/components/wui-list/wui-list.vue +235 -235
  57. package/components/wui-login/wui-login.vue +43 -43
  58. package/components/wui-login1/wui-login.vue +41 -41
  59. package/components/wui-menus/wui-menus-top.vue +137 -137
  60. package/components/wui-menus/wui-menus-top1.vue +8 -8
  61. package/components/wui-menus/wui-menus.vue +247 -247
  62. package/components/wui-menus1/components/banner-carousel.vue +320 -320
  63. package/components/wui-menus1/components/navbar.vue +43 -43
  64. package/components/wui-menus1/components/quick-panel.vue +55 -55
  65. package/components/wui-menus1/components/search-bar.vue +49 -49
  66. package/components/wui-menus1/components/section-menus.vue +208 -208
  67. package/components/wui-menus1/wui-menus-top.vue +718 -718
  68. package/components/wui-menus1/wui-menus-top1.vue +398 -398
  69. package/components/wui-menus1/wui-menus.vue +564 -564
  70. package/components/wui-notify-info/notify-handle.vue +53 -53
  71. package/components/wui-notify-info/wui-notify-info.vue +280 -280
  72. package/components/wui-scan-binding-sensor/wui-scan-binding-sensor.vue +75 -75
  73. package/components/wui-search-history-babbar/components/SearchBar.vue +70 -70
  74. package/components/wui-search-history-babbar/wui-search-history-babbar.vue +204 -204
  75. package/components/wui-select-list/wui-select-list.vue +310 -310
  76. package/components/wui-select-popup/wui-select-popup.vue +613 -612
  77. package/components/wui-system-settings/wui-system-settings.vue +144 -144
  78. package/components/wui-tabbar/wui-tabbar.vue +106 -106
  79. package/components/wui-tree-page/components/tree-item.vue +238 -238
  80. package/components/wui-tree-page/wui-tree-page.vue +297 -297
  81. package/components/wui-update-component/wui-update-component.vue +221 -221
  82. package/components/wui-user/wui-user.vue +202 -202
  83. package/composables/types/theme.ts +65 -65
  84. package/composables/types/user.ts +5 -5
  85. package/composables/useColorGenerator.ts +221 -221
  86. package/composables/useCompanyFieldFilter.ts +91 -91
  87. package/composables/useEnumes.ts +43 -43
  88. package/composables/useEventBus.ts +37 -37
  89. package/composables/useGlobalLoading.ts +47 -47
  90. package/composables/useGlobalMessage.ts +53 -53
  91. package/composables/useGlobalToast.ts +63 -63
  92. package/composables/useLocale.ts +54 -54
  93. package/composables/useManualTheme.ts +179 -179
  94. package/composables/useMenus.ts +193 -193
  95. package/composables/useSectionMenus.ts +120 -120
  96. package/composables/useTabbar.ts +50 -50
  97. package/composables/useTheme.ts +74 -74
  98. package/composables/useUser.ts +24 -24
  99. package/index.d.ts +90 -90
  100. package/index.ts +83 -83
  101. package/package.json +24 -24
  102. package/static/iconfont/iconfont.css +63 -63
  103. package/store/language.ts +151 -151
  104. package/store/manualThemeStore.ts +143 -143
  105. package/store/persist.ts +41 -41
  106. package/store/themeStore.ts +74 -74
  107. package/store/userStore.ts +22 -22
  108. package/styles/dark-mode.css +523 -523
  109. package/styles/dark-mode.min.css +1 -1
  110. package/styles/dark-mode.scss +498 -498
  111. package/type.ts +154 -154
  112. package/utils/control-tree.ts +353 -353
  113. package/utils/control-type-supportor.ts +148 -148
  114. package/utils/eventBus.ts +36 -36
  115. package/utils/idata-scan.ts +99 -99
  116. package/utils/index.ts +979 -979
  117. package/utils/rsaEncrypt.ts +10 -10
@@ -1,353 +1,353 @@
1
- // tree组件的请求控制逻辑
2
- import { onMounted, ref } from 'vue'
3
- import { treeConfigApi, treeDataApi, treeNodeDataApi } from '../api/tree'
4
- import { pageConfig } from '../api/page'
5
- import type { Config } from '../type'
6
-
7
- export interface TreeConfig {
8
- leafRatmplId?: string // 叶子节点ID
9
- leafTitle?: string // 叶子节点标题
10
- branchRatmplId?: string // 分支节点ID
11
- branchTitle?: string // 分支节点标题
12
- rootGtmplId: string // 根节ID
13
- id: string // 树ID
14
- title: string // 树标题
15
- rootLTmplConfig: Config
16
- branchLTmplConfig?: Config
17
- leafLTmplConfig?: Config
18
- }
19
-
20
- export interface TreeNode {
21
- id: string
22
- parentId: string
23
- label: string
24
- expanded: boolean
25
- type: nodeType
26
- loading: boolean
27
- children?: TreeNode[]
28
- [key: string]: any // 允许其他自定义属性
29
- }
30
-
31
- export type nodeType = 'branch' | 'leaf' | 'root'
32
- export function useTreeControlInit(sourceId: string, Zpaging?: any) {
33
- const treeConfig = ref<TreeConfig>({
34
- id: '',
35
- title: '',
36
- rootGtmplId: '',
37
- rootLTmplConfig: {
38
- id: '',
39
- columns: [],
40
- primaryColumn: {
41
- controlType: '',
42
- extControlType: '',
43
- sourceId: '',
44
- mstrucId: '',
45
- },
46
- primaryCriteria: {
47
- hidden: false,
48
- controlType: '',
49
- extControlType: '',
50
- sourceId: '',
51
- mstrucId: '',
52
- disabled: false,
53
- defaultValue: '',
54
- transDefaultValue: '',
55
- required: false,
56
- },
57
- secondColumn: {
58
- controlType: '',
59
- extControlType: '',
60
- sourceId: '',
61
- mstrucId: '',
62
- },
63
- criterias: [],
64
- buttons: [],
65
- fields: [],
66
- title: '',
67
- type: '',
68
- pointSourceId: '',
69
- mstrucId: '',
70
- relationNames: [],
71
- readOnly: false,
72
- displayConfig: [],
73
- },
74
- })
75
-
76
- const treeData = ref<TreeNode[]>([])
77
-
78
- // 获取树根节点配置
79
- const getRootLTmplConfig = async (rootGtmplId: string) => {
80
- try {
81
- const res = await pageConfig(rootGtmplId)
82
- treeConfig.value.rootLTmplConfig = res.ltmplConfig
83
- }
84
- catch (err) {
85
- console.log(err)
86
- }
87
- }
88
-
89
- // 获取树分支节点配置
90
- const getBranchLTmplConfig = async (branchRatmplId: string) => {
91
- try {
92
- const res = await pageConfig(branchRatmplId)
93
- treeConfig.value.branchLTmplConfig = res.ltmplConfig
94
- }
95
- catch (err) {
96
- console.log(err)
97
- }
98
- }
99
-
100
- // 获取树叶子节点配置
101
- const getLeafLTmplConfig = async (leafRatmplId: string) => {
102
- try {
103
- const res = await pageConfig(leafRatmplId)
104
- treeConfig.value.leafLTmplConfig = res.ltmplConfig
105
- }
106
- catch (err) {
107
- console.log(err)
108
- }
109
- }
110
- // 获取树结构数据
111
- const getTreeConfig = async () => {
112
- try {
113
- const res = await treeConfigApi(sourceId)
114
- treeConfig.value.leafRatmplId = res.ttmplConfig.leafRatmplId
115
- treeConfig.value.leafTitle = res.ttmplConfig.leafTitle
116
- treeConfig.value.branchRatmplId = res.ttmplConfig.branchRatmplId
117
- treeConfig.value.branchTitle = res.ttmplConfig.branchTitle
118
- treeConfig.value.rootGtmplId = res.ttmplConfig.rootGtmplId
119
- treeConfig.value.id = res.ttmplConfig.id
120
- treeConfig.value.title = res.ttmplConfig.title
121
- if (res.ttmplConfig.rootGtmplId) {
122
- getRootLTmplConfig(res.ttmplConfig.rootGtmplId)
123
- }
124
- if (res.ttmplConfig.leafRatmplId) {
125
- getLeafLTmplConfig(res.ttmplConfig.leafRatmplId)
126
- }
127
- if (res.ttmplConfig.branchRatmplId) {
128
- getBranchLTmplConfig(res.ttmplConfig.branchRatmplId)
129
- }
130
- }
131
- catch (err) {
132
- console.log(err)
133
- }
134
- }
135
-
136
- onMounted(() => {
137
- getTreeConfig()
138
- })
139
-
140
- // 根据id找到树节点插入数据,appendData为要追加的数据
141
-
142
- async function findTreeNodeandAppend(id: string, arr: TreeNode[], appendData: any, type: nodeType) {
143
- for (let index = 0; index < arr.length; index++) {
144
- const element = arr[index]
145
- if (element.id === id) {
146
- if (type === 'branch' && treeConfig.value.branchLTmplConfig) {
147
- // children有值追加分支节点,没值就赋值
148
- if (element.children) {
149
- const arr = appendData.map((item: any) => {
150
- return {
151
- id: item.code,
152
- parentId: element.id,
153
- label: item.fieldMap[type === 'branch' && treeConfig.value.branchLTmplConfig ? treeConfig.value.branchLTmplConfig.primaryColumn.sourceId : ''],
154
- expanded: false,
155
- type: 'branch',
156
- loading: false,
157
- children: [],
158
- }
159
- })
160
-
161
- const arr2 = findDifferentElements(element.children, arr, 'id')
162
-
163
- element.children = [...element.children, ...arr2]
164
- }
165
- else {
166
- element.children = appendData.map((item: any) => {
167
- return {
168
- id: item.code,
169
- parentId: element.id,
170
- label: item.fieldMap[type === 'branch' && treeConfig.value.branchLTmplConfig ? treeConfig.value.branchLTmplConfig.primaryColumn.sourceId : ''],
171
- expanded: false,
172
- type: 'branch',
173
- loading: false,
174
- children: [],
175
- }
176
- })
177
- }
178
- }
179
- if (type === 'leaf' && treeConfig.value.leafLTmplConfig) {
180
- // children有值追加页子节点,没值就赋值
181
- if (element.children) {
182
- const arr = appendData.map((item: any) => {
183
- return {
184
- id: item.code,
185
- parentId: element.id,
186
- label: item.fieldMap[type === 'leaf' && treeConfig.value.leafLTmplConfig ? treeConfig.value.leafLTmplConfig.primaryColumn.sourceId : ''],
187
- expanded: false,
188
- type: 'leaf',
189
- loading: false,
190
- children: [],
191
- }
192
- })
193
-
194
- const arr2 = findDifferentElements(element.children, arr, 'id')
195
- element.children = [...element.children, ...arr2]
196
- }
197
- else {
198
- element.children = appendData.map((item: any) => {
199
- return {
200
- id: item.code,
201
- parentId: element.id,
202
- label: item.fieldMap[type === 'leaf' && treeConfig.value.leafLTmplConfig ? treeConfig.value.leafLTmplConfig.primaryColumn.sourceId : ''],
203
- expanded: false,
204
- type: 'leaf',
205
- loading: false,
206
- children: [],
207
- }
208
- })
209
- }
210
- }
211
- }
212
- else {
213
- if (element.children)
214
- findTreeNodeandAppend(id, element.children, appendData, type)
215
- }
216
- }
217
- }
218
-
219
- // 获取树顶层数据
220
- async function getTreeRootData(id: string) {
221
- try {
222
- const res = await treeDataApi(id)
223
- treeData.value = res.entities.map((item: any) => {
224
- return {
225
- id: item.code,
226
- parentId: '',
227
- label: item.fieldMap[treeConfig.value.rootLTmplConfig.primaryColumn.sourceId],
228
- expanded: false,
229
- type: 'root',
230
- loading: false,
231
- children: [],
232
- }
233
- })
234
- if (Zpaging) {
235
- Zpaging.value.complete(treeData.value)
236
- }
237
- }
238
- catch (error) {
239
- console.log('error:', error)
240
- // TODO handle the exception
241
- }
242
- finally {
243
- close()
244
- }
245
- }
246
-
247
- // 获取树分支节点数据
248
- async function getTreeNodeData(node: TreeNode) {
249
- // 如果是叶子节点则不请求
250
- if (node.type === 'leaf')
251
- return
252
- try {
253
- if (treeConfig.value.branchRatmplId) {
254
- const res = await treeNodeDataApi(treeConfig.value.branchRatmplId, node.id)
255
- if (res.entities.length > 0) {
256
- // 追加分支节点
257
- findTreeNodeandAppend(node.id, treeData.value, res.entities, 'branch')
258
- }
259
- }
260
-
261
- if (treeConfig.value.leafRatmplId) {
262
- const res = await treeNodeDataApi(treeConfig.value.leafRatmplId, node.id)
263
- if (res.entities.length > 0) {
264
- // 追加叶子节点
265
- findTreeNodeandAppend(node.id, treeData.value, res.entities, 'leaf')
266
- }
267
- }
268
- }
269
- catch (error) {
270
- console.log('error:', error)
271
- }
272
- }
273
-
274
- // 根据id查找树节点,展开该节点和请求该节点的子节点
275
- async function findTreeNodeandExpand(node: TreeNode, nodes: TreeNode[], triggerType = 'click') {
276
- for (let index = 0; index < nodes.length; index++) {
277
- const element = nodes[index]
278
- if (element.id === node.id) {
279
- if (triggerType === 'click') {
280
- element.expanded = !element.expanded
281
- }
282
- if (element.expanded) {
283
- element.loading = true
284
- await getTreeNodeData(node)
285
- element.loading = false
286
- }
287
- break
288
- }
289
- else {
290
- if (element.children) {
291
- findTreeNodeandExpand(node, element.children, triggerType)
292
- }
293
- }
294
- }
295
- }
296
-
297
- return {
298
- treeConfig,
299
- treeData,
300
- findTreeNodeandExpand,
301
- getTreeNodeData,
302
- getTreeRootData,
303
- }
304
- }
305
-
306
- /**
307
- * 判断两个数组中是否存在具有相同 id 的元素
308
- * @param arr1 第一个数组
309
- * @param arr2 第二个数组
310
- * @param key 用于比较的属性名,默认为 'id'
311
- * @returns 存在相同 id 返回 true,否则返回 false
312
- */
313
- export function hasSameIdElement<T extends Record<string, any>>(
314
- arr1: T[],
315
- arr2: T[],
316
- key: keyof T = 'id',
317
- ): boolean {
318
- const idSet = new Set(arr2.map(item => item[key]))
319
-
320
- for (const item of arr1) {
321
- if (idSet.has(item.id)) {
322
- return true
323
- }
324
- }
325
-
326
- return false
327
- }
328
-
329
- /**
330
- * 找出两个数组中第二个数组不同id的元素合集
331
- * @param arr1 第一个数组
332
- * @param arr2 第二个数组
333
- * @param idKey id属性的键名,默认为'id'
334
- * @returns 第二个数组中存在但第一个数组中不存在的元素
335
- */
336
- function findDifferentElements<T extends Record<string, any>>(
337
- arr1: T[],
338
- arr2: T[],
339
- idKey: string = 'id',
340
- ): T[] {
341
- // 获取第一个数组中存在但第二个数组中不存在的元素
342
- // const inArr1NotInArr2 = arr1.filter(item1 =>
343
- // !arr2.some(item2 => item2[idKey] === item1[idKey])
344
- // );
345
-
346
- // 获取第二个数组中存在但第一个数组中不存在的元素
347
- const inArr2NotInArr1 = arr2.filter(item2 =>
348
- !arr1.some(item1 => item1[idKey] === item2[idKey]),
349
- )
350
-
351
- // 合并两个结果数组
352
- return [...inArr2NotInArr1]
353
- }
1
+ // tree组件的请求控制逻辑
2
+ import { onMounted, ref } from 'vue'
3
+ import { treeConfigApi, treeDataApi, treeNodeDataApi } from '../api/tree'
4
+ import { pageConfig } from '../api/page'
5
+ import type { Config } from '../type'
6
+
7
+ export interface TreeConfig {
8
+ leafRatmplId?: string // 叶子节点ID
9
+ leafTitle?: string // 叶子节点标题
10
+ branchRatmplId?: string // 分支节点ID
11
+ branchTitle?: string // 分支节点标题
12
+ rootGtmplId: string // 根节ID
13
+ id: string // 树ID
14
+ title: string // 树标题
15
+ rootLTmplConfig: Config
16
+ branchLTmplConfig?: Config
17
+ leafLTmplConfig?: Config
18
+ }
19
+
20
+ export interface TreeNode {
21
+ id: string
22
+ parentId: string
23
+ label: string
24
+ expanded: boolean
25
+ type: nodeType
26
+ loading: boolean
27
+ children?: TreeNode[]
28
+ [key: string]: any // 允许其他自定义属性
29
+ }
30
+
31
+ export type nodeType = 'branch' | 'leaf' | 'root'
32
+ export function useTreeControlInit(sourceId: string, Zpaging?: any) {
33
+ const treeConfig = ref<TreeConfig>({
34
+ id: '',
35
+ title: '',
36
+ rootGtmplId: '',
37
+ rootLTmplConfig: {
38
+ id: '',
39
+ columns: [],
40
+ primaryColumn: {
41
+ controlType: '',
42
+ extControlType: '',
43
+ sourceId: '',
44
+ mstrucId: '',
45
+ },
46
+ primaryCriterion: {
47
+ hidden: false,
48
+ controlType: '',
49
+ extControlType: '',
50
+ sourceId: '',
51
+ mstrucId: '',
52
+ disabled: false,
53
+ defaultValue: '',
54
+ transDefaultValue: '',
55
+ required: false,
56
+ },
57
+ secondColumn: {
58
+ controlType: '',
59
+ extControlType: '',
60
+ sourceId: '',
61
+ mstrucId: '',
62
+ },
63
+ criteria: [],
64
+ buttons: [],
65
+ fields: [],
66
+ title: '',
67
+ type: '',
68
+ pointSourceId: '',
69
+ mstrucId: '',
70
+ relationNames: [],
71
+ readOnly: false,
72
+ displayConfig: [],
73
+ },
74
+ })
75
+
76
+ const treeData = ref<TreeNode[]>([])
77
+
78
+ // 获取树根节点配置
79
+ const getRootLTmplConfig = async (rootGtmplId: string) => {
80
+ try {
81
+ const res = await pageConfig(rootGtmplId)
82
+ treeConfig.value.rootLTmplConfig = res.ltmplConfig
83
+ }
84
+ catch (err) {
85
+ console.log(err)
86
+ }
87
+ }
88
+
89
+ // 获取树分支节点配置
90
+ const getBranchLTmplConfig = async (branchRatmplId: string) => {
91
+ try {
92
+ const res = await pageConfig(branchRatmplId)
93
+ treeConfig.value.branchLTmplConfig = res.ltmplConfig
94
+ }
95
+ catch (err) {
96
+ console.log(err)
97
+ }
98
+ }
99
+
100
+ // 获取树叶子节点配置
101
+ const getLeafLTmplConfig = async (leafRatmplId: string) => {
102
+ try {
103
+ const res = await pageConfig(leafRatmplId)
104
+ treeConfig.value.leafLTmplConfig = res.ltmplConfig
105
+ }
106
+ catch (err) {
107
+ console.log(err)
108
+ }
109
+ }
110
+ // 获取树结构数据
111
+ const getTreeConfig = async () => {
112
+ try {
113
+ const res = await treeConfigApi(sourceId)
114
+ treeConfig.value.leafRatmplId = res.ttmplConfig.leafRatmplId
115
+ treeConfig.value.leafTitle = res.ttmplConfig.leafTitle
116
+ treeConfig.value.branchRatmplId = res.ttmplConfig.branchRatmplId
117
+ treeConfig.value.branchTitle = res.ttmplConfig.branchTitle
118
+ treeConfig.value.rootGtmplId = res.ttmplConfig.rootGtmplId
119
+ treeConfig.value.id = res.ttmplConfig.id
120
+ treeConfig.value.title = res.ttmplConfig.title
121
+ if (res.ttmplConfig.rootGtmplId) {
122
+ getRootLTmplConfig(res.ttmplConfig.rootGtmplId)
123
+ }
124
+ if (res.ttmplConfig.leafRatmplId) {
125
+ getLeafLTmplConfig(res.ttmplConfig.leafRatmplId)
126
+ }
127
+ if (res.ttmplConfig.branchRatmplId) {
128
+ getBranchLTmplConfig(res.ttmplConfig.branchRatmplId)
129
+ }
130
+ }
131
+ catch (err) {
132
+ console.log(err)
133
+ }
134
+ }
135
+
136
+ onMounted(() => {
137
+ getTreeConfig()
138
+ })
139
+
140
+ // 根据id找到树节点插入数据,appendData为要追加的数据
141
+
142
+ async function findTreeNodeandAppend(id: string, arr: TreeNode[], appendData: any, type: nodeType) {
143
+ for (let index = 0; index < arr.length; index++) {
144
+ const element = arr[index]
145
+ if (element.id === id) {
146
+ if (type === 'branch' && treeConfig.value.branchLTmplConfig) {
147
+ // children有值追加分支节点,没值就赋值
148
+ if (element.children) {
149
+ const arr = appendData.map((item: any) => {
150
+ return {
151
+ id: item.code,
152
+ parentId: element.id,
153
+ label: item.fieldMap[type === 'branch' && treeConfig.value.branchLTmplConfig ? treeConfig.value.branchLTmplConfig.primaryColumn.sourceId : ''],
154
+ expanded: false,
155
+ type: 'branch',
156
+ loading: false,
157
+ children: [],
158
+ }
159
+ })
160
+
161
+ const arr2 = findDifferentElements(element.children, arr, 'id')
162
+
163
+ element.children = [...element.children, ...arr2]
164
+ }
165
+ else {
166
+ element.children = appendData.map((item: any) => {
167
+ return {
168
+ id: item.code,
169
+ parentId: element.id,
170
+ label: item.fieldMap[type === 'branch' && treeConfig.value.branchLTmplConfig ? treeConfig.value.branchLTmplConfig.primaryColumn.sourceId : ''],
171
+ expanded: false,
172
+ type: 'branch',
173
+ loading: false,
174
+ children: [],
175
+ }
176
+ })
177
+ }
178
+ }
179
+ if (type === 'leaf' && treeConfig.value.leafLTmplConfig) {
180
+ // children有值追加页子节点,没值就赋值
181
+ if (element.children) {
182
+ const arr = appendData.map((item: any) => {
183
+ return {
184
+ id: item.code,
185
+ parentId: element.id,
186
+ label: item.fieldMap[type === 'leaf' && treeConfig.value.leafLTmplConfig ? treeConfig.value.leafLTmplConfig.primaryColumn.sourceId : ''],
187
+ expanded: false,
188
+ type: 'leaf',
189
+ loading: false,
190
+ children: [],
191
+ }
192
+ })
193
+
194
+ const arr2 = findDifferentElements(element.children, arr, 'id')
195
+ element.children = [...element.children, ...arr2]
196
+ }
197
+ else {
198
+ element.children = appendData.map((item: any) => {
199
+ return {
200
+ id: item.code,
201
+ parentId: element.id,
202
+ label: item.fieldMap[type === 'leaf' && treeConfig.value.leafLTmplConfig ? treeConfig.value.leafLTmplConfig.primaryColumn.sourceId : ''],
203
+ expanded: false,
204
+ type: 'leaf',
205
+ loading: false,
206
+ children: [],
207
+ }
208
+ })
209
+ }
210
+ }
211
+ }
212
+ else {
213
+ if (element.children)
214
+ findTreeNodeandAppend(id, element.children, appendData, type)
215
+ }
216
+ }
217
+ }
218
+
219
+ // 获取树顶层数据
220
+ async function getTreeRootData(id: string) {
221
+ try {
222
+ const res = await treeDataApi(id)
223
+ treeData.value = res.entities.map((item: any) => {
224
+ return {
225
+ id: item.code,
226
+ parentId: '',
227
+ label: item.fieldMap[treeConfig.value.rootLTmplConfig.primaryColumn.sourceId],
228
+ expanded: false,
229
+ type: 'root',
230
+ loading: false,
231
+ children: [],
232
+ }
233
+ })
234
+ if (Zpaging) {
235
+ Zpaging.value.complete(treeData.value)
236
+ }
237
+ }
238
+ catch (error) {
239
+ console.log('error:', error)
240
+ // TODO handle the exception
241
+ }
242
+ finally {
243
+ close()
244
+ }
245
+ }
246
+
247
+ // 获取树分支节点数据
248
+ async function getTreeNodeData(node: TreeNode) {
249
+ // 如果是叶子节点则不请求
250
+ if (node.type === 'leaf')
251
+ return
252
+ try {
253
+ if (treeConfig.value.branchRatmplId) {
254
+ const res = await treeNodeDataApi(treeConfig.value.branchRatmplId, node.id)
255
+ if (res.entities.length > 0) {
256
+ // 追加分支节点
257
+ findTreeNodeandAppend(node.id, treeData.value, res.entities, 'branch')
258
+ }
259
+ }
260
+
261
+ if (treeConfig.value.leafRatmplId) {
262
+ const res = await treeNodeDataApi(treeConfig.value.leafRatmplId, node.id)
263
+ if (res.entities.length > 0) {
264
+ // 追加叶子节点
265
+ findTreeNodeandAppend(node.id, treeData.value, res.entities, 'leaf')
266
+ }
267
+ }
268
+ }
269
+ catch (error) {
270
+ console.log('error:', error)
271
+ }
272
+ }
273
+
274
+ // 根据id查找树节点,展开该节点和请求该节点的子节点
275
+ async function findTreeNodeandExpand(node: TreeNode, nodes: TreeNode[], triggerType = 'click') {
276
+ for (let index = 0; index < nodes.length; index++) {
277
+ const element = nodes[index]
278
+ if (element.id === node.id) {
279
+ if (triggerType === 'click') {
280
+ element.expanded = !element.expanded
281
+ }
282
+ if (element.expanded) {
283
+ element.loading = true
284
+ await getTreeNodeData(node)
285
+ element.loading = false
286
+ }
287
+ break
288
+ }
289
+ else {
290
+ if (element.children) {
291
+ findTreeNodeandExpand(node, element.children, triggerType)
292
+ }
293
+ }
294
+ }
295
+ }
296
+
297
+ return {
298
+ treeConfig,
299
+ treeData,
300
+ findTreeNodeandExpand,
301
+ getTreeNodeData,
302
+ getTreeRootData,
303
+ }
304
+ }
305
+
306
+ /**
307
+ * 判断两个数组中是否存在具有相同 id 的元素
308
+ * @param arr1 第一个数组
309
+ * @param arr2 第二个数组
310
+ * @param key 用于比较的属性名,默认为 'id'
311
+ * @returns 存在相同 id 返回 true,否则返回 false
312
+ */
313
+ export function hasSameIdElement<T extends Record<string, any>>(
314
+ arr1: T[],
315
+ arr2: T[],
316
+ key: keyof T = 'id',
317
+ ): boolean {
318
+ const idSet = new Set(arr2.map(item => item[key]))
319
+
320
+ for (const item of arr1) {
321
+ if (idSet.has(item.id)) {
322
+ return true
323
+ }
324
+ }
325
+
326
+ return false
327
+ }
328
+
329
+ /**
330
+ * 找出两个数组中第二个数组不同id的元素合集
331
+ * @param arr1 第一个数组
332
+ * @param arr2 第二个数组
333
+ * @param idKey id属性的键名,默认为'id'
334
+ * @returns 第二个数组中存在但第一个数组中不存在的元素
335
+ */
336
+ function findDifferentElements<T extends Record<string, any>>(
337
+ arr1: T[],
338
+ arr2: T[],
339
+ idKey: string = 'id',
340
+ ): T[] {
341
+ // 获取第一个数组中存在但第二个数组中不存在的元素
342
+ // const inArr1NotInArr2 = arr1.filter(item1 =>
343
+ // !arr2.some(item2 => item2[idKey] === item1[idKey])
344
+ // );
345
+
346
+ // 获取第二个数组中存在但第一个数组中不存在的元素
347
+ const inArr2NotInArr1 = arr2.filter(item2 =>
348
+ !arr1.some(item1 => item1[idKey] === item2[idKey]),
349
+ )
350
+
351
+ // 合并两个结果数组
352
+ return [...inArr2NotInArr1]
353
+ }