@duxweb/dvha-core 1.0.42 → 1.0.43

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 v=require("lodash-es"),o=require("vue"),y=require("./data.cjs");function k(t){const r=o.ref(),i=o.ref({page:1,pageSize:typeof t.pagination=="number"?t.pagination:t.pagination?20:0}),c=o.ref(!1),b=v.debounce(e=>{r.value=e},t.debounce||300),h=e=>{b(e)},{data:s,isLoading:V,total:S,pageCount:w}=y.useList({get path(){return t.path||""},get filters(){const e={...t.params};return r.value&&(e[t.keywordField||"keyword"]=r.value),e},get pagination(){return t.pagination?i.value:void 0},get providerName(){return t.providerName}}),d=o.ref([]),f=e=>{const a=t.optionField||t.optionValue;return typeof a=="string"?e[a]||e.value||e.id:typeof a=="function"?a(e):e.value||e.id},x=e=>{const{optionLabel:a="label",optionValue:l="value"}=t;let n;typeof a=="function"?n=a(e):typeof a=="string"?n=e[a]||e.label||e.name||e.title||String(e.value||e.id||""):n=e.label||e.name||e.title||String(e.value||e.id||"");let u;return typeof l=="function"?u=l(e):typeof l=="string"?u=e[l]||e.value||e.id:u=e.value||e.id,{label:n,value:u,raw:e}},g=o.computed(()=>{const e=s.value?.data||[],a=[...d.value];return e.forEach(l=>{a.some(u=>f(u)===f(l))||a.push(l)}),a.map(l=>x(l))}),F=o.computed(()=>s.value?.meta||{}),{refetch:N}=y.useMany({get path(){return t.path||""},get ids(){return t.defaultValue?v.isArray(t.defaultValue)?t.defaultValue:[t.defaultValue]:[]},options:{enabled:!1},providerName:t.providerName});o.watch(()=>t.defaultValue,async e=>{if(!(c.value||!e||(c.value=!0,(Array.isArray(e)?e:[e]).every(n=>g.value.some(u=>u.value===n)))))try{const n=await N();d.value=n?.data?.data||[]}catch(n){console.warn("Failed to fetch selected items:",n)}},{immediate:!0});const O=o.computed(()=>V.value);return{onSearch:h,options:g,meta:F,loading:O,pagination:i,total:S,pageCount:w}}exports.useSelect=k;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("lodash-es"),o=require("vue"),p=require("./data.cjs");function A(t){const r=o.toRef(t,"defaultValue"),c=o.ref(),i=o.ref({page:1,pageSize:typeof t.pagination=="number"?t.pagination:t.pagination?20:0}),d=o.ref(!1),s=o.ref({...t.params,keyword:""}),b=h.debounce(e=>{c.value=e,s.value.keyword=e},t.debounce||300),S=e=>{b(e)};o.watch(()=>t.params,e=>{s.value={keyword:c.value,...e}},{deep:!0});const{data:f,isLoading:V,total:w,pageCount:k}=p.useList({get path(){return t.path||""},filters:s,get pagination(){return t.pagination?i.value:void 0},get providerName(){return t.providerName}}),v=o.ref([]),g=e=>{const a=t.optionField||t.optionValue;return typeof a=="string"?e[a]||e.value||e.id:typeof a=="function"?a(e):e.value||e.id},x=e=>{const{optionLabel:a="label",optionValue:l="value"}=t;let n;typeof a=="function"?n=a(e):typeof a=="string"?n=e[a]||e.label||e.name||e.title||String(e.value||e.id||""):n=e.label||e.name||e.title||String(e.value||e.id||"");let u;return typeof l=="function"?u=l(e):typeof l=="string"?u=e[l]||e.value||e.id:u=e.value||e.id,{label:n,value:u,raw:e}},y=o.computed(()=>{const e=f.value?.data||[],a=[...v.value];return e.forEach(l=>{a.some(u=>g(u)===g(l))||a.push(l)}),a.map(l=>x(l))}),N=o.computed(()=>f.value?.meta||{}),{refetch:O}=p.useMany({get path(){return t.path||""},get ids(){return h.isArray(r.value)?r.value:[r.value]},options:{enabled:!1},providerName:t.providerName});o.watch(r,async e=>{if(!(d.value||!e||(d.value=!0,(Array.isArray(e)?e:[e]).every(n=>y.value.some(u=>u.value===n)))))try{const n=await O();v.value=n?.data?.data||[]}catch(n){console.warn("Failed to fetch selected items:",n)}},{immediate:!0,deep:!0});const q=o.computed(()=>V.value);return{onSearch:S,options:y,meta:N,loading:q,pagination:i,total:w,pageCount:k}}exports.useSelect=A;
@@ -1,82 +1,91 @@
1
- import { debounce as N, isArray as k } from "lodash-es";
2
- import { ref as u, computed as i, watch as A } from "vue";
3
- import { useList as E, useMany as L } from "./data.js";
4
- function z(t) {
5
- const r = u(), s = u({
1
+ import { debounce as E, isArray as F } from "lodash-es";
2
+ import { toRef as L, ref as u, watch as h, computed as s } from "vue";
3
+ import { useList as O, useMany as C } from "./data.js";
4
+ function M(a) {
5
+ const r = L(a, "defaultValue"), c = u(), d = u({
6
6
  page: 1,
7
- pageSize: typeof t.pagination == "number" ? t.pagination : t.pagination ? 20 : 0
8
- }), c = u(!1), y = N((e) => {
9
- r.value = e;
10
- }, t.debounce || 300), h = (e) => {
11
- y(e);
12
- }, { data: d, isLoading: V, total: b, pageCount: w } = E({
7
+ pageSize: typeof a.pagination == "number" ? a.pagination : a.pagination ? 20 : 0
8
+ }), f = u(!1), i = u({
9
+ ...a.params,
10
+ keyword: ""
11
+ }), b = E((e) => {
12
+ c.value = e, i.value.keyword = e;
13
+ }, a.debounce || 300), V = (e) => {
14
+ b(e);
15
+ };
16
+ h(() => a.params, (e) => {
17
+ i.value = {
18
+ keyword: c.value,
19
+ ...e
20
+ };
21
+ }, {
22
+ deep: !0
23
+ });
24
+ const { data: v, isLoading: w, total: S, pageCount: x } = O({
13
25
  get path() {
14
- return t.path || "";
15
- },
16
- get filters() {
17
- const e = { ...t.params };
18
- return r.value && (e[t.keywordField || "keyword"] = r.value), e;
26
+ return a.path || "";
19
27
  },
28
+ filters: i,
20
29
  get pagination() {
21
- return t.pagination ? s.value : void 0;
30
+ return a.pagination ? d.value : void 0;
22
31
  },
23
32
  get providerName() {
24
- return t.providerName;
33
+ return a.providerName;
25
34
  }
26
- }), f = u([]), g = (e) => {
27
- const a = t.optionField || t.optionValue;
28
- return typeof a == "string" ? e[a] || e.value || e.id : typeof a == "function" ? a(e) : e.value || e.id;
29
- }, S = (e) => {
30
- const { optionLabel: a = "label", optionValue: l = "value" } = t;
35
+ }), g = u([]), y = (e) => {
36
+ const t = a.optionField || a.optionValue;
37
+ return typeof t == "string" ? e[t] || e.value || e.id : typeof t == "function" ? t(e) : e.value || e.id;
38
+ }, k = (e) => {
39
+ const { optionLabel: t = "label", optionValue: o = "value" } = a;
31
40
  let n;
32
- typeof a == "function" ? n = a(e) : typeof a == "string" ? n = e[a] || e.label || e.name || e.title || String(e.value || e.id || "") : n = e.label || e.name || e.title || String(e.value || e.id || "");
33
- let o;
34
- return typeof l == "function" ? o = l(e) : typeof l == "string" ? o = e[l] || e.value || e.id : o = e.value || e.id, {
41
+ typeof t == "function" ? n = t(e) : typeof t == "string" ? n = e[t] || e.label || e.name || e.title || String(e.value || e.id || "") : n = e.label || e.name || e.title || String(e.value || e.id || "");
42
+ let l;
43
+ return typeof o == "function" ? l = o(e) : typeof o == "string" ? l = e[o] || e.value || e.id : l = e.value || e.id, {
35
44
  label: n,
36
- value: o,
45
+ value: l,
37
46
  raw: e
38
47
  };
39
- }, v = i(() => {
40
- const e = d.value?.data || [], a = [...f.value];
41
- return e.forEach((l) => {
42
- a.some(
43
- (o) => g(o) === g(l)
44
- ) || a.push(l);
45
- }), a.map((l) => S(l));
46
- }), x = i(() => d.value?.meta || {}), { refetch: p } = L({
48
+ }, p = s(() => {
49
+ const e = v.value?.data || [], t = [...g.value];
50
+ return e.forEach((o) => {
51
+ t.some(
52
+ (l) => y(l) === y(o)
53
+ ) || t.push(o);
54
+ }), t.map((o) => k(o));
55
+ }), N = s(() => v.value?.meta || {}), { refetch: m } = C({
47
56
  get path() {
48
- return t.path || "";
57
+ return a.path || "";
49
58
  },
50
59
  get ids() {
51
- return t.defaultValue ? k(t.defaultValue) ? t.defaultValue : [t.defaultValue] : [];
60
+ return F(r.value) ? r.value : [r.value];
52
61
  },
53
62
  options: {
54
63
  enabled: !1
55
64
  },
56
- providerName: t.providerName
65
+ providerName: a.providerName
57
66
  });
58
- A(() => t.defaultValue, async (e) => {
59
- if (!(c.value || !e || (c.value = !0, (Array.isArray(e) ? e : [e]).every(
60
- (n) => v.value.some((o) => o.value === n)
67
+ h(r, async (e) => {
68
+ if (!(f.value || !e || (f.value = !0, (Array.isArray(e) ? e : [e]).every(
69
+ (n) => p.value.some((l) => l.value === n)
61
70
  ))))
62
71
  try {
63
- const n = await p();
64
- f.value = n?.data?.data || [];
72
+ const n = await m();
73
+ g.value = n?.data?.data || [];
65
74
  } catch (n) {
66
75
  console.warn("Failed to fetch selected items:", n);
67
76
  }
68
- }, { immediate: !0 });
69
- const F = i(() => V.value);
77
+ }, { immediate: !0, deep: !0 });
78
+ const A = s(() => w.value);
70
79
  return {
71
- onSearch: h,
72
- options: v,
73
- meta: x,
74
- loading: F,
75
- pagination: s,
76
- total: b,
77
- pageCount: w
80
+ onSearch: V,
81
+ options: p,
82
+ meta: N,
83
+ loading: A,
84
+ pagination: d,
85
+ total: S,
86
+ pageCount: x
78
87
  };
79
88
  }
80
89
  export {
81
- z as useSelect
90
+ M as useSelect
82
91
  };
@@ -1,7 +1,8 @@
1
+ import type { MaybeRef } from 'vue';
1
2
  type SelectValue = Array<string | number> | string | number | null | undefined;
2
3
  export interface IUseSelectProps {
3
4
  /** 默认选中值,可以是单个值或数组 */
4
- defaultValue?: SelectValue;
5
+ defaultValue?: MaybeRef<SelectValue>;
5
6
  /** 数据请求路径 */
6
7
  path?: string;
7
8
  /** 请求参数 */
@@ -1,3 +1,4 @@
1
+ import type { MaybeRef } from 'vue';
1
2
  import type { IManageHook } from '../hooks';
2
3
  import type { IUserState } from '../stores';
3
4
  /**
@@ -42,8 +43,8 @@ export interface IDataProviderPagination {
42
43
  export interface IDataProviderListOptions {
43
44
  path: string;
44
45
  pagination?: IDataProviderPagination | boolean;
45
- sorters?: Record<string, 'asc' | 'desc'>;
46
- filters?: Record<string, any>;
46
+ sorters?: MaybeRef<Record<string, 'asc' | 'desc'>>;
47
+ filters?: MaybeRef<Record<string, any>>;
47
48
  meta?: Record<string, any>;
48
49
  }
49
50
  export interface IDataProviderCreateOptions {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@duxweb/dvha-core",
3
3
  "type": "module",
4
- "version": "1.0.42",
4
+ "version": "1.0.43",
5
5
  "author": "DuxWeb",
6
6
  "license": "MIT",
7
7
  "repository": {