@duxweb/dvha-core 1.1.18 → 1.1.19
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 w=require("lodash-es"),a=require("vue"),S=require("./data.cjs");function q(r){const s=a.toRef(r,"defaultValue"),c=a.ref(),i=a.computed(()=>a.unref(r.path)||""),d=a.computed(()=>a.unref(r.params)||{}),f=a.computed(()=>a.unref(r.providerName)),v=a.ref({page:1,pageSize:typeof r.pagination=="number"?r.pagination:r.pagination?20:0}),g=a.ref(!1),l=a.reactive({keyword:"",...d.value}),V=w.debounce(e=>{c.value=e,l.keyword=e},r.debounce||300),O=e=>{V(e)};a.watch(d,e=>{const t=e||{};Object.keys(l).forEach(n=>{n!=="keyword"&&(n in t||delete l[n])}),Object.entries(t).forEach(([n,o])=>{l[n]=o}),l.keyword=c.value||""},{deep:!0,immediate:!0});const{data:p,isLoading:m,total:E,pageCount:k}=S.useList({get path(){return i.value},filters:l,get pagination(){return r.pagination?v.value:void 0},get providerName(){return f.value}}),y=a.ref([]),h=e=>{const t=r.optionField||r.optionValue;return typeof t=="string"?e[t]||e.value||e.id:typeof t=="function"?t(e):e.value||e.id},x=e=>{const{optionLabel:t="label",optionValue:n="value"}=r;let o;typeof t=="function"?o=t(e):typeof t=="string"?o=e[t]||e.label||e.name||e.title||String(e.value||e.id||""):o=e.label||e.name||e.title||String(e.value||e.id||"");let u;return typeof n=="function"?u=n(e):typeof n=="string"?u=e[n]||e.value||e.id:u=e.value||e.id,{label:o,value:u,raw:e}},b=a.computed(()=>{const e=p.value?.data||[],t=[...y.value];return e.forEach(n=>{t.some(u=>h(u)===h(n))||t.push(n)}),t.map(n=>x(n))}),N=a.computed(()=>p.value?.meta||{}),{refetch:P}=S.useMany({get path(){return i.value},get ids(){return w.isArray(s.value)?s.value:[s.value]},options:{enabled:!1},providerName:f.value});a.watch(s,async e=>{if(!(g.value||!e||(g.value=!0,(Array.isArray(e)?e:[e]).every(o=>b.value.some(u=>u.value===o)))))try{const o=await P();y.value=o?.data?.data||[]}catch(o){console.warn("Failed to fetch selected items:",o)}},{immediate:!0,deep:!0});const j=a.computed(()=>m.value);return{onSearch:O,options:b,meta:N,loading:j,pagination:v,total:E,pageCount:k}}exports.useSelect=q;
|
package/dist/cjs/hooks/tree.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("vue");require("../utils/bus.cjs");const s=require("../utils/tree.cjs"),y=require("./data.cjs");function f(t){const l=e.computed(()=>e.unref(t.path)||""),c=e.computed(()=>e.unref(t.params)||{}),h=e.computed(()=>e.unref(t.providerName)),a=e.reactive({...c.value});e.watch(c,i=>{const o=i||{};Object.keys(a).forEach(n=>{n in o||delete a[n]}),Object.entries(o).forEach(([n,r])=>{a[n]=r})},{deep:!0,immediate:!0});const{data:u,isLoading:m}=y.useList({get path(){return l.value},filters:a,get providerName(){return h.value}}),d=e.computed(()=>t.converTree?s.arrayToTree(u.value?.data||[],{idKey:t.treeOptions?.valueKey||"id",parentKey:t.treeOptions?.parentKey||"parent_id",sortKey:t.treeOptions?.sortKey||"sort",childrenKey:t.treeOptions?.childrenKey||"children"}):u.value?.data||[]),v=e.computed(()=>s.treeToArr(d.value,t.treeOptions?.valueKey||"id",t.treeOptions?.childrenKey||"children")),p=e.computed(()=>m.value);return{options:e.computed(()=>{const i=o=>o.map(n=>{const r={...n};return Array.isArray(r.children)&&(r.children.length===0?delete r.children:r.children=i(r.children)),r});return i(d.value||[])}),loading:p,expanded:v}}exports.useTree=f;
|
package/dist/esm/hooks/select.js
CHANGED
|
@@ -1,91 +1,94 @@
|
|
|
1
|
-
import { debounce as
|
|
2
|
-
import { toRef as
|
|
3
|
-
import { useList as
|
|
4
|
-
function
|
|
5
|
-
const
|
|
1
|
+
import { debounce as P, isArray as j } from "lodash-es";
|
|
2
|
+
import { toRef as C, ref as i, computed as u, unref as c, reactive as z, watch as S } from "vue";
|
|
3
|
+
import { useList as D, useMany as I } from "./data.js";
|
|
4
|
+
function B(o) {
|
|
5
|
+
const s = C(o, "defaultValue"), d = i(), f = u(() => c(o.path) || ""), v = u(() => c(o.params) || {}), g = u(() => c(o.providerName)), p = i({
|
|
6
6
|
page: 1,
|
|
7
|
-
pageSize: typeof
|
|
8
|
-
}),
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}),
|
|
12
|
-
|
|
13
|
-
},
|
|
14
|
-
|
|
7
|
+
pageSize: typeof o.pagination == "number" ? o.pagination : o.pagination ? 20 : 0
|
|
8
|
+
}), y = i(!1), r = z({
|
|
9
|
+
keyword: "",
|
|
10
|
+
...v.value
|
|
11
|
+
}), m = P((e) => {
|
|
12
|
+
d.value = e, r.keyword = e;
|
|
13
|
+
}, o.debounce || 300), x = (e) => {
|
|
14
|
+
m(e);
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
16
|
+
S(v, (e) => {
|
|
17
|
+
const t = e || {};
|
|
18
|
+
Object.keys(r).forEach((a) => {
|
|
19
|
+
a !== "keyword" && (a in t || delete r[a]);
|
|
20
|
+
}), Object.entries(t).forEach(([a, n]) => {
|
|
21
|
+
r[a] = n;
|
|
22
|
+
}), r.keyword = d.value || "";
|
|
21
23
|
}, {
|
|
22
|
-
deep: !0
|
|
24
|
+
deep: !0,
|
|
25
|
+
immediate: !0
|
|
23
26
|
});
|
|
24
|
-
const { data:
|
|
27
|
+
const { data: h, isLoading: E, total: O, pageCount: k } = D({
|
|
25
28
|
get path() {
|
|
26
|
-
return
|
|
29
|
+
return f.value;
|
|
27
30
|
},
|
|
28
|
-
filters:
|
|
31
|
+
filters: r,
|
|
29
32
|
get pagination() {
|
|
30
|
-
return
|
|
33
|
+
return o.pagination ? p.value : void 0;
|
|
31
34
|
},
|
|
32
35
|
get providerName() {
|
|
33
|
-
return
|
|
36
|
+
return g.value;
|
|
34
37
|
}
|
|
35
|
-
}),
|
|
36
|
-
const t =
|
|
38
|
+
}), b = i([]), w = (e) => {
|
|
39
|
+
const t = o.optionField || o.optionValue;
|
|
37
40
|
return typeof t == "string" ? e[t] || e.value || e.id : typeof t == "function" ? t(e) : e.value || e.id;
|
|
38
|
-
},
|
|
39
|
-
const { optionLabel: t = "label", optionValue:
|
|
41
|
+
}, N = (e) => {
|
|
42
|
+
const { optionLabel: t = "label", optionValue: a = "value" } = o;
|
|
40
43
|
let n;
|
|
41
44
|
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
45
|
let l;
|
|
43
|
-
return typeof
|
|
46
|
+
return typeof a == "function" ? l = a(e) : typeof a == "string" ? l = e[a] || e.value || e.id : l = e.value || e.id, {
|
|
44
47
|
label: n,
|
|
45
48
|
value: l,
|
|
46
49
|
raw: e
|
|
47
50
|
};
|
|
48
|
-
},
|
|
49
|
-
const e =
|
|
50
|
-
return e.forEach((
|
|
51
|
+
}, V = u(() => {
|
|
52
|
+
const e = h.value?.data || [], t = [...b.value];
|
|
53
|
+
return e.forEach((a) => {
|
|
51
54
|
t.some(
|
|
52
|
-
(l) =>
|
|
53
|
-
) || t.push(
|
|
54
|
-
}), t.map((
|
|
55
|
-
}),
|
|
55
|
+
(l) => w(l) === w(a)
|
|
56
|
+
) || t.push(a);
|
|
57
|
+
}), t.map((a) => N(a));
|
|
58
|
+
}), A = u(() => h.value?.meta || {}), { refetch: F } = I({
|
|
56
59
|
get path() {
|
|
57
|
-
return
|
|
60
|
+
return f.value;
|
|
58
61
|
},
|
|
59
62
|
get ids() {
|
|
60
|
-
return
|
|
63
|
+
return j(s.value) ? s.value : [s.value];
|
|
61
64
|
},
|
|
62
65
|
options: {
|
|
63
66
|
enabled: !1
|
|
64
67
|
},
|
|
65
|
-
providerName:
|
|
68
|
+
providerName: g.value
|
|
66
69
|
});
|
|
67
|
-
|
|
68
|
-
if (!(
|
|
69
|
-
(n) =>
|
|
70
|
+
S(s, async (e) => {
|
|
71
|
+
if (!(y.value || !e || (y.value = !0, (Array.isArray(e) ? e : [e]).every(
|
|
72
|
+
(n) => V.value.some((l) => l.value === n)
|
|
70
73
|
))))
|
|
71
74
|
try {
|
|
72
|
-
const n = await
|
|
73
|
-
|
|
75
|
+
const n = await F();
|
|
76
|
+
b.value = n?.data?.data || [];
|
|
74
77
|
} catch (n) {
|
|
75
78
|
console.warn("Failed to fetch selected items:", n);
|
|
76
79
|
}
|
|
77
80
|
}, { immediate: !0, deep: !0 });
|
|
78
|
-
const
|
|
81
|
+
const L = u(() => E.value);
|
|
79
82
|
return {
|
|
80
|
-
onSearch:
|
|
81
|
-
options:
|
|
82
|
-
meta:
|
|
83
|
-
loading:
|
|
84
|
-
pagination:
|
|
85
|
-
total:
|
|
86
|
-
pageCount:
|
|
83
|
+
onSearch: x,
|
|
84
|
+
options: V,
|
|
85
|
+
meta: A,
|
|
86
|
+
loading: L,
|
|
87
|
+
pagination: p,
|
|
88
|
+
total: O,
|
|
89
|
+
pageCount: k
|
|
87
90
|
};
|
|
88
91
|
}
|
|
89
92
|
export {
|
|
90
|
-
|
|
93
|
+
B as useSelect
|
|
91
94
|
};
|
package/dist/esm/hooks/tree.js
CHANGED
|
@@ -1,30 +1,48 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { computed as r, unref as c, reactive as y, watch as f } from "vue";
|
|
2
2
|
import "../utils/bus.js";
|
|
3
|
-
import { arrayToTree as
|
|
4
|
-
import { useList as
|
|
5
|
-
function
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
import { arrayToTree as K, treeToArr as O } from "../utils/tree.js";
|
|
4
|
+
import { useList as g } from "./data.js";
|
|
5
|
+
function j(e) {
|
|
6
|
+
const u = r(() => c(e.path) || ""), s = r(() => c(e.params) || {}), h = r(() => c(e.providerName)), i = y({
|
|
7
|
+
...s.value
|
|
8
|
+
});
|
|
9
|
+
f(s, (a) => {
|
|
10
|
+
const o = a || {};
|
|
11
|
+
Object.keys(i).forEach((n) => {
|
|
12
|
+
n in o || delete i[n];
|
|
13
|
+
}), Object.entries(o).forEach(([n, t]) => {
|
|
14
|
+
i[n] = t;
|
|
15
|
+
});
|
|
16
|
+
}, {
|
|
17
|
+
deep: !0,
|
|
18
|
+
immediate: !0
|
|
19
|
+
});
|
|
20
|
+
const { data: d, isLoading: m } = g({
|
|
21
|
+
get path() {
|
|
22
|
+
return u.value;
|
|
23
|
+
},
|
|
24
|
+
filters: i,
|
|
25
|
+
get providerName() {
|
|
26
|
+
return h.value;
|
|
27
|
+
}
|
|
28
|
+
}), l = r(() => e.converTree ? K(d.value?.data || [], {
|
|
11
29
|
idKey: e.treeOptions?.valueKey || "id",
|
|
12
30
|
parentKey: e.treeOptions?.parentKey || "parent_id",
|
|
13
31
|
sortKey: e.treeOptions?.sortKey || "sort",
|
|
14
32
|
childrenKey: e.treeOptions?.childrenKey || "children"
|
|
15
|
-
}) :
|
|
33
|
+
}) : d.value?.data || []), v = r(() => O(l.value, e.treeOptions?.valueKey || "id", e.treeOptions?.childrenKey || "children")), p = r(() => m.value);
|
|
16
34
|
return {
|
|
17
35
|
options: r(() => {
|
|
18
|
-
const
|
|
19
|
-
const t = { ...
|
|
20
|
-
return Array.isArray(t.children) && (t.children.length === 0 ? delete t.children : t.children =
|
|
36
|
+
const a = (o) => o.map((n) => {
|
|
37
|
+
const t = { ...n };
|
|
38
|
+
return Array.isArray(t.children) && (t.children.length === 0 ? delete t.children : t.children = a(t.children)), t;
|
|
21
39
|
});
|
|
22
|
-
return
|
|
40
|
+
return a(l.value || []);
|
|
23
41
|
}),
|
|
24
|
-
loading:
|
|
25
|
-
expanded:
|
|
42
|
+
loading: p,
|
|
43
|
+
expanded: v
|
|
26
44
|
};
|
|
27
45
|
}
|
|
28
46
|
export {
|
|
29
|
-
|
|
47
|
+
j as useTree
|
|
30
48
|
};
|
|
@@ -4,13 +4,13 @@ export interface IUseSelectProps {
|
|
|
4
4
|
/** 默认选中值,可以是单个值或数组 */
|
|
5
5
|
defaultValue?: MaybeRef<SelectValue>;
|
|
6
6
|
/** 数据请求路径 */
|
|
7
|
-
path?: string
|
|
7
|
+
path?: MaybeRef<string | undefined>;
|
|
8
8
|
/** 请求参数 */
|
|
9
|
-
params?: Record<string, any>;
|
|
9
|
+
params?: MaybeRef<Record<string, any> | undefined>;
|
|
10
10
|
/** 分页配置,false表示不分页,true表示默认20条/页,数字表示指定每页条数 */
|
|
11
11
|
pagination?: boolean | number;
|
|
12
12
|
/** 数据提供者名称 */
|
|
13
|
-
providerName?: string
|
|
13
|
+
providerName?: MaybeRef<string | undefined>;
|
|
14
14
|
/**
|
|
15
15
|
* 选项显示标签配置
|
|
16
16
|
* - 字符串:指定用作显示标签的字段名
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { MaybeRef } from 'vue';
|
|
1
2
|
export interface IUseTreeProps {
|
|
2
|
-
path?: string
|
|
3
|
-
params?: Record<string, any>;
|
|
3
|
+
path?: MaybeRef<string | undefined>;
|
|
4
|
+
params?: MaybeRef<Record<string, any> | undefined>;
|
|
4
5
|
treeOptions?: {
|
|
5
6
|
valueKey?: string;
|
|
6
7
|
parentKey?: string;
|
|
@@ -8,7 +9,7 @@ export interface IUseTreeProps {
|
|
|
8
9
|
childrenKey?: string;
|
|
9
10
|
};
|
|
10
11
|
converTree?: boolean;
|
|
11
|
-
providerName?: string
|
|
12
|
+
providerName?: MaybeRef<string | undefined>;
|
|
12
13
|
}
|
|
13
14
|
export declare function useTree(props: IUseTreeProps): {
|
|
14
15
|
options: import("vue").ComputedRef<any[]>;
|