@duxweb/dvha-core 1.0.23 → 1.0.24

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.
Files changed (85) hide show
  1. package/dist/cjs/components/auth/can.cjs +1 -1
  2. package/dist/cjs/components/loader/iframe.cjs +1 -1
  3. package/dist/cjs/components/loader/remote/loader.cjs +1 -1
  4. package/dist/cjs/components/loader/remote/render.cjs +1 -1
  5. package/dist/cjs/components/overlay/overlay.cjs +1 -1
  6. package/dist/cjs/components/status/exception.cjs +1 -1
  7. package/dist/cjs/directive/permission.cjs +1 -1
  8. package/dist/cjs/hooks/auth.cjs +1 -1
  9. package/dist/cjs/hooks/data.cjs +1 -1
  10. package/dist/cjs/hooks/export.cjs +1 -1
  11. package/dist/cjs/hooks/exportCsv.cjs +2 -2
  12. package/dist/cjs/hooks/form.cjs +1 -1
  13. package/dist/cjs/hooks/formExtend.cjs +1 -1
  14. package/dist/cjs/hooks/i18n.cjs +1 -1
  15. package/dist/cjs/hooks/import.cjs +1 -1
  16. package/dist/cjs/hooks/importCsv.cjs +2 -2
  17. package/dist/cjs/hooks/json/utils/expressionParser.cjs +1 -1
  18. package/dist/cjs/hooks/json/vFor.cjs +1 -1
  19. package/dist/cjs/hooks/json/vOn.cjs +1 -1
  20. package/dist/cjs/hooks/json/vShow.cjs +1 -1
  21. package/dist/cjs/hooks/json.cjs +1 -1
  22. package/dist/cjs/hooks/list.cjs +1 -1
  23. package/dist/cjs/hooks/manage.cjs +1 -1
  24. package/dist/cjs/hooks/menu.cjs +1 -1
  25. package/dist/cjs/hooks/select.cjs +1 -1
  26. package/dist/cjs/hooks/theme.cjs +3 -3
  27. package/dist/cjs/hooks/tree.cjs +1 -1
  28. package/dist/cjs/hooks/upload/s3.cjs +1 -1
  29. package/dist/cjs/hooks/upload.cjs +1 -1
  30. package/dist/cjs/preset/authProvider.cjs +1 -1
  31. package/dist/cjs/preset/dataProvider.cjs +1 -1
  32. package/dist/cjs/preset/i18nProvider.cjs +1 -1
  33. package/dist/cjs/provider/app.cjs +1 -1
  34. package/dist/cjs/router/route.cjs +1 -1
  35. package/dist/cjs/stores/auth.cjs +1 -1
  36. package/dist/cjs/stores/i18n.cjs +1 -1
  37. package/dist/cjs/stores/jsonSchema.cjs +1 -1
  38. package/dist/cjs/stores/manage.cjs +1 -1
  39. package/dist/cjs/stores/route.cjs +1 -1
  40. package/dist/cjs/stores/tab.cjs +1 -1
  41. package/dist/cjs/stores/theme.cjs +1 -1
  42. package/dist/cjs/utils/tree.cjs +1 -1
  43. package/dist/esm/components/auth/can.js +8 -11
  44. package/dist/esm/components/loader/iframe.js +14 -17
  45. package/dist/esm/components/loader/remote/loader.js +103 -105
  46. package/dist/esm/components/loader/remote/render.js +10 -11
  47. package/dist/esm/components/overlay/overlay.js +7 -7
  48. package/dist/esm/components/status/exception.js +10 -13
  49. package/dist/esm/directive/permission.js +6 -7
  50. package/dist/esm/hooks/auth.js +73 -83
  51. package/dist/esm/hooks/data.js +290 -345
  52. package/dist/esm/hooks/export.js +16 -17
  53. package/dist/esm/hooks/exportCsv.js +26 -27
  54. package/dist/esm/hooks/form.js +49 -54
  55. package/dist/esm/hooks/formExtend.js +24 -25
  56. package/dist/esm/hooks/i18n.js +11 -29
  57. package/dist/esm/hooks/import.js +31 -32
  58. package/dist/esm/hooks/importCsv.js +24 -25
  59. package/dist/esm/hooks/json/utils/expressionParser.js +36 -42
  60. package/dist/esm/hooks/json/vFor.js +15 -16
  61. package/dist/esm/hooks/json/vOn.js +17 -18
  62. package/dist/esm/hooks/json/vShow.js +9 -10
  63. package/dist/esm/hooks/json.js +88 -94
  64. package/dist/esm/hooks/list.js +100 -127
  65. package/dist/esm/hooks/manage.js +13 -17
  66. package/dist/esm/hooks/menu.js +39 -52
  67. package/dist/esm/hooks/select.js +35 -40
  68. package/dist/esm/hooks/theme.js +127 -141
  69. package/dist/esm/hooks/tree.js +22 -28
  70. package/dist/esm/hooks/upload/s3.js +22 -23
  71. package/dist/esm/hooks/upload.js +152 -159
  72. package/dist/esm/preset/authProvider.js +63 -117
  73. package/dist/esm/preset/dataProvider.js +69 -76
  74. package/dist/esm/preset/i18nProvider.js +18 -18
  75. package/dist/esm/provider/app.js +74 -81
  76. package/dist/esm/router/route.js +16 -24
  77. package/dist/esm/stores/auth.js +17 -20
  78. package/dist/esm/stores/i18n.js +10 -10
  79. package/dist/esm/stores/jsonSchema.js +20 -23
  80. package/dist/esm/stores/manage.js +33 -33
  81. package/dist/esm/stores/route.js +38 -50
  82. package/dist/esm/stores/tab.js +38 -54
  83. package/dist/esm/stores/theme.js +28 -29
  84. package/dist/esm/utils/tree.js +23 -24
  85. package/package.json +1 -1
