@vue-ui-kit/ant 1.8.5 → 1.8.7
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/README.md +934 -308
- package/dist/cjs/index.js +1 -1
- package/dist/declarations/antProxy.d.ts +3 -4
- package/dist/es/index.js +11 -12
- package/dist/index.d.ts +8 -0
- package/dist/packages/store/renderStore.d.ts +4 -4
- package/package.json +1 -1
- package/src/declarations/antProxy.ts +15 -10
- package/src/index.ts +7 -8
- package/src/packages/store/renderStore.tsx +125 -118
- package/src/packages/utils/treeHelper.ts +62 -72
|
@@ -4,7 +4,6 @@ import { ColProps } from 'ant-design-vue/lib/grid/Col';
|
|
|
4
4
|
import { FormProps } from 'ant-design-vue/lib/form/Form';
|
|
5
5
|
import { TableColumnType, TableProps, TooltipProps } from 'ant-design-vue';
|
|
6
6
|
import { ButtonType } from 'ant-design-vue/lib/button/buttonTypes';
|
|
7
|
-
import { ComputedRef } from 'vue';
|
|
8
7
|
|
|
9
8
|
export interface CellFuncArg<D = Recordable> {
|
|
10
9
|
row: D;
|
|
@@ -54,8 +53,8 @@ export interface PFormItemProps<F = Recordable> {
|
|
|
54
53
|
title?: string;
|
|
55
54
|
span?: number;
|
|
56
55
|
colon?: boolean;
|
|
57
|
-
labelCol?: ColProps
|
|
58
|
-
wrapperCol?: ColProps
|
|
56
|
+
labelCol?: ColProps;
|
|
57
|
+
wrapperCol?: ColProps;
|
|
59
58
|
forceRequired?: boolean; // 在页面需要必填标示,但field不需要必填校验时使用
|
|
60
59
|
align?: 'left' | 'right' | 'center';
|
|
61
60
|
col?: ColProps;
|
|
@@ -67,9 +66,9 @@ export interface PFormItemProps<F = Recordable> {
|
|
|
67
66
|
default?: (
|
|
68
67
|
{ data, field }: ItemFuncArg<F>,
|
|
69
68
|
passTrigger?: (cusFields?: string | string[]) => void,
|
|
70
|
-
passDelayTrigger?: (cusFields?: string | string[], time?: number) => void
|
|
69
|
+
passDelayTrigger?: (cusFields?: string | string[], time?: number) => void,
|
|
71
70
|
) => any;
|
|
72
|
-
defaultValue?: any
|
|
71
|
+
defaultValue?: any;
|
|
73
72
|
};
|
|
74
73
|
}
|
|
75
74
|
|
|
@@ -151,7 +150,13 @@ export interface ToolbarButtonProps extends PButtonProps {
|
|
|
151
150
|
|
|
152
151
|
export interface ToolbarConfig {
|
|
153
152
|
buttons?: Array<ToolbarButtonProps>;
|
|
154
|
-
tools?: Array<{
|
|
153
|
+
tools?: Array<{
|
|
154
|
+
code: string;
|
|
155
|
+
icon: string;
|
|
156
|
+
type?: ButtonType;
|
|
157
|
+
disabled?: boolean;
|
|
158
|
+
size?: 'small' | 'large' | 'middle';
|
|
159
|
+
}>;
|
|
155
160
|
disabled?: boolean;
|
|
156
161
|
}
|
|
157
162
|
|
|
@@ -167,11 +172,11 @@ export interface ResponsePathConfig<D = Recordable> {
|
|
|
167
172
|
| ((res: Recordable) => string | { status: string; content: string; icon?: string });
|
|
168
173
|
}
|
|
169
174
|
|
|
170
|
-
|
|
175
|
+
export type HandlerMultiDel = (ids: Array<string | number>) => any;
|
|
171
176
|
|
|
172
177
|
export interface AjaxConfig<F = Recordable> {
|
|
173
178
|
query: (Q: { page?: IPage; form: Partial<F> }) => Promise<Recordable>;
|
|
174
|
-
multiDelete?:
|
|
179
|
+
multiDelete?: HandlerMultiDel;
|
|
175
180
|
}
|
|
176
181
|
|
|
177
182
|
export interface ProxyConfig<D = Recordable, F = Recordable> {
|
|
@@ -195,7 +200,7 @@ export type PGridProps<D = Recordable, F = Recordable> = {
|
|
|
195
200
|
selectConfig?: SelectConfig<D>;
|
|
196
201
|
rowKey?: string;
|
|
197
202
|
manualFetch?: boolean;
|
|
198
|
-
align?: 'left' | 'right' | 'center'
|
|
203
|
+
align?: 'left' | 'right' | 'center';
|
|
199
204
|
formConfig?: PFormProps<F>;
|
|
200
205
|
columns?: ColumnProps<D>[];
|
|
201
206
|
toolbarConfig?: ToolbarConfig;
|
|
@@ -303,7 +308,7 @@ export interface PFormBlockInstance {
|
|
|
303
308
|
$form: Recordable;
|
|
304
309
|
}
|
|
305
310
|
|
|
306
|
-
export interface PFormGroupInstance
|
|
311
|
+
export interface PFormGroupInstance {
|
|
307
312
|
activeKey: number;
|
|
308
313
|
setActiveKey: (activeKey: number) => void;
|
|
309
314
|
validateAll: () => Promise<void>;
|
package/src/index.ts
CHANGED
|
@@ -7,7 +7,6 @@ import PromisePicker from '@/components/PromisePicker.vue';
|
|
|
7
7
|
import { addFormatter } from '@/utils/AFormatters';
|
|
8
8
|
import { addRender } from '@/store/renderStore';
|
|
9
9
|
import { setUIKitConfig, getUIKitConfig, resetUIKitConfig, UIKitConfig } from '@/utils/config';
|
|
10
|
-
import * as utils from '@/utils/core';
|
|
11
10
|
|
|
12
11
|
// 创建setup方法
|
|
13
12
|
function setup(config?: Partial<UIKitConfig>) {
|
|
@@ -30,12 +29,12 @@ export default {
|
|
|
30
29
|
setup,
|
|
31
30
|
};
|
|
32
31
|
|
|
32
|
+
// 导出所有类型
|
|
33
33
|
export * from '#/antProxy';
|
|
34
34
|
export * from '@/utils/core';
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
};
|
|
35
|
+
|
|
36
|
+
// 导出配置方法
|
|
37
|
+
export { setup, setUIKitConfig, getUIKitConfig, resetUIKitConfig, type UIKitConfig };
|
|
38
|
+
|
|
39
|
+
// 直接导出组件,使用户可以直接导入使用
|
|
40
|
+
export { PForm, PGrid, PFormGroup, PGroupBlock, PromisePicker, addFormatter, addRender };
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
} from 'ant-design-vue';
|
|
24
24
|
import { set, isFunction, merge, omit } from 'xe-utils';
|
|
25
25
|
import { ButtonProps } from 'ant-design-vue/lib/button';
|
|
26
|
-
import { isBadValue, isGoodValue,
|
|
26
|
+
import { isBadValue, isGoodValue, valued } from '@/utils/is';
|
|
27
27
|
import TableInput from '@/renders/TableInput.vue';
|
|
28
28
|
import Icon from '@/renders/Icon';
|
|
29
29
|
import { computed } from 'vue';
|
|
@@ -223,184 +223,191 @@ const renders = {
|
|
|
223
223
|
...Object.fromEntries(Object.keys(componentsMap).map((name) => [name, renderBasic(name)])),
|
|
224
224
|
// 简单按钮
|
|
225
225
|
$button: {
|
|
226
|
-
renderItemContent(
|
|
227
|
-
|
|
228
|
-
field,
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
226
|
+
renderItemContent(
|
|
227
|
+
{ props = {}, events = {} }: RenderOptions,
|
|
228
|
+
{ data, field }: RenderFormParams,
|
|
229
|
+
defaultHandler: {
|
|
230
|
+
[key: string]: (...args: any[]) => any;
|
|
231
|
+
},
|
|
232
|
+
) {
|
|
232
233
|
return (
|
|
233
234
|
<Button
|
|
234
235
|
{...omit(props, ['content'])}
|
|
235
236
|
icon={props.icon ? <Icon icon={props.icon} /> : null}
|
|
236
237
|
onClick={() => {
|
|
237
|
-
events.click?.({ data, field })
|
|
238
|
+
events.click?.({ data, field });
|
|
238
239
|
if (props.htmlType === 'reset' && defaultHandler?.reset) {
|
|
239
240
|
if (props.beforeClick && isFunction(props.beforeClick)) {
|
|
240
241
|
props.beforeClick({ data, field }).then((res: void | Recordable) => {
|
|
241
|
-
defaultHandler.reset(res ? { data: res, field } : { data, field })
|
|
242
|
-
})
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
defaultHandler.reset({ data, field })
|
|
242
|
+
defaultHandler.reset(res ? { data: res, field } : { data, field });
|
|
243
|
+
});
|
|
244
|
+
} else {
|
|
245
|
+
defaultHandler.reset({ data, field });
|
|
246
246
|
}
|
|
247
247
|
}
|
|
248
248
|
}}
|
|
249
249
|
>
|
|
250
250
|
{props.content}
|
|
251
|
-
{
|
|
252
|
-
props.suffix?.({ data, field }) ?? null
|
|
253
|
-
}
|
|
251
|
+
{props.suffix?.({ data, field }) ?? null}
|
|
254
252
|
</Button>
|
|
255
|
-
)
|
|
253
|
+
);
|
|
256
254
|
},
|
|
257
|
-
renderDefault(
|
|
258
|
-
|
|
259
|
-
field,
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
255
|
+
renderDefault(
|
|
256
|
+
{ props = {}, events = {} }: RenderOptions,
|
|
257
|
+
{ row, field }: RenderTableParams,
|
|
258
|
+
defaultHandler: {
|
|
259
|
+
[key: string]: (...args: any[]) => any;
|
|
260
|
+
},
|
|
261
|
+
) {
|
|
263
262
|
return (
|
|
264
263
|
<Button
|
|
265
264
|
{...omit(props, ['content'])}
|
|
266
265
|
icon={props.icon ? <Icon icon={props.icon} /> : null}
|
|
267
266
|
onClick={() => {
|
|
268
|
-
events.click?.({ row, field })
|
|
267
|
+
events.click?.({ row, field });
|
|
269
268
|
if (props.htmlType === 'reset' && defaultHandler?.reset) {
|
|
270
269
|
if (props.beforeClick && isFunction(props.beforeClick)) {
|
|
271
|
-
defaultHandler?.setLoadings?.(true)
|
|
272
|
-
props
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
270
|
+
defaultHandler?.setLoadings?.(true);
|
|
271
|
+
props
|
|
272
|
+
.beforeClick({ row, field })
|
|
273
|
+
.then((res: void | Recordable) => {
|
|
274
|
+
defaultHandler.reset(res ? { row: res, field } : { row, field });
|
|
275
|
+
})
|
|
276
|
+
.finally(() => {
|
|
277
|
+
defaultHandler?.setLoadings?.(false);
|
|
278
|
+
});
|
|
279
|
+
} else {
|
|
280
|
+
defaultHandler.reset({ row, field });
|
|
280
281
|
}
|
|
281
282
|
}
|
|
282
283
|
if (props.htmlType === 'pick' && defaultHandler?.pick) {
|
|
283
284
|
if (props.beforeClick && isFunction(props.beforeClick)) {
|
|
284
|
-
defaultHandler?.setLoadings?.(true)
|
|
285
|
-
props
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
285
|
+
defaultHandler?.setLoadings?.(true);
|
|
286
|
+
props
|
|
287
|
+
.beforeClick({ row, field })
|
|
288
|
+
.then((res: void | Recordable) => {
|
|
289
|
+
defaultHandler.pick(res ? { row: res, field } : { row, field });
|
|
290
|
+
})
|
|
291
|
+
.finally(() => {
|
|
292
|
+
defaultHandler?.setLoadings?.(false);
|
|
293
|
+
});
|
|
294
|
+
} else {
|
|
295
|
+
defaultHandler.pick({ row, field });
|
|
293
296
|
}
|
|
294
297
|
}
|
|
295
298
|
}}
|
|
296
299
|
>
|
|
297
300
|
{props.content}
|
|
298
301
|
</Button>
|
|
299
|
-
)
|
|
302
|
+
);
|
|
300
303
|
},
|
|
301
304
|
},
|
|
302
305
|
// 简单按钮组
|
|
303
306
|
$buttons: {
|
|
304
|
-
renderItemContent(
|
|
305
|
-
|
|
306
|
-
field,
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
307
|
+
renderItemContent(
|
|
308
|
+
{ props = {}, children = [] }: RenderOptions,
|
|
309
|
+
{ data, field }: RenderFormParams,
|
|
310
|
+
defaultHandler: {
|
|
311
|
+
[key: string]: (...args: any[]) => any;
|
|
312
|
+
},
|
|
313
|
+
) {
|
|
310
314
|
return (
|
|
311
315
|
<span class="align-gap-box w-fit">
|
|
312
|
-
{
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
if (
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
else {
|
|
327
|
-
defaultHandler.reset({ data, field })
|
|
328
|
-
}
|
|
316
|
+
{children.map((m) => {
|
|
317
|
+
return (
|
|
318
|
+
<Button
|
|
319
|
+
{...omit(Object.assign({}, props, m.props), ['content'])}
|
|
320
|
+
icon={m.props.icon ? <Icon icon={m.props.icon} /> : null}
|
|
321
|
+
onClick={() => {
|
|
322
|
+
m.events?.click?.({ data, field });
|
|
323
|
+
if (m.props.htmlType === 'reset' && defaultHandler?.reset) {
|
|
324
|
+
if (props.beforeClick && isFunction(props.beforeClick)) {
|
|
325
|
+
props.beforeClick({ data, field }).then((res: void | Recordable) => {
|
|
326
|
+
defaultHandler.reset(res ? { data: res, field } : { data, field });
|
|
327
|
+
});
|
|
328
|
+
} else {
|
|
329
|
+
defaultHandler.reset({ data, field });
|
|
329
330
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
})
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
}
|
|
331
|
+
}
|
|
332
|
+
if (m.props.htmlType === 'pick' && defaultHandler?.pick) {
|
|
333
|
+
if (props.beforeClick && isFunction(props.beforeClick)) {
|
|
334
|
+
props.beforeClick({ data, field }).then((res: void | Recordable) => {
|
|
335
|
+
defaultHandler.pick(res ? { data: res, field } : { data, field });
|
|
336
|
+
});
|
|
337
|
+
} else {
|
|
338
|
+
defaultHandler.pick({ data, field });
|
|
339
339
|
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}
|
|
340
|
+
}
|
|
341
|
+
}}
|
|
342
|
+
>
|
|
343
|
+
{m.props.content}
|
|
344
|
+
</Button>
|
|
345
|
+
);
|
|
346
|
+
})}
|
|
347
347
|
</span>
|
|
348
|
-
)
|
|
348
|
+
);
|
|
349
349
|
},
|
|
350
|
-
renderDefault(
|
|
351
|
-
|
|
352
|
-
row,
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
350
|
+
renderDefault(
|
|
351
|
+
{ props = {}, children = [] }: RenderOptions,
|
|
352
|
+
{ data, row, field }: RenderTableParams,
|
|
353
|
+
defaultHandler: {
|
|
354
|
+
[key: string]: (...args: any[]) => any;
|
|
355
|
+
},
|
|
356
|
+
) {
|
|
357
357
|
return (
|
|
358
358
|
<span class="align-gap-box w-fit">
|
|
359
|
-
{
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
359
|
+
{children
|
|
360
|
+
.filter(
|
|
361
|
+
(f) =>
|
|
362
|
+
!f?.props?.hiddenIf?.({
|
|
363
|
+
data,
|
|
364
|
+
row,
|
|
365
|
+
field,
|
|
366
|
+
}),
|
|
367
|
+
)
|
|
368
|
+
.map((m) => (
|
|
365
369
|
<Button
|
|
366
370
|
{...omit(Object.assign({}, props, m.props), ['content', 'hiddenIf'])}
|
|
367
371
|
icon={m.props.icon ? <Icon icon={m.props.icon} /> : null}
|
|
368
372
|
onClick={() => {
|
|
369
|
-
m.events?.click?.({ data, row, field })
|
|
373
|
+
m.events?.click?.({ data, row, field });
|
|
370
374
|
if (m.props.htmlType === 'reset' && defaultHandler?.reset) {
|
|
371
375
|
if (props.beforeClick && isFunction(props.beforeClick)) {
|
|
372
|
-
defaultHandler?.setLoadings?.(true)
|
|
373
|
-
props
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
376
|
+
defaultHandler?.setLoadings?.(true);
|
|
377
|
+
props
|
|
378
|
+
.beforeClick({ row, field })
|
|
379
|
+
.then((res: void | Recordable) => {
|
|
380
|
+
defaultHandler.reset(res ? { row: res, field } : { row, field });
|
|
381
|
+
})
|
|
382
|
+
.finally(() => {
|
|
383
|
+
defaultHandler?.setLoadings?.(false);
|
|
384
|
+
});
|
|
385
|
+
} else {
|
|
386
|
+
defaultHandler.reset({ row, field });
|
|
381
387
|
}
|
|
382
388
|
}
|
|
383
389
|
if (m.props.htmlType === 'pick' && defaultHandler?.pick) {
|
|
384
390
|
if (props.beforeClick && isFunction(props.beforeClick)) {
|
|
385
|
-
defaultHandler?.setLoadings?.(true)
|
|
386
|
-
props
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
391
|
+
defaultHandler?.setLoadings?.(true);
|
|
392
|
+
props
|
|
393
|
+
.beforeClick({ row, field })
|
|
394
|
+
.then((res: void | Recordable) => {
|
|
395
|
+
defaultHandler.pick(res ? { row: res, field } : { row, field });
|
|
396
|
+
})
|
|
397
|
+
.finally(() => {
|
|
398
|
+
defaultHandler?.setLoadings?.(false);
|
|
399
|
+
});
|
|
400
|
+
} else {
|
|
401
|
+
defaultHandler.pick({ row, field });
|
|
394
402
|
}
|
|
395
403
|
}
|
|
396
404
|
}}
|
|
397
405
|
>
|
|
398
406
|
{m.props.content}
|
|
399
407
|
</Button>
|
|
400
|
-
))
|
|
401
|
-
}
|
|
408
|
+
))}
|
|
402
409
|
</span>
|
|
403
|
-
)
|
|
410
|
+
);
|
|
404
411
|
},
|
|
405
412
|
},
|
|
406
413
|
ButtonTree: {
|
|
@@ -1,72 +1,62 @@
|
|
|
1
|
-
interface TreeConfig {
|
|
2
|
-
children?: string;
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
type TreeDefaultHandler<T> = (
|
|
6
|
-
arent: null | ITreeAble<T>,
|
|
7
|
-
parent: ITreeAble<T>[],
|
|
8
|
-
treeData: (
|
|
9
|
-
item: T | ITreeAble<T>,
|
|
10
|
-
index?: number,
|
|
11
|
-
treeData?: ITreeAble<T>[],
|
|
12
|
-
paths?: string[],
|
|
13
|
-
parent?: null | ITreeAble<T>,
|
|
14
|
-
nodes?: Array<T | ITreeAble<T>>,
|
|
15
|
-
) => any,
|
|
16
|
-
iterate: any,
|
|
17
|
-
context: string[],
|
|
18
|
-
path: Array<T | ITreeAble<T>>,
|
|
19
|
-
node: string,
|
|
20
|
-
parseChildren: TreeConfig,
|
|
21
|
-
) => any;
|
|
22
|
-
|
|
23
|
-
const helperCreateTreeFunc = <T extends Recordable>(handle: TreeDefaultHandler<T>) => {
|
|
24
|
-
return function (
|
|
25
|
-
treeData: ITreeAble<T>[],
|
|
26
|
-
iterate: (item: T | ITreeAble<T>) => any,
|
|
27
|
-
options?: TreeConfig,
|
|
28
|
-
context?: any,
|
|
29
|
-
) {
|
|
30
|
-
const opts = options || {};
|
|
31
|
-
const optChildren = opts.children || 'children';
|
|
32
|
-
return handle(null, treeData, iterate, context, [], [], optChildren, opts);
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
const eachTreeItem = <T extends Recordable>(
|
|
36
|
-
parent: null | ITreeAble<T>,
|
|
37
|
-
treeData: ITreeAble<T>[],
|
|
38
|
-
iterate: (
|
|
39
|
-
item: T | ITreeAble<T>,
|
|
40
|
-
index?: number,
|
|
41
|
-
treeData?: ITreeAble<T>[],
|
|
42
|
-
paths?: string[],
|
|
43
|
-
parent?: null | ITreeAble<T>,
|
|
44
|
-
nodes?: Array<T | ITreeAble<T>>,
|
|
45
|
-
) => any,
|
|
46
|
-
context: any,
|
|
47
|
-
path: string[],
|
|
48
|
-
node: Array<T | ITreeAble<T>>,
|
|
49
|
-
parseChildren: string,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
context,
|
|
64
|
-
paths,
|
|
65
|
-
nodes,
|
|
66
|
-
parseChildren,
|
|
67
|
-
opts,
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
export const eachTree = helperCreateTreeFunc(eachTreeItem);
|
|
1
|
+
interface TreeConfig {
|
|
2
|
+
children?: string;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
type TreeDefaultHandler<T> = (
|
|
6
|
+
arent: null | ITreeAble<T>,
|
|
7
|
+
parent: ITreeAble<T>[],
|
|
8
|
+
treeData: (
|
|
9
|
+
item: T | ITreeAble<T>,
|
|
10
|
+
index?: number,
|
|
11
|
+
treeData?: ITreeAble<T>[],
|
|
12
|
+
paths?: string[],
|
|
13
|
+
parent?: null | ITreeAble<T>,
|
|
14
|
+
nodes?: Array<T | ITreeAble<T>>,
|
|
15
|
+
) => any,
|
|
16
|
+
iterate: any,
|
|
17
|
+
context: string[],
|
|
18
|
+
path: Array<T | ITreeAble<T>>,
|
|
19
|
+
node: string,
|
|
20
|
+
parseChildren: TreeConfig,
|
|
21
|
+
) => any;
|
|
22
|
+
|
|
23
|
+
const helperCreateTreeFunc = <T extends Recordable>(handle: TreeDefaultHandler<T>) => {
|
|
24
|
+
return function (
|
|
25
|
+
treeData: ITreeAble<T>[],
|
|
26
|
+
iterate: (item: T | ITreeAble<T>) => any,
|
|
27
|
+
options?: TreeConfig,
|
|
28
|
+
context?: any,
|
|
29
|
+
) {
|
|
30
|
+
const opts = options || {};
|
|
31
|
+
const optChildren = opts.children || 'children';
|
|
32
|
+
return handle(null, treeData, iterate, context, [], [], optChildren, opts);
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const eachTreeItem = <T extends Recordable>(
|
|
36
|
+
parent: null | ITreeAble<T>,
|
|
37
|
+
treeData: ITreeAble<T>[],
|
|
38
|
+
iterate: (
|
|
39
|
+
item: T | ITreeAble<T>,
|
|
40
|
+
index?: number,
|
|
41
|
+
treeData?: ITreeAble<T>[],
|
|
42
|
+
paths?: string[],
|
|
43
|
+
parent?: null | ITreeAble<T>,
|
|
44
|
+
nodes?: Array<T | ITreeAble<T>>,
|
|
45
|
+
) => any,
|
|
46
|
+
context: any,
|
|
47
|
+
path: string[],
|
|
48
|
+
node: Array<T | ITreeAble<T>>,
|
|
49
|
+
parseChildren: string,
|
|
50
|
+
) => {
|
|
51
|
+
let paths: string[], nodes: Array<T | ITreeAble<T>>;
|
|
52
|
+
treeData.forEach((item, index) => {
|
|
53
|
+
paths = path.concat(['' + index]);
|
|
54
|
+
nodes = node.concat([item]);
|
|
55
|
+
iterate.call(context, item, index, treeData, paths, parent, nodes);
|
|
56
|
+
if (item && parseChildren) {
|
|
57
|
+
paths.push(parseChildren);
|
|
58
|
+
eachTreeItem(item, item[parseChildren] || [], iterate, context, paths, nodes, parseChildren);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
export const eachTree = helperCreateTreeFunc(eachTreeItem);
|