@duxweb/dvha-pro 1.0.22 → 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 (157) hide show
  1. package/dist/cjs/component.cjs +1 -1
  2. package/dist/cjs/components/card/card.cjs +1 -1
  3. package/dist/cjs/components/card/store.cjs +1 -1
  4. package/dist/cjs/components/carousel/carousel.cjs +1 -1
  5. package/dist/cjs/components/crop/imageCrop.cjs +1 -1
  6. package/dist/cjs/components/crop/imageCropModal.cjs +1 -1
  7. package/dist/cjs/components/dashboard/hello.cjs +1 -1
  8. package/dist/cjs/components/dashboard/helloBig.cjs +1 -1
  9. package/dist/cjs/components/dashboard/quick.cjs +1 -1
  10. package/dist/cjs/components/data/dynamicData.cjs +1 -1
  11. package/dist/cjs/components/data/dynamicSelect.cjs +1 -1
  12. package/dist/cjs/components/data/selectModal.cjs +1 -1
  13. package/dist/cjs/components/dialog/dialog.cjs +1 -1
  14. package/dist/cjs/components/drawer/drawer.cjs +1 -1
  15. package/dist/cjs/components/drawer/drawerPage.cjs +1 -1
  16. package/dist/cjs/components/editor/aiEditor.cjs +1 -1
  17. package/dist/cjs/components/form/drawerForm.cjs +1 -0
  18. package/dist/cjs/components/form/formItem.cjs +1 -1
  19. package/dist/cjs/components/form/formLayout.cjs +1 -1
  20. package/dist/cjs/components/form/modalForm.cjs +1 -1
  21. package/dist/cjs/components/form/pageForm.cjs +1 -1
  22. package/dist/cjs/components/form/settingForm.cjs +1 -1
  23. package/dist/cjs/components/icon/iconPicker.cjs +1 -1
  24. package/dist/cjs/components/layout/filter.cjs +1 -1
  25. package/dist/cjs/components/layout/filterLayout.cjs +1 -1
  26. package/dist/cjs/components/layout/list.cjs +1 -1
  27. package/dist/cjs/components/layout/table.cjs +1 -1
  28. package/dist/cjs/components/layout/tools.cjs +1 -1
  29. package/dist/cjs/components/list/card.cjs +1 -1
  30. package/dist/cjs/components/list/list.cjs +1 -1
  31. package/dist/cjs/components/media/media.cjs +1 -1
  32. package/dist/cjs/components/modal/modal.cjs +1 -1
  33. package/dist/cjs/components/modal/modalPage.cjs +1 -1
  34. package/dist/cjs/components/modal/modalTab.cjs +1 -1
  35. package/dist/cjs/components/panel/alert.cjs +1 -1
  36. package/dist/cjs/components/panel/collapse.cjs +1 -1
  37. package/dist/cjs/components/panel/setting.cjs +1 -1
  38. package/dist/cjs/components/select/cardSelect.cjs +1 -1
  39. package/dist/cjs/components/status/listEmpty.cjs +1 -1
  40. package/dist/cjs/components/table/tablePage.cjs +1 -1
  41. package/dist/cjs/components/tree/treeFilter.cjs +1 -1
  42. package/dist/cjs/components/upload/config.cjs +1 -1
  43. package/dist/cjs/components/upload/file.cjs +1 -1
  44. package/dist/cjs/components/upload/image.cjs +1 -1
  45. package/dist/cjs/components/upload/manage/item.cjs +1 -1
  46. package/dist/cjs/components/upload/manager.cjs +1 -1
  47. package/dist/cjs/components/widget/connect.cjs +1 -1
  48. package/dist/cjs/dvha-pro.css +1 -1
  49. package/dist/cjs/hooks/action.cjs +1 -1
  50. package/dist/cjs/hooks/download.cjs +1 -1
  51. package/dist/cjs/hooks/echart.cjs +1 -1
  52. package/dist/cjs/hooks/image.cjs +1 -1
  53. package/dist/cjs/hooks/level.cjs +1 -1
  54. package/dist/cjs/hooks/table/color.cjs +1 -0
  55. package/dist/cjs/hooks/table/column.cjs +1 -1
  56. package/dist/cjs/hooks/table/image.cjs +1 -1
  57. package/dist/cjs/hooks/table/input.cjs +1 -1
  58. package/dist/cjs/hooks/table/map.cjs +1 -1
  59. package/dist/cjs/hooks/table/status.cjs +1 -1
  60. package/dist/cjs/hooks/table/switch.cjs +1 -1
  61. package/dist/cjs/hooks/table.cjs +1 -1
  62. package/dist/cjs/index.cjs +1 -1
  63. package/dist/cjs/pages/layout/global.cjs +1 -1
  64. package/dist/cjs/pages/layout/tab.cjs +1 -1
  65. package/dist/cjs/pages/login.cjs +1 -1
  66. package/dist/cjs/pages/menu/avatar.cjs +1 -1
  67. package/dist/cjs/pages/menu/button.cjs +1 -1
  68. package/dist/cjs/pages/menu/cmd.cjs +1 -1
  69. package/dist/cjs/pages/page.cjs +1 -1
  70. package/dist/cjs/pages/pageStatus.cjs +1 -1
  71. package/dist/cjs/stores/ui.cjs +1 -1
  72. package/dist/cjs/theme/uno.css.cjs +2 -1
  73. package/dist/esm/component.js +3 -3
  74. package/dist/esm/components/card/card.js +24 -27
  75. package/dist/esm/components/card/store.js +33 -39
  76. package/dist/esm/components/carousel/carousel.js +16 -19
  77. package/dist/esm/components/crop/imageCrop.js +32 -35
  78. package/dist/esm/components/crop/imageCropModal.js +36 -37
  79. package/dist/esm/components/dashboard/hello.js +27 -30
  80. package/dist/esm/components/dashboard/helloBig.js +328 -331
  81. package/dist/esm/components/dashboard/quick.js +30 -33
  82. package/dist/esm/components/data/dynamicData.js +86 -98
  83. package/dist/esm/components/data/dynamicSelect.js +29 -31
  84. package/dist/esm/components/data/selectModal.js +45 -49
  85. package/dist/esm/components/dialog/dialog.js +54 -55
  86. package/dist/esm/components/drawer/drawer.js +23 -22
  87. package/dist/esm/components/drawer/drawerPage.js +39 -49
  88. package/dist/esm/components/editor/aiEditor.js +64 -70
  89. package/dist/esm/components/form/drawerForm.js +149 -0
  90. package/dist/esm/components/form/formItem.js +44 -50
  91. package/dist/esm/components/form/formLayout.js +7 -10
  92. package/dist/esm/components/form/modalForm.js +50 -50
  93. package/dist/esm/components/form/pageForm.js +47 -50
  94. package/dist/esm/components/form/settingForm.js +34 -37
  95. package/dist/esm/components/icon/iconPicker.js +54 -58
  96. package/dist/esm/components/layout/filter.js +13 -16
  97. package/dist/esm/components/layout/filterLayout.js +7 -10
  98. package/dist/esm/components/layout/list.js +299 -326
  99. package/dist/esm/components/layout/table.js +268 -283
  100. package/dist/esm/components/layout/tools.js +38 -41
  101. package/dist/esm/components/list/card.js +35 -38
  102. package/dist/esm/components/list/list.js +15 -18
  103. package/dist/esm/components/media/media.js +35 -36
  104. package/dist/esm/components/modal/modal.js +10 -10
  105. package/dist/esm/components/modal/modalPage.js +32 -36
  106. package/dist/esm/components/modal/modalTab.js +39 -45
  107. package/dist/esm/components/panel/alert.js +19 -22
  108. package/dist/esm/components/panel/collapse.js +33 -36
  109. package/dist/esm/components/panel/setting.js +25 -31
  110. package/dist/esm/components/select/cardSelect.js +27 -28
  111. package/dist/esm/components/status/listEmpty.js +13 -13
  112. package/dist/esm/components/table/tablePage.js +25 -25
  113. package/dist/esm/components/tree/treeFilter.js +137 -147
  114. package/dist/esm/components/upload/config.js +15 -27
  115. package/dist/esm/components/upload/file.js +90 -94
  116. package/dist/esm/components/upload/image.js +116 -123
  117. package/dist/esm/components/upload/manage/item.js +44 -47
  118. package/dist/esm/components/upload/manager.js +190 -207
  119. package/dist/esm/components/widget/connect.js +103 -106
  120. package/dist/esm/dvha-pro.css +1 -1
  121. package/dist/esm/hooks/action.js +141 -157
  122. package/dist/esm/hooks/download.js +55 -56
  123. package/dist/esm/hooks/echart.js +156 -179
  124. package/dist/esm/hooks/image.js +14 -15
  125. package/dist/esm/hooks/level.js +7 -7
  126. package/dist/esm/hooks/table/color.js +19 -0
  127. package/dist/esm/hooks/table/column.js +25 -23
  128. package/dist/esm/hooks/table/image.js +2 -2
  129. package/dist/esm/hooks/table/input.js +28 -28
  130. package/dist/esm/hooks/table/map.js +7 -7
  131. package/dist/esm/hooks/table/status.js +8 -9
  132. package/dist/esm/hooks/table/switch.js +19 -19
  133. package/dist/esm/hooks/table.js +27 -31
  134. package/dist/esm/index.js +162 -158
  135. package/dist/esm/pages/layout/global.js +12 -15
  136. package/dist/esm/pages/layout/tab.js +58 -71
  137. package/dist/esm/pages/login.js +81 -85
  138. package/dist/esm/pages/menu/avatar.js +136 -149
  139. package/dist/esm/pages/menu/button.js +16 -20
  140. package/dist/esm/pages/menu/cmd.js +68 -74
  141. package/dist/esm/pages/page.js +21 -25
  142. package/dist/esm/pages/pageStatus.js +21 -24
  143. package/dist/esm/stores/ui.js +15 -15
  144. package/dist/esm/theme/uno.css.js +2 -1
  145. package/dist/types/components/drawer/drawerPage.d.ts +1 -1
  146. package/dist/types/components/form/drawerForm.d.ts +104 -0
  147. package/dist/types/components/form/index.d.ts +1 -0
  148. package/dist/types/components/form/modalForm.d.ts +6 -0
  149. package/dist/types/components/form/pageForm.d.ts +6 -0
  150. package/dist/types/components/form/settingForm.d.ts +6 -0
  151. package/dist/types/components/layout/table.d.ts +9 -0
  152. package/dist/types/components/table/tablePage.d.ts +9 -0
  153. package/dist/types/hooks/table/color.d.ts +13 -0
  154. package/dist/types/hooks/table/column.d.ts +1 -0
  155. package/dist/types/hooks/table/index.d.ts +1 -0
  156. package/dist/types/hooks/table/types.d.ts +2 -2
  157. package/package.json +3 -3
