@duxweb/dvha-core 1.1.30 → 1.2.0
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.
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -0
- package/dist/cjs/components/auth/can.cjs +1 -1
- package/dist/cjs/components/auth/index.cjs +1 -0
- package/dist/cjs/components/common/icon.cjs +1 -1
- package/dist/cjs/components/common/index.cjs +1 -0
- package/dist/cjs/components/common/logo.cjs +1 -1
- package/dist/cjs/components/index.cjs +1 -0
- package/dist/cjs/components/loader/iframe.cjs +1 -1
- package/dist/cjs/components/loader/index.cjs +1 -0
- package/dist/cjs/components/loader/loader.cjs +1 -1
- package/dist/cjs/components/loader/remote/index.cjs +1 -0
- package/dist/cjs/components/loader/remote/loader.cjs +1 -1
- package/dist/cjs/components/loader/remote/render.cjs +1 -1
- package/dist/cjs/components/overlay/index.cjs +1 -0
- package/dist/cjs/components/overlay/overlay.cjs +1 -1
- package/dist/cjs/components/status/error.cjs +1 -1
- package/dist/cjs/components/status/exception.cjs +1 -1
- package/dist/cjs/components/status/index.cjs +1 -0
- package/dist/cjs/components/status/notAuthorized.cjs +1 -1
- package/dist/cjs/components/status/notFound.cjs +1 -1
- package/dist/cjs/config/color.cjs +1 -1
- package/dist/cjs/directive/index.cjs +1 -0
- package/dist/cjs/directive/permission.cjs +1 -1
- package/dist/cjs/hooks/auth.cjs +1 -1
- package/dist/cjs/hooks/config.cjs +1 -1
- package/dist/cjs/hooks/data.cjs +1 -1
- package/dist/cjs/hooks/export.cjs +1 -1
- package/dist/cjs/hooks/exportCsv.cjs +2 -2
- package/dist/cjs/hooks/form.cjs +1 -1
- package/dist/cjs/hooks/formExtend.cjs +1 -1
- package/dist/cjs/hooks/formValidate.cjs +1 -1
- package/dist/cjs/hooks/i18n.cjs +1 -1
- package/dist/cjs/hooks/import.cjs +1 -1
- package/dist/cjs/hooks/importCsv.cjs +2 -2
- package/dist/cjs/hooks/index.cjs +1 -0
- package/dist/cjs/hooks/json/index.cjs +1 -1
- package/dist/cjs/hooks/json/utils/contextManager.cjs +1 -1
- package/dist/cjs/hooks/json/utils/expressionParser.cjs +1 -1
- package/dist/cjs/hooks/json/vFor.cjs +1 -1
- package/dist/cjs/hooks/json/vIf.cjs +1 -1
- package/dist/cjs/hooks/json/vModel.cjs +1 -1
- package/dist/cjs/hooks/json/vOn.cjs +1 -1
- package/dist/cjs/hooks/json/vShow.cjs +1 -1
- package/dist/cjs/hooks/json/vText.cjs +1 -1
- package/dist/cjs/hooks/json.cjs +1 -1
- package/dist/cjs/hooks/list.cjs +1 -1
- package/dist/cjs/hooks/manage.cjs +1 -1
- package/dist/cjs/hooks/menu.cjs +1 -1
- package/dist/cjs/hooks/overlay.cjs +1 -1
- package/dist/cjs/hooks/select.cjs +1 -1
- package/dist/cjs/hooks/theme.cjs +4 -8
- package/dist/cjs/hooks/tree.cjs +1 -1
- package/dist/cjs/hooks/upload/index.cjs +1 -0
- package/dist/cjs/hooks/upload/local.cjs +1 -1
- package/dist/cjs/hooks/upload/s3.cjs +1 -1
- package/dist/cjs/hooks/upload.cjs +1 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/main.cjs +1 -1
- package/dist/cjs/preset/authProvider.cjs +1 -1
- package/dist/cjs/preset/dataProvider.cjs +1 -1
- package/dist/cjs/preset/i18nProvider.cjs +1 -1
- package/dist/cjs/preset/index.cjs +1 -0
- package/dist/cjs/provider/app.cjs +1 -1
- package/dist/cjs/provider/index.cjs +1 -0
- package/dist/cjs/provider/tab.cjs +1 -1
- package/dist/cjs/router/index.cjs +1 -0
- package/dist/cjs/router/route.cjs +1 -1
- package/dist/cjs/stores/auth.cjs +1 -1
- package/dist/cjs/stores/i18n.cjs +1 -1
- package/dist/cjs/stores/index.cjs +1 -0
- package/dist/cjs/stores/jsonSchema.cjs +1 -1
- package/dist/cjs/stores/manage.cjs +1 -1
- package/dist/cjs/stores/route.cjs +1 -1
- package/dist/cjs/stores/tab.cjs +1 -1
- package/dist/cjs/stores/theme.cjs +1 -1
- package/dist/cjs/utils/bus.cjs +1 -1
- package/dist/cjs/utils/index.cjs +1 -0
- package/dist/cjs/utils/theme.cjs +8 -8
- package/dist/cjs/utils/tree.cjs +1 -1
- package/dist/esm/_virtual/_rolldown/runtime.js +9 -0
- package/dist/esm/components/auth/can.js +17 -36
- package/dist/esm/components/auth/index.js +1 -0
- package/dist/esm/components/common/icon.js +16 -24
- package/dist/esm/components/common/index.js +2 -0
- package/dist/esm/components/common/logo.js +50 -49
- package/dist/esm/components/index.js +14 -0
- package/dist/esm/components/loader/iframe.js +16 -18
- package/dist/esm/components/loader/index.js +1 -0
- package/dist/esm/components/loader/loader.js +11 -40
- package/dist/esm/components/loader/remote/index.js +2 -0
- package/dist/esm/components/loader/remote/loader.js +118 -156
- package/dist/esm/components/loader/remote/render.js +12 -17
- package/dist/esm/components/overlay/index.js +1 -0
- package/dist/esm/components/overlay/overlay.js +54 -70
- package/dist/esm/components/status/error.js +7 -9
- package/dist/esm/components/status/exception.js +21 -37
- package/dist/esm/components/status/index.js +4 -0
- package/dist/esm/components/status/notAuthorized.js +7 -9
- package/dist/esm/components/status/notFound.js +7 -9
- package/dist/esm/config/color.js +288 -290
- package/dist/esm/directive/index.js +1 -0
- package/dist/esm/directive/permission.js +7 -27
- package/dist/esm/hooks/auth.js +154 -120
- package/dist/esm/hooks/config.js +11 -9
- package/dist/esm/hooks/data.js +416 -415
- package/dist/esm/hooks/export.js +32 -36
- package/dist/esm/hooks/exportCsv.js +42 -46
- package/dist/esm/hooks/form.js +86 -95
- package/dist/esm/hooks/formExtend.js +36 -40
- package/dist/esm/hooks/formValidate.js +22 -25
- package/dist/esm/hooks/i18n.js +14 -18
- package/dist/esm/hooks/import.js +45 -54
- package/dist/esm/hooks/importCsv.js +90 -83
- package/dist/esm/hooks/index.js +31 -0
- package/dist/esm/hooks/json/index.js +14 -22
- package/dist/esm/hooks/json/utils/contextManager.js +35 -26
- package/dist/esm/hooks/json/utils/expressionParser.js +100 -123
- package/dist/esm/hooks/json/vFor.js +50 -55
- package/dist/esm/hooks/json/vIf.js +17 -16
- package/dist/esm/hooks/json/vModel.js +96 -106
- package/dist/esm/hooks/json/vOn.js +30 -32
- package/dist/esm/hooks/json/vShow.js +20 -22
- package/dist/esm/hooks/json/vText.js +44 -51
- package/dist/esm/hooks/json.js +131 -132
- package/dist/esm/hooks/list.js +150 -184
- package/dist/esm/hooks/manage.js +25 -22
- package/dist/esm/hooks/menu.js +57 -61
- package/dist/esm/hooks/overlay.js +6 -23
- package/dist/esm/hooks/select.js +84 -94
- package/dist/esm/hooks/theme.js +289 -219
- package/dist/esm/hooks/tree.js +43 -47
- package/dist/esm/hooks/upload/index.js +2 -0
- package/dist/esm/hooks/upload/local.js +24 -30
- package/dist/esm/hooks/upload/s3.js +70 -80
- package/dist/esm/hooks/upload.js +256 -272
- package/dist/esm/index.js +150 -141
- package/dist/esm/main.js +24 -45
- package/dist/esm/preset/authProvider.js +62 -68
- package/dist/esm/preset/dataProvider.js +154 -180
- package/dist/esm/preset/i18nProvider.js +28 -30
- package/dist/esm/preset/index.js +3 -0
- package/dist/esm/provider/app.js +124 -151
- package/dist/esm/provider/index.js +2 -0
- package/dist/esm/provider/tab.js +49 -66
- package/dist/esm/router/index.js +1 -0
- package/dist/esm/router/route.js +39 -46
- package/dist/esm/stores/auth.js +51 -46
- package/dist/esm/stores/i18n.js +32 -29
- package/dist/esm/stores/index.js +7 -0
- package/dist/esm/stores/jsonSchema.js +47 -34
- package/dist/esm/stores/manage.js +63 -48
- package/dist/esm/stores/route.js +60 -56
- package/dist/esm/stores/tab.js +55 -60
- package/dist/esm/stores/theme.js +48 -55
- package/dist/esm/utils/bus.js +3 -5
- package/dist/esm/utils/index.js +3 -0
- package/dist/esm/utils/theme.js +110 -93
- package/dist/esm/utils/tree.js +28 -37
- package/package.json +1 -1
package/dist/esm/hooks/upload.js
CHANGED
|
@@ -1,273 +1,257 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
progress: x,
|
|
257
|
-
open: N,
|
|
258
|
-
trigger: M,
|
|
259
|
-
resetFiles: B,
|
|
260
|
-
clearFiles: y,
|
|
261
|
-
removeFiles: K,
|
|
262
|
-
addFiles: C,
|
|
263
|
-
addDataFiles: (e) => {
|
|
264
|
-
!l.multiple && o.value.length > 0 && y();
|
|
265
|
-
const t = e.map((n) => q(n));
|
|
266
|
-
o.value.push(...t);
|
|
267
|
-
},
|
|
268
|
-
cancelFiles: D
|
|
269
|
-
};
|
|
1
|
+
import { createLocalUploadDriver as e } from "./upload/local.js";
|
|
2
|
+
import { computed as t, ref as n, watch as r } from "vue";
|
|
3
|
+
import { uniqueId as i } from "lodash-es";
|
|
4
|
+
import { useFileDialog as a } from "@vueuse/core";
|
|
5
|
+
function o(o) {
|
|
6
|
+
o ||= {};
|
|
7
|
+
let s = n(!1), c = n([]), l = n(-1), u = n(/* @__PURE__ */ new Map()), d = o.driver || e(), f = t(() => {
|
|
8
|
+
let { onProgress: e, onDataCallback: t, onCancel: n, onComplete: r, maxFileSize: i, maxFileCount: a, accept: s, multiple: c, autoUpload: l, options: u, onSuccess: d, onError: f, method: p, driver: m, params: h, ...g } = o;
|
|
9
|
+
return g;
|
|
10
|
+
}), p = t(() => o.method || "POST"), m = t(() => {
|
|
11
|
+
let e = c.value.length, t = c.value.reduce((e, t) => e + (t.filesize || 0), 0), n = 0, r = 0;
|
|
12
|
+
return c.value.forEach((e, t) => {
|
|
13
|
+
t < l.value ? n += e.filesize || 0 : t === l.value && (n += Math.min(e.progress?.loaded || 0, e.filesize || 0));
|
|
14
|
+
}), t > 0 && (r = Math.max(0, Math.min(100, Math.round(n / t * 100)))), {
|
|
15
|
+
index: l.value >= 0 ? l.value + 1 : 0,
|
|
16
|
+
totalFiles: e,
|
|
17
|
+
currentFile: c.value[l.value],
|
|
18
|
+
totalPercent: r,
|
|
19
|
+
totalLoaded: n,
|
|
20
|
+
totalSize: t
|
|
21
|
+
};
|
|
22
|
+
}), h = (e) => {
|
|
23
|
+
if (e === 0) return "0 Bytes";
|
|
24
|
+
let t = 1024, n = [
|
|
25
|
+
"Bytes",
|
|
26
|
+
"KB",
|
|
27
|
+
"MB",
|
|
28
|
+
"GB"
|
|
29
|
+
], r = Math.floor(Math.log(e) / Math.log(t));
|
|
30
|
+
return `${Number.parseFloat((e / t ** r).toFixed(2))} ${n[r]}`;
|
|
31
|
+
}, g = (e) => {
|
|
32
|
+
if (e === 0) return "0 B/s";
|
|
33
|
+
let t = 1024, n = [
|
|
34
|
+
"B/s",
|
|
35
|
+
"KB/s",
|
|
36
|
+
"MB/s",
|
|
37
|
+
"GB/s"
|
|
38
|
+
], r = Math.floor(Math.log(e) / Math.log(t));
|
|
39
|
+
return `${Number.parseFloat((e / t ** r).toFixed(2))} ${n[r]}`;
|
|
40
|
+
}, _ = () => i("upload-"), v = async (e, t, n) => {
|
|
41
|
+
switch (t) {
|
|
42
|
+
case "file":
|
|
43
|
+
if (!(e instanceof File)) throw TypeError("Payload must be a File when type is \"file\"");
|
|
44
|
+
return e;
|
|
45
|
+
case "blob":
|
|
46
|
+
if (!(e instanceof Blob)) throw TypeError("Payload must be a Blob when type is \"blob\"");
|
|
47
|
+
return new File([e], n || "blob-file", { type: e.type });
|
|
48
|
+
case "base64": {
|
|
49
|
+
if (typeof e != "string") throw TypeError("Payload must be a string when type is \"base64\"");
|
|
50
|
+
let t = e.includes(",") ? e.split(",")[1] : e, r = e.includes(",") ? e.split(",")[0].split(":")[1].split(";")[0] : "application/octet-stream", i = atob(t), a = new Uint8Array(i.length);
|
|
51
|
+
for (let e = 0; e < i.length; e++) a[e] = i.charCodeAt(e);
|
|
52
|
+
let o = new Blob([a], { type: r });
|
|
53
|
+
return new File([o], n || "base64-file", { type: r });
|
|
54
|
+
}
|
|
55
|
+
case "arrayBuffer": {
|
|
56
|
+
if (!(e instanceof ArrayBuffer)) throw TypeError("Payload must be ArrayBuffer when type is \"arrayBuffer\"");
|
|
57
|
+
let t = new Blob([e]);
|
|
58
|
+
return new File([t], n || "array-buffer-file", { type: "application/octet-stream" });
|
|
59
|
+
}
|
|
60
|
+
default: throw Error(`Unsupported upload type: ${t}`);
|
|
61
|
+
}
|
|
62
|
+
}, y = (e) => {
|
|
63
|
+
if (o.maxFileSize && e.size > o.maxFileSize) throw Error(`File size cannot exceed ${h(o.maxFileSize)}`);
|
|
64
|
+
if (o.maxFileCount && c.value.length > o.maxFileCount) throw Error(`File count cannot exceed ${o.maxFileCount}`);
|
|
65
|
+
}, b = async (e, t, n) => {
|
|
66
|
+
let r = await v(e, t, n);
|
|
67
|
+
y(r);
|
|
68
|
+
let i = {
|
|
69
|
+
id: _(),
|
|
70
|
+
file: r,
|
|
71
|
+
filename: r.name,
|
|
72
|
+
filesize: r.size,
|
|
73
|
+
filetype: r.type,
|
|
74
|
+
filesizeText: h(r.size),
|
|
75
|
+
status: "pending",
|
|
76
|
+
progress: {
|
|
77
|
+
loaded: 0,
|
|
78
|
+
total: r.size,
|
|
79
|
+
percent: 0,
|
|
80
|
+
speed: 0,
|
|
81
|
+
speedText: g(0),
|
|
82
|
+
remainingTime: 0,
|
|
83
|
+
uploadTime: 0
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
return c.value.push(i), i;
|
|
87
|
+
}, x = (e, t) => {
|
|
88
|
+
let n = c.value.findIndex((t) => t.id === e);
|
|
89
|
+
n !== -1 && (c.value[n] = {
|
|
90
|
+
...c.value[n],
|
|
91
|
+
...t
|
|
92
|
+
});
|
|
93
|
+
}, S = () => {
|
|
94
|
+
c.value.every((e) => e.status !== "uploading") && o.onComplete?.(c.value);
|
|
95
|
+
}, C = (e) => {
|
|
96
|
+
let t = c.value.find((t) => t.id === e);
|
|
97
|
+
if (!t || t.status !== "pending" && t.status !== "uploading") return !1;
|
|
98
|
+
if (t.status === "uploading") {
|
|
99
|
+
let t = u.value.get(e);
|
|
100
|
+
t && (t.abort(), u.value.delete(e));
|
|
101
|
+
}
|
|
102
|
+
return x(e, { status: "cancelled" }), o.onCancel?.(e), S(), !0;
|
|
103
|
+
}, w = (e) => {
|
|
104
|
+
e ? e.forEach((e) => C(e)) : c.value.forEach((e) => C(e.id));
|
|
105
|
+
}, T = async (e) => {
|
|
106
|
+
if (!e.file) throw Error("File not found");
|
|
107
|
+
y(e.file);
|
|
108
|
+
let t = new AbortController();
|
|
109
|
+
u.value.set(e.id, t);
|
|
110
|
+
let n = Date.now();
|
|
111
|
+
return x(e.id, { status: "uploading" }), d.upload(e.file, {
|
|
112
|
+
...f.value,
|
|
113
|
+
method: p.value,
|
|
114
|
+
signal: t.signal,
|
|
115
|
+
params: o.params,
|
|
116
|
+
onUploadProgress: (t) => {
|
|
117
|
+
let r = (Date.now() - n) / 1e3, i = r > 0 ? t.loaded / r : 0, a = (t.total || 0) - t.loaded, s = i > 0 ? a / i : 0, c = {
|
|
118
|
+
loaded: t.total ? Math.min(t.loaded, t.total) : t.loaded,
|
|
119
|
+
total: t.total,
|
|
120
|
+
percent: Math.max(0, Math.min(100, t.percent || 0)),
|
|
121
|
+
speed: Math.round(i),
|
|
122
|
+
speedText: g(i),
|
|
123
|
+
uploadTime: Math.round(r),
|
|
124
|
+
remainingTime: Math.round(s)
|
|
125
|
+
};
|
|
126
|
+
x(e.id, {
|
|
127
|
+
status: "uploading",
|
|
128
|
+
progress: c
|
|
129
|
+
}), o.onProgress?.(m.value);
|
|
130
|
+
}
|
|
131
|
+
}).then((t) => {
|
|
132
|
+
if (e.status === "cancelled") throw Error("Upload cancelled");
|
|
133
|
+
let r = o.onDataCallback?.(t, e) || t.data, i = Math.round((Date.now() - n) / 1e3), a = {
|
|
134
|
+
...e,
|
|
135
|
+
status: "success",
|
|
136
|
+
data: t,
|
|
137
|
+
...r,
|
|
138
|
+
progress: {
|
|
139
|
+
...e.progress,
|
|
140
|
+
loaded: e.filesize || 0,
|
|
141
|
+
percent: 100,
|
|
142
|
+
speed: 0,
|
|
143
|
+
speedText: g(0),
|
|
144
|
+
uploadTime: i,
|
|
145
|
+
remainingTime: 0
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
return x(e.id, a), u.value.delete(e.id), o.onSuccess?.(t), a;
|
|
149
|
+
}).catch((t) => {
|
|
150
|
+
throw t.message === "canceled" || e.status === "cancelled" ? Error("Upload cancelled") : (x(e.id, {
|
|
151
|
+
status: "error",
|
|
152
|
+
error: t.message
|
|
153
|
+
}), u.value.delete(e.id), t);
|
|
154
|
+
}).finally(() => {
|
|
155
|
+
S();
|
|
156
|
+
});
|
|
157
|
+
}, E = async () => {
|
|
158
|
+
let e = c.value.filter((e) => e.status === "pending");
|
|
159
|
+
if (e.length === 0) return [];
|
|
160
|
+
s.value = !0;
|
|
161
|
+
try {
|
|
162
|
+
let t = [];
|
|
163
|
+
for (let n = 0; n < e.length; n++) {
|
|
164
|
+
let r = e[n];
|
|
165
|
+
l.value = c.value.findIndex((e) => e.id === r.id);
|
|
166
|
+
let i = await T(r);
|
|
167
|
+
t.push(i);
|
|
168
|
+
}
|
|
169
|
+
return t;
|
|
170
|
+
} catch (e) {
|
|
171
|
+
throw o.onError?.({
|
|
172
|
+
status: e?.status || 500,
|
|
173
|
+
message: e?.message || "upload failed"
|
|
174
|
+
}), e;
|
|
175
|
+
} finally {
|
|
176
|
+
s.value = !1, l.value = -1;
|
|
177
|
+
}
|
|
178
|
+
}, D = () => {
|
|
179
|
+
c.value.forEach((e) => {
|
|
180
|
+
C(e.id);
|
|
181
|
+
}), u.value.clear(), c.value = [], l.value = -1;
|
|
182
|
+
}, O = async (e, t = "file") => {
|
|
183
|
+
try {
|
|
184
|
+
if (!o.multiple && e.length > 1) throw Error("Single file mode: only one file can be selected");
|
|
185
|
+
if (!o.multiple && c.value.length > 0 && D(), o.maxFileCount && c.value.length + e.length > o.maxFileCount) throw Error(`Adding ${e.length} files would exceed the maximum limit of ${o.maxFileCount}`);
|
|
186
|
+
for (let n of e) await b(n, t);
|
|
187
|
+
} catch (e) {
|
|
188
|
+
throw o.onError?.({
|
|
189
|
+
status: e?.status || 400,
|
|
190
|
+
message: e?.message || "Failed to add files"
|
|
191
|
+
}), e;
|
|
192
|
+
}
|
|
193
|
+
o.autoUpload && E().catch((e) => {
|
|
194
|
+
console.warn("Auto upload failed:", e);
|
|
195
|
+
});
|
|
196
|
+
}, k = (e) => {
|
|
197
|
+
let t = c.value.find((t) => t.id === e);
|
|
198
|
+
if (t && t.status === "uploading") {
|
|
199
|
+
x(e, { status: "cancelled" });
|
|
200
|
+
let t = u.value.get(e);
|
|
201
|
+
if (!t) return;
|
|
202
|
+
t.abort(), u.value.delete(e);
|
|
203
|
+
}
|
|
204
|
+
let n = c.value.findIndex((t) => t.id === e);
|
|
205
|
+
n !== -1 && c.value.splice(n, 1);
|
|
206
|
+
}, A = (e) => {
|
|
207
|
+
e ? e.forEach((e) => k(e)) : c.value.forEach((e) => k(e.id));
|
|
208
|
+
}, { files: j, open: M, reset: N } = a({
|
|
209
|
+
accept: o.accept,
|
|
210
|
+
multiple: o.multiple || !1
|
|
211
|
+
}), P = (e) => ({
|
|
212
|
+
id: _(),
|
|
213
|
+
...e,
|
|
214
|
+
filesizeText: e.filesize ? h(e.filesize) : void 0,
|
|
215
|
+
status: e.url ? "success" : "pending",
|
|
216
|
+
progress: {
|
|
217
|
+
loaded: 0,
|
|
218
|
+
total: e.filesize || 0,
|
|
219
|
+
percent: e.url ? 100 : 0,
|
|
220
|
+
speed: 0,
|
|
221
|
+
speedText: g(0),
|
|
222
|
+
remainingTime: 0,
|
|
223
|
+
uploadTime: 0
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
return r(j, async (e) => {
|
|
227
|
+
if (e && e.length > 0) {
|
|
228
|
+
let t = Array.from(e);
|
|
229
|
+
N(), await O(t, "file").catch((e) => {
|
|
230
|
+
console.warn("Failed to add selected files:", e);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
}), {
|
|
234
|
+
isUploading: s,
|
|
235
|
+
uploadFiles: c,
|
|
236
|
+
dataFiles: t(() => c.value.filter((e) => e.status === "success").map((e) => ({
|
|
237
|
+
url: e.url,
|
|
238
|
+
filename: e.filename,
|
|
239
|
+
filesize: e.filesize,
|
|
240
|
+
filetype: e.filetype
|
|
241
|
+
}))),
|
|
242
|
+
progress: m,
|
|
243
|
+
open: M,
|
|
244
|
+
trigger: E,
|
|
245
|
+
resetFiles: N,
|
|
246
|
+
clearFiles: D,
|
|
247
|
+
removeFiles: A,
|
|
248
|
+
addFiles: O,
|
|
249
|
+
addDataFiles: (e) => {
|
|
250
|
+
!o.multiple && c.value.length > 0 && D();
|
|
251
|
+
let t = e.map((e) => P(e));
|
|
252
|
+
c.value.push(...t);
|
|
253
|
+
},
|
|
254
|
+
cancelFiles: w
|
|
255
|
+
};
|
|
270
256
|
}
|
|
271
|
-
export {
|
|
272
|
-
ne as useUpload
|
|
273
|
-
};
|
|
257
|
+
export { o as useUpload };
|