@vue-ui-kit/ant 1.4.0 → 1.5.0
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/dist/cjs/index.js +1 -1
- package/dist/declarations/antProxy.d.ts +3 -1
- package/dist/es/index.js +1085 -1058
- package/dist/packages/components/PGrid.vue.d.ts +54 -15
- package/dist/packages/utils/is.d.ts +2 -0
- package/package.json +1 -1
- package/src/declarations/antProxy.ts +3 -1
- package/src/packages/components/PForm.vue +5 -2
- package/src/packages/components/PGrid.vue +62 -15
- package/src/packages/store/renderStore.tsx +3 -3
- package/src/packages/utils/is.ts +2 -0
|
@@ -1,20 +1,40 @@
|
|
|
1
1
|
import { PGridProps } from '../../declarations/antProxy';
|
|
2
2
|
declare const _default: <D = Recordable<any>, F = Recordable<any>>(__VLS_props: NonNullable<Awaited<typeof __VLS_setup>>["props"], __VLS_ctx?: __VLS_Prettify<Pick<NonNullable<Awaited<typeof __VLS_setup>>, "attrs" | "emit" | "slots">>, __VLS_expose?: NonNullable<Awaited<typeof __VLS_setup>>["expose"], __VLS_setup?: Promise<{
|
|
3
3
|
props: __VLS_Prettify<Pick<Partial<{}> & Omit<{
|
|
4
|
-
readonly
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
readonly onToolbarButtonClick?: ((
|
|
9
|
-
|
|
4
|
+
readonly onPick?: ((data: {
|
|
5
|
+
row: D;
|
|
6
|
+
field: string;
|
|
7
|
+
}) => any) | undefined;
|
|
8
|
+
readonly onToolbarButtonClick?: ((data: {
|
|
9
|
+
data: D[];
|
|
10
|
+
code: string;
|
|
11
|
+
selectedKeys: Array<string | number>;
|
|
12
|
+
records: D[];
|
|
13
|
+
}) => any) | undefined;
|
|
14
|
+
readonly onToolbarToolClick?: ((data: {
|
|
15
|
+
data: D[];
|
|
16
|
+
code: string;
|
|
17
|
+
selectedKeys: Array<string | number>;
|
|
18
|
+
records: D[];
|
|
19
|
+
}) => any) | undefined;
|
|
10
20
|
} & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps & Readonly<{}> & Readonly<{
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
onToolbarButtonClick?: ((
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
onPick?: ((data: {
|
|
22
|
+
row: D;
|
|
23
|
+
field: string;
|
|
24
|
+
}) => any) | undefined;
|
|
25
|
+
onToolbarButtonClick?: ((data: {
|
|
26
|
+
data: D[];
|
|
27
|
+
code: string;
|
|
28
|
+
selectedKeys: Array<string | number>;
|
|
29
|
+
records: D[];
|
|
30
|
+
}) => any) | undefined;
|
|
31
|
+
onToolbarToolClick?: ((data: {
|
|
32
|
+
data: D[];
|
|
33
|
+
code: string;
|
|
34
|
+
selectedKeys: Array<string | number>;
|
|
35
|
+
records: D[];
|
|
36
|
+
}) => any) | undefined;
|
|
37
|
+
}>, never>, "onPick" | "onToolbarButtonClick" | "onToolbarToolClick"> & PGridProps<D, F>> & import('vue').PublicProps;
|
|
18
38
|
expose(exposed: import('vue').ShallowUnwrapRef<{
|
|
19
39
|
commitProxy: {
|
|
20
40
|
query: import('lodash').DebouncedFunc<() => Promise<D[]>>;
|
|
@@ -23,13 +43,32 @@ declare const _default: <D = Recordable<any>, F = Recordable<any>>(__VLS_props:
|
|
|
23
43
|
passQuery: (params: Partial<F>, lazy?: boolean) => Promise<void> | Promise<D[]> | undefined;
|
|
24
44
|
};
|
|
25
45
|
$table: import('vue').ComputedRef<any>;
|
|
26
|
-
selectedRowKeys: import('vue').ComputedRef<string
|
|
46
|
+
selectedRowKeys: import('vue').ComputedRef<(string | number)[]>;
|
|
47
|
+
setBtnLoading: (code: string, value: boolean) => void;
|
|
48
|
+
selectedRecords: import('vue').ComputedRef<D[]>;
|
|
27
49
|
$form: import('vue').ComputedRef<any>;
|
|
28
50
|
setLoadings: (value: boolean) => void;
|
|
29
51
|
}>): void;
|
|
30
52
|
attrs: any;
|
|
31
53
|
slots: ReturnType<() => {}>;
|
|
32
|
-
emit:
|
|
54
|
+
emit: {
|
|
55
|
+
(event: "toolbarButtonClick", data: {
|
|
56
|
+
data: D[];
|
|
57
|
+
code: string;
|
|
58
|
+
selectedKeys: Array<string | number>;
|
|
59
|
+
records: D[];
|
|
60
|
+
}): void;
|
|
61
|
+
(event: "toolbarToolClick", data: {
|
|
62
|
+
data: D[];
|
|
63
|
+
code: string;
|
|
64
|
+
selectedKeys: Array<string | number>;
|
|
65
|
+
records: D[];
|
|
66
|
+
}): void;
|
|
67
|
+
(event: "pick", data: {
|
|
68
|
+
row: D;
|
|
69
|
+
field: string;
|
|
70
|
+
}): void;
|
|
71
|
+
} & {};
|
|
33
72
|
}>) => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
|
|
34
73
|
[key: string]: any;
|
|
35
74
|
}> & {
|
package/package.json
CHANGED
|
@@ -58,6 +58,7 @@ export interface PFormItemProps<F = Recordable> {
|
|
|
58
58
|
itemRender?: ItemRender;
|
|
59
59
|
tooltipConfig?: TooltipConfig;
|
|
60
60
|
slots?: {
|
|
61
|
+
title?: () => any;
|
|
61
62
|
default?: (
|
|
62
63
|
{ data, field }: ItemFuncArg<F>,
|
|
63
64
|
passTrigger?: (cusFields?: string | string[]) => void,
|
|
@@ -153,7 +154,7 @@ export interface ResponsePathConfig<D = Recordable> {
|
|
|
153
154
|
| ((res: Recordable) => string | { status: string; content: string; icon?: string });
|
|
154
155
|
}
|
|
155
156
|
|
|
156
|
-
declare type HandlerMulti = (ids: string
|
|
157
|
+
declare type HandlerMulti = (ids: Array<string | number>) => any;
|
|
157
158
|
|
|
158
159
|
export interface AjaxConfig<F = Recordable> {
|
|
159
160
|
query: (Q: { page?: IPage; form: Partial<F> }) => Promise<Recordable>;
|
|
@@ -257,6 +258,7 @@ export interface PGridInstance<D = Recordable, F = Recordable> {
|
|
|
257
258
|
$table: Recordable;
|
|
258
259
|
$form: Recordable;
|
|
259
260
|
setLoadings: (value: boolean) => void;
|
|
261
|
+
setBtnLoading: (code: string, status: boolean) => void;
|
|
260
262
|
}
|
|
261
263
|
|
|
262
264
|
export interface PFormInstance {
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { v4 as uuid_v4 } from 'uuid';
|
|
6
6
|
import RenderAntItem from '@/components/RenderAntItem';
|
|
7
7
|
import RenderItemSlots from '@/components/RenderItemSlots';
|
|
8
|
-
import { valued } from '@/utils/is';
|
|
8
|
+
import { isGoodValue, valued } from '@/utils/is';
|
|
9
9
|
import { eachTree } from '@/utils/treeHelper';
|
|
10
10
|
import { defaultItemResponsive } from '@/utils/core';
|
|
11
11
|
import {
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
const obj: Partial<F> = {};
|
|
40
40
|
eachTree(items.value, (item) => {
|
|
41
41
|
if (item.field && item.itemRender) {
|
|
42
|
-
if (
|
|
42
|
+
if (isGoodValue(item.itemRender.defaultValue)) {
|
|
43
43
|
obj[item.field] = item.itemRender.defaultValue;
|
|
44
44
|
} else {
|
|
45
45
|
obj[item.field] = undefined;
|
|
@@ -103,6 +103,9 @@
|
|
|
103
103
|
])
|
|
104
104
|
"
|
|
105
105
|
>
|
|
106
|
+
<template v-if="item.slots?.title" #label>
|
|
107
|
+
<component :is="item.slots.title" />
|
|
108
|
+
</template>
|
|
106
109
|
<render-item-slots
|
|
107
110
|
v-if="item.slots?.default"
|
|
108
111
|
:form-data="formData"
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import RenderTitleSlots from '@/components/RenderTitleSlots';
|
|
9
9
|
import RenderDefaultSlots from '@/components/RenderDefaultSlots';
|
|
10
10
|
import { v4 as uuid_v4 } from 'uuid';
|
|
11
|
-
import { valued } from '@/utils/is';
|
|
11
|
+
import { isGoodValue, valued } from '@/utils/is';
|
|
12
12
|
import RenderItemSlots from '@/components/RenderItemSlots';
|
|
13
13
|
import { cleanCol, defaultItemResponsive, defaultLabelCol } from '@/utils/core';
|
|
14
14
|
import Icon from '@/renders/Icon';
|
|
@@ -45,7 +45,8 @@
|
|
|
45
45
|
const submitOnReset = true;
|
|
46
46
|
const boxEl = ref<HTMLDivElement>();
|
|
47
47
|
const renderHeight = ref(500);
|
|
48
|
-
const selectedRowKeys = ref<string
|
|
48
|
+
const selectedRowKeys = ref<Array<string | number>>([]);
|
|
49
|
+
const selectedCaches = ref<D[]>([]);
|
|
49
50
|
const innerToolbarHandler = (code: string) => {
|
|
50
51
|
const { ajax } = proxyConfig.value!;
|
|
51
52
|
switch (code) {
|
|
@@ -69,6 +70,7 @@
|
|
|
69
70
|
.finally(() => {
|
|
70
71
|
loading.table = false;
|
|
71
72
|
loading.toolbar = false;
|
|
73
|
+
codeLoadings.multiDelete = false;
|
|
72
74
|
});
|
|
73
75
|
});
|
|
74
76
|
} else {
|
|
@@ -97,6 +99,21 @@
|
|
|
97
99
|
const refreshForm = () => {
|
|
98
100
|
renderFormKey.value = uuid_v4();
|
|
99
101
|
};
|
|
102
|
+
const codeLoadings = reactive<Record<string, boolean>>(
|
|
103
|
+
[
|
|
104
|
+
...(props.toolbarConfig?.buttons?.map((m) => m.code) ?? []).filter((f) => f),
|
|
105
|
+
...(props.toolbarConfig?.tools?.map((m) => m.code) ?? []).filter((f) => f),
|
|
106
|
+
].reduce(
|
|
107
|
+
(acc, cur) => {
|
|
108
|
+
acc[cur!] = false;
|
|
109
|
+
return acc;
|
|
110
|
+
},
|
|
111
|
+
{} as Record<string, boolean>,
|
|
112
|
+
),
|
|
113
|
+
);
|
|
114
|
+
const setBtnLoading = (code: string, value: boolean) => {
|
|
115
|
+
codeLoadings[code] = value;
|
|
116
|
+
};
|
|
100
117
|
const refreshTable = () => {
|
|
101
118
|
renderTableKey.value = uuid_v4();
|
|
102
119
|
};
|
|
@@ -129,26 +146,41 @@
|
|
|
129
146
|
: 'bad',
|
|
130
147
|
);
|
|
131
148
|
const attrs = useAttrs();
|
|
132
|
-
const emit = defineEmits
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
149
|
+
const emit = defineEmits<{
|
|
150
|
+
(
|
|
151
|
+
event: 'toolbarButtonClick',
|
|
152
|
+
data: { data: D[]; code: string; selectedKeys: Array<string | number>; records: D[] },
|
|
153
|
+
): void;
|
|
154
|
+
(
|
|
155
|
+
event: 'toolbarToolClick',
|
|
156
|
+
data: { data: D[]; code: string; selectedKeys: Array<string | number>; records: D[] },
|
|
157
|
+
): void;
|
|
158
|
+
(event: 'pick', data: { row: D; field: string }): void;
|
|
159
|
+
}>();
|
|
160
|
+
// @ts-ignore
|
|
161
|
+
const selectedRecords = computed<D[]>(() =>
|
|
162
|
+
selectedCaches.value.filter((f) =>
|
|
163
|
+
selectedRowKeys.value.includes(f[props.rowKey ?? 'id'] as string | number),
|
|
164
|
+
),
|
|
165
|
+
);
|
|
140
166
|
const toolBtnClick = (code: string) => {
|
|
141
167
|
emit('toolbarButtonClick', {
|
|
142
168
|
data: tableData.value,
|
|
143
169
|
code,
|
|
144
170
|
selectedKeys: selectedRowKeys.value,
|
|
171
|
+
records: selectedRecords.value,
|
|
145
172
|
});
|
|
146
173
|
innerToolbarHandler(code);
|
|
147
174
|
};
|
|
148
175
|
const debounceToolBtnClick = debounce(toolBtnClick, 100);
|
|
149
176
|
const toolBtnMenuClick = ({ key }) => debounceToolBtnClick(key);
|
|
150
177
|
const toolToolClick = (code: string) => {
|
|
151
|
-
emit('toolbarToolClick', {
|
|
178
|
+
emit('toolbarToolClick', {
|
|
179
|
+
data: tableData.value,
|
|
180
|
+
code,
|
|
181
|
+
selectedKeys: selectedRowKeys.value,
|
|
182
|
+
records: selectedRecords.value,
|
|
183
|
+
});
|
|
152
184
|
innerToolbarHandler(code);
|
|
153
185
|
};
|
|
154
186
|
const debounceToolToolClick = debounce(toolToolClick, 100);
|
|
@@ -164,7 +196,7 @@
|
|
|
164
196
|
const obj: Partial<F> = {};
|
|
165
197
|
eachTree(formConfig.value.items, (item) => {
|
|
166
198
|
if (item.field && item.itemRender) {
|
|
167
|
-
if (
|
|
199
|
+
if (isGoodValue(item.itemRender.defaultValue)) {
|
|
168
200
|
obj[item.field] = item.itemRender.defaultValue;
|
|
169
201
|
} else {
|
|
170
202
|
obj[item.field] = undefined;
|
|
@@ -214,6 +246,7 @@
|
|
|
214
246
|
};
|
|
215
247
|
const resetPage = () => {
|
|
216
248
|
pagination.page = 1;
|
|
249
|
+
selectedCaches.value = [];
|
|
217
250
|
selectedRowKeys.value = [];
|
|
218
251
|
return fetchData();
|
|
219
252
|
};
|
|
@@ -309,6 +342,14 @@
|
|
|
309
342
|
selectedRowKeys: selectedRowKeys.value,
|
|
310
343
|
onChange: (selectedKeys: string[] | number[]) => {
|
|
311
344
|
selectedRowKeys.value = selectedKeys;
|
|
345
|
+
const primaryKey = props.rowKey ?? 'id';
|
|
346
|
+
const cachedKeys = selectedCaches.value.map((m) => m[primaryKey]);
|
|
347
|
+
const newKeys = selectedKeys.filter((f) => !cachedKeys.includes(f));
|
|
348
|
+
const newRecords: D[] = newKeys
|
|
349
|
+
.map((m) => tableData.value.find((f) => f[primaryKey] === m))
|
|
350
|
+
.filter((f) => !!f) as D[];
|
|
351
|
+
// @ts-ignore
|
|
352
|
+
selectedCaches.value = [...selectedCaches.value, ...newRecords];
|
|
312
353
|
},
|
|
313
354
|
getCheckboxProps: selectConfig.value.getCheckboxProps,
|
|
314
355
|
},
|
|
@@ -345,6 +386,8 @@
|
|
|
345
386
|
},
|
|
346
387
|
$table: computed(() => tableEl.value),
|
|
347
388
|
selectedRowKeys: computed(() => selectedRowKeys.value),
|
|
389
|
+
setBtnLoading,
|
|
390
|
+
selectedRecords,
|
|
348
391
|
$form: computed(() => formEl.value),
|
|
349
392
|
setLoadings: (value: boolean) => {
|
|
350
393
|
loading.form = value;
|
|
@@ -459,7 +502,11 @@
|
|
|
459
502
|
</a-menu-item>
|
|
460
503
|
</a-menu>
|
|
461
504
|
</template>
|
|
462
|
-
<a-button
|
|
505
|
+
<a-button
|
|
506
|
+
:type="btn.type"
|
|
507
|
+
:size="btn.size ?? 'small'"
|
|
508
|
+
:loading="loading.toolbar || (!!btn.code && codeLoadings[btn.code])"
|
|
509
|
+
>
|
|
463
510
|
<Icon v-if="btn.icon" :icon="btn.icon" />
|
|
464
511
|
{{ btn.content }}
|
|
465
512
|
<DownOutlined />
|
|
@@ -469,7 +516,7 @@
|
|
|
469
516
|
v-else-if="btn.code"
|
|
470
517
|
:type="btn.type"
|
|
471
518
|
:size="btn.size ?? 'small'"
|
|
472
|
-
:loading="loading.toolbar"
|
|
519
|
+
:loading="loading.toolbar || (!!btn.code && codeLoadings[btn.code])"
|
|
473
520
|
@click="debounceToolBtnClick(btn.code)"
|
|
474
521
|
>
|
|
475
522
|
<Icon v-if="btn.icon" :icon="btn.icon" />
|
|
@@ -487,7 +534,7 @@
|
|
|
487
534
|
:type="tool.type"
|
|
488
535
|
size="small"
|
|
489
536
|
@click="debounceToolToolClick(tool.code)"
|
|
490
|
-
:loading="loading.toolbar"
|
|
537
|
+
:loading="loading.toolbar || (!!tool.code && codeLoadings[tool.code])"
|
|
491
538
|
>
|
|
492
539
|
<Icon :icon="tool.icon" />
|
|
493
540
|
</a-button>
|
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
} from 'ant-design-vue';
|
|
24
24
|
import { set, isFunction, merge, omit } from 'lodash-es';
|
|
25
25
|
import { ButtonProps } from 'ant-design-vue/lib/button';
|
|
26
|
-
import { noValue, valued } from '@/utils/is';
|
|
26
|
+
import { isBadValue, isGoodValue, noValue, 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';
|
|
@@ -130,7 +130,7 @@ const renderBasic = (name: string) => {
|
|
|
130
130
|
{ props = {}, attrs = {}, events = {}, defaultValue }: RenderOptions,
|
|
131
131
|
{ data, field }: RenderFormParams,
|
|
132
132
|
) {
|
|
133
|
-
if (
|
|
133
|
+
if (isGoodValue(defaultValue) && valued(field) && isBadValue(data[field!])) {
|
|
134
134
|
data[field!] = defaultValue;
|
|
135
135
|
}
|
|
136
136
|
return field ? (
|
|
@@ -151,7 +151,7 @@ const renderBasic = (name: string) => {
|
|
|
151
151
|
{ props = antDefaultProps[name] ?? {}, attrs = {}, events = {}, defaultValue }: RenderOptions,
|
|
152
152
|
{ data, row, field }: RenderTableParams,
|
|
153
153
|
) {
|
|
154
|
-
if (
|
|
154
|
+
if (isGoodValue(defaultValue) && valued(field) && isBadValue(row[field!])) {
|
|
155
155
|
row[field!] = defaultValue;
|
|
156
156
|
}
|
|
157
157
|
return field ? (
|
package/src/packages/utils/is.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export const noValue = (val: any) => val === null || val === undefined || val === '';
|
|
2
2
|
export const valued = (val: any) => !noValue(val);
|
|
3
|
+
export const isBadValue = (val: any) => val === null || val === undefined;
|
|
4
|
+
export const isGoodValue = (val: any) => !isBadValue(val);
|