vft 0.0.339 → 0.0.342
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/es/components/form/form.vue.d.ts +1 -1
- package/es/components/form/form.vue2.js +10 -10
- package/es/components/form/index.d.ts +3 -3
- package/es/components/super-form/types.d.ts +1 -1
- package/es/components/super-form/use/use-form-events.js +177 -154
- package/es/package.json.d.ts +1 -1
- package/es/package.json.js +1 -1
- package/lib/components/form/form.vue.d.ts +1 -1
- package/lib/components/form/form.vue2.cjs +1 -1
- package/lib/components/form/index.d.ts +3 -3
- package/lib/components/super-form/types.d.ts +1 -1
- package/lib/components/super-form/use/use-form-events.cjs +1 -1
- package/lib/package.json.cjs +1 -1
- package/lib/package.json.d.ts +1 -1
- package/package.json +4 -4
- package/web-types.json +1 -1
|
@@ -7,7 +7,7 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
|
|
|
7
7
|
/**
|
|
8
8
|
* @description Validate the whole form. Receives a callback or returns `Promise`.
|
|
9
9
|
*/
|
|
10
|
-
validate: (callback?: FormValidateCallback) => FormValidationResult;
|
|
10
|
+
validate: (callback?: FormValidateCallback, props?: Arrayable<FormItemProp>) => FormValidationResult;
|
|
11
11
|
/**
|
|
12
12
|
* @description Validate specified fields.
|
|
13
13
|
*/
|
|
@@ -61,32 +61,32 @@ const H = b({
|
|
|
61
61
|
if (l.length === 0) return [];
|
|
62
62
|
const t = f(l, e);
|
|
63
63
|
return t.length ? t : (n(i.b(), "please pass correct props!"), []);
|
|
64
|
-
}, h = async (e) => c(void 0, e), R = async (e = []) => {
|
|
64
|
+
}, h = async (e, t) => c(t || void 0, e), R = async (e = []) => {
|
|
65
65
|
if (!k.value) return !1;
|
|
66
66
|
const t = P(e);
|
|
67
67
|
if (t.length === 0) return !0;
|
|
68
68
|
let r = {};
|
|
69
|
-
for (const
|
|
69
|
+
for (const a of t)
|
|
70
70
|
try {
|
|
71
|
-
await
|
|
72
|
-
} catch (
|
|
71
|
+
await a.validate(""), a.validateState === "error" && a.resetField();
|
|
72
|
+
} catch (s) {
|
|
73
73
|
r = {
|
|
74
74
|
...r,
|
|
75
|
-
...
|
|
75
|
+
...s
|
|
76
76
|
};
|
|
77
77
|
}
|
|
78
78
|
return Object.keys(r).length === 0 ? !0 : Promise.reject(r);
|
|
79
79
|
}, c = async (e = [], t) => {
|
|
80
80
|
let r = !1;
|
|
81
|
-
const
|
|
81
|
+
const a = !K(t);
|
|
82
82
|
try {
|
|
83
83
|
return r = await R(e), r === !0 && await t?.(r), o.model;
|
|
84
|
-
} catch (
|
|
85
|
-
if (
|
|
86
|
-
const v =
|
|
84
|
+
} catch (s) {
|
|
85
|
+
if (s instanceof Error) throw s;
|
|
86
|
+
const v = s;
|
|
87
87
|
return o.scrollToError && d.value && d.value.querySelector(
|
|
88
88
|
`.${i.b()}-item.is-error`
|
|
89
|
-
)?.scrollIntoView(o.scrollIntoViewOptions), !r && await t?.(!1, v),
|
|
89
|
+
)?.scrollIntoView(o.scrollIntoViewOptions), console.error(s), !r && await t?.(!1, v), a && Promise.reject(v);
|
|
90
90
|
}
|
|
91
91
|
}, S = (e) => {
|
|
92
92
|
const t = u(e);
|
|
@@ -53,7 +53,7 @@ export declare const VftForm: import("vft/es/utils").SFCWithInstall<{
|
|
|
53
53
|
}>> & Readonly<{
|
|
54
54
|
onValidate?: ((...args: any[]) => any) | undefined;
|
|
55
55
|
}>, {
|
|
56
|
-
validate: (callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
|
|
56
|
+
validate: (callback?: import("./types").FormValidateCallback, props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => import("./types").FormValidationResult;
|
|
57
57
|
validateField: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>, callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
|
|
58
58
|
resetFields: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
|
|
59
59
|
clearValidate: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
|
|
@@ -119,7 +119,7 @@ export declare const VftForm: import("vft/es/utils").SFCWithInstall<{
|
|
|
119
119
|
}>> & Readonly<{
|
|
120
120
|
onValidate?: ((...args: any[]) => any) | undefined;
|
|
121
121
|
}>, {
|
|
122
|
-
validate: (callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
|
|
122
|
+
validate: (callback?: import("./types").FormValidateCallback, props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => import("./types").FormValidationResult;
|
|
123
123
|
validateField: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>, callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
|
|
124
124
|
resetFields: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
|
|
125
125
|
clearValidate: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
|
|
@@ -180,7 +180,7 @@ export declare const VftForm: import("vft/es/utils").SFCWithInstall<{
|
|
|
180
180
|
}>> & Readonly<{
|
|
181
181
|
onValidate?: ((...args: any[]) => any) | undefined;
|
|
182
182
|
}>, {
|
|
183
|
-
validate: (callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
|
|
183
|
+
validate: (callback?: import("./types").FormValidateCallback, props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => import("./types").FormValidationResult;
|
|
184
184
|
validateField: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>, callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
|
|
185
185
|
resetFields: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
|
|
186
186
|
clearValidate: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
|
|
@@ -79,7 +79,7 @@ export interface FormActionType {
|
|
|
79
79
|
/** 验证指定字段 */
|
|
80
80
|
validateField: (nameList?: NamePath[]) => Promise<any>;
|
|
81
81
|
/** 验证表单 */
|
|
82
|
-
validate: (nameList?: NamePath[]) => Promise<any>;
|
|
82
|
+
validate: (callback?: Function, nameList?: NamePath[]) => Promise<any>;
|
|
83
83
|
/** 滚动到指定字段 */
|
|
84
84
|
scrollToField: (name: NamePath, options?: ScrollOptions) => Promise<void>;
|
|
85
85
|
/** 设置表单项错误信息 */
|
|
@@ -1,210 +1,233 @@
|
|
|
1
|
-
import { isDef as
|
|
2
|
-
import { formatToDate as
|
|
3
|
-
import { get as st, cloneDeep as
|
|
4
|
-
import { unref as
|
|
5
|
-
import { isInput as
|
|
1
|
+
import { isDef as G, isFunction as j, isString as A, isObject as V, isArray as I, deepMerge as it, findDifferentValuesForObj as nt, isNullOrUndefined as H, isEmpty as rt, isEmptyObject as lt } from "@vft/utils";
|
|
2
|
+
import { formatToDate as J } from "@vft/utils/date";
|
|
3
|
+
import { get as st, cloneDeep as O, uniqBy as ot, isEqual as ft, set as W } from "lodash-es";
|
|
4
|
+
import { unref as n, toRaw as S, nextTick as P } from "vue";
|
|
5
|
+
import { isInput as ct, FormCompEnum as x, isDatePicker as at } from "../component-map.js";
|
|
6
6
|
import { handleInputNumberValue as ut } from "./helper.js";
|
|
7
|
-
function
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
function Q(h, y) {
|
|
8
|
+
const { show: s, ifShow: f } = h;
|
|
9
|
+
let p = !0, a = !0;
|
|
10
|
+
return typeof s == "boolean" ? p = s : typeof s == "function" && (p = s({
|
|
11
|
+
field: h.field,
|
|
12
|
+
model: y,
|
|
13
|
+
values: {
|
|
14
|
+
...y
|
|
15
|
+
},
|
|
16
|
+
schema: h
|
|
17
|
+
})), typeof f == "boolean" ? a = f : typeof f == "function" && (a = f({
|
|
18
|
+
field: h.field,
|
|
19
|
+
model: y,
|
|
20
|
+
values: {
|
|
21
|
+
...y
|
|
22
|
+
},
|
|
23
|
+
schema: h
|
|
24
|
+
})), p && a;
|
|
25
|
+
}
|
|
26
|
+
function dt(h, y = {}) {
|
|
27
|
+
const s = /^\[(.+)\]$/;
|
|
28
|
+
if (s.test(h)) {
|
|
29
|
+
const f = h.match(s);
|
|
30
|
+
if (f && f[1]) {
|
|
31
|
+
const p = f[1].split(",");
|
|
32
|
+
if (!p.length)
|
|
14
33
|
return;
|
|
15
|
-
const
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
}),
|
|
34
|
+
const a = [];
|
|
35
|
+
return p.forEach((v, D) => {
|
|
36
|
+
W(a, D, y[v.trim()]);
|
|
37
|
+
}), a.filter(Boolean).length ? a : void 0;
|
|
19
38
|
}
|
|
20
39
|
}
|
|
21
40
|
}
|
|
22
|
-
function
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
const
|
|
26
|
-
if (
|
|
27
|
-
const
|
|
28
|
-
if (!
|
|
41
|
+
function ht(h, y = {}) {
|
|
42
|
+
const s = /^\{(.+)\}$/;
|
|
43
|
+
if (s.test(h)) {
|
|
44
|
+
const f = h.match(s);
|
|
45
|
+
if (f && f[1]) {
|
|
46
|
+
const p = f[1].split(",");
|
|
47
|
+
if (!p.length)
|
|
29
48
|
return;
|
|
30
|
-
const
|
|
31
|
-
return
|
|
32
|
-
|
|
33
|
-
}), Object.values(
|
|
49
|
+
const a = {};
|
|
50
|
+
return p.forEach((v) => {
|
|
51
|
+
W(a, v.trim(), y[v.trim()]);
|
|
52
|
+
}), Object.values(a).filter(Boolean).length ? a : void 0;
|
|
34
53
|
}
|
|
35
54
|
}
|
|
36
55
|
}
|
|
37
|
-
function
|
|
38
|
-
emit:
|
|
39
|
-
getProps:
|
|
40
|
-
formModel:
|
|
41
|
-
getSchema:
|
|
42
|
-
defaultValueRef:
|
|
43
|
-
formElRef:
|
|
44
|
-
schemaRef:
|
|
45
|
-
handleFormValues:
|
|
46
|
-
initValues:
|
|
56
|
+
function Dt({
|
|
57
|
+
emit: h,
|
|
58
|
+
getProps: y,
|
|
59
|
+
formModel: s,
|
|
60
|
+
getSchema: f,
|
|
61
|
+
defaultValueRef: p,
|
|
62
|
+
formElRef: a,
|
|
63
|
+
schemaRef: v,
|
|
64
|
+
handleFormValues: D,
|
|
65
|
+
initValues: _
|
|
47
66
|
}) {
|
|
48
|
-
async function
|
|
49
|
-
const { resetFunc:
|
|
50
|
-
|
|
51
|
-
const
|
|
52
|
-
if (
|
|
67
|
+
async function X(t) {
|
|
68
|
+
const { resetFunc: i, submitOnReset: l } = n(y);
|
|
69
|
+
i && j(i) && await i();
|
|
70
|
+
const r = n(a);
|
|
71
|
+
if (r) {
|
|
53
72
|
if (t?.length)
|
|
54
|
-
return
|
|
55
|
-
Object.keys(
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
}),
|
|
73
|
+
return r.resetFields(t);
|
|
74
|
+
Object.keys(s).forEach((c) => {
|
|
75
|
+
const o = n(f).find((u) => u.field === c), e = O(p.value[c]);
|
|
76
|
+
s[c] = ct(o?.type) ? e || "" : e;
|
|
77
|
+
}), P(() => B()), h("reset", S(s)), l && await $();
|
|
59
78
|
}
|
|
60
79
|
}
|
|
61
|
-
async function
|
|
62
|
-
const
|
|
63
|
-
(e) => String(e).indexOf(
|
|
64
|
-
),
|
|
65
|
-
|
|
66
|
-
const
|
|
67
|
-
let
|
|
80
|
+
async function m(t, i = !0) {
|
|
81
|
+
const l = n(f).map((e) => e.field).filter(Boolean), r = ".", c = l.filter(
|
|
82
|
+
(e) => String(e).indexOf(r) >= 0
|
|
83
|
+
), o = [];
|
|
84
|
+
l.forEach((e) => {
|
|
85
|
+
const u = n(f).find((d) => d.field === e);
|
|
86
|
+
let b = st(t, e);
|
|
68
87
|
const C = Reflect.has(t, e);
|
|
69
|
-
|
|
70
|
-
const { componentProps:
|
|
71
|
-
let
|
|
72
|
-
typeof
|
|
73
|
-
const
|
|
74
|
-
if (C ||
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
if (Array.isArray(
|
|
88
|
+
b = ut(u?.type, b);
|
|
89
|
+
const { componentProps: U } = u || {};
|
|
90
|
+
let w = U;
|
|
91
|
+
typeof U == "function" && (w = w({ formModel: n(s) }));
|
|
92
|
+
const z = dt(e, t) || ht(e, t);
|
|
93
|
+
if (C || z) {
|
|
94
|
+
const d = z || b;
|
|
95
|
+
if (M(e))
|
|
96
|
+
if (Array.isArray(d)) {
|
|
78
97
|
const F = [];
|
|
79
|
-
for (const
|
|
80
|
-
F.push(
|
|
81
|
-
|
|
98
|
+
for (const E of d)
|
|
99
|
+
F.push(E ? J(E) : null);
|
|
100
|
+
n(s)[e] = F;
|
|
82
101
|
} else
|
|
83
|
-
|
|
102
|
+
n(s)[e] = d ? w?.valueFormat ? d : J(d) : null;
|
|
84
103
|
else
|
|
85
|
-
|
|
86
|
-
|
|
104
|
+
n(s)[e] = d;
|
|
105
|
+
w?.onChange && w?.onChange(d), o.push(e);
|
|
87
106
|
} else
|
|
88
|
-
c.forEach((
|
|
107
|
+
c.forEach((d) => {
|
|
89
108
|
try {
|
|
90
|
-
const F =
|
|
91
|
-
|
|
109
|
+
const F = d.split(".").reduce((E, et) => E[et], t);
|
|
110
|
+
G(F) && (n(s)[d] = n(F), o.push(d));
|
|
92
111
|
} catch {
|
|
93
|
-
|
|
94
|
-
|
|
112
|
+
G(p.value[d]) && (n(s)[d] = O(
|
|
113
|
+
n(p.value[d])
|
|
95
114
|
));
|
|
96
115
|
}
|
|
97
116
|
});
|
|
98
|
-
}),
|
|
99
|
-
await
|
|
117
|
+
}), i && P(async () => {
|
|
118
|
+
await q(o).catch((e) => {
|
|
100
119
|
});
|
|
101
120
|
});
|
|
102
121
|
}
|
|
103
|
-
async function
|
|
104
|
-
const
|
|
122
|
+
async function Y(t) {
|
|
123
|
+
const i = O(n(f));
|
|
105
124
|
if (!t)
|
|
106
125
|
return;
|
|
107
|
-
let
|
|
108
|
-
A(t) && (
|
|
109
|
-
for (const
|
|
110
|
-
|
|
111
|
-
|
|
126
|
+
let l = A(t) ? [t] : t;
|
|
127
|
+
A(t) && (l = [t]);
|
|
128
|
+
for (const r of l)
|
|
129
|
+
Z(r, i);
|
|
130
|
+
v.value = i;
|
|
112
131
|
}
|
|
113
|
-
function
|
|
132
|
+
function Z(t, i) {
|
|
114
133
|
if (A(t)) {
|
|
115
|
-
const
|
|
116
|
-
|
|
134
|
+
const l = i.findIndex((r) => r.field === t);
|
|
135
|
+
l !== -1 && (delete s[t], i.splice(l, 1));
|
|
117
136
|
}
|
|
118
137
|
}
|
|
119
|
-
async function
|
|
120
|
-
const
|
|
121
|
-
if (!
|
|
122
|
-
|
|
138
|
+
async function L(t, i, l = !1) {
|
|
139
|
+
const r = O(n(f)), c = r.findIndex((e) => e.field === i), o = V(t) ? [t] : t;
|
|
140
|
+
if (!i || c === -1 || l) {
|
|
141
|
+
l ? r.unshift(...o) : r.push(...o), v.value = r, g(t);
|
|
123
142
|
return;
|
|
124
143
|
}
|
|
125
|
-
c !== -1 &&
|
|
144
|
+
c !== -1 && r.splice(c + 1, 0, ...o), g(t), v.value = r;
|
|
126
145
|
}
|
|
127
|
-
async function
|
|
128
|
-
let
|
|
129
|
-
if (
|
|
130
|
-
(
|
|
146
|
+
async function K(t) {
|
|
147
|
+
let i = [];
|
|
148
|
+
if (V(t) && i.push(t), I(t) && (i = [...t]), !i.every(
|
|
149
|
+
(r) => r.type === x.DIVIDER || Reflect.has(r, "field") && r.field
|
|
131
150
|
)) {
|
|
132
151
|
console.error(
|
|
133
152
|
"All children of the form Schema array that need to be updated must contain the `field` field"
|
|
134
153
|
);
|
|
135
154
|
return;
|
|
136
155
|
}
|
|
137
|
-
|
|
156
|
+
v.value = i;
|
|
138
157
|
}
|
|
139
|
-
async function
|
|
140
|
-
let
|
|
141
|
-
if (
|
|
142
|
-
(
|
|
158
|
+
async function R(t) {
|
|
159
|
+
let i = [];
|
|
160
|
+
if (V(t) && i.push(t), I(t) && (i = [...t]), !i.every(
|
|
161
|
+
(o) => o.type === x.DIVIDER || Reflect.has(o, "field") && o.field
|
|
143
162
|
)) {
|
|
144
163
|
console.error(
|
|
145
164
|
"All children of the form Schema array that need to be updated must contain the `field` field"
|
|
146
165
|
);
|
|
147
166
|
return;
|
|
148
167
|
}
|
|
149
|
-
const
|
|
150
|
-
|
|
168
|
+
const r = [], c = [];
|
|
169
|
+
n(f).forEach((o) => {
|
|
151
170
|
let e;
|
|
152
|
-
if (
|
|
153
|
-
|
|
154
|
-
}), e !== void 0 &&
|
|
155
|
-
const
|
|
156
|
-
c.push(
|
|
171
|
+
if (i.forEach((u) => {
|
|
172
|
+
o.field === u.field && (e = u), u.defaultValue && u.field && r.push(u.field);
|
|
173
|
+
}), e !== void 0 && o.field === e.field) {
|
|
174
|
+
const u = it(o, e);
|
|
175
|
+
c.push(u);
|
|
157
176
|
} else
|
|
158
|
-
c.push(
|
|
159
|
-
}), g(c,
|
|
177
|
+
c.push(o);
|
|
178
|
+
}), g(c, r), v.value = ot(c, "field");
|
|
160
179
|
}
|
|
161
|
-
function g(t,
|
|
162
|
-
if (
|
|
180
|
+
function g(t, i, l = !0) {
|
|
181
|
+
if (I(i) && i?.length === 0)
|
|
163
182
|
return;
|
|
164
|
-
let
|
|
165
|
-
|
|
166
|
-
const c = {},
|
|
167
|
-
|
|
168
|
-
e.type !== x.DIVIDER && Reflect.has(e, "field") && e.field && !
|
|
169
|
-
}),
|
|
183
|
+
let r = [];
|
|
184
|
+
V(t) && r.push(t), I(t) && (r = [...t]);
|
|
185
|
+
const c = {}, o = T();
|
|
186
|
+
r.forEach((e) => {
|
|
187
|
+
e.type !== x.DIVIDER && Reflect.has(e, "field") && e.field && !H(e.defaultValue) && (!(e.field in o) || H(o[e.field]) || rt(o[e.field])) && (c[e.field] = e.defaultValue);
|
|
188
|
+
}), lt(c) || m(c, l);
|
|
170
189
|
}
|
|
171
190
|
function T() {
|
|
172
|
-
return
|
|
173
|
-
}
|
|
174
|
-
function R(t) {
|
|
175
|
-
return r(u) ? B(r(o))[t] : {};
|
|
191
|
+
return n(a) ? D(S(n(s))) : {};
|
|
176
192
|
}
|
|
177
193
|
function k(t) {
|
|
178
|
-
return
|
|
194
|
+
return n(a) ? S(n(s))[t] : {};
|
|
179
195
|
}
|
|
180
|
-
|
|
181
|
-
return
|
|
196
|
+
function M(t) {
|
|
197
|
+
return n(f).some((i) => i.field === t ? at(i.type) : !1);
|
|
182
198
|
}
|
|
183
199
|
async function q(t) {
|
|
184
|
-
return
|
|
200
|
+
return t || (t = n(f).filter((l) => Q(l, n(s))).map((l) => l.field).filter(Boolean)), n(a)?.validateField(t);
|
|
185
201
|
}
|
|
186
|
-
async function
|
|
187
|
-
await
|
|
202
|
+
async function N(t) {
|
|
203
|
+
return t || (t = n(f).filter((l) => Q(l, n(s))).map((l) => l.field).filter(Boolean)), await n(a)?.validate(() => {
|
|
204
|
+
}, t);
|
|
188
205
|
}
|
|
189
|
-
async function
|
|
190
|
-
await
|
|
206
|
+
async function B(t) {
|
|
207
|
+
await n(a)?.clearValidate(t);
|
|
191
208
|
}
|
|
192
|
-
async function
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
209
|
+
async function tt(t, i) {
|
|
210
|
+
await n(a)?.scrollToField(t, i);
|
|
211
|
+
}
|
|
212
|
+
async function $(t) {
|
|
213
|
+
const { autoCleanErrorMessage: i, watchDataIsChange: l } = n(y);
|
|
214
|
+
t && t.preventDefault(), i && await B();
|
|
215
|
+
const { submitFunc: r, beforeSubmitFunc: c } = n(y);
|
|
216
|
+
if (c && j(c) && await c(), r && j(r)) {
|
|
217
|
+
await r();
|
|
198
218
|
return;
|
|
199
219
|
}
|
|
200
|
-
if (
|
|
220
|
+
if (n(a))
|
|
201
221
|
try {
|
|
202
|
-
const e = await
|
|
203
|
-
if (
|
|
204
|
-
|
|
205
|
-
|
|
222
|
+
const e = await N();
|
|
223
|
+
if (!e)
|
|
224
|
+
return;
|
|
225
|
+
const u = D(e);
|
|
226
|
+
if (l) {
|
|
227
|
+
const b = ft(_.value, u), C = nt(_.value, u);
|
|
228
|
+
h("submit", u, !b, C);
|
|
206
229
|
} else
|
|
207
|
-
|
|
230
|
+
h("submit", u);
|
|
208
231
|
} catch (e) {
|
|
209
232
|
if (e?.outOfDate === !1 && e?.errorFields)
|
|
210
233
|
return;
|
|
@@ -212,21 +235,21 @@ function Et({
|
|
|
212
235
|
}
|
|
213
236
|
}
|
|
214
237
|
return {
|
|
215
|
-
handleSubmit:
|
|
216
|
-
clearValidate:
|
|
217
|
-
validate:
|
|
218
|
-
validateField:
|
|
238
|
+
handleSubmit: $,
|
|
239
|
+
clearValidate: B,
|
|
240
|
+
validate: N,
|
|
241
|
+
validateField: q,
|
|
219
242
|
getFieldsValue: T,
|
|
220
|
-
updateSchema:
|
|
221
|
-
resetSchema:
|
|
222
|
-
appendSchemaByField:
|
|
223
|
-
removeSchemaByField:
|
|
224
|
-
resetFields:
|
|
225
|
-
setFieldsValue:
|
|
226
|
-
scrollToField:
|
|
227
|
-
getFieldValue:
|
|
243
|
+
updateSchema: R,
|
|
244
|
+
resetSchema: K,
|
|
245
|
+
appendSchemaByField: L,
|
|
246
|
+
removeSchemaByField: Y,
|
|
247
|
+
resetFields: X,
|
|
248
|
+
setFieldsValue: m,
|
|
249
|
+
scrollToField: tt,
|
|
250
|
+
getFieldValue: k
|
|
228
251
|
};
|
|
229
252
|
}
|
|
230
253
|
export {
|
|
231
|
-
|
|
254
|
+
Dt as useFormEvents
|
|
232
255
|
};
|
package/es/package.json.d.ts
CHANGED
package/es/package.json.js
CHANGED
|
@@ -7,7 +7,7 @@ declare const __VLS_component: import("vue").DefineComponent<import("vue").Extra
|
|
|
7
7
|
/**
|
|
8
8
|
* @description Validate the whole form. Receives a callback or returns `Promise`.
|
|
9
9
|
*/
|
|
10
|
-
validate: (callback?: FormValidateCallback) => FormValidationResult;
|
|
10
|
+
validate: (callback?: FormValidateCallback, props?: Arrayable<FormItemProp>) => FormValidationResult;
|
|
11
11
|
/**
|
|
12
12
|
* @description Validate specified fields.
|
|
13
13
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("vue");require("@vueuse/core");const E=require("@vft/utils"),d=require("../../utils/error.cjs");require("../config-provider/hooks/use-global-config.cjs");require("lodash-es");const k=require("../../hooks/use-namespace/index.cjs");require("../../hooks/use-model-toggle/index.cjs");require("@popperjs/core");require("../../hooks/use-z-index/index.cjs");const R=require("./constants.cjs"),W=require("./hooks/use-form-common-props.cjs"),u=require("./utils.cjs"),x=r.defineComponent({name:"vft-form"}),M=r.defineComponent({...x,props:{size:{},disabled:{type:Boolean},model:{},rules:{},labelPosition:{default:"right"},requireAsteriskPosition:{default:"left"},labelWidth:{default:""},labelSuffix:{default:""},inline:{type:Boolean},inlineMessage:{type:Boolean},statusIcon:{type:Boolean},showMessage:{type:Boolean,default:!0},validateOnRuleChange:{type:Boolean,default:!0},hideRequiredAsterisk:{type:Boolean,default:!1},scrollToError:{type:Boolean},scrollIntoViewOptions:{type:Boolean,default:!0}},emits:["validate"],setup(o,{expose:y,emit:q}){const g=q,p=r.getCurrentInstance(),c=r.ref(),l=r.reactive([]),w=W.useFormSize(),s=k.useNamespace("form"),B=r.computed(()=>[s.b(),s.m(w.value||"default"),{[s.m(`label-${o.labelPosition}`)]:o.labelPosition,[s.m("inline")]:o.inline}]),m=e=>u.filterFields(l,[e])[0],V=e=>{l.push(e)},C=e=>{e.prop&&l.splice(l.indexOf(e),1)},h=(e=[])=>{if(!o.model){d.debugWarn(s.b(),"model is required for resetFields to work.");return}u.filterFields(l,e).forEach(t=>t.resetField())},v=(e=[])=>{u.filterFields(l,e).forEach(t=>t.clearValidate())},I=r.computed(()=>{const e=!!o.model;return e||d.debugWarn(s.b(),"model is required for validate to work."),e}),O=e=>{if(l.length===0)return[];const t=u.filterFields(l,e);return t.length?t:(d.debugWarn(s.b(),"please pass correct props!"),[])},F=async
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const r=require("vue");require("@vueuse/core");const E=require("@vft/utils"),d=require("../../utils/error.cjs");require("../config-provider/hooks/use-global-config.cjs");require("lodash-es");const k=require("../../hooks/use-namespace/index.cjs");require("../../hooks/use-model-toggle/index.cjs");require("@popperjs/core");require("../../hooks/use-z-index/index.cjs");const R=require("./constants.cjs"),W=require("./hooks/use-form-common-props.cjs"),u=require("./utils.cjs"),x=r.defineComponent({name:"vft-form"}),M=r.defineComponent({...x,props:{size:{},disabled:{type:Boolean},model:{},rules:{},labelPosition:{default:"right"},requireAsteriskPosition:{default:"left"},labelWidth:{default:""},labelSuffix:{default:""},inline:{type:Boolean},inlineMessage:{type:Boolean},statusIcon:{type:Boolean},showMessage:{type:Boolean,default:!0},validateOnRuleChange:{type:Boolean,default:!0},hideRequiredAsterisk:{type:Boolean,default:!1},scrollToError:{type:Boolean},scrollIntoViewOptions:{type:Boolean,default:!0}},emits:["validate"],setup(o,{expose:y,emit:q}){const g=q,p=r.getCurrentInstance(),c=r.ref(),l=r.reactive([]),w=W.useFormSize(),s=k.useNamespace("form"),B=r.computed(()=>[s.b(),s.m(w.value||"default"),{[s.m(`label-${o.labelPosition}`)]:o.labelPosition,[s.m("inline")]:o.inline}]),m=e=>u.filterFields(l,[e])[0],V=e=>{l.push(e)},C=e=>{e.prop&&l.splice(l.indexOf(e),1)},h=(e=[])=>{if(!o.model){d.debugWarn(s.b(),"model is required for resetFields to work.");return}u.filterFields(l,e).forEach(t=>t.resetField())},v=(e=[])=>{u.filterFields(l,e).forEach(t=>t.clearValidate())},I=r.computed(()=>{const e=!!o.model;return e||d.debugWarn(s.b(),"model is required for validate to work."),e}),O=e=>{if(l.length===0)return[];const t=u.filterFields(l,e);return t.length?t:(d.debugWarn(s.b(),"please pass correct props!"),[])},F=async(e,t)=>f(t||void 0,e),P=async(e=[])=>{if(!I.value)return!1;const t=O(e);if(t.length===0)return!0;let i={};for(const a of t)try{await a.validate(""),a.validateState==="error"&&a.resetField()}catch(n){i={...i,...n}}return Object.keys(i).length===0?!0:Promise.reject(i)},f=async(e=[],t)=>{let i=!1;const a=!E.isFunction(t);try{return i=await P(e),i===!0&&await t?.(i),o.model}catch(n){if(n instanceof Error)throw n;const b=n;return o.scrollToError&&c.value&&c.value.querySelector(`.${s.b()}-item.is-error`)?.scrollIntoView(o.scrollIntoViewOptions),console.error(n),!i&&await t?.(!1,b),a&&Promise.reject(b)}},S=e=>{const t=m(e);t&&t.$el?.scrollIntoView(o.scrollIntoViewOptions)};return r.watch(()=>o.rules,()=>{o.validateOnRuleChange&&F().catch(e=>d.debugWarn(e))},{deep:!0,flush:"post"}),r.provide(R.formContextKey,r.reactive({...r.toRefs(p.props),emit:g,resetFields:h,clearValidate:v,validateField:f,getField:m,addField:V,removeField:C,...u.useFormLabelWidth()})),y({validate:F,validateField:f,resetFields:h,clearValidate:v,scrollToField:S}),(e,t)=>(r.openBlock(),r.createElementBlock("form",{ref_key:"formRef",ref:c,class:r.normalizeClass(B.value)},[r.renderSlot(e.$slots,"default")],2))}});exports.default=M;
|
|
@@ -53,7 +53,7 @@ export declare const VftForm: import("vft/es/utils").SFCWithInstall<{
|
|
|
53
53
|
}>> & Readonly<{
|
|
54
54
|
onValidate?: ((...args: any[]) => any) | undefined;
|
|
55
55
|
}>, {
|
|
56
|
-
validate: (callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
|
|
56
|
+
validate: (callback?: import("./types").FormValidateCallback, props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => import("./types").FormValidationResult;
|
|
57
57
|
validateField: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>, callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
|
|
58
58
|
resetFields: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
|
|
59
59
|
clearValidate: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
|
|
@@ -119,7 +119,7 @@ export declare const VftForm: import("vft/es/utils").SFCWithInstall<{
|
|
|
119
119
|
}>> & Readonly<{
|
|
120
120
|
onValidate?: ((...args: any[]) => any) | undefined;
|
|
121
121
|
}>, {
|
|
122
|
-
validate: (callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
|
|
122
|
+
validate: (callback?: import("./types").FormValidateCallback, props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => import("./types").FormValidationResult;
|
|
123
123
|
validateField: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>, callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
|
|
124
124
|
resetFields: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
|
|
125
125
|
clearValidate: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
|
|
@@ -180,7 +180,7 @@ export declare const VftForm: import("vft/es/utils").SFCWithInstall<{
|
|
|
180
180
|
}>> & Readonly<{
|
|
181
181
|
onValidate?: ((...args: any[]) => any) | undefined;
|
|
182
182
|
}>, {
|
|
183
|
-
validate: (callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
|
|
183
|
+
validate: (callback?: import("./types").FormValidateCallback, props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => import("./types").FormValidationResult;
|
|
184
184
|
validateField: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>, callback?: import("./types").FormValidateCallback) => import("./types").FormValidationResult;
|
|
185
185
|
resetFields: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
|
|
186
186
|
clearValidate: (props?: import("vft/es/utils").Arrayable<import("./types").FormItemProp>) => void;
|
|
@@ -79,7 +79,7 @@ export interface FormActionType {
|
|
|
79
79
|
/** 验证指定字段 */
|
|
80
80
|
validateField: (nameList?: NamePath[]) => Promise<any>;
|
|
81
81
|
/** 验证表单 */
|
|
82
|
-
validate: (nameList?: NamePath[]) => Promise<any>;
|
|
82
|
+
validate: (callback?: Function, nameList?: NamePath[]) => Promise<any>;
|
|
83
83
|
/** 滚动到指定字段 */
|
|
84
84
|
scrollToField: (name: NamePath, options?: ScrollOptions) => Promise<void>;
|
|
85
85
|
/** 设置表单项错误信息 */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@vft/utils"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("@vft/utils"),N=require("@vft/utils/date"),b=require("lodash-es"),i=require("vue"),O=require("../component-map.cjs"),Z=require("./helper.cjs");function U(p,F){const{show:u,ifShow:l}=p;let y=!0,a=!0;return typeof u=="boolean"?y=u:typeof u=="function"&&(y=u({field:p.field,model:F,values:{...F},schema:p})),typeof l=="boolean"?a=l:typeof l=="function"&&(a=l({field:p.field,model:F,values:{...F},schema:p})),y&&a}function L(p,F={}){const u=/^\[(.+)\]$/;if(u.test(p)){const l=p.match(u);if(l&&l[1]){const y=l[1].split(",");if(!y.length)return;const a=[];return y.forEach((v,V)=>{b.set(a,V,F[v.trim()])}),a.filter(Boolean).length?a:void 0}}}function K(p,F={}){const u=/^\{(.+)\}$/;if(u.test(p)){const l=p.match(u);if(l&&l[1]){const y=l[1].split(",");if(!y.length)return;const a={};return y.forEach(v=>{b.set(a,v.trim(),F[v.trim()])}),Object.values(a).filter(Boolean).length?a:void 0}}}function R({emit:p,getProps:F,formModel:u,getSchema:l,defaultValueRef:y,formElRef:a,schemaRef:v,handleFormValues:V,initValues:A}){async function $(e){const{resetFunc:t,submitOnReset:s}=i.unref(F);t&&c.isFunction(t)&&await t();const r=i.unref(a);if(r){if(e?.length)return r.resetFields(e);Object.keys(u).forEach(o=>{const f=i.unref(l).find(d=>d.field===o),n=b.cloneDeep(y.value[o]);u[o]=O.isInput(f?.type)?n||"":n}),i.nextTick(()=>j()),p("reset",i.toRaw(u)),s&&await x()}}async function C(e,t=!0){const s=i.unref(l).map(n=>n.field).filter(Boolean),r=".",o=s.filter(n=>String(n).indexOf(r)>=0),f=[];s.forEach(n=>{const d=i.unref(l).find(h=>h.field===n);let E=b.get(e,n);const S=Reflect.has(e,n);E=Z.handleInputNumberValue(d?.type,E);const{componentProps:_}=d||{};let w=_;typeof _=="function"&&(w=w({formModel:i.unref(u)}));const m=L(n,e)||K(n,e);if(S||m){const h=m||E;if(W(n))if(Array.isArray(h)){const D=[];for(const g of h)D.push(g?N.formatToDate(g):null);i.unref(u)[n]=D}else i.unref(u)[n]=h?w?.valueFormat?h:N.formatToDate(h):null;else i.unref(u)[n]=h;w?.onChange&&w?.onChange(h),f.push(n)}else o.forEach(h=>{try{const D=h.split(".").reduce((g,Y)=>g[Y],e);c.isDef(D)&&(i.unref(u)[h]=i.unref(D),f.push(h))}catch{c.isDef(y.value[h])&&(i.unref(u)[h]=b.cloneDeep(i.unref(y.value[h])))}})}),t&&i.nextTick(async()=>{await q(f).catch(n=>{})})}async function P(e){const t=b.cloneDeep(i.unref(l));if(!e)return;let s=c.isString(e)?[e]:e;c.isString(e)&&(s=[e]);for(const r of s)z(r,t);v.value=t}function z(e,t){if(c.isString(e)){const s=t.findIndex(r=>r.field===e);s!==-1&&(delete u[e],t.splice(s,1))}}async function G(e,t,s=!1){const r=b.cloneDeep(i.unref(l)),o=r.findIndex(n=>n.field===t),f=c.isObject(e)?[e]:e;if(!t||o===-1||s){s?r.unshift(...f):r.push(...f),v.value=r,I(e);return}o!==-1&&r.splice(o+1,0,...f),I(e),v.value=r}async function H(e){let t=[];if(c.isObject(e)&&t.push(e),c.isArray(e)&&(t=[...e]),!t.every(r=>r.type===O.FormCompEnum.DIVIDER||Reflect.has(r,"field")&&r.field)){console.error("All children of the form Schema array that need to be updated must contain the `field` field");return}v.value=t}async function J(e){let t=[];if(c.isObject(e)&&t.push(e),c.isArray(e)&&(t=[...e]),!t.every(f=>f.type===O.FormCompEnum.DIVIDER||Reflect.has(f,"field")&&f.field)){console.error("All children of the form Schema array that need to be updated must contain the `field` field");return}const r=[],o=[];i.unref(l).forEach(f=>{let n;if(t.forEach(d=>{f.field===d.field&&(n=d),d.defaultValue&&d.field&&r.push(d.field)}),n!==void 0&&f.field===n.field){const d=c.deepMerge(f,n);o.push(d)}else o.push(f)}),I(o,r),v.value=b.uniqBy(o,"field")}function I(e,t,s=!0){if(c.isArray(t)&&t?.length===0)return;let r=[];c.isObject(e)&&r.push(e),c.isArray(e)&&(r=[...e]);const o={},f=B();r.forEach(n=>{n.type!==O.FormCompEnum.DIVIDER&&Reflect.has(n,"field")&&n.field&&!c.isNullOrUndefined(n.defaultValue)&&(!(n.field in f)||c.isNullOrUndefined(f[n.field])||c.isEmpty(f[n.field]))&&(o[n.field]=n.defaultValue)}),c.isEmptyObject(o)||C(o,s)}function B(){return i.unref(a)?V(i.toRaw(i.unref(u))):{}}function Q(e){return i.unref(a)?i.toRaw(i.unref(u))[e]:{}}function W(e){return i.unref(l).some(t=>t.field===e?O.isDatePicker(t.type):!1)}async function q(e){return e||(e=i.unref(l).filter(s=>U(s,i.unref(u))).map(s=>s.field).filter(Boolean)),i.unref(a)?.validateField(e)}async function T(e){return e||(e=i.unref(l).filter(s=>U(s,i.unref(u))).map(s=>s.field).filter(Boolean)),await i.unref(a)?.validate(()=>{},e)}async function j(e){await i.unref(a)?.clearValidate(e)}async function X(e,t){await i.unref(a)?.scrollToField(e,t)}async function x(e){const{autoCleanErrorMessage:t,watchDataIsChange:s}=i.unref(F);e&&e.preventDefault(),t&&await j();const{submitFunc:r,beforeSubmitFunc:o}=i.unref(F);if(o&&c.isFunction(o)&&await o(),r&&c.isFunction(r)){await r();return}if(i.unref(a))try{const n=await T();if(!n)return;const d=V(n);if(s){const E=b.isEqual(A.value,d),S=c.findDifferentValuesForObj(A.value,d);p("submit",d,!E,S)}else p("submit",d)}catch(n){if(n?.outOfDate===!1&&n?.errorFields)return;throw new Error(n.message)}}return{handleSubmit:x,clearValidate:j,validate:T,validateField:q,getFieldsValue:B,updateSchema:J,resetSchema:H,appendSchemaByField:G,removeSchemaByField:P,resetFields:$,setFieldsValue:C,scrollToField:X,getFieldValue:Q}}exports.useFormEvents=R;
|
package/lib/package.json.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.0.
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e="0.0.342";exports.version=e;
|
package/lib/package.json.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vft",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.342",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -55,12 +55,12 @@
|
|
|
55
55
|
"resize-detector": "0.3.0",
|
|
56
56
|
"sortablejs": "1.15.0",
|
|
57
57
|
"photoswipe": "5.4.4",
|
|
58
|
-
"@vft/directives": "0.0.33",
|
|
59
|
-
"@vft/utils": "0.0.128",
|
|
60
58
|
"@vft/router": "0.0.65",
|
|
61
59
|
"@vft/store": "0.0.54",
|
|
62
60
|
"@vft/constants": "0.0.72",
|
|
63
|
-
"@vft/
|
|
61
|
+
"@vft/utils": "0.0.128",
|
|
62
|
+
"@vft/use": "0.0.76",
|
|
63
|
+
"@vft/directives": "0.0.33"
|
|
64
64
|
},
|
|
65
65
|
"vetur": {
|
|
66
66
|
"tags": "tags.json",
|
package/web-types.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"$schema":"http://json.schemastore.org/web-types","framework":"vue","name":"vft","version":"0.0.
|
|
1
|
+
{"$schema":"http://json.schemastore.org/web-types","framework":"vue","name":"vft","version":"0.0.342","js-types-syntax":"typescript","description-markup":"markdown","contributions":{"html":{}}}
|