@vue-ui-kit/ant 1.9.0 → 1.9.1
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 +2 -1
- package/dist/es/index.js +911 -882
- package/dist/packages/components/PFormGroup.vue.d.ts +1 -0
- package/package.json +1 -1
- package/src/declarations/antProxy.ts +2 -1
- package/src/packages/components/PFormGroup.vue +134 -94
- package/src/packages/components/PGroupBlock.vue +3 -3
|
@@ -12,6 +12,7 @@ declare const _default: <F = Recordable<any>>(__VLS_props: NonNullable<Awaited<t
|
|
|
12
12
|
setActiveKey: (key: number) => void;
|
|
13
13
|
validateAll: () => Promise<PromiseSettledResult<any>[]>;
|
|
14
14
|
validate: (__index: number, ignoreTabError?: boolean) => Promise<void>;
|
|
15
|
+
validateFields: (__index: number, fields: string[], ignoreTabError?: boolean) => Promise<void>;
|
|
15
16
|
}>): void;
|
|
16
17
|
attrs: any;
|
|
17
18
|
slots: ReturnType<() => {
|
package/package.json
CHANGED
|
@@ -312,5 +312,6 @@ export interface PFormGroupInstance {
|
|
|
312
312
|
activeKey: number;
|
|
313
313
|
setActiveKey: (activeKey: number) => void;
|
|
314
314
|
validateAll: () => Promise<void>;
|
|
315
|
-
validate: (index: number) => Promise<void>;
|
|
315
|
+
validate: (index: number, ignoreTabError?: boolean) => Promise<void>;
|
|
316
|
+
validateFields: (index: number, fields: string[], ignoreTabError?: boolean) => Promise<void>;
|
|
316
317
|
}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
import { computed, nextTick, PropType, ref, watch, watchEffect } from 'vue';
|
|
3
3
|
import { PFormGroupProps, PFormBlockInstance } from '#/antProxy';
|
|
4
4
|
import { MoreOutlined } from '@ant-design/icons-vue';
|
|
5
|
-
import type { Tabs } from 'ant-design-vue'
|
|
6
|
-
import {
|
|
5
|
+
import type { Tabs } from 'ant-design-vue';
|
|
6
|
+
import type { Rule } from 'ant-design-vue/lib/form';
|
|
7
|
+
import { Form } from 'ant-design-vue';
|
|
7
8
|
import { clone, toString, isFunction, omit, max, debounce } from 'xe-utils';
|
|
8
9
|
import PGroupBlock from '@/components/PGroupBlock.vue';
|
|
9
10
|
import {
|
|
@@ -18,17 +19,17 @@
|
|
|
18
19
|
import { valued } from '@/utils/is';
|
|
19
20
|
import { MenuInfo } from 'ant-design-vue/es/menu/src/interface';
|
|
20
21
|
import { $warning } from '@/hooks/useMessage';
|
|
21
|
-
|
|
22
|
-
const useForm = Form.useForm
|
|
23
|
-
const tabsRef = ref<InstanceType<typeof Tabs>>()
|
|
22
|
+
|
|
23
|
+
const useForm = Form.useForm;
|
|
24
|
+
const tabsRef = ref<InstanceType<typeof Tabs>>();
|
|
24
25
|
const props = defineProps<PFormGroupProps<F>>();
|
|
25
|
-
const rootRef = ref<InstanceType<typeof ACard>>()
|
|
26
|
+
const rootRef = ref<InstanceType<typeof ACard>>();
|
|
26
27
|
const model = defineModel({
|
|
27
28
|
type: Array as PropType<Partial<F & { __index: number }>[]>,
|
|
28
29
|
default: () => [],
|
|
29
30
|
});
|
|
30
31
|
const activeKey = ref(0);
|
|
31
|
-
const error_indexes = ref<number[]>([])
|
|
32
|
+
const error_indexes = ref<number[]>([]);
|
|
32
33
|
const blockInstance = ref<PFormBlockInstance[]>([]);
|
|
33
34
|
const setActiveKey = (key: number) => {
|
|
34
35
|
activeKey.value = key;
|
|
@@ -51,34 +52,38 @@
|
|
|
51
52
|
{ content: '复制', code: 'copy' },
|
|
52
53
|
{ content: '删除', code: 'delete' },
|
|
53
54
|
];
|
|
54
|
-
const getPopupContainer = () => rootRef.value?.$el ?? document.body
|
|
55
|
+
const getPopupContainer = () => rootRef.value?.$el ?? document.body;
|
|
55
56
|
// 实际是否强制渲染
|
|
56
57
|
const fr = computed(() => {
|
|
57
|
-
return props.forceRender || model.value.length <= 5
|
|
58
|
-
})
|
|
58
|
+
return props.forceRender || model.value.length <= 5;
|
|
59
|
+
});
|
|
59
60
|
const handleBlockFocus = (idx: number) => {
|
|
60
|
-
const target_index = model.value.find((f, index) => index === idx)?.__index
|
|
61
|
+
const target_index = model.value.find((f, index) => index === idx)?.__index;
|
|
61
62
|
if (valued(target_index)) {
|
|
62
|
-
error_indexes.value = error_indexes.value.filter(f => f !== target_index)
|
|
63
|
+
error_indexes.value = error_indexes.value.filter((f) => f !== target_index);
|
|
63
64
|
}
|
|
64
|
-
}
|
|
65
|
+
};
|
|
65
66
|
const handleTabChange = () => {
|
|
66
67
|
nextTick().then(() => {
|
|
67
|
-
handleBlockFocus(activeKey.value)
|
|
68
|
-
blockInstance.value[activeKey.value]?.$form?.validate()
|
|
69
|
-
})
|
|
70
|
-
}
|
|
71
|
-
watch(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
68
|
+
handleBlockFocus(activeKey.value);
|
|
69
|
+
blockInstance.value[activeKey.value]?.$form?.validate();
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
watch(
|
|
73
|
+
() => model.value,
|
|
74
|
+
() => {
|
|
75
|
+
if (!props.keepSerial) {
|
|
76
|
+
const unSortItems = model.value.filter((f) => !valued(f.__index));
|
|
77
|
+
if (unSortItems.length > 0) {
|
|
78
|
+
unSortItems.forEach((item) => {
|
|
79
|
+
// @ts-ignore
|
|
80
|
+
item.__index = (max(model.value, (m) => m.__index ?? -1)?.__index ?? -1) + 1;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
{ immediate: true },
|
|
86
|
+
);
|
|
82
87
|
const handleMenu = ({ key }: MenuInfo, item: Partial<F & { __index: number }>, idx: number) => {
|
|
83
88
|
if (props.menuHandler && isFunction(props.menuHandler)) {
|
|
84
89
|
props.menuHandler({ code: toString(key), data: item, index: idx });
|
|
@@ -95,8 +100,8 @@
|
|
|
95
100
|
break;
|
|
96
101
|
case 'copy':
|
|
97
102
|
if (model.value.length >= maxLen.value) {
|
|
98
|
-
$warning('已达到最大数量')
|
|
99
|
-
return
|
|
103
|
+
$warning('已达到最大数量');
|
|
104
|
+
return;
|
|
100
105
|
}
|
|
101
106
|
model.value = [
|
|
102
107
|
...model.value,
|
|
@@ -118,73 +123,117 @@
|
|
|
118
123
|
}
|
|
119
124
|
});
|
|
120
125
|
|
|
121
|
-
const debounceHandleBlockFocus = debounce(handleBlockFocus, 50)
|
|
126
|
+
const debounceHandleBlockFocus = debounce(handleBlockFocus, 50);
|
|
122
127
|
watchEffect(() => {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
128
|
+
const errorKeys = model.value
|
|
129
|
+
.map((m, idx) => (error_indexes.value.includes(m.__index!) ? idx : undefined))
|
|
130
|
+
.filter(valued);
|
|
131
|
+
const rootDom = tabsRef.value?.$el;
|
|
132
|
+
if (rootDom) {
|
|
133
|
+
const tabPanel = rootDom.querySelectorAll(
|
|
134
|
+
':scope >.ant-tabs-nav>.ant-tabs-nav-wrap>.ant-tabs-nav-list>.ant-tabs-tab>.ant-tabs-tab-btn',
|
|
135
|
+
);
|
|
136
|
+
tabPanel.forEach((tab, idx) => {
|
|
137
|
+
if (errorKeys.includes(idx)) {
|
|
138
|
+
tab.classList.add('p-error-group-tab');
|
|
139
|
+
} else {
|
|
140
|
+
tab.classList.remove('p-error-group-tab');
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
});
|
|
137
145
|
defineExpose({
|
|
138
146
|
activeKey: computed(() => activeKey.value),
|
|
139
147
|
setActiveKey,
|
|
140
148
|
validateAll: () => {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
149
|
+
const promiseList = fr.value
|
|
150
|
+
? blockInstance.value.map((block) => block.$form?.validate())
|
|
151
|
+
: model.value.map(
|
|
152
|
+
(m) => useForm(m, props.getFormSetting(m).rules)?.validate() ?? Promise.resolve(),
|
|
153
|
+
);
|
|
154
|
+
return Promise.allSettled(promiseList).then((results) => {
|
|
155
|
+
// 更新 error_indexes
|
|
156
|
+
error_indexes.value = results
|
|
157
|
+
.map((res, idx) =>
|
|
158
|
+
res.status === 'rejected' && typeof model.value[idx]?.__index === 'number'
|
|
159
|
+
? (model.value[idx].__index as number)
|
|
160
|
+
: undefined,
|
|
161
|
+
)
|
|
162
|
+
.filter((v): v is number => typeof v === 'number');
|
|
163
|
+
if (!props.lazyErrorMark && error_indexes.value.length) {
|
|
164
|
+
// 跳到第一个出错的tab
|
|
165
|
+
const firstErrorIndex = error_indexes.value[0];
|
|
166
|
+
const firstErrorTab = model.value.findIndex((f) => f.__index === firstErrorIndex);
|
|
167
|
+
if (firstErrorTab !== -1) {
|
|
168
|
+
activeKey.value = firstErrorTab;
|
|
169
|
+
}
|
|
155
170
|
}
|
|
171
|
+
// 判断是否有错误
|
|
172
|
+
if (error_indexes.value.length) {
|
|
173
|
+
return Promise.reject({ error_indexes: error_indexes.value, results });
|
|
174
|
+
}
|
|
175
|
+
return Promise.resolve(results);
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
validate: async (__index: number, ignoreTabError?: boolean) => {
|
|
179
|
+
const index = model.value.findIndex((f) => f.__index === __index);
|
|
180
|
+
try {
|
|
181
|
+
await (fr.value
|
|
182
|
+
? (blockInstance.value[index]?.$form?.validate() ?? Promise.resolve())
|
|
183
|
+
: (useForm(
|
|
184
|
+
model.value[index],
|
|
185
|
+
props.getFormSetting(model.value[index]).rules,
|
|
186
|
+
)?.validate() ?? Promise.resolve()));
|
|
187
|
+
// 校验通过,移除error_indexes中的__index
|
|
188
|
+
error_indexes.value = error_indexes.value.filter((f) => f !== __index);
|
|
189
|
+
return Promise.resolve();
|
|
190
|
+
} catch (e) {
|
|
191
|
+
// 校验失败,加入error_indexes
|
|
192
|
+
if (!error_indexes.value.includes(__index) && !ignoreTabError) {
|
|
193
|
+
error_indexes.value = [...error_indexes.value, __index];
|
|
194
|
+
}
|
|
195
|
+
return Promise.reject(e);
|
|
156
196
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
197
|
+
},
|
|
198
|
+
validateFields: async (__index: number, fields: string[], ignoreTabError?: boolean) => {
|
|
199
|
+
const index = model.value.findIndex((f) => f.__index === __index);
|
|
200
|
+
const formSettings = props.getFormSetting(model.value[index]);
|
|
201
|
+
const rules = formSettings.rules as Record<string, Rule[]>;
|
|
202
|
+
const dataFormFactory = useForm(model.value[index], rules);
|
|
203
|
+
try {
|
|
204
|
+
await (fr.value
|
|
205
|
+
? (blockInstance.value[index]?.$form?.validateFields(fields) ?? Promise.resolve())
|
|
206
|
+
: Promise.allSettled(
|
|
207
|
+
fields.map((m) =>
|
|
208
|
+
dataFormFactory.validateField(
|
|
209
|
+
m,
|
|
210
|
+
model.value[index][m],
|
|
211
|
+
(rules[m] as Record<string, unknown>[]) ?? [],
|
|
212
|
+
),
|
|
213
|
+
),
|
|
214
|
+
));
|
|
215
|
+
return Promise.resolve();
|
|
216
|
+
} catch (e) {
|
|
217
|
+
// 校验失败,加入error_indexes
|
|
218
|
+
if (!error_indexes.value.includes(__index) && !ignoreTabError) {
|
|
219
|
+
error_indexes.value = [...error_indexes.value, __index];
|
|
220
|
+
}
|
|
221
|
+
return Promise.reject(e);
|
|
178
222
|
}
|
|
179
|
-
|
|
180
|
-
}
|
|
181
|
-
},
|
|
223
|
+
},
|
|
182
224
|
});
|
|
183
225
|
</script>
|
|
184
226
|
<template>
|
|
185
227
|
<a-card ref="rootRef" :title="title" size="small">
|
|
186
228
|
<a-spin v-if="loading" class="w-full" />
|
|
187
|
-
<a-tabs
|
|
229
|
+
<a-tabs
|
|
230
|
+
v-else
|
|
231
|
+
ref="tabsRef"
|
|
232
|
+
type="editable-card"
|
|
233
|
+
v-model:activeKey="activeKey"
|
|
234
|
+
hide-add
|
|
235
|
+
@change="handleTabChange"
|
|
236
|
+
>
|
|
188
237
|
<template #rightExtra>
|
|
189
238
|
<slot name="rightExtra">
|
|
190
239
|
<a-button
|
|
@@ -219,17 +268,8 @@
|
|
|
219
268
|
</template>
|
|
220
269
|
</a-dropdown>
|
|
221
270
|
</template>
|
|
222
|
-
<!-- @vue-ignore -->
|
|
223
271
|
<p-group-block
|
|
224
|
-
|
|
225
|
-
(i: PFormBlockInstance) => {
|
|
226
|
-
if (i) {
|
|
227
|
-
blockInstance[idx] = i;
|
|
228
|
-
} else if (blockInstance) {
|
|
229
|
-
blockInstance = blockInstance.filter((_, i) => i !== idx);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
"
|
|
272
|
+
ref="blockInstance"
|
|
233
273
|
:key="idx"
|
|
234
274
|
:source="item"
|
|
235
275
|
:get-form-setting="getFormSetting"
|
|
@@ -4,13 +4,13 @@
|
|
|
4
4
|
import PForm from '@/components/PForm.vue';
|
|
5
5
|
|
|
6
6
|
const props = defineProps<PBlockProps<F>>();
|
|
7
|
-
const formEl = ref<PFormInstance>()
|
|
7
|
+
const formEl = ref<PFormInstance>();
|
|
8
8
|
const { source } = toRefs(props);
|
|
9
|
-
const $form = computed(() => formEl.value?.$form)
|
|
9
|
+
const $form = computed(() => formEl.value?.$form);
|
|
10
10
|
const formSetting = computed<PFormProps<Partial<F>>>(() => props.getFormSetting(source.value));
|
|
11
11
|
defineExpose({
|
|
12
12
|
$form,
|
|
13
|
-
})
|
|
13
|
+
});
|
|
14
14
|
</script>
|
|
15
15
|
<template>
|
|
16
16
|
<p-form ref="formEl" v-bind="formSetting" :data="source!" />
|