@duxweb/dvha-core 1.0.42 → 1.0.44
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
|
|
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;
|
package/dist/esm/hooks/select.js
CHANGED
|
@@ -1,82 +1,91 @@
|
|
|
1
|
-
import { debounce as
|
|
2
|
-
import { ref as u,
|
|
3
|
-
import { useList as
|
|
4
|
-
function
|
|
5
|
-
const r = 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
|
|
8
|
-
}),
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
|
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
|
|
30
|
+
return a.pagination ? d.value : void 0;
|
|
22
31
|
},
|
|
23
32
|
get providerName() {
|
|
24
|
-
return
|
|
33
|
+
return a.providerName;
|
|
25
34
|
}
|
|
26
|
-
}),
|
|
27
|
-
const
|
|
28
|
-
return typeof
|
|
29
|
-
},
|
|
30
|
-
const { optionLabel:
|
|
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
|
|
33
|
-
let
|
|
34
|
-
return typeof
|
|
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:
|
|
45
|
+
value: l,
|
|
37
46
|
raw: e
|
|
38
47
|
};
|
|
39
|
-
},
|
|
40
|
-
const e =
|
|
41
|
-
return e.forEach((
|
|
42
|
-
|
|
43
|
-
(
|
|
44
|
-
) ||
|
|
45
|
-
}),
|
|
46
|
-
}),
|
|
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
|
|
57
|
+
return a.path || "";
|
|
49
58
|
},
|
|
50
59
|
get ids() {
|
|
51
|
-
return
|
|
60
|
+
return F(r.value) ? r.value : [r.value];
|
|
52
61
|
},
|
|
53
62
|
options: {
|
|
54
63
|
enabled: !1
|
|
55
64
|
},
|
|
56
|
-
providerName:
|
|
65
|
+
providerName: a.providerName
|
|
57
66
|
});
|
|
58
|
-
|
|
59
|
-
if (!(
|
|
60
|
-
(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
|
|
64
|
-
|
|
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
|
|
77
|
+
}, { immediate: !0, deep: !0 });
|
|
78
|
+
const A = s(() => w.value);
|
|
70
79
|
return {
|
|
71
|
-
onSearch:
|
|
72
|
-
options:
|
|
73
|
-
meta:
|
|
74
|
-
loading:
|
|
75
|
-
pagination:
|
|
76
|
-
total:
|
|
77
|
-
pageCount:
|
|
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
|
-
|
|
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 {
|