@@ -1,36 +1,35 @@
1
- import { ref as h, computed as c } from "vue";
2
- import { useInfiniteList as w } from "./data.js";
3
- const y = (e) => new Promise((a) => setTimeout(a, e));
1
+ import { ref as P, computed as o } from "vue";
2
+ import { useInfiniteList as x } from "./data.js";
3
+ const d = (e) => new Promise((a) => setTimeout(a, e));
4
4
  function b(e) {
5
- const a = h(!1), r = c(() => {
6
- const { onSuccess: n, onProgress: i, interval: l, maxPage: u, ...f } = e;
5
+ const a = P(!1), l = o(() => {
6
+ const { onSuccess: n, onProgress: h, interval: w, maxPage: y, ...r } = e;
7
7
  return {
8
- ...f,
8
+ ...r,
9
9
  options: {
10
- ...f.options,
10
+ ...r.options,
11
11
  enabled: !1,
12
12
  refetchOnMount: !1,
13
13
  refetchOnWindowFocus: !1,
14
14
  refetchOnReconnect: !1
15
15
  }
16
16
  };
17
- }), o = c(() => e.interval || 300), { data: s, isLoading: g, fetchNextPage: v, hasNextPage: m, refetch: P, pagination: t } = w(r.value), x = async () => {
18
- var n, i, l;
17
+ }), i = o(() => e.interval || 300), { data: s, isLoading: u, fetchNextPage: c, hasNextPage: f, refetch: g, pagination: t } = x(l.value), v = async () => {
19
18
  if (!a.value)
20
19
  try {
21
- a.value = !0, t.value.page = 1, (n = e.onProgress) == null || n.call(e, t.value), await P();
22
- const u = typeof e.maxPage == "function" ? e.maxPage() : e.maxPage || 0;
23
- for (; m.value && !(u > 0 && t.value.page >= u); )
24
- o.value > 0 && await y(o.value), await v(), (i = e.onProgress) == null || i.call(e, t.value);
25
- (l = e.onSuccess) == null || l.call(e, s.value);
20
+ a.value = !0, t.value.page = 1, e.onProgress?.(t.value), await g();
21
+ const n = typeof e.maxPage == "function" ? e.maxPage() : e.maxPage || 0;
22
+ for (; f.value && !(n > 0 && t.value.page >= n); )
23
+ i.value > 0 && await d(i.value), await c(), e.onProgress?.(t.value);
24
+ e.onSuccess?.(s.value);
26
25
  } finally {
27
26
  a.value = !1;
28
27
  }
29
- }, d = c(() => g.value || a.value);
28
+ }, m = o(() => u.value || a.value);
30
29
  return {
31
30
  data: s,
32
- isLoading: d,
33
- trigger: x
31
+ isLoading: m,
32
+ trigger: v
34
33
  };
35
34
  }
