@duxweb/dvha-core 1.1.4 → 1.1.5
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/hooks/form.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("lodash-es"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("lodash-es"),u=require("vue"),l=require("./data.cjs");function R(a){const t=u.toRef(a,"form",{}),o=u.toRef(a,"id",void 0),i=u.toRef(a,"meta",{}),v=u.toRef(a,"params",{}),c=u.ref(r.cloneDeep(t.value||{})),d=u.ref(r.cloneDeep(t.value||{})),n=u.computed(()=>a.action==="edit"||!!o.value),{data:m,isLoading:b,refetch:g}=l.useOne({get path(){return a.path||""},get id(){return o.value},get meta(){return{params:{...v.value},...i.value}},options:{enabled:!1},providerName:a.providerName}),s=()=>{let e={};n.value?e=r.cloneDeep(c.value):e=r.cloneDeep(d.value),Object.assign(t.value,e)};u.watch([o,n],async()=>{if(!n.value){s();return}await g();const e=r.cloneDeep(m.value?.data||{});Object.assign(t.value,e),Object.assign(c.value,e)},{immediate:!0,deep:!0}),u.watch([v,i],async()=>{if(!n.value)return;await g();const e=r.cloneDeep(m.value?.data||{});Object.assign(t.value,e),Object.assign(c.value,e)},{deep:!0});const f=l.useCreate({path:a.path??"",data:t.value,get meta(){return i.value||{}},onSuccess:e=>{s(),a.onSuccess?.(e)},onError:e=>{a.onError?.(e)},providerName:a.providerName}),D=l.useUpdate({get path(){return a.path??""},get id(){return o.value},data:t.value,get meta(){return i.value||{}},onSuccess:e=>{a.onSuccess?.(e)},onError:e=>{a.onError?.(e)},providerName:a.providerName}),h=e=>{n.value?D.mutate({id:o.value,data:e||t.value}):f.mutate({data:e||t.value})},O=u.computed(()=>b.value||f.isLoading.value||D.isLoading.value);return{form:t,initData:n.value?c.value:d.value,isLoading:O,isEdit:n,onSubmit:h,onReset:s}}exports.useForm=R;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("vue"),d=require("./form.cjs"),c=require("./formValidate.cjs");function l(e){const o=m.toRef(e,"form",{}),{validate:r,reset:n}=c.useValidateForm({data:o,rules:e.rules}),t=d.useForm({id:e.id,path:e.path,form:o,action:e.action,onSuccess:e.onSuccess,onError:e.onError,providerName:e.providerName,meta:e.meta,params:e.params}),i=s=>{r().then(u=>{if(!u.valid){e.onError?.({message:"表单验证失败"});return}t.onSubmit(s)})},a=()=>{t.onReset(),n()};return{isLoading:t.isLoading,isEdit:t.isEdit,form:o,onSubmit:i,onReset:a}}exports.useExtendForm=l;
|
package/dist/esm/hooks/form.js
CHANGED
|
@@ -1,52 +1,72 @@
|
|
|
1
|
-
import { cloneDeep as
|
|
2
|
-
import { toRef as
|
|
3
|
-
import { useOne as E, useCreate as L, useUpdate as
|
|
4
|
-
function
|
|
5
|
-
const t =
|
|
1
|
+
import { cloneDeep as n } from "lodash-es";
|
|
2
|
+
import { toRef as s, ref as h, computed as b, watch as O } from "vue";
|
|
3
|
+
import { useOne as E, useCreate as L, useUpdate as S } from "./data.js";
|
|
4
|
+
function x(a) {
|
|
5
|
+
const t = s(a, "form", {}), r = s(a, "id", void 0), i = s(a, "meta", {}), l = s(a, "params", {}), o = h(n(t.value || {})), c = h(n(t.value || {})), u = b(() => a.action === "edit" || !!r.value), { data: d, isLoading: D, refetch: m } = E({
|
|
6
6
|
get path() {
|
|
7
7
|
return a.path || "";
|
|
8
8
|
},
|
|
9
9
|
get id() {
|
|
10
|
-
return
|
|
10
|
+
return r.value;
|
|
11
|
+
},
|
|
12
|
+
get meta() {
|
|
13
|
+
return {
|
|
14
|
+
params: {
|
|
15
|
+
...l.value
|
|
16
|
+
},
|
|
17
|
+
...i.value
|
|
18
|
+
};
|
|
11
19
|
},
|
|
12
20
|
options: {
|
|
13
21
|
enabled: !1
|
|
14
22
|
},
|
|
15
23
|
providerName: a.providerName
|
|
16
|
-
}),
|
|
24
|
+
}), v = () => {
|
|
17
25
|
let e = {};
|
|
18
|
-
|
|
26
|
+
u.value ? e = n(o.value) : e = n(c.value), Object.assign(t.value, e);
|
|
19
27
|
};
|
|
20
|
-
|
|
21
|
-
if (!
|
|
22
|
-
|
|
28
|
+
O([r, u], async () => {
|
|
29
|
+
if (!u.value) {
|
|
30
|
+
v();
|
|
23
31
|
return;
|
|
24
32
|
}
|
|
25
|
-
await
|
|
26
|
-
const e =
|
|
33
|
+
await m();
|
|
34
|
+
const e = n(d.value?.data || {});
|
|
27
35
|
Object.assign(t.value, e), Object.assign(o.value, e);
|
|
28
36
|
}, {
|
|
29
37
|
immediate: !0,
|
|
30
38
|
deep: !0
|
|
31
|
-
})
|
|
32
|
-
|
|
39
|
+
}), O([l, i], async () => {
|
|
40
|
+
if (!u.value)
|
|
41
|
+
return;
|
|
42
|
+
await m();
|
|
43
|
+
const e = n(d.value?.data || {});
|
|
44
|
+
Object.assign(t.value, e), Object.assign(o.value, e);
|
|
45
|
+
}, { deep: !0 });
|
|
46
|
+
const g = L({
|
|
33
47
|
path: a.path ?? "",
|
|
34
48
|
data: t.value,
|
|
49
|
+
get meta() {
|
|
50
|
+
return i.value || {};
|
|
51
|
+
},
|
|
35
52
|
onSuccess: (e) => {
|
|
36
|
-
|
|
53
|
+
v(), a.onSuccess?.(e);
|
|
37
54
|
},
|
|
38
55
|
onError: (e) => {
|
|
39
56
|
a.onError?.(e);
|
|
40
57
|
},
|
|
41
58
|
providerName: a.providerName
|
|
42
|
-
}),
|
|
59
|
+
}), f = S({
|
|
43
60
|
get path() {
|
|
44
61
|
return a.path ?? "";
|
|
45
62
|
},
|
|
46
63
|
get id() {
|
|
47
|
-
return
|
|
64
|
+
return r.value;
|
|
48
65
|
},
|
|
49
66
|
data: t.value,
|
|
67
|
+
get meta() {
|
|
68
|
+
return i.value || {};
|
|
69
|
+
},
|
|
50
70
|
onSuccess: (e) => {
|
|
51
71
|
a.onSuccess?.(e);
|
|
52
72
|
},
|
|
@@ -54,23 +74,23 @@ function w(a) {
|
|
|
54
74
|
a.onError?.(e);
|
|
55
75
|
},
|
|
56
76
|
providerName: a.providerName
|
|
57
|
-
}),
|
|
58
|
-
|
|
59
|
-
id:
|
|
77
|
+
}), N = (e) => {
|
|
78
|
+
u.value ? f.mutate({
|
|
79
|
+
id: r.value,
|
|
60
80
|
data: e || t.value
|
|
61
|
-
}) :
|
|
81
|
+
}) : g.mutate({
|
|
62
82
|
data: e || t.value
|
|
63
83
|
});
|
|
64
|
-
},
|
|
84
|
+
}, j = b(() => D.value || g.isLoading.value || f.isLoading.value);
|
|
65
85
|
return {
|
|
66
86
|
form: t,
|
|
67
|
-
initData:
|
|
68
|
-
isLoading:
|
|
69
|
-
isEdit:
|
|
70
|
-
onSubmit:
|
|
71
|
-
onReset:
|
|
87
|
+
initData: u.value ? o.value : c.value,
|
|
88
|
+
isLoading: j,
|
|
89
|
+
isEdit: u,
|
|
90
|
+
onSubmit: N,
|
|
91
|
+
onReset: v
|
|
72
92
|
};
|
|
73
93
|
}
|
|
74
94
|
export {
|
|
75
|
-
|
|
95
|
+
x as useForm
|
|
76
96
|
};
|
|
@@ -1,39 +1,41 @@
|
|
|
1
|
-
import { toRef as
|
|
2
|
-
import { useForm as
|
|
3
|
-
import { useValidateForm as
|
|
4
|
-
function
|
|
5
|
-
const
|
|
6
|
-
data:
|
|
7
|
-
rules:
|
|
8
|
-
}),
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
1
|
+
import { toRef as d } from "vue";
|
|
2
|
+
import { useForm as u } from "./form.js";
|
|
3
|
+
import { useValidateForm as c } from "./formValidate.js";
|
|
4
|
+
function v(t) {
|
|
5
|
+
const o = d(t, "form", {}), { validate: i, reset: n } = c({
|
|
6
|
+
data: o,
|
|
7
|
+
rules: t.rules
|
|
8
|
+
}), e = u({
|
|
9
|
+
id: t.id,
|
|
10
|
+
path: t.path,
|
|
11
|
+
form: o,
|
|
12
|
+
action: t.action,
|
|
13
|
+
onSuccess: t.onSuccess,
|
|
14
|
+
onError: t.onError,
|
|
15
|
+
providerName: t.providerName,
|
|
16
|
+
meta: t.meta,
|
|
17
|
+
params: t.params
|
|
18
|
+
}), r = (m) => {
|
|
19
|
+
i().then((s) => {
|
|
20
|
+
if (!s.valid) {
|
|
21
|
+
t.onError?.({
|
|
20
22
|
message: "表单验证失败"
|
|
21
23
|
});
|
|
22
24
|
return;
|
|
23
25
|
}
|
|
24
|
-
|
|
26
|
+
e.onSubmit(m);
|
|
25
27
|
});
|
|
26
28
|
}, a = () => {
|
|
27
|
-
|
|
29
|
+
e.onReset(), n();
|
|
28
30
|
};
|
|
29
31
|
return {
|
|
30
|
-
isLoading:
|
|
31
|
-
isEdit:
|
|
32
|
-
form:
|
|
33
|
-
onSubmit:
|
|
32
|
+
isLoading: e.isLoading,
|
|
33
|
+
isEdit: e.isEdit,
|
|
34
|
+
form: o,
|
|
35
|
+
onSubmit: r,
|
|
34
36
|
onReset: a
|
|
35
37
|
};
|
|
36
38
|
}
|
|
37
39
|
export {
|
|
38
|
-
|
|
40
|
+
v as useExtendForm
|
|
39
41
|
};
|
|
@@ -9,6 +9,8 @@ export interface IUseFormProps {
|
|
|
9
9
|
onError?: (error: IDataProviderError) => void;
|
|
10
10
|
action?: 'create' | 'edit';
|
|
11
11
|
providerName?: string;
|
|
12
|
+
meta?: MaybeRef<Record<string, any>>;
|
|
13
|
+
params?: MaybeRef<Record<string, any>>;
|
|
12
14
|
}
|
|
13
15
|
export declare function useForm(props: IUseFormProps): {
|
|
14
16
|
form: import("vue").Ref<MaybeRef<Record<string, any>>, MaybeRef<Record<string, any>>>;
|