@duxweb/dvha-core 1.0.26 → 1.0.28
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"),n=require("vue"),s=require("./data.cjs");function b(a){const t=n.toRef(a,"form",{}),o=n.toRef(a,"id",void 0),i=n.ref(r.cloneDeep(t.value||{})),l=n.ref(r.cloneDeep(t.value||{})),u=n.computed(()=>a.action==="edit"||!!o.value),{data:m,isLoading:g,refetch:f}=s.useOne({get path(){return a.path||""},get id(){return o.value},options:{enabled:!1},providerName:a.providerName}),c=()=>{let e={};u.value?e=r.cloneDeep(i.value):e=r.cloneDeep(l.value),Object.assign(t.value,e)};n.watch([o,u],async()=>{if(!u.value){c();return}await f();const e=r.cloneDeep(m.value?.data||{});Object.assign(t.value,e),Object.assign(i.value,e)},{immediate:!0,deep:!0});const d=s.useCreate({path:a.path??"",data:t.value,onSuccess:e=>{c(),a.onSuccess?.(e)},onError:e=>{a.onError?.(e)},providerName:a.providerName}),v=s.useUpdate({get path(){return a.path??""},get id(){return o.value},data:t.value,onSuccess:e=>{a.onSuccess?.(e)},onError:e=>{a.onError?.(e)},providerName:a.providerName}),D=e=>{u.value?v.mutate({id:o.value,data:e||t.value}):d.mutate({data:e||t.value})},h=n.computed(()=>g.value||d.isLoading.value||v.isLoading.value);return{form:t,initData:u.value?i.value:l.value,isLoading:h,isEdit:u,onSubmit:D,onReset:c}}exports.useForm=b;
|
package/dist/esm/hooks/form.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { cloneDeep as i } from "lodash-es";
|
|
2
|
-
import { toRef as
|
|
2
|
+
import { toRef as v, ref as l, computed as m, watch as b } from "vue";
|
|
3
3
|
import { useOne as E, useCreate as L, useUpdate as O } from "./data.js";
|
|
4
4
|
function w(a) {
|
|
5
|
-
const t =
|
|
5
|
+
const t = v(a, "form", {}), u = v(a, "id", void 0), o = l(i(t.value || {})), s = l(i(t.value || {})), n = m(() => a.action === "edit" || !!u.value), { data: f, isLoading: g, refetch: h } = E({
|
|
6
6
|
get path() {
|
|
7
7
|
return a.path || "";
|
|
8
8
|
},
|
|
@@ -10,12 +10,12 @@ function w(a) {
|
|
|
10
10
|
return u.value;
|
|
11
11
|
},
|
|
12
12
|
options: {
|
|
13
|
-
enabled:
|
|
13
|
+
enabled: !1
|
|
14
14
|
},
|
|
15
15
|
providerName: a.providerName
|
|
16
16
|
}), r = () => {
|
|
17
17
|
let e = {};
|
|
18
|
-
n.value ? e = i(o.value) : e = i(
|
|
18
|
+
n.value ? e = i(o.value) : e = i(s.value), Object.assign(t.value, e);
|
|
19
19
|
};
|
|
20
20
|
b([u, n], async () => {
|
|
21
21
|
if (!n.value) {
|
|
@@ -26,7 +26,8 @@ function w(a) {
|
|
|
26
26
|
const e = i(f.value?.data || {});
|
|
27
27
|
Object.assign(t.value, e), Object.assign(o.value, e);
|
|
28
28
|
}, {
|
|
29
|
-
immediate: !0
|
|
29
|
+
immediate: !0,
|
|
30
|
+
deep: !0
|
|
30
31
|
});
|
|
31
32
|
const c = L({
|
|
32
33
|
path: a.path ?? "",
|
|
@@ -38,7 +39,7 @@ function w(a) {
|
|
|
38
39
|
a.onError?.(e);
|
|
39
40
|
},
|
|
40
41
|
providerName: a.providerName
|
|
41
|
-
}),
|
|
42
|
+
}), d = O({
|
|
42
43
|
get path() {
|
|
43
44
|
return a.path ?? "";
|
|
44
45
|
},
|
|
@@ -54,16 +55,16 @@ function w(a) {
|
|
|
54
55
|
},
|
|
55
56
|
providerName: a.providerName
|
|
56
57
|
}), D = (e) => {
|
|
57
|
-
n.value ?
|
|
58
|
+
n.value ? d.mutate({
|
|
58
59
|
id: u.value,
|
|
59
60
|
data: e || t.value
|
|
60
61
|
}) : c.mutate({
|
|
61
62
|
data: e || t.value
|
|
62
63
|
});
|
|
63
|
-
}, N = m(() => g.value || c.isLoading.value ||
|
|
64
|
+
}, N = m(() => g.value || c.isLoading.value || d.isLoading.value);
|
|
64
65
|
return {
|
|
65
66
|
form: t,
|
|
66
|
-
initData: n.value ? o.value :
|
|
67
|
+
initData: n.value ? o.value : s.value,
|
|
67
68
|
isLoading: N,
|
|
68
69
|
isEdit: n,
|
|
69
70
|
onSubmit: D,
|
|
@@ -48,7 +48,7 @@ export interface IDataProviderListOptions {
|
|
|
48
48
|
}
|
|
49
49
|
export interface IDataProviderCreateOptions {
|
|
50
50
|
path?: string;
|
|
51
|
-
data
|
|
51
|
+
data?: any;
|
|
52
52
|
meta?: Record<string, any>;
|
|
53
53
|
}
|
|
54
54
|
export interface IDataProviderUpdateOptions extends IDataProviderCreateOptions {
|