36
35
  export {
@@ -1,41 +1,40 @@
1
- import { json2csv as v } from "json-2-csv";
2
- import { computed as s } from "vue";
3
- import { useExport as f } from "./export.js";
4
- function b(e) {
5
- const l = s(() => {
6
- const { filename: t, headers: n, csvOptions: c, ...a } = e;
7
- return a;
8
- }), u = s(() => {
9
- const t = e.csvOptions || {}, n = t.quote;
1
+ import { json2csv as d } from "json-2-csv";
2
+ import { computed as a } from "vue";
3
+ import { useExport as l } from "./export.js";
4
+ function h(t) {
5
+ const c = a(() => {
6
+ const { filename: e, headers: o, csvOptions: n, ...s } = t;
7
+ return s;
8
+ }), i = a(() => {
9
+ const e = t.csvOptions || {}, o = e.quote;
10
10
  return {
11
- prependHeader: e.headers !== !1,
12
- keys: Array.isArray(e.headers) ? e.headers : void 0,
11
+ prependHeader: t.headers !== !1,
12
+ keys: Array.isArray(t.headers) ? t.headers : void 0,
13
13
  delimiter: {
14
- field: t.delimiter || ",",
15
- wrap: typeof n == "string" ? n : '"',
16
- eol: t.eol || `
14
+ field: e.delimiter || ",",
15
+ wrap: typeof o == "string" ? o : '"',
16
+ eol: e.eol || `
17
17
  `
18
18
  },
19
- excelBOM: t.writeBOM || !1
19
+ excelBOM: e.writeBOM || !1
20
20
  };
21
21
  });
22
- return f({
23
- ...l.value,
24
- onSuccess: async (t) => {
25
- var n, c, a, i;
26
- if (!(t != null && t.data) || !((n = t == null ? void 0 : t.data) != null && n.length)) {
27
- (c = e.onError) == null || c.call(e, {
22
+ return l({
23
+ ...c.value,
24
+ onSuccess: async (e) => {
25
+ if (!e?.data || !e?.data?.length) {
26
+ t.onError?.({
28
27
  message: "No data to export",
29
28
  status: 400
30
29
  });
31
30
  return;
32
31
  }
33
32
  try {
34
- const r = await v(t.data, u.value), m = new Blob([r], { type: "text/csv;charset=utf-8;" }), d = URL.createObjectURL(m), o = document.createElement("a");
35
- o.href = d, o.download = e.filename || "export.csv", o.style.display = "none", document.body.appendChild(o), o.click(), document.body.removeChild(o), URL.revokeObjectURL(d), (a = e.onSuccess) == null || a.call(e, t);
36
- } catch (r) {
37
- (i = e.onError) == null || i.call(e, {
38
- message: `CSV Export Error: ${r}`,
33
+ const o = await d(e.data, i.value), n = new Blob([o], { type: "text/csv;charset=utf-8;" }), s = URL.createObjectURL(n), r = document.createElement("a");
34
+ r.href = s, r.download = t.filename || "export.csv", r.style.display = "none", document.body.appendChild(r), r.click(), document.body.removeChild(r), URL.revokeObjectURL(s), t.onSuccess?.(e);
35
+ } catch (o) {
36
+ t.onError?.({
37
+ message: `CSV Export Error: ${o}`,
39
38
  status: 500
40
39
  });
41
40
  }
@@ -43,5 +42,5 @@ function b(e) {
43
42
  });
44
43
  }
45
44
  export {
46
- b as useExportCsv
45
+ h as useExportCsv
47
46
  };
@@ -1,80 +1,75 @@
1
- import { cloneDeep as v } from "lodash-es";
2
- import { toRef as m, ref as s, computed as f, watch as E } from "vue";
3
- import { useOne as L, useCreate as O, useUpdate as S } from "./data.js";
4
- function x(e) {
5
- const n = m(e, "form", {}), i = m(e, "id", void 0), c = s(v(n.value || {})), l = s(v(n.value || {})), u = f(() => e.action === "edit" || !!i.value), { data: g, isLoading: h, refetch: D } = L({
1
+ import { cloneDeep as i } from "lodash-es";
2
+ import { toRef as d, 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 = d(a, "form", {}), u = d(a, "id", void 0), o = l(i(t.value || {})), v = l(i(t.value || {})), n = m(() => a.action === "edit" || !!u.value), { data: f, isLoading: g, refetch: h } = E({
6
6
  get path() {
7
- return e.path || "";
7
+ return a.path || "";
8
8
  },
9
9
  get id() {
10
- return i.value;
10
+ return u.value;
11
11
  },
12
12
  options: {
13
- enabled: u.value
13
+ enabled: n.value
14
14
  },
15
- providerName: e.providerName
16
- }), d = () => {
17
- let a = {};
18
- u.value ? a = v(c.value) : a = v(l.value), Object.assign(n.value, a);
15
+ providerName: a.providerName
16
+ }), r = () => {
17
+ let e = {};
18
+ n.value ? e = i(o.value) : e = i(v.value), Object.assign(t.value, e);
19
19
  };
20
- E([i, u], async () => {
21
- var t;
22
- if (!u.value) {
23
- d();
20
+ b([u, n], async () => {
21
+ if (!n.value) {
22
+ r();
24
23
  return;
25
24
  }
26
- await D();
27
- const a = v(((t = g.value) == null ? void 0 : t.data) || {});
28
- Object.assign(n.value, a), Object.assign(c.value, a);
25
+ await h();
26
+ const e = i(f.value?.data || {});
27
+ Object.assign(t.value, e), Object.assign(o.value, e);
29
28
  }, {
30
29
  immediate: !0
31
30
  });
32
- const o = O({
33
- path: e.path ?? "",
34
- data: n.value,
35
- onSuccess: (a) => {
36
- var t;
37
- d(), (t = e.onSuccess) == null || t.call(e, a);
31
+ const c = L({
32
+ path: a.path ?? "",
33
+ data: t.value,
34
+ onSuccess: (e) => {
35
+ r(), a.onSuccess?.(e);
38
36
  },
39
- onError: (a) => {
40
- var t;
41
- (t = e.onError) == null || t.call(e, a);
37
+ onError: (e) => {
38
+ a.onError?.(e);
42
39
  },
43
- providerName: e.providerName
44
- }), r = S({
40
+ providerName: a.providerName
41
+ }), s = O({
45
42
  get path() {
46
- return e.path ?? "";
43
+ return a.path ?? "";
47
44
  },
48
45
  get id() {
49
- return i.value;
46
+ return u.value;
50
47
  },
51
- data: n.value,
52
- onSuccess: (a) => {
53
- var t;
54
- (t = e.onSuccess) == null || t.call(e, a);
48
+ data: t.value,
49
+ onSuccess: (e) => {
50
+ a.onSuccess?.(e);
55
51
  },
56
- onError: (a) => {
57
- var t;
58
- (t = e.onError) == null || t.call(e, a);
52
+ onError: (e) => {
53
+ a.onError?.(e);
59
54
  },
60
- providerName: e.providerName
61
- }), N = (a) => {
62
- u.value ? r.mutate({
63
- id: i.value,
64
- data: a || n.value
65
- }) : o.mutate({
66
- data: a || n.value
55
+ providerName: a.providerName
56
+ }), D = (e) => {
57
+ n.value ? s.mutate({
58
+ id: u.value,
59
+ data: e || t.value
60
+ }) : c.mutate({
61
+ data: e || t.value
67
62
  });
68
- }, b = f(() => h.value || o.isLoading.value || r.isLoading.value);
63
+ }, N = m(() => g.value || c.isLoading.value || s.isLoading.value);
69
64
  return {
70
- form: n,
71
- initData: u.value ? c.value : l.value,
72
- isLoading: b,
73
- isEdit: u,
74
- onSubmit: N,
75
- onReset: d
65
+ form: t,
66
+ initData: n.value ? o.value : v.value,
67
+ isLoading: N,
68
+ isEdit: n,
69
+ onSubmit: D,
70
+ onReset: r
76
71
  };
77
72
  }
78
73
  export {
79
- x as useForm
74
+ w as useForm
80
75
  };
@@ -1,40 +1,39 @@
1
- import { toRef as d, computed as c } from "vue";
2
- import { useForm as l } from "./form.js";
3
- import { useValidateForm as v } from "./formValidate.js";
4
- function F(t) {
5
- const o = d(t, "form", {}), { validate: m, reset: s } = v({
6
- data: o,
7
- rules: t.rules
8
- }), u = c(() => {
9
- const { form: n, ...r } = t;
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
10
  return {
11
11
  ...r
12
12
  };
13
- }), e = l({
14
- ...u.value,
15
- form: o.value
16
- }), a = (n) => {
17
- m().then((r) => {
18
- var i;
13
+ }), t = c({
14
+ ...m.value,
15
+ form: e.value
16
+ }), u = (n) => {
17
+ s().then((r) => {
19
18
  if (!r.valid) {
20
- (i = t.onError) == null || i.call(t, {
19
+ o.onError?.({
21
20
  message: "表单验证失败"
22
21
  });
23
22
  return;
24
23
  }
25
- e.onSubmit(n);
24
+ t.onSubmit(n);
26
25
  });
27
- }, f = () => {
28
- e.onReset(), s();
26
+ }, a = () => {
27
+ t.onReset(), i();
29
28
  };
30
29
  return {
31
- isLoading: e.isLoading,
32
- isEdit: e.isEdit,
33
- form: o,
34
- onSubmit: a,
35
- onReset: f
30
+ isLoading: t.isLoading,
31
+ isEdit: t.isEdit,
32
+ form: e,
33
+ onSubmit: u,
34
+ onReset: a
36
35
  };
37
36
  }
38
37
  export {
39
- F as useExtendForm
38
+ g as useExtendForm
40
39
  };
@@ -1,37 +1,19 @@
1
1
  import "pinia";
2
2
  import "vue";
3
- import { useI18nStore as i } from "../stores/i18n.js";
3
+ import { useI18nStore as t } from "../stores/i18n.js";
4
4
  import "lodash-es";
5
- import { useManage as g } from "./manage.js";
6
- function I() {
7
- const a = i(), c = g();
5
+ import { useManage as a } from "./manage.js";
6
+ function P() {
7
+ const n = t(), o = a();
8
8
  return {
9
- t: (e, o, r) => {
10
- var n, t;
11
- return (t = (n = c.config) == null ? void 0 : n.i18nProvider) == null ? void 0 : t.t(e, o, r);
12
- },
13
- changeLocale: (e) => {
14
- var o, r;
15
- return a.setLocale(e), (r = (o = c.config) == null ? void 0 : o.i18nProvider) == null ? void 0 : r.changeLocale(e);
16
- },
17
- getLocale: () => {
18
- var e, o;
19
- return (o = (e = c.config) == null ? void 0 : e.i18nProvider) == null ? void 0 : o.getLocale();
20
- },
21
- loadLocale: (e, o) => {
22
- var r, n;
23
- return (n = (r = c.config) == null ? void 0 : r.i18nProvider) == null ? void 0 : n.loadLocale(e, o);
24
- },
25
- mergeLocale: (e, o) => {
26
- var r, n;
27
- return (n = (r = c.config) == null ? void 0 : r.i18nProvider) == null ? void 0 : n.mergeLocale(e, o);
28
- },
29
- getLocales: () => {
30
- var e, o;
31
- return (o = (e = c.config) == null ? void 0 : e.i18nProvider) == null ? void 0 : o.getLocales();
32
- }
9
+ t: (e, r, c) => o.config?.i18nProvider?.t(e, r, c),
10
+ changeLocale: (e) => (n.setLocale(e), o.config?.i18nProvider?.changeLocale(e)),
11
+ getLocale: () => o.config?.i18nProvider?.getLocale(),
12
+ loadLocale: (e, r) => o.config?.i18nProvider?.loadLocale(e, r),
13
+ mergeLocale: (e, r) => o.config?.i18nProvider?.mergeLocale(e, r),
14
+ getLocales: () => o.config?.i18nProvider?.getLocales()
33
15
  };
34
16
  }
35
17
  export {
36
- I as useI18n
18
+ P as useI18n
37
19
  };
@@ -1,56 +1,55 @@
1
- import { ref as f, computed as u } from "vue";
2
- import { useCustomMutation as B } from "./data.js";
3
- const P = (e) => new Promise((a) => setTimeout(a, e));
4
- function z(e) {
5
- const a = f(!1), n = f({
1
+ import { ref as g, computed as u } from "vue";
2
+ import { useCustomMutation as d } from "./data.js";
3
+ const f = (t) => new Promise((s) => setTimeout(s, t));
4
+ function P(t) {
5
+ const s = g(!1), o = g({
6
6
  totalItems: 0,
7
7
  processedItems: 0,
8
8
  totalBatches: 0,
9
9
  processedBatches: 0,
10
10
  percentage: 0
11
11
  }), i = u(() => {
12
- const { onComplete: c, onProgress: l, onError: m, interval: s, chunkSize: o, ...r } = e;
13
- return r;
14
- }), { mutate: I } = B({
15
- path: e.path,
12
+ const { onComplete: r, onProgress: c, onError: m, interval: a, chunkSize: n, ...l } = t;
13
+ return l;
14
+ }), { mutate: v } = d({
15
+ path: t.path,
16
16
  method: "POST",
17
17
  ...i.value,
18
18
  options: {
19
19
  ...i.value.options
20
20
  }
21
- }), k = async (c) => {
22
- var h, g, v;
23
- if (a.value)
21
+ }), p = async (r) => {
22
+ if (s.value)
24
23
  return;
25
- const l = e.chunkSize || 100, m = e.interval || 100, s = c.length, o = [];
26
- for (let t = 0; t < s; t += l)
27
- o.push(c.slice(t, t + l));
28
- const r = o.length;
29
- n.value = {
30
- totalItems: s,
24
+ const c = t.chunkSize || 100, m = t.interval || 100, a = r.length, n = [];
25
+ for (let e = 0; e < a; e += c)
26
+ n.push(r.slice(e, e + c));
27
+ const l = n.length;
28
+ o.value = {
29
+ totalItems: a,
31
30
  processedItems: 0,
32
- totalBatches: r,
31
+ totalBatches: l,
33
32
  processedBatches: 0,
34
33
  percentage: 0
35
- }, a.value = !0;
34
+ }, s.value = !0;
36
35
  try {
37
- for (let t = 0; t < o.length; t++) {
38
- const d = o[t];
39
- await I({
40
- payload: d
41
- }), n.value.processedBatches = t + 1, n.value.processedItems += d.length, n.value.percentage = Math.round(n.value.processedItems / s * 100), (h = e.onProgress) == null || h.call(e, n.value), t < o.length - 1 && await P(m);
36
+ for (let e = 0; e < n.length; e++) {
37
+ const h = n[e];
38
+ await v({
39
+ payload: h
40
+ }), o.value.processedBatches = e + 1, o.value.processedItems += h.length, o.value.percentage = Math.round(o.value.processedItems / a * 100), t.onProgress?.(o.value), e < n.length - 1 && await f(m);
42
41
  }
43
- a.value = !1, (g = e.onComplete) == null || g.call(e, n.value);
44
- } catch (t) {
45
- a.value = !1, (v = e.onError) == null || v.call(e, t);
42
+ s.value = !1, t.onComplete?.(o.value);
43
+ } catch (e) {
44
+ s.value = !1, t.onError?.(e);
46
45
  }
47
46
  };
48
47
  return {
49
- isLoading: u(() => a.value),
50
- progress: u(() => n.value),
51
- trigger: k
48
+ isLoading: u(() => s.value),
49
+ progress: u(() => o.value),
50
+ trigger: p
52
51
  };
53
52
  }
54
53
  export {
55
- z as useImport
54
+ P as useImport
56
55
  };
@@ -1,13 +1,13 @@
1
- import { useFileDialog as g } from "@vueuse/core";
2
- import { csv2json as v } from "json-2-csv";
3
- import { computed as l } from "vue";
4
- import { useImport as F } from "./import.js";
5
- function C(t) {
6
- const c = l(() => {
7
- const { csvOptions: e, ...s } = t;
8
- return s;
9
- }), m = l(() => {
10
- const e = t.csvOptions || {};
1
+ import { useFileDialog as u } from "@vueuse/core";
2
+ import { csv2json as d } from "json-2-csv";
3
+ import { computed as n } from "vue";
4
+ import { useImport as f } from "./import.js";
5
+ function w(s) {
6
+ const a = n(() => {
7
+ const { csvOptions: e, ...t } = s;
8
+ return t;
9
+ }), l = n(() => {
10
+ const e = s.csvOptions || {};
11
11
  return {
12
12
  delimiter: {
13
13
  field: e.delimiter || ",",
@@ -21,36 +21,35 @@ function C(t) {
21
21
  trimHeaderFields: e.trimHeaderFields || !1,
22
22
  trimFieldValues: e.trimFieldValues || !1
23
23
  };
24
- }), r = F({
25
- ...c.value
26
- }), n = async (e) => {
27
- var s, a;
24
+ }), r = f({
25
+ ...a.value
26
+ }), i = async (e) => {
28
27
  try {
29
- const i = await e.text(), o = await v(i, m.value);
30
- o && o.length > 0 ? await r.trigger(o) : (s = t.onError) == null || s.call(t, {
28
+ const t = await e.text(), o = await d(t, l.value);
29
+ o && o.length > 0 ? await r.trigger(o) : s.onError?.({
31
30
  message: "CSV 文件为空或格式不正确",
32
31
  status: 400
33
32
  });
34
- } catch (i) {
35
- (a = t.onError) == null || a.call(t, {
36
- message: `CSV 解析错误: ${i}`,
33
+ } catch (t) {
34
+ s.onError?.({
35
+ message: `CSV 解析错误: ${t}`,
37
36
  status: 500
38
37
  });
39
38
  }
40
- }, { open: u, reset: d, onChange: f } = g({
39
+ }, { open: c, reset: m, onChange: p } = u({
41
40
  accept: ".csv",
42
41
  multiple: !1
43
42
  });
44
- return f((e) => {
45
- e && e.length > 0 && n(e[0]);
43
+ return p((e) => {
44
+ e && e.length > 0 && i(e[0]);
46
45
  }), {
47
46
  ...r,
48
47
  open: () => {
49
- d(), u();
48
+ m(), c();
50
49
  },
51
- readFile: n
50
+ readFile: i
52
51
  };
53
52
  }
54
53
  export {
55
- C as useImportCsv
54
+ w as useImportCsv
56
55
  };