@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 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
+ "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;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("vue");require("../utils/bus.cjs");const o=require("../utils/tree.cjs"),m=require("./data.cjs");function p(e){const d=t.toRef(e,"path"),u=t.toRef(e,"params"),c=t.toRef(e,"providerName"),{data:n,isLoading:s}=m.useList({path:d.value||"",filters:u.value,providerName:c.value}),a=t.computed(()=>e.converTree?o.arrayToTree(n.value?.data||[],{idKey:e.treeOptions?.valueKey||"id",parentKey:e.treeOptions?.parentKey||"parent_id",sortKey:e.treeOptions?.sortKey||"sort",childrenKey:e.treeOptions?.childrenKey||"children"}):n.value?.data||[]),l=t.computed(()=>o.treeToArr(a.value,e.treeOptions?.valueKey||"id",e.treeOptions?.childrenKey||"children")),v=t.computed(()=>s.value);return{options:t.computed(()=>{const i=y=>y.map(h=>{const r={...h};return Array.isArray(r.children)&&(r.children.length===0?delete r.children:r.children=i(r.children)),r});return i(a.value||[])}),loading:v,expanded:l}}exports.useTree=p;
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;
@@ -1,91 +1,94 @@
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({
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 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);
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
- h(() => a.params, (e) => {
17
- i.value = {
18
- keyword: c.value,
19
- ...e
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: v, isLoading: w, total: S, pageCount: x } = O({
27
+ const { data: h, isLoading: E, total: O, pageCount: k } = D({
25
28
  get path() {
26
- return a.path || "";
29
+ return f.value;
27
30
  },
28
- filters: i,
31
+ filters: r,
29
32
  get pagination() {
30
- return a.pagination ? d.value : void 0;
33
+ return o.pagination ? p.value : void 0;
31
34
  },
32
35
  get providerName() {
33
- return a.providerName;
36
+ return g.value;
34
37
  }
35
- }), g = u([]), y = (e) => {
36
- const t = a.optionField || a.optionValue;
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
- }, k = (e) => {
39
- const { optionLabel: t = "label", optionValue: o = "value" } = a;
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 o == "function" ? l = o(e) : typeof o == "string" ? l = e[o] || e.value || e.id : l = e.value || e.id, {
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
- }, p = s(() => {
49
- const e = v.value?.data || [], t = [...g.value];
50
- return e.forEach((o) => {
51
+ }, V = u(() => {
52
+ const e = h.value?.data || [], t = [...b.value];
53
+ return e.forEach((a) => {
51
54
  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({
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 a.path || "";
60
+ return f.value;
58
61
  },
59
62
  get ids() {
60
- return F(r.value) ? r.value : [r.value];
63
+ return j(s.value) ? s.value : [s.value];
61
64
  },
62
65
  options: {
63
66
  enabled: !1
64
67
  },
65
- providerName: a.providerName
68
+ providerName: g.value
66
69
  });
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)
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 m();
73
- g.value = n?.data?.data || [];
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 A = s(() => w.value);
81
+ const L = u(() => E.value);
79
82
  return {
80
- onSearch: V,
81
- options: p,
82
- meta: N,
83
- loading: A,
84
- pagination: d,
85
- total: S,
86
- pageCount: x
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
- M as useSelect
93
+ B as useSelect
91
94
  };
@@ -1,30 +1,48 @@
1
- import { toRef as n, computed as r } from "vue";
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 p, treeToArr as y } from "../utils/tree.js";
4
- import { useList as K } from "./data.js";
5
- function N(e) {
6
- const d = n(e, "path"), s = n(e, "params"), l = n(e, "providerName"), { data: i, isLoading: c } = K({
7
- path: d.value || "",
8
- filters: s.value,
9
- providerName: l.value
10
- }), a = r(() => e.converTree ? p(i.value?.data || [], {
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
- }) : i.value?.data || []), u = r(() => y(a.value, e.treeOptions?.valueKey || "id", e.treeOptions?.childrenKey || "children")), m = r(() => c.value);
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 o = (h) => h.map((v) => {
19
- const t = { ...v };
20
- return Array.isArray(t.children) && (t.children.length === 0 ? delete t.children : t.children = o(t.children)), t;
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 o(a.value || []);
40
+ return a(l.value || []);
23
41
  }),
24
- loading: m,
25
- expanded: u
42
+ loading: p,
43
+ expanded: v
26
44
  };
27
45
  }
28
46
  export {
29
- N as useTree
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[]>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@duxweb/dvha-core",
3
3
  "type": "module",
4
- "version": "1.1.18",
4
+ "version": "1.1.19",
5
5
  "author": "DuxWeb",
6
6
  "license": "MIT",
7
7
  "repository": {