vue3-chunked-upload 1.0.4

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.
@@ -0,0 +1,350 @@
1
+ import { ComponentOptionsMixin } from 'vue';
2
+ import { ComponentProvideOptions } from 'vue';
3
+ import { ComputedRef } from 'vue';
4
+ import { DefineComponent } from 'vue';
5
+ import { ExtractPropTypes } from 'vue';
6
+ import { PropType } from 'vue';
7
+ import { PublicProps } from 'vue';
8
+ import { Ref } from 'vue';
9
+
10
+ declare const __VLS_component: DefineComponent<ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
11
+ modelValue?: UploadFile[];
12
+ options?: ChunkUploadOptions;
13
+ disabled?: boolean;
14
+ }>, {
15
+ modelValue: () => never[];
16
+ disabled: boolean;
17
+ }>>, {
18
+ tasks: Ref<UploadTask[], UploadTask[]>;
19
+ addFiles: (fileList: FileList | File[]) => string[];
20
+ pauseUpload: (taskId: string) => void;
21
+ resumeUpload: (taskId: string) => void;
22
+ removeTask: (taskId: string) => boolean;
23
+ retryTask: (taskId: string) => void;
24
+ }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
25
+ "update:modelValue": (value: UploadFile[]) => void;
26
+ success: (task: UploadTask) => void;
27
+ error: (task: UploadTask, error: Error) => void;
28
+ progress: (task: UploadTask) => void;
29
+ notice: (type: NoticeType, message: string) => void;
30
+ allComplete: (completedTasks: UploadTask[]) => void;
31
+ taskAdd: (task: UploadTask) => void;
32
+ taskRemove: (task: UploadTask) => void;
33
+ }, string, PublicProps, Readonly<ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<{
34
+ modelValue?: UploadFile[];
35
+ options?: ChunkUploadOptions;
36
+ disabled?: boolean;
37
+ }>, {
38
+ modelValue: () => never[];
39
+ disabled: boolean;
40
+ }>>> & Readonly<{
41
+ onSuccess?: ((task: UploadTask) => any) | undefined;
42
+ onError?: ((task: UploadTask, error: Error) => any) | undefined;
43
+ onProgress?: ((task: UploadTask) => any) | undefined;
44
+ "onUpdate:modelValue"?: ((value: UploadFile[]) => any) | undefined;
45
+ onNotice?: ((type: NoticeType, message: string) => any) | undefined;
46
+ onAllComplete?: ((completedTasks: UploadTask[]) => any) | undefined;
47
+ onTaskAdd?: ((task: UploadTask) => any) | undefined;
48
+ onTaskRemove?: ((task: UploadTask) => any) | undefined;
49
+ }>, {
50
+ modelValue: UploadFile[];
51
+ disabled: boolean;
52
+ }, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>;
53
+
54
+ declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
55
+
56
+ declare type __VLS_Prettify<T> = {
57
+ [K in keyof T]: T[K];
58
+ } & {};
59
+
60
+ declare function __VLS_template(): {
61
+ trigger?(_: {}): any;
62
+ };
63
+
64
+ declare type __VLS_TypePropsToRuntimeProps<T> = {
65
+ [K in keyof T]-?: {} extends Pick<T, K> ? {
66
+ type: PropType<__VLS_NonUndefinedable<T[K]>>;
67
+ } : {
68
+ type: PropType<T[K]>;
69
+ required: true;
70
+ };
71
+ };
72
+
73
+ declare type __VLS_WithDefaults<P, D> = {
74
+ [K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
75
+ default: D[K];
76
+ }> : P[K];
77
+ };
78
+
79
+ declare type __VLS_WithTemplateSlots<T, S> = T & {
80
+ new (): {
81
+ $slots: S;
82
+ };
83
+ };
84
+
85
+ /**
86
+ * 分片上传配置选项
87
+ */
88
+ export declare interface ChunkUploadOptions {
89
+ /** 分片大小,默认 10MB (10485760) */
90
+ chunkSize?: number;
91
+ /** 最大并发上传数,默认 3 */
92
+ maxConcurrent?: number;
93
+ /** 分片上传接口地址 */
94
+ uploadUrl?: string;
95
+ /** 文件合并接口地址 */
96
+ mergeUrl?: string;
97
+ /** 最大文件大小,默认 10GB (10737418240) */
98
+ maxFileSize?: number;
99
+ /** 是否自动开始上传,默认 true */
100
+ autoStart?: boolean;
101
+ /** 分片失败重试次数,默认 3 */
102
+ retryTimes?: number;
103
+ /** 重试延迟时间(毫秒),默认 1000 */
104
+ retryDelay?: number;
105
+ /** 是否支持拖拽上传,默认 true */
106
+ draggable?: boolean;
107
+ /** 接受的文件类型,如 '.pdf,.doc,.docx' 或 'image/*' */
108
+ accept?: string;
109
+ /** 最大文件数量,默认为 0 表示不限制 */
110
+ limit?: number;
111
+ /** 自定义请求头 */
112
+ headers?: Record<string, string>;
113
+ /** 上传前校验,返回 true 允许上传,false 拒绝 */
114
+ onBeforeUpload?: (files: File[]) => boolean | Promise<boolean>;
115
+ /** 上传进度回调 */
116
+ onProgress?: (task: UploadTask) => void;
117
+ /** 上传成功回调 */
118
+ onSuccess?: (task: UploadTask) => void;
119
+ /** 上传错误回调 */
120
+ onError?: (task: UploadTask, error: Error) => void;
121
+ /** 添加任务回调 */
122
+ onTaskAdd?: (task: UploadTask) => void;
123
+ /** 删除任务回调 */
124
+ onTaskRemove?: (task: UploadTask) => void;
125
+ /** 提示消息回调 */
126
+ onNotice?: (type: NoticeType, message: string) => void;
127
+ /** 全部上传完成回调 */
128
+ onAllComplete?: (completedTasks: UploadTask[]) => void;
129
+ }
130
+
131
+ /**
132
+ * 分片上传请求参数
133
+ */
134
+ export declare interface ChunkUploadRequest {
135
+ /** 文件唯一标识 */
136
+ fileId: string;
137
+ /** 文件名 */
138
+ fileName: string;
139
+ /** 当前分片索引(从 0 开始) */
140
+ chunkIndex: number;
141
+ /** 总分片数 */
142
+ totalChunks: number;
143
+ /** 当前分片数据 */
144
+ chunk: Blob;
145
+ }
146
+
147
+ /**
148
+ * 分片上传响应结果
149
+ */
150
+ export declare interface ChunkUploadResponse {
151
+ /** 是否成功 */
152
+ success: boolean;
153
+ /** 提示消息 */
154
+ message?: string;
155
+ /** 响应数据 */
156
+ data?: {
157
+ /** 文件路径(部分场景下分片上传也会返回路径) */
158
+ path?: string;
159
+ /** 其他自定义字段 */
160
+ [key: string]: any;
161
+ };
162
+ }
163
+
164
+ /**
165
+ * 已存在文件类型(用于初始化已上传文件列表)
166
+ */
167
+ export declare interface ExistingFile {
168
+ /** 文件唯一标识 */
169
+ id: string;
170
+ /** 文件名 */
171
+ name: string;
172
+ /** 文件大小(字节) */
173
+ size: number;
174
+ /** 服务器上的文件路径 */
175
+ path?: string;
176
+ }
177
+
178
+ export declare function formatFileSize(bytes: number): string;
179
+
180
+ /**
181
+ * 合并文件请求参数
182
+ */
183
+ export declare interface MergeUploadRequest {
184
+ /** 文件唯一标识 */
185
+ fileId: string;
186
+ /** 文件名 */
187
+ fileName: string;
188
+ /** 总分片数 */
189
+ totalChunks: number;
190
+ /** 文件总大小(字节) */
191
+ fileSize: number;
192
+ }
193
+
194
+ /**
195
+ * 合并文件响应结果
196
+ */
197
+ export declare interface MergeUploadResponse {
198
+ /** 是否成功 */
199
+ success: boolean;
200
+ /** 提示消息 */
201
+ message?: string;
202
+ /** 响应数据 */
203
+ data?: {
204
+ /** 上传成功后的文件路径 */
205
+ path?: string;
206
+ /** 其他自定义字段 */
207
+ [key: string]: any;
208
+ };
209
+ }
210
+
211
+ /**
212
+ * 提示消息类型
213
+ */
214
+ export declare type NoticeType = 'success' | 'error' | 'warning' | 'info';
215
+
216
+ /**
217
+ * 组件使用的文件类型(用于 v-model 绑定)
218
+ */
219
+ export declare interface UploadFile {
220
+ /** 文件唯一标识 */
221
+ id: string;
222
+ /** 文件名 */
223
+ name: string;
224
+ /** 文件大小(字节) */
225
+ size: number;
226
+ /** 服务器返回的文件路径 */
227
+ path?: string;
228
+ /** 文件状态 */
229
+ status: string;
230
+ }
231
+
232
+ /**
233
+ * 上传器整体状态
234
+ */
235
+ export declare interface UploadState {
236
+ /** 所有上传任务列表 */
237
+ tasks: UploadTask[];
238
+ /** 总任务数 */
239
+ totalCount: number;
240
+ /** 已完成任务数 */
241
+ completedCount: number;
242
+ /** 整体上传进度(0-100) */
243
+ totalProgress: number;
244
+ /** 是否正在上传 */
245
+ isUploading: boolean;
246
+ /** 所有文件总大小(字节) */
247
+ totalSize: number;
248
+ /** 已上传大小(字节) */
249
+ uploadedSize: number;
250
+ }
251
+
252
+ /**
253
+ * 上传任务对象
254
+ */
255
+ export declare interface UploadTask {
256
+ /** 任务唯一标识 */
257
+ id: string;
258
+ /** 原始文件对象 */
259
+ file: File;
260
+ /** 任务状态:等待中、上传中、已暂停、已完成、失败 */
261
+ status: 'pending' | 'uploading' | 'paused' | 'completed' | 'error';
262
+ /** 上传进度(0-100) */
263
+ progress: number;
264
+ /** 分片大小(字节) */
265
+ chunkSize: number;
266
+ /** 总分片数 */
267
+ totalChunks: number;
268
+ /** 已上传的分片索引集合 */
269
+ uploadedChunks: Set<number>;
270
+ /** 当前正在上传的分片索引 */
271
+ currentChunk: number;
272
+ /** 文件唯一标识(由文件名、大小、最后修改时间生成) */
273
+ fileId: string;
274
+ /** 正在进行的请求列表,用于暂停时取消请求 */
275
+ xhrList: XMLHttpRequest[];
276
+ /** 上传开始时间戳 */
277
+ startTime?: number;
278
+ /** 上传结束时间戳 */
279
+ endTime?: number;
280
+ /** 当前上传速度(KB/s) */
281
+ speed?: number;
282
+ /** 错误信息 */
283
+ errorMessage?: string;
284
+ /** 当前重试次数 */
285
+ retryCount: number;
286
+ /** 每个分片的上传状态 */
287
+ chunkStatus: Map<number, 'pending' | 'uploading' | 'completed' | 'error'>;
288
+ /** 上传成功后服务器返回的文件路径 */
289
+ path?: string;
290
+ }
291
+
292
+ export declare function useChunkUpload(options?: ChunkUploadOptions): {
293
+ config: {
294
+ chunkSize: number;
295
+ maxConcurrent: number;
296
+ uploadUrl: string;
297
+ mergeUrl: string;
298
+ maxFileSize: number;
299
+ autoStart: boolean;
300
+ retryTimes: number;
301
+ retryDelay: number;
302
+ draggable: boolean;
303
+ accept: string;
304
+ limit: number;
305
+ headers: Record<string, string>;
306
+ onBeforeUpload: (files: File[]) => boolean | Promise<boolean>;
307
+ onProgress: (task: UploadTask) => void;
308
+ onSuccess: (task: UploadTask) => void;
309
+ onError: (task: UploadTask, error: Error) => void;
310
+ onTaskAdd: (task: UploadTask) => void;
311
+ onTaskRemove: (task: UploadTask) => void;
312
+ onNotice: (type: NoticeType, message: string) => void;
313
+ onAllComplete: (completedTasks: UploadTask[]) => void;
314
+ };
315
+ tasks: Ref<UploadTask[]>;
316
+ isUploading: Ref<boolean>;
317
+ totalCount: ComputedRef<number>;
318
+ completedCount: ComputedRef<number>;
319
+ totalProgress: ComputedRef<number>;
320
+ totalSize: ComputedRef<number>;
321
+ uploadedSize: ComputedRef<number>;
322
+ updateCounter: Ref<number, number>;
323
+ maxFileSize: number;
324
+ addFiles: (fileList: FileList | File[]) => string[];
325
+ addExistingFiles: (existingFiles: ExistingFile[]) => void;
326
+ startUpload: (taskId: string) => Promise<void>;
327
+ pauseUpload: (taskId: string) => void;
328
+ resumeUpload: (taskId: string) => void;
329
+ removeTask: (taskId: string) => boolean;
330
+ clearAllTasks: () => void;
331
+ retryTask: (taskId: string) => void;
332
+ pauseAll: () => void;
333
+ resumeAll: () => void;
334
+ getTask: (taskId: string) => UploadTask | undefined;
335
+ getTaskStats: () => {
336
+ pending: number;
337
+ uploading: number;
338
+ paused: number;
339
+ completed: number;
340
+ error: number;
341
+ total: number;
342
+ };
343
+ getUploadedChunks: (taskId: string) => number[];
344
+ forceUpdate: () => void;
345
+ formatFileSize: typeof formatFileSize;
346
+ };
347
+
348
+ export declare const Vue3ChunkedUpload: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
349
+
350
+ export { }