@duxweb/dvha-core 1.1.3 → 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.
@@ -1 +1 @@
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;
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 s=require("vue"),c=require("./form.cjs"),f=require("./formValidate.cjs");function l(e){const o=s.toRef(e,"form",{}),{validate:i,reset:u}=f.useValidateForm({data:o,rules:e.rules}),a=s.computed(()=>{const{form:n,...r}=e;return{...r}}),t=c.useForm({...a.value,form:o.value}),m=n=>{i().then(r=>{if(!r.valid){e.onError?.({message:"表单验证失败"});return}t.onSubmit(n)})},d=()=>{t.onReset(),u()};return{isLoading:t.isLoading,isEdit:t.isEdit,form:o,onSubmit:m,onReset:d}}exports.useExtendForm=l;
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;
@@ -1,52 +1,72 @@
1
- import { cloneDeep as i } from "lodash-es";
2
- import { toRef as v, ref as l, computed as m, watch as b } from "vue";
3
- import { useOne as E, useCreate as L, useUpdate as O } from "./data.js";
4
- function w(a) {
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({
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 u.value;
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
- }), r = () => {
24
+ }), v = () => {
17
25
  let e = {};
18
- n.value ? e = i(o.value) : e = i(s.value), Object.assign(t.value, e);
26
+ u.value ? e = n(o.value) : e = n(c.value), Object.assign(t.value, e);
19
27
  };
20
- b([u, n], async () => {
21
- if (!n.value) {
22
- r();
28
+ O([r, u], async () => {
29
+ if (!u.value) {
30
+ v();
23
31
  return;
24
32
  }
25
- await h();
26
- const e = i(f.value?.data || {});
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
- const c = L({
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
- r(), a.onSuccess?.(e);
53
+ v(), a.onSuccess?.(e);
37
54
  },
38
55
  onError: (e) => {
39
56
  a.onError?.(e);
40
57
  },
41
58
  providerName: a.providerName
42
- }), d = O({
59
+ }), f = S({
43
60
  get path() {
44
61
  return a.path ?? "";
45
62
  },
46
63
  get id() {
47
- return u.value;
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
- }), D = (e) => {
58
- n.value ? d.mutate({
59
- id: u.value,
77
+ }), N = (e) => {
78
+ u.value ? f.mutate({
79
+ id: r.value,
60
80
  data: e || t.value
61
- }) : c.mutate({
81
+ }) : g.mutate({
62
82
  data: e || t.value
63
83
  });
64
- }, N = m(() => g.value || c.isLoading.value || d.isLoading.value);
84
+ }, j = b(() => D.value || g.isLoading.value || f.isLoading.value);
65
85
  return {
66
86
  form: t,
67
- initData: n.value ? o.value : s.value,
68
- isLoading: N,
69
- isEdit: n,
70
- onSubmit: D,
71
- onReset: r
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
- w as useForm
95
+ x as useForm
76
96
  };
@@ -1,39 +1,41 @@
1
- import { toRef as f, computed as d } from "vue";
2
- import { useForm as c } from "./form.js";
3
- import { useValidateForm as l } from "./formValidate.js";
4
- function g(o) {
5
- const e = f(o, "form", {}), { validate: s, reset: i } = l({
6
- data: e,
7
- rules: o.rules
8
- }), m = d(() => {
9
- const { form: n, ...r } = o;
10
- return {
11
- ...r
12
- };
13
- }), t = c({
14
- ...m.value,
15
- form: e.value
16
- }), u = (n) => {
17
- s().then((r) => {
18
- if (!r.valid) {
19
- o.onError?.({
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
- t.onSubmit(n);
26
+ e.onSubmit(m);
25
27
  });
26
28
  }, a = () => {
27
- t.onReset(), i();
29
+ e.onReset(), n();
28
30
  };
29
31
  return {
30
- isLoading: t.isLoading,
31
- isEdit: t.isEdit,
32
- form: e,
33
- onSubmit: u,
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
- g as useExtendForm
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>>>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@duxweb/dvha-core",
3
3
  "type": "module",
4
- "version": "1.1.3",
4
+ "version": "1.1.5",
5
5
  "author": "DuxWeb",
6
6
  "license": "MIT",
7
7
  "repository": {