@@ -1,208 +1,192 @@
1
- import { useI18n as b, useManage as S, useCustomMutation as D, useDelete as C } from "@duxweb/dvha-core";
2
- import { useMessage as I, NButton as j, NDropdown as N } from "naive-ui";
3
- import { h as s } from "vue";
4
- import { useRouter as $ } from "vue-router";
5
- import { useDialog as B } from "./dialog.js";
6
- import { useDrawer as E } from "./drawer.js";
7
- import { useModal as T } from "./modal.js";
8
- function Q(n) {
9
- const y = T(), d = E(), o = B(), {
10
- t: c
11
- } = b(), a = I(), l = S(), u = $(), v = D({
12
- onSuccess: (e) => {
13
- a.success(e.message || c("common.success"));
1
+ import { useI18n as h, useManage as A, useCustomMutation as M, useDelete as S } from "@duxweb/dvha-core";
2
+ import { useMessage as D, NButton as b, NDropdown as C } from "naive-ui";
3
+ import { h as l } from "vue";
4
+ import { useRouter as I } from "vue-router";
5
+ import { useDialog as N } from "./dialog.js";
6
+ import { useDrawer as $ } from "./drawer.js";
7
+ import { useModal as B } from "./modal.js";
8
+ function K(o) {
9
+ const u = B(), i = $(), m = N(), {
10
+ t: n
11
+ } = h(), c = D(), g = A(), w = I(), P = M({
12
+ onSuccess: (t) => {
13
+ c.success(t.message || n("common.success"));
14
14
  },
15
- onError: (e) => {
16
- a.error(e.message || c("common.error"));
15
+ onError: (t) => {
16
+ c.error(t.message || n("common.error"));
17
17
  }
18
- }), A = C({
19
- onSuccess: (e) => {
20
- a.success(e.message || c("common.success"));
18
+ }), k = S({
19
+ onSuccess: (t) => {
20
+ c.success(t.message || n("common.success"));
21
21
  },
22
- onError: (e) => {
23
- a.error(e.message || c("common.error"));
22
+ onError: (t) => {
23
+ c.error(t.message || n("common.error"));
24
24
  }
25
- }), g = (n == null ? void 0 : n.path) || l.getPath(), x = (e) => {
26
- var f, k;
27
- const i = c(e.item.title || "", {}, e.item.title), r = c(e.item.label || "", {}, e.item.label);
28
- if (e.item.type === "modal") {
29
- const t = e.item, m = typeof t.componentProps == "function" ? t.componentProps(e.data) : t.componentProps;
30
- y.show({
31
- title: i || r,
32
- component: t.component,
25
+ }), r = o?.path || g.getPath(), f = (t) => {
26
+ const a = n(t.item.title || "", {}, t.item.title), s = n(t.item.label || "", {}, t.item.label);
27
+ if (t.item.type === "modal") {
28
+ const e = t.item, d = typeof e.componentProps == "function" ? e.componentProps(t.data) : e.componentProps;
29
+ u.show({
30
+ title: a || s,
31
+ component: e.component,
33
32
  componentProps: {
34
- id: e.id,
35
- ...m
33
+ id: t.id,
34
+ ...d
36
35
  },
37
- width: t.width,
38
- draggable: t.draggable !== void 0 ? t.draggable : !0
36
+ width: e.width,
37
+ draggable: e.draggable !== void 0 ? e.draggable : !0
39
38
  });
40
39
  }
41
- if (e.item.type === "drawer") {
42
- const t = e.item, m = typeof t.componentProps == "function" ? t.componentProps(e.data) : t.componentProps;
43
- d.show({
44
- title: i || r,
45
- component: t.component,
40
+ if (t.item.type === "drawer") {
41
+ const e = t.item, d = typeof e.componentProps == "function" ? e.componentProps(t.data) : e.componentProps;
42
+ i.show({
43
+ title: a || s,
44
+ component: e.component,
46
45
  componentProps: {
47
- id: e.id,
48
- ...m
46
+ id: t.id,
47
+ ...d
49
48
  },
50
- width: t.width,
51
- maxWidth: t.maxWidth
49
+ width: e.width,
50
+ maxWidth: e.maxWidth
52
51
  });
53
52
  }
54
- if (e.item.type === "confirm") {
55
- const t = e.item;
56
- o.confirm({
57
- title: i || r,
58
- content: t.content
59
- }).then((m) => {
60
- var h;
61
- m && ((h = t.callback) == null || h.call(t, e.id, e.data));
53
+ if (t.item.type === "confirm") {
54
+ const e = t.item;
55
+ m.confirm({
56
+ title: a || s,
57
+ content: e.content
58
+ }).then((d) => {
59
+ d && e.callback?.(t.id, t.data);
62
60
  });
63
61
  }
64
- if (e.item.type === "request") {
65
- const t = e.item;
66
- o.confirm({
67
- title: i || r,
68
- content: t.content
62
+ if (t.item.type === "request") {
63
+ const e = t.item;
64
+ m.confirm({
65
+ title: a || s,
66
+ content: e.content
69
67
  }).then(() => {
70
- const m = typeof t.data == "function" ? t.data(e.id, e.data) : t.data, h = (t.method || "post").toLowerCase(), M = t.path || g;
71
- v.mutate({
72
- path: M,
73
- method: h,
74
- payload: m
68
+ const d = typeof e.data == "function" ? e.data(t.id, t.data) : e.data, j = (e.method || "post").toLowerCase(), v = typeof e.path == "function" ? e.path(t.id, t.data) : e.path || r;
69
+ P.mutate({
70
+ path: v,
71
+ method: j,
72
+ payload: d
75
73
  });
76
74
  });
77
75
  }
78
- if (e.item.type === "delete") {
79
- const t = e.item;
80
- o.confirm({
81
- title: i || r,
82
- content: t.content
76
+ if (t.item.type === "delete") {
77
+ const e = t.item;
78
+ m.confirm({
79
+ title: a || s,
80
+ content: e.content
83
81
  }).then(() => {
84
- A.mutate({
85
- id: e.id,
86
- path: t.path || g
82
+ k.mutate({
83
+ id: t.id,
84
+ path: typeof e.path == "function" ? e.path(t.id, t.data) : e.path || r
87
85
  });
88
86
  });
89
87
  }
90
- if (e.item.type === "link") {
91
- const t = e.item, m = typeof t.path == "function" ? (f = t.path) == null ? void 0 : f.call(t, e.id, e.data) : l.getRoutePath(e.id ? `${t.path || g}${e.data === void 0 ? "" : `/${e.id}`}` : t.path || g);
92
- u.push(m);
93
- }
94
- if (e.item.type === "callback") {
95
- const t = e.item;
96
- (k = t.callback) == null || k.call(t, e.id, e.data);
88
+ if (t.item.type === "link") {
89
+ const e = t.item, d = typeof e.path == "function" ? e.path?.(t.id, t.data) : g.getRoutePath(t.id ? `${e.path || r}${t.data === void 0 ? "" : `/${t.id}`}` : e.path || r);
90
+ w.push(d);
97
91
  }
98
- }, w = W(), P = q();
92
+ t.item.type === "callback" && t.item.callback?.(t.id, t.data);
93
+ }, y = E(), x = T();
99
94
  return {
100
- target: x,
101
- renderTable: (e) => (i, r) => {
102
- const f = {
103
- id: i[e.key || (n == null ? void 0 : n.key) || "id"],
104
- data: i,
105
- index: r,
106
- target: x,
107
- text: e.text !== void 0 ? e.text : (n == null ? void 0 : n.text) || !1,
108
- align: e.align !== void 0 ? e.align : (n == null ? void 0 : n.align) || "left"
95
+ target: f,
96
+ renderTable: (t) => (a, s) => {
97
+ const e = {
98
+ id: a[t.key || o?.key || "id"],
99
+ data: a,
100
+ index: s,
101
+ target: f,
102
+ text: t.text !== void 0 ? t.text : o?.text || !1,
103
+ align: t.align !== void 0 ? t.align : o?.align || "left"
109
104
  };
110
- return (e.type || (n == null ? void 0 : n.type)) === "button" ? w.render({
111
- ...f,
112
- action: e || n
113
- }) : P.render({
114
- ...f,
115
- action: e || n
105
+ return (t.type || o?.type) === "button" ? y.render({
106
+ ...e,
107
+ action: t || o
108
+ }) : x.render({
109
+ ...e,
110
+ action: t || o
116
111
  });
117
112
  },
118
- renderAction: (e) => {
119
- const i = {
120
- target: x,
121
- text: e.text !== void 0 ? e.text : (n == null ? void 0 : n.text) || !1,
122
- align: e.align !== void 0 ? e.align : (n == null ? void 0 : n.align) || "left"
113
+ renderAction: (t) => {
114
+ const a = {
115
+ target: f,
116
+ text: t.text !== void 0 ? t.text : o?.text || !1,
117
+ align: t.align !== void 0 ? t.align : o?.align || "left"
123
118
  };
124
- return (e.type || (n == null ? void 0 : n.type)) === "button" ? w.render({
125
- ...i,
126
- action: e || n
127
- }) : P.render({
128
- ...i,
129
- action: e || n
119
+ return (t.type || o?.type) === "button" ? y.render({
120
+ ...a,
121
+ action: t || o
122
+ }) : x.render({
123
+ ...a,
124
+ action: t || o
130
125
  });
131
126
  }
132
127
  };
133
128
  }
134
- function W() {
129
+ function E() {
135
130
  const {
136
- t: n
137
- } = b();
131
+ t: o
132
+ } = h();
138
133
  return {
139
- render: (d) => {
140
- var c;
141
- const o = (c = d.action.items) == null ? void 0 : c.filter((a) => {
142
- var l;
143
- return !a.show || ((l = a.show) == null ? void 0 : l.call(a, d.data, d.index));
144
- }).map((a, l) => s(j, {
145
- key: l,
146
- type: a.color || (a.type === "delete" ? "error" : "primary"),
147
- text: d.text,
148
- secondary: !d.text,
134
+ render: (i) => {
135
+ const m = i.action.items?.filter((n) => !n.show || n.show?.(i.data, i.index)).map((n, c) => l(b, {
136
+ key: c,
137
+ type: n.color || (n.type === "delete" ? "error" : "primary"),
138
+ text: i.text,
139
+ secondary: !i.text,
149
140
  onClick: () => {
150
- var u;
151
- (u = d == null ? void 0 : d.target) == null || u.call(d, {
152
- id: d.id,
153
- data: d.data,
154
- item: a
141
+ i?.target?.({
142
+ id: i.id,
143
+ data: i.data,
144
+ item: n
155
145
  });
156
146
  },
157
- renderIcon: a.icon ? () => s("div", {
158
- class: ["n-icon", a.icon]
147
+ renderIcon: n.icon ? () => l("div", {
148
+ class: ["n-icon", n.icon]
159
149
  }) : void 0
160
- }, () => n(a.label || "", {}, a.label)));
161
- return s("div", {
162
- class: ["flex gap-2 flex-wrap items-center", d.align === "right" ? "justify-end" : d.align === "center" ? "justify-center" : "justify-start"]
163
- }, o);
150
+ }, () => o(n.label || "", {}, n.label)));
151
+ return l("div", {
152
+ class: ["flex gap-2 flex-wrap items-center", i.align === "right" ? "justify-end" : i.align === "center" ? "justify-center" : "justify-start"]
153
+ }, m);
164
154
  }
165
155
  };
166
156
  }
167
- function q() {
157
+ function T() {
168
158
  const {
169
- t: n
170
- } = b();
159
+ t: o
160
+ } = h();
171
161
  return {
172
- render: (d) => {
173
- var c;
174
- const o = (c = d.action.items) == null ? void 0 : c.filter((a) => {
175
- var l;
176
- return !a.show || ((l = a.show) == null ? void 0 : l.call(a, d.data, d.index));
177
- }).map((a, l) => ({
178
- label: n(a.label || "", {}, a.label),
179
- key: l,
180
- icon: a.icon ? () => s("div", {
181
- class: ["n-icon", a.icon]
162
+ render: (i) => {
163
+ const m = i.action.items?.filter((n) => !n.show || n.show?.(i.data, i.index)).map((n, c) => ({
164
+ label: o(n.label || "", {}, n.label),
165
+ key: c,
166
+ icon: n.icon ? () => l("div", {
167
+ class: ["n-icon", n.icon]
182
168
  }) : void 0,
183
169
  onSelect: () => {
184
- var u;
185
- (u = d == null ? void 0 : d.target) == null || u.call(d, {
186
- id: d.id,
187
- data: d.data,
188
- item: a
170
+ i?.target?.({
171
+ id: i.id,
172
+ data: i.data,
173
+ item: n
189
174
  });
190
175
  }
191
176
  }));
192
- return s(N, {
177
+ return l(C, {
193
178
  trigger: "click",
194
- options: o,
195
- onSelect: (a, l) => {
196
- var u;
197
- (u = l == null ? void 0 : l.onSelect) == null || u.call(l);
179
+ options: m,
180
+ onSelect: (n, c) => {
181
+ c?.onSelect?.();
198
182
  }
199
- }, () => [s("div", {
200
- class: ["flex items-center", d.align === "right" ? "justify-end" : d.align === "center" ? "justify-center" : "justify-start"]
201
- }, s(j, {
183
+ }, () => [l("div", {
184
+ class: ["flex items-center", i.align === "right" ? "justify-end" : i.align === "center" ? "justify-center" : "justify-start"]
185
+ }, l(b, {
202
186
  type: "default",
203
- text: d.text,
204
- secondary: !d.text,
205
- renderIcon: () => s("div", {
187
+ text: i.text,
188
+ secondary: !i.text,
189
+ renderIcon: () => l("div", {
206
190
  class: ["n-icon", "i-tabler:dots-vertical"]
207
191
  })
208
192
  }))]);
@@ -210,7 +194,7 @@ function q() {
210
194
  };
211
195
  }
212
196
  export {
213
- Q as useAction,
214
- W as useActionButton,
215
- q as useActionDropdown
197
+ K as useAction,
198
+ E as useActionButton,
199
+ T as useActionDropdown
216
200
  };
@@ -1,28 +1,28 @@
1
- import { useI18n as g, useClient as x } from "@duxweb/dvha-core";
2
- import C from "dayjs";
3
- import k from "mime";
4
- import { useMessage as U } from "naive-ui";
5
- import { ref as B } from "vue";
6
- function q() {
7
- const { t: y } = g(), M = x(), f = B(!1), c = B({
1
+ import { useI18n as B, useClient as M } from "@duxweb/dvha-core";
2
+ import x from "dayjs";
3
+ import C from "mime";
4
+ import { useMessage as k } from "naive-ui";
5
+ import { ref as y } from "vue";
6
+ function I() {
7
+ const { t: f } = B(), T = M(), p = y(!1), d = y({
8
8
  loaded: 0,
9
9
  total: 0,
10
10
  percent: 0,
11
11
  speed: 0,
12
12
  speedText: "0 B/s",
13
13
  remainingTime: 0
14
- }), T = U(), v = (n) => {
15
- if (n === 0)
14
+ }), b = k(), g = (o) => {
15
+ if (o === 0)
16
16
  return "0 B/s";
17
- const a = ["B/s", "KB/s", "MB/s", "GB/s"], e = Math.floor(Math.log(n) / Math.log(1024));
18
- return `${(n / 1024 ** e).toFixed(1)} ${a[e]}`;
19
- }, r = (n, a) => {
20
- const e = window.URL || window.webkitURL, d = e.createObjectURL(n), o = document.createElement("a");
21
- o.href = d, o.download = a || "", document.body.appendChild(o), o.click(), document.body.removeChild(o), e.revokeObjectURL(d);
17
+ const n = ["B/s", "KB/s", "MB/s", "GB/s"], e = Math.floor(Math.log(o) / Math.log(1024));
18
+ return `${(o / 1024 ** e).toFixed(1)} ${n[e]}`;
19
+ }, l = (o, n) => {
20
+ const e = window.URL || window.webkitURL, a = e.createObjectURL(o), s = document.createElement("a");
21
+ s.href = a, s.download = n || "", document.body.appendChild(s), s.click(), document.body.removeChild(s), e.revokeObjectURL(a);
22
22
  };
23
23
  return {
24
- file: (n, a, e, d, o) => {
25
- f.value = !0, c.value = {
24
+ file: (o, n, e, a, s) => {
25
+ p.value = !0, d.value = {
26
26
  loaded: 0,
27
27
  total: 0,
28
28
  percent: 0,
@@ -30,71 +30,70 @@ function q() {
30
30
  speedText: "0 B/s",
31
31
  remainingTime: 0
32
32
  };
33
- const b = Date.now();
34
- M.request({
35
- path: n,
33
+ const u = Date.now();
34
+ T.request({
35
+ path: o,
36
36
  method: "GET",
37
- query: a,
37
+ query: n,
38
38
  onDownloadProgress: (t) => {
39
- const p = (Date.now() - b) / 1e3, l = p > 0 ? t.loaded / p : 0, u = (t.total || 0) - t.loaded, h = l > 0 ? u / l : 0, i = {
39
+ const m = (Date.now() - u) / 1e3, r = m > 0 ? t.loaded / m : 0, c = (t.total || 0) - t.loaded, v = r > 0 ? c / r : 0, w = {
40
40
  loaded: t.loaded,
41
41
  total: t.total,
42
42
  percent: t.percent || 0,
43
- speed: Math.round(l),
44
- speedText: v(l),
45
- remainingTime: Math.round(h)
43
+ speed: Math.round(r),
44
+ speedText: g(r),
45
+ remainingTime: Math.round(v)
46
46
  };
47
- c.value = i, o == null || o(i);
47
+ d.value = w, s?.(w);
48
48
  }
49
49
  }).then((t) => {
50
- var u, h, i;
51
- const m = e || t.data.headers["content-type"], w = t.data.headers["content-disposition"];
52
- if (d || (d = C().format("YYYY-MM-DD-HH:mm:ss"), m && (d = `${d}.${k.getExtension(m)}`)), w) {
53
- const s = /filename=["']?([^"']+)/.exec(w);
54
- s && (s == null ? void 0 : s.length) > 1 && (d = decodeURIComponent(s[1]));
50
+ const i = e || t.data.headers["content-type"], h = t.data.headers["content-disposition"];
51
+ if (a || (a = x().format("YYYY-MM-DD-HH:mm:ss"), i && (a = `${a}.${C.getExtension(i)}`)), h) {
52
+ const c = /filename=["']?([^"']+)/.exec(h);
53
+ c && c?.length > 1 && (a = decodeURIComponent(c[1]));
55
54
  }
56
- const p = ((u = t.data) == null ? void 0 : u.data) instanceof Blob ? (h = t.data) == null ? void 0 : h.data : new Blob([(i = t.data) == null ? void 0 : i.data], { type: m || "application/octet-stream" });
57
- r(p, d);
58
- const l = {
59
- loaded: c.value.total || c.value.loaded,
60
- total: c.value.total || c.value.loaded,
55
+ const m = t.data?.data instanceof Blob ? t.data?.data : new Blob([t.data?.data], { type: i || "application/octet-stream" });
56
+ l(m, a);
57
+ const r = {
58
+ loaded: d.value.total || d.value.loaded,
59
+ total: d.value.total || d.value.loaded,
61
60
  percent: 100,
62
61
  speed: 0,
63
- speedText: v(0),
62
+ speedText: g(0),
64
63
  remainingTime: 0
65
64
  };
66
- c.value = l, o == null || o(l);
65
+ d.value = r, s?.(r);
67
66
  }).catch((t) => {
68
- T.error(t.error || y("hooks.download.failed"));
67
+ b.error(t.error || f("hooks.download.failed"));
69
68
  }).finally(() => {
70
- f.value = !1;
69
+ p.value = !1;
71
70
  });
72
71
  },
73
- url: (n, a) => {
72
+ url: (o, n) => {
74
73
  const e = document.createElement("a");
75
- e.href = n, e.download = a || "", document.body.appendChild(e), e.click(), document.body.removeChild(e);
74
+ e.href = o, e.download = n || "", document.body.appendChild(e), e.click(), document.body.removeChild(e);
76
75
  },
77
- blob: r,
78
- base64: (n, a) => {
79
- const e = atob(n.split(",")[1]), d = Array.from({ length: e.length });
76
+ blob: l,
77
+ base64: (o, n) => {
78
+ const e = atob(o.split(",")[1]), a = Array.from({ length: e.length });
80
79
  for (let t = 0; t < e.length; t++)
81
- d[t] = e.charCodeAt(t);
82
- const o = new Uint8Array(d), b = new Blob([o], { type: "application/octet-stream" });
83
- r(b, a);
80
+ a[t] = e.charCodeAt(t);
81
+ const s = new Uint8Array(a), u = new Blob([s], { type: "application/octet-stream" });
82
+ l(u, n);
84
83
  },
85
- loading: f,
86
- progress: c,
87
- image: (n) => {
88
- fetch(n).then((a) => {
89
- a.blob().then((e) => {
90
- r(e);
84
+ loading: p,
85
+ progress: d,
86
+ image: (o) => {
87
+ fetch(o).then((n) => {
88
+ n.blob().then((e) => {
89
+ l(e);
91
90
  });
92
- }).catch((a) => {
93
- T.error(a.error || y("hooks.download.failed"));
91
+ }).catch((n) => {
92
+ b.error(n.error || f("hooks.download.failed"));
94
93
  });
95
94
  }
96
95
  };
97
96
  }
98
97
  export {
99
- q as useDownload
98
+ I as useDownload
100
99
  };