@vunk/form 1.1.12 → 1.1.13
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/components/form/index.js +112 -21
- package/components/form/src/ctx.d.ts +27 -1
- package/components/form/src/ctx.js +12 -0
- package/components/form/src/index.vue.d.ts +30 -0
- package/components/form/src/types.d.ts +12 -2
- package/components/form/src/utils.d.ts +15 -0
- package/components/form/src/utils.js +55 -0
- package/components/upload-plus/index.css +85 -0
- package/components/upload-plus/index.d.ts +6 -0
- package/components/upload-plus/index.js +485 -0
- package/components/upload-plus/src/api.d.ts +31 -0
- package/components/upload-plus/src/api.js +65 -0
- package/components/upload-plus/src/const.d.ts +7 -0
- package/components/upload-plus/src/const.js +10 -0
- package/components/upload-plus/src/ctx.d.ts +59 -0
- package/components/upload-plus/src/ctx.js +34 -0
- package/components/upload-plus/src/index.vue.d.ts +163 -0
- package/components/upload-plus/src/types.d.ts +24 -0
- package/components/upload-plus/src/types.js +1 -0
- package/index.css +86 -0
- package/package.json +1 -1
- package/shared/types/source/index.d.ts +6 -0
- package/shared/upload/index.d.ts +7 -0
- package/shared/upload/index.js +767 -0
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
import { _VkfFormItemCtx, VkfFormItem } from '@vunk/form/components/form-item';
|
|
2
|
+
import { openBlock, createElementBlock, createElementVNode, defineComponent, reactive, ref, computed, resolveComponent, createBlock, mergeProps, withCtx, createVNode, normalizeClass, createCommentVNode, Fragment, renderList, normalizeStyle, createTextVNode } from 'vue';
|
|
3
|
+
import { ElInput, ElButtonGroup, ElButton, ElIcon } from 'element-plus';
|
|
4
|
+
import { createFileChunk, calculateFileHashSample } from '@vunk/form/shared/upload';
|
|
5
|
+
import { RestFetch } from '@vunk/core/shared/utils-fetch';
|
|
6
|
+
|
|
7
|
+
var __defProp = Object.defineProperty;
|
|
8
|
+
var __defProps = Object.defineProperties;
|
|
9
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
10
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
11
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
12
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
13
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
14
|
+
var __spreadValues = (a, b) => {
|
|
15
|
+
for (var prop in b || (b = {}))
|
|
16
|
+
if (__hasOwnProp.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
if (__getOwnPropSymbols)
|
|
19
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
+
if (__propIsEnum.call(b, prop))
|
|
21
|
+
__defNormalProp(a, prop, b[prop]);
|
|
22
|
+
}
|
|
23
|
+
return a;
|
|
24
|
+
};
|
|
25
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
26
|
+
const props = __spreadProps(__spreadValues({}, _VkfFormItemCtx.props), {
|
|
27
|
+
size: {
|
|
28
|
+
type: Number,
|
|
29
|
+
default: 1024 / (16 * 16) * 1024 * 1024
|
|
30
|
+
},
|
|
31
|
+
dictId: {
|
|
32
|
+
type: String,
|
|
33
|
+
default: ""
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const emits = {};
|
|
37
|
+
|
|
38
|
+
var Status = /* @__PURE__ */ ((Status2) => {
|
|
39
|
+
Status2["wait"] = "wait";
|
|
40
|
+
Status2["pause"] = "pause";
|
|
41
|
+
Status2["uploading"] = "uploading";
|
|
42
|
+
Status2["error"] = "error";
|
|
43
|
+
Status2["done"] = "done";
|
|
44
|
+
return Status2;
|
|
45
|
+
})(Status || {});
|
|
46
|
+
|
|
47
|
+
var _const = /*#__PURE__*/Object.freeze({
|
|
48
|
+
__proto__: null,
|
|
49
|
+
Status: Status
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const restFetch = new RestFetch({
|
|
53
|
+
baseURL: "http://192.168.110.209:36800"
|
|
54
|
+
});
|
|
55
|
+
const verify = async (params) => {
|
|
56
|
+
return restFetch.request({
|
|
57
|
+
method: "GET",
|
|
58
|
+
url: "/dict/hdfs/getChunkList",
|
|
59
|
+
params
|
|
60
|
+
}).then((res) => {
|
|
61
|
+
return res.data.map((item) => item.identifier);
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
const upload = async (data, init) => {
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
var _a;
|
|
67
|
+
const xhr = new XMLHttpRequest();
|
|
68
|
+
xhr.upload.onprogress = (init == null ? void 0 : init.onprogress) || null;
|
|
69
|
+
xhr.open("post", restFetch.baseURL + "/dict/hdfs/chunk/upload");
|
|
70
|
+
const form = new FormData();
|
|
71
|
+
form.append("file", data.chunk);
|
|
72
|
+
form.append("identifier", data.fileHash);
|
|
73
|
+
form.append("filename", data.fileName);
|
|
74
|
+
form.append("chunkNumber", data.index + 1 + "");
|
|
75
|
+
form.append("chunkIdentifier", data.hash + "");
|
|
76
|
+
form.append("totalChunk", data.chunksLength + "");
|
|
77
|
+
form.append("chunkSize", data.sliceSize + "");
|
|
78
|
+
form.append("currentChunkSize", data.chunk.size + "");
|
|
79
|
+
form.append("totalSize", data.fileSize + "");
|
|
80
|
+
xhr.send(form);
|
|
81
|
+
xhr.onreadystatechange = (e) => {
|
|
82
|
+
const target = e.target;
|
|
83
|
+
if (xhr.readyState === 4) {
|
|
84
|
+
if (xhr.status === 200) {
|
|
85
|
+
if (init == null ? void 0 : init.xhrs) {
|
|
86
|
+
const i = init.xhrs.findIndex((req) => req === xhr);
|
|
87
|
+
init.xhrs.splice(i, 1);
|
|
88
|
+
}
|
|
89
|
+
resolve({
|
|
90
|
+
data: target.response
|
|
91
|
+
});
|
|
92
|
+
} else if (xhr.status === 500) {
|
|
93
|
+
reject(target.response);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
xhr.timeout = 5 * 1e3;
|
|
98
|
+
xhr.ontimeout = (e) => {
|
|
99
|
+
reject(e);
|
|
100
|
+
};
|
|
101
|
+
(_a = init == null ? void 0 : init.xhrs) == null ? void 0 : _a.push(xhr);
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
const merge = async (data) => {
|
|
105
|
+
return restFetch.request({
|
|
106
|
+
method: "POST",
|
|
107
|
+
url: "/dict/hdfs/chunk/merge",
|
|
108
|
+
data
|
|
109
|
+
}).then((res) => {
|
|
110
|
+
return res.datas;
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
var api = /*#__PURE__*/Object.freeze({
|
|
115
|
+
__proto__: null,
|
|
116
|
+
restFetch: restFetch,
|
|
117
|
+
verify: verify,
|
|
118
|
+
upload: upload,
|
|
119
|
+
merge: merge
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
/*! Element Plus Icons Vue v2.1.0 */
|
|
123
|
+
|
|
124
|
+
// unplugin-vue:/plugin-vue/export-helper
|
|
125
|
+
var export_helper_default = (sfc, props) => {
|
|
126
|
+
let target = sfc.__vccOpts || sfc;
|
|
127
|
+
for (let [key, val] of props)
|
|
128
|
+
target[key] = val;
|
|
129
|
+
return target;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
// unplugin-vue:/home/runner/work/element-plus-icons/element-plus-icons/packages/vue/src/components/circle-close-filled.vue?vue&type=script&lang.ts
|
|
133
|
+
var circle_close_filled_vue_vue_type_script_lang_default = {
|
|
134
|
+
name: "CircleCloseFilled"
|
|
135
|
+
};
|
|
136
|
+
var _hoisted_150 = {
|
|
137
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
138
|
+
viewBox: "0 0 1024 1024"
|
|
139
|
+
}, _hoisted_250 = /* @__PURE__ */ createElementVNode(
|
|
140
|
+
"path",
|
|
141
|
+
{
|
|
142
|
+
fill: "currentColor",
|
|
143
|
+
d: "M512 64a448 448 0 1 1 0 896 448 448 0 0 1 0-896zm0 393.664L407.936 353.6a38.4 38.4 0 1 0-54.336 54.336L457.664 512 353.6 616.064a38.4 38.4 0 1 0 54.336 54.336L512 566.336 616.064 670.4a38.4 38.4 0 1 0 54.336-54.336L566.336 512 670.4 407.936a38.4 38.4 0 1 0-54.336-54.336L512 457.664z"
|
|
144
|
+
},
|
|
145
|
+
null,
|
|
146
|
+
-1
|
|
147
|
+
/* HOISTED */
|
|
148
|
+
), _hoisted_349 = [
|
|
149
|
+
_hoisted_250
|
|
150
|
+
];
|
|
151
|
+
function _sfc_render50(_ctx, _cache, $props, $setup, $data, $options) {
|
|
152
|
+
return openBlock(), createElementBlock("svg", _hoisted_150, _hoisted_349);
|
|
153
|
+
}
|
|
154
|
+
var circle_close_filled_default = /* @__PURE__ */ export_helper_default(circle_close_filled_vue_vue_type_script_lang_default, [["render", _sfc_render50], ["__file", "circle-close-filled.vue"]]);
|
|
155
|
+
|
|
156
|
+
// unplugin-vue:/home/runner/work/element-plus-icons/element-plus-icons/packages/vue/src/components/success-filled.vue?vue&type=script&lang.ts
|
|
157
|
+
var success_filled_vue_vue_type_script_lang_default = {
|
|
158
|
+
name: "SuccessFilled"
|
|
159
|
+
};
|
|
160
|
+
var _hoisted_1249 = {
|
|
161
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
162
|
+
viewBox: "0 0 1024 1024"
|
|
163
|
+
}, _hoisted_2249 = /* @__PURE__ */ createElementVNode(
|
|
164
|
+
"path",
|
|
165
|
+
{
|
|
166
|
+
fill: "currentColor",
|
|
167
|
+
d: "M512 64a448 448 0 1 1 0 896 448 448 0 0 1 0-896zm-55.808 536.384-99.52-99.584a38.4 38.4 0 1 0-54.336 54.336l126.72 126.72a38.272 38.272 0 0 0 54.336 0l262.4-262.464a38.4 38.4 0 1 0-54.272-54.336L456.192 600.384z"
|
|
168
|
+
},
|
|
169
|
+
null,
|
|
170
|
+
-1
|
|
171
|
+
/* HOISTED */
|
|
172
|
+
), _hoisted_3248 = [
|
|
173
|
+
_hoisted_2249
|
|
174
|
+
];
|
|
175
|
+
function _sfc_render249(_ctx, _cache, $props, $setup, $data, $options) {
|
|
176
|
+
return openBlock(), createElementBlock("svg", _hoisted_1249, _hoisted_3248);
|
|
177
|
+
}
|
|
178
|
+
var success_filled_default = /* @__PURE__ */ export_helper_default(success_filled_vue_vue_type_script_lang_default, [["render", _sfc_render249], ["__file", "success-filled.vue"]]);
|
|
179
|
+
|
|
180
|
+
// unplugin-vue:/home/runner/work/element-plus-icons/element-plus-icons/packages/vue/src/components/upload-filled.vue?vue&type=script&lang.ts
|
|
181
|
+
var upload_filled_vue_vue_type_script_lang_default = {
|
|
182
|
+
name: "UploadFilled"
|
|
183
|
+
};
|
|
184
|
+
var _hoisted_1274 = {
|
|
185
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
186
|
+
viewBox: "0 0 1024 1024"
|
|
187
|
+
}, _hoisted_2274 = /* @__PURE__ */ createElementVNode(
|
|
188
|
+
"path",
|
|
189
|
+
{
|
|
190
|
+
fill: "currentColor",
|
|
191
|
+
d: "M544 864V672h128L512 480 352 672h128v192H320v-1.6c-5.376.32-10.496 1.6-16 1.6A240 240 0 0 1 64 624c0-123.136 93.12-223.488 212.608-237.248A239.808 239.808 0 0 1 512 192a239.872 239.872 0 0 1 235.456 194.752c119.488 13.76 212.48 114.112 212.48 237.248a240 240 0 0 1-240 240c-5.376 0-10.56-1.28-16-1.6v1.6H544z"
|
|
192
|
+
},
|
|
193
|
+
null,
|
|
194
|
+
-1
|
|
195
|
+
/* HOISTED */
|
|
196
|
+
), _hoisted_3273 = [
|
|
197
|
+
_hoisted_2274
|
|
198
|
+
];
|
|
199
|
+
function _sfc_render274(_ctx, _cache, $props, $setup, $data, $options) {
|
|
200
|
+
return openBlock(), createElementBlock("svg", _hoisted_1274, _hoisted_3273);
|
|
201
|
+
}
|
|
202
|
+
var upload_filled_default = /* @__PURE__ */ export_helper_default(upload_filled_vue_vue_type_script_lang_default, [["render", _sfc_render274], ["__file", "upload-filled.vue"]]);
|
|
203
|
+
|
|
204
|
+
var _export_sfc = (sfc, props) => {
|
|
205
|
+
const target = sfc.__vccOpts || sfc;
|
|
206
|
+
for (const [key, val] of props) {
|
|
207
|
+
target[key] = val;
|
|
208
|
+
}
|
|
209
|
+
return target;
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
const _sfc_main = defineComponent({
|
|
213
|
+
name: "VkfUploadPlus",
|
|
214
|
+
components: {
|
|
215
|
+
VkfFormItem,
|
|
216
|
+
ElInput,
|
|
217
|
+
ElButtonGroup,
|
|
218
|
+
ElButton,
|
|
219
|
+
ElIcon,
|
|
220
|
+
SuccessFilled: success_filled_default
|
|
221
|
+
},
|
|
222
|
+
emits,
|
|
223
|
+
props,
|
|
224
|
+
setup(props2, { emit }) {
|
|
225
|
+
const formItemBindProps = _VkfFormItemCtx.createBindProps(props2);
|
|
226
|
+
const uuid = Math.random().toString(36).slice(-8);
|
|
227
|
+
const container = reactive({});
|
|
228
|
+
const fileStatus = ref(Status.wait);
|
|
229
|
+
const chunks = ref([]);
|
|
230
|
+
const uploadingXhrs = ref([]);
|
|
231
|
+
const filePrefixIcon = computed(() => {
|
|
232
|
+
if (fileStatus.value === Status.done) {
|
|
233
|
+
return success_filled_default;
|
|
234
|
+
}
|
|
235
|
+
if (fileStatus.value === Status.error) {
|
|
236
|
+
return circle_close_filled_default;
|
|
237
|
+
}
|
|
238
|
+
return upload_filled_default;
|
|
239
|
+
});
|
|
240
|
+
const handleFileChange = (e) => {
|
|
241
|
+
const target = e.target;
|
|
242
|
+
const file = target.files?.[0];
|
|
243
|
+
if (file) {
|
|
244
|
+
container.file = file;
|
|
245
|
+
fileStatus.value = Status.wait;
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
const handleUpload = async () => {
|
|
249
|
+
if (!container.file)
|
|
250
|
+
return;
|
|
251
|
+
fileStatus.value = Status.uploading;
|
|
252
|
+
const chunkFiles = createFileChunk(container.file, props2.size);
|
|
253
|
+
const hash = await calculateFileHashSample(container.file);
|
|
254
|
+
container.hash = hash;
|
|
255
|
+
const uploadedList = await verify({
|
|
256
|
+
identifier: hash
|
|
257
|
+
});
|
|
258
|
+
const sliceSize = chunkFiles[0].size;
|
|
259
|
+
chunks.value = chunkFiles.map((chunk, index) => {
|
|
260
|
+
const _container = container;
|
|
261
|
+
const chunkHash = _container.hash + "-" + index;
|
|
262
|
+
return {
|
|
263
|
+
fileName: _container.file.name,
|
|
264
|
+
fileHash: _container.hash,
|
|
265
|
+
fileSize: _container.file.size,
|
|
266
|
+
chunk,
|
|
267
|
+
hash: chunkHash,
|
|
268
|
+
index,
|
|
269
|
+
progress: uploadedList.indexOf(chunkHash) > -1 ? 100 : 0,
|
|
270
|
+
chunksLength: chunkFiles.length,
|
|
271
|
+
sliceSize,
|
|
272
|
+
status: Status.wait
|
|
273
|
+
};
|
|
274
|
+
});
|
|
275
|
+
const needUpload = chunks.value.filter((v) => uploadedList.indexOf(v.hash) === -1);
|
|
276
|
+
cUploadedChunks(
|
|
277
|
+
needUpload
|
|
278
|
+
).then(() => {
|
|
279
|
+
return cFile();
|
|
280
|
+
}).then(() => {
|
|
281
|
+
fileStatus.value = Status.done;
|
|
282
|
+
}).catch(() => {
|
|
283
|
+
fileStatus.value = Status.error;
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
const handlePause = () => {
|
|
287
|
+
uploadingXhrs.value.forEach((xhr) => {
|
|
288
|
+
xhr.abort();
|
|
289
|
+
});
|
|
290
|
+
uploadingXhrs.value = [];
|
|
291
|
+
fileStatus.value = Status.pause;
|
|
292
|
+
};
|
|
293
|
+
async function cUploadedChunks(urls, max = 4, retrys = 3) {
|
|
294
|
+
return new Promise((resolve, reject) => {
|
|
295
|
+
const len = urls.length;
|
|
296
|
+
let counter = 0;
|
|
297
|
+
const retryArr = [];
|
|
298
|
+
const start = async () => {
|
|
299
|
+
while (counter < len && max > 0) {
|
|
300
|
+
max--;
|
|
301
|
+
const i = urls.findIndex((v) => v.status === Status.wait || v.status === Status.error);
|
|
302
|
+
const currentChunk = urls[i];
|
|
303
|
+
if (currentChunk) {
|
|
304
|
+
currentChunk.status = Status.uploading;
|
|
305
|
+
upload(currentChunk, {
|
|
306
|
+
onprogress(ev) {
|
|
307
|
+
chunks.value[currentChunk.index].progress = parseInt(ev.loaded / ev.total * 100 + "");
|
|
308
|
+
},
|
|
309
|
+
xhrs: uploadingXhrs.value
|
|
310
|
+
}).then(() => {
|
|
311
|
+
urls[i].status = Status.done;
|
|
312
|
+
max++;
|
|
313
|
+
counter++;
|
|
314
|
+
}).then(() => {
|
|
315
|
+
if (counter === len) {
|
|
316
|
+
resolve(void 0);
|
|
317
|
+
} else {
|
|
318
|
+
start();
|
|
319
|
+
}
|
|
320
|
+
}).catch(() => {
|
|
321
|
+
const index = urls[i].index;
|
|
322
|
+
urls[i].status = Status.error;
|
|
323
|
+
if (typeof retryArr[index] !== "number") {
|
|
324
|
+
retryArr[index] = 0;
|
|
325
|
+
}
|
|
326
|
+
retryArr[index]++;
|
|
327
|
+
console.warn(
|
|
328
|
+
index,
|
|
329
|
+
urls[i],
|
|
330
|
+
retryArr[index],
|
|
331
|
+
"\u6B21\u62A5\u9519"
|
|
332
|
+
);
|
|
333
|
+
chunks.value[index].progress = -1;
|
|
334
|
+
if (retryArr[index] >= retrys) {
|
|
335
|
+
return reject();
|
|
336
|
+
}
|
|
337
|
+
max++;
|
|
338
|
+
start();
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
start();
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
function cFile() {
|
|
347
|
+
if (!container.file)
|
|
348
|
+
return;
|
|
349
|
+
if (!container.hash)
|
|
350
|
+
return;
|
|
351
|
+
return merge({
|
|
352
|
+
filename: container.file.name,
|
|
353
|
+
identifier: container.hash,
|
|
354
|
+
dictId: props2.dictId
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
formItemBindProps,
|
|
359
|
+
handleFileChange,
|
|
360
|
+
uuid,
|
|
361
|
+
container,
|
|
362
|
+
handleUpload,
|
|
363
|
+
fileStatus,
|
|
364
|
+
chunks,
|
|
365
|
+
Status,
|
|
366
|
+
filePrefixIcon,
|
|
367
|
+
handlePause
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
const _hoisted_1 = { class: "vkf-upload-plus-main" };
|
|
372
|
+
const _hoisted_2 = ["for"];
|
|
373
|
+
const _hoisted_3 = {
|
|
374
|
+
key: 0,
|
|
375
|
+
class: "vkf-upload-plus-msg-x"
|
|
376
|
+
};
|
|
377
|
+
const _hoisted_4 = /* @__PURE__ */ createElementVNode("span", { class: "vkf-upload-plus-msg" }, " \u4E0A\u4F20\u6210\u529F ", -1);
|
|
378
|
+
const _hoisted_5 = {
|
|
379
|
+
key: 1,
|
|
380
|
+
class: "vkf-upload-plus-cube-x"
|
|
381
|
+
};
|
|
382
|
+
const _hoisted_6 = ["id"];
|
|
383
|
+
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
|
|
384
|
+
const _component_ElInput = resolveComponent("ElInput");
|
|
385
|
+
const _component_SuccessFilled = resolveComponent("SuccessFilled");
|
|
386
|
+
const _component_ElIcon = resolveComponent("ElIcon");
|
|
387
|
+
const _component_ElButton = resolveComponent("ElButton");
|
|
388
|
+
const _component_el_button = resolveComponent("el-button");
|
|
389
|
+
const _component_el_button_group = resolveComponent("el-button-group");
|
|
390
|
+
const _component_VkfFormItem = resolveComponent("VkfFormItem");
|
|
391
|
+
return openBlock(), createBlock(_component_VkfFormItem, mergeProps(_ctx.formItemBindProps, { class: "vkf-upload-plus" }), {
|
|
392
|
+
default: withCtx(() => [
|
|
393
|
+
createElementVNode("div", _hoisted_1, [
|
|
394
|
+
createElementVNode("label", {
|
|
395
|
+
for: _ctx.uuid,
|
|
396
|
+
class: "vkf-upload-plus-label"
|
|
397
|
+
}, [
|
|
398
|
+
createVNode(_component_ElInput, {
|
|
399
|
+
class: normalizeClass({
|
|
400
|
+
"is-success": _ctx.fileStatus === _ctx.Status.done,
|
|
401
|
+
"is-error": _ctx.fileStatus === _ctx.Status.error
|
|
402
|
+
}),
|
|
403
|
+
modelValue: _ctx.container.file?.name,
|
|
404
|
+
prefixIcon: _ctx.filePrefixIcon,
|
|
405
|
+
placeholder: "\u8BF7\u9009\u62E9\u6587\u4EF6"
|
|
406
|
+
}, null, 8, ["class", "modelValue", "prefixIcon"]),
|
|
407
|
+
_ctx.fileStatus === _ctx.Status.done ? (openBlock(), createElementBlock("div", _hoisted_3, [
|
|
408
|
+
createVNode(_component_ElIcon, null, {
|
|
409
|
+
default: withCtx(() => [
|
|
410
|
+
createVNode(_component_SuccessFilled)
|
|
411
|
+
]),
|
|
412
|
+
_: 1
|
|
413
|
+
}),
|
|
414
|
+
_hoisted_4
|
|
415
|
+
])) : createCommentVNode("v-if", true),
|
|
416
|
+
_ctx.fileStatus === _ctx.Status.uploading || _ctx.fileStatus === _ctx.Status.pause ? (openBlock(), createElementBlock("div", _hoisted_5, [
|
|
417
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.chunks, (chunk) => {
|
|
418
|
+
return openBlock(), createElementBlock("div", {
|
|
419
|
+
class: normalizeClass(["vkf-upload-plus-cube", {
|
|
420
|
+
"error": chunk.status == _ctx.Status.error
|
|
421
|
+
}]),
|
|
422
|
+
key: chunk.hash,
|
|
423
|
+
style: normalizeStyle({
|
|
424
|
+
width: 100 / chunk.chunksLength + "%"
|
|
425
|
+
})
|
|
426
|
+
}, [
|
|
427
|
+
createElementVNode("div", {
|
|
428
|
+
class: normalizeClass({
|
|
429
|
+
"uploading": chunk.progress > 0 && chunk.progress < 100,
|
|
430
|
+
"success": chunk.progress == 100
|
|
431
|
+
}),
|
|
432
|
+
style: normalizeStyle({
|
|
433
|
+
height: chunk.progress + "%"
|
|
434
|
+
})
|
|
435
|
+
}, null, 6)
|
|
436
|
+
], 6);
|
|
437
|
+
}), 128))
|
|
438
|
+
])) : createCommentVNode("v-if", true)
|
|
439
|
+
], 8, _hoisted_2),
|
|
440
|
+
createElementVNode("input", {
|
|
441
|
+
type: "file",
|
|
442
|
+
id: _ctx.uuid,
|
|
443
|
+
class: "vkf-upload-plus-input",
|
|
444
|
+
onChange: _cache[0] || (_cache[0] = (...args) => _ctx.handleFileChange && _ctx.handleFileChange(...args))
|
|
445
|
+
}, null, 40, _hoisted_6),
|
|
446
|
+
createVNode(_component_el_button_group, { class: "vkf-upload-plus-btng" }, {
|
|
447
|
+
default: withCtx(() => [
|
|
448
|
+
_ctx.fileStatus === _ctx.Status.uploading ? (openBlock(), createBlock(_component_ElButton, {
|
|
449
|
+
key: 0,
|
|
450
|
+
type: "danger",
|
|
451
|
+
onClick: _ctx.handlePause
|
|
452
|
+
}, {
|
|
453
|
+
default: withCtx(() => [
|
|
454
|
+
createTextVNode(" \u6682\u505C ")
|
|
455
|
+
]),
|
|
456
|
+
_: 1
|
|
457
|
+
}, 8, ["onClick"])) : (openBlock(), createBlock(_component_el_button, {
|
|
458
|
+
key: 1,
|
|
459
|
+
type: "primary",
|
|
460
|
+
onClick: _ctx.handleUpload
|
|
461
|
+
}, {
|
|
462
|
+
default: withCtx(() => [
|
|
463
|
+
createTextVNode("\u4E0A\u4F20")
|
|
464
|
+
]),
|
|
465
|
+
_: 1
|
|
466
|
+
}, 8, ["onClick"]))
|
|
467
|
+
]),
|
|
468
|
+
_: 1
|
|
469
|
+
})
|
|
470
|
+
])
|
|
471
|
+
]),
|
|
472
|
+
_: 1
|
|
473
|
+
}, 16);
|
|
474
|
+
}
|
|
475
|
+
var VkfUploadPlus = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "index.vue"]]);
|
|
476
|
+
|
|
477
|
+
var types = /*#__PURE__*/Object.freeze({
|
|
478
|
+
__proto__: null
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
VkfUploadPlus.install = (app) => {
|
|
482
|
+
app.component(VkfUploadPlus.name, VkfUploadPlus);
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
export { VkfUploadPlus, api as _VkfUploadPlusApi, _const as _VkfUploadPlusConst, types as __VkfUploadPlus, VkfUploadPlus as default };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { RestFetch } from '@vunk/core/shared/utils-fetch';
|
|
2
|
+
import { Chunk } from './types';
|
|
3
|
+
export declare const restFetch: RestFetch;
|
|
4
|
+
/**
|
|
5
|
+
* https://app.apifox.com/link/project/2335162/apis/api-92811427
|
|
6
|
+
* @param data
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare const verify: (params: {
|
|
10
|
+
identifier: string;
|
|
11
|
+
}) => Promise<string[]>;
|
|
12
|
+
/**
|
|
13
|
+
* https://app.apifox.com/link/project/2335162/apis/api-92025462
|
|
14
|
+
* @param data
|
|
15
|
+
* @param init
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
export declare const upload: (data: Chunk, init?: {
|
|
19
|
+
onprogress?: XMLHttpRequestEventTarget['onprogress'];
|
|
20
|
+
xhrs?: XMLHttpRequest[];
|
|
21
|
+
}) => Promise<unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* https://app.apifox.com/link/project/2335162/apis/api-92729706
|
|
24
|
+
* @param data
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
export declare const merge: (data: {
|
|
28
|
+
identifier: string;
|
|
29
|
+
filename: string;
|
|
30
|
+
dictId?: string;
|
|
31
|
+
}) => Promise<any>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { RestFetch } from '@vunk/core/shared/utils-fetch';
|
|
2
|
+
|
|
3
|
+
const restFetch = new RestFetch({
|
|
4
|
+
baseURL: "http://192.168.110.209:36800"
|
|
5
|
+
});
|
|
6
|
+
const verify = async (params) => {
|
|
7
|
+
return restFetch.request({
|
|
8
|
+
method: "GET",
|
|
9
|
+
url: "/dict/hdfs/getChunkList",
|
|
10
|
+
params
|
|
11
|
+
}).then((res) => {
|
|
12
|
+
return res.data.map((item) => item.identifier);
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
const upload = async (data, init) => {
|
|
16
|
+
return new Promise((resolve, reject) => {
|
|
17
|
+
var _a;
|
|
18
|
+
const xhr = new XMLHttpRequest();
|
|
19
|
+
xhr.upload.onprogress = (init == null ? void 0 : init.onprogress) || null;
|
|
20
|
+
xhr.open("post", restFetch.baseURL + "/dict/hdfs/chunk/upload");
|
|
21
|
+
const form = new FormData();
|
|
22
|
+
form.append("file", data.chunk);
|
|
23
|
+
form.append("identifier", data.fileHash);
|
|
24
|
+
form.append("filename", data.fileName);
|
|
25
|
+
form.append("chunkNumber", data.index + 1 + "");
|
|
26
|
+
form.append("chunkIdentifier", data.hash + "");
|
|
27
|
+
form.append("totalChunk", data.chunksLength + "");
|
|
28
|
+
form.append("chunkSize", data.sliceSize + "");
|
|
29
|
+
form.append("currentChunkSize", data.chunk.size + "");
|
|
30
|
+
form.append("totalSize", data.fileSize + "");
|
|
31
|
+
xhr.send(form);
|
|
32
|
+
xhr.onreadystatechange = (e) => {
|
|
33
|
+
const target = e.target;
|
|
34
|
+
if (xhr.readyState === 4) {
|
|
35
|
+
if (xhr.status === 200) {
|
|
36
|
+
if (init == null ? void 0 : init.xhrs) {
|
|
37
|
+
const i = init.xhrs.findIndex((req) => req === xhr);
|
|
38
|
+
init.xhrs.splice(i, 1);
|
|
39
|
+
}
|
|
40
|
+
resolve({
|
|
41
|
+
data: target.response
|
|
42
|
+
});
|
|
43
|
+
} else if (xhr.status === 500) {
|
|
44
|
+
reject(target.response);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
xhr.timeout = 5 * 1e3;
|
|
49
|
+
xhr.ontimeout = (e) => {
|
|
50
|
+
reject(e);
|
|
51
|
+
};
|
|
52
|
+
(_a = init == null ? void 0 : init.xhrs) == null ? void 0 : _a.push(xhr);
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
const merge = async (data) => {
|
|
56
|
+
return restFetch.request({
|
|
57
|
+
method: "POST",
|
|
58
|
+
url: "/dict/hdfs/chunk/merge",
|
|
59
|
+
data
|
|
60
|
+
}).then((res) => {
|
|
61
|
+
return res.datas;
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export { merge, restFetch, upload, verify };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export declare const props: {
|
|
2
|
+
size: {
|
|
3
|
+
type: NumberConstructor;
|
|
4
|
+
default: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* 上传目录
|
|
8
|
+
*/
|
|
9
|
+
dictId: {
|
|
10
|
+
type: StringConstructor;
|
|
11
|
+
default: string;
|
|
12
|
+
};
|
|
13
|
+
required: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, undefined, boolean>;
|
|
14
|
+
label: StringConstructor;
|
|
15
|
+
labelWidth: import("element-plus/es/utils").EpPropFinalized<readonly [StringConstructor, NumberConstructor], unknown, unknown, "", boolean>;
|
|
16
|
+
prop: {
|
|
17
|
+
readonly type: import("vue").PropType<import("element-plus/es/utils").EpPropMergeType<(new (...args: any[]) => import("element-plus").FormItemProp & {}) | (() => import("element-plus").FormItemProp) | ((new (...args: any[]) => import("element-plus").FormItemProp & {}) | (() => import("element-plus").FormItemProp))[], unknown, unknown>>;
|
|
18
|
+
readonly required: false;
|
|
19
|
+
readonly validator: ((val: unknown) => boolean) | undefined;
|
|
20
|
+
__epPropKey: true;
|
|
21
|
+
};
|
|
22
|
+
rules: {
|
|
23
|
+
readonly type: import("vue").PropType<import("element-plus/es/utils").EpPropMergeType<(new (...args: any[]) => import("element-plus").FormItemRule | import("element-plus").FormItemRule[]) | (() => import("element-plus/es/utils").Arrayable<import("element-plus").FormItemRule>) | ((new (...args: any[]) => import("element-plus").FormItemRule | import("element-plus").FormItemRule[]) | (() => import("element-plus/es/utils").Arrayable<import("element-plus").FormItemRule>))[], unknown, unknown>>;
|
|
24
|
+
readonly required: false;
|
|
25
|
+
readonly validator: ((val: unknown) => boolean) | undefined;
|
|
26
|
+
__epPropKey: true;
|
|
27
|
+
};
|
|
28
|
+
error: StringConstructor;
|
|
29
|
+
validateStatus: {
|
|
30
|
+
readonly type: import("vue").PropType<import("element-plus/es/utils").EpPropMergeType<StringConstructor, "" | "error" | "success" | "validating", unknown>>;
|
|
31
|
+
readonly required: false;
|
|
32
|
+
readonly validator: ((val: unknown) => boolean) | undefined;
|
|
33
|
+
__epPropKey: true;
|
|
34
|
+
};
|
|
35
|
+
for: StringConstructor;
|
|
36
|
+
inlineMessage: import("element-plus/es/utils").EpPropFinalized<readonly [StringConstructor, BooleanConstructor], unknown, unknown, "", boolean>;
|
|
37
|
+
showMessage: import("element-plus/es/utils").EpPropFinalized<BooleanConstructor, unknown, unknown, true, boolean>;
|
|
38
|
+
formItemSize: {
|
|
39
|
+
type: import("vue").PropType<"default" | "small" | "large">;
|
|
40
|
+
default: string;
|
|
41
|
+
};
|
|
42
|
+
formItemSlots: {
|
|
43
|
+
type: import("vue").PropType<import("../../form-item/src/types").FormItemSlots>;
|
|
44
|
+
default: undefined;
|
|
45
|
+
};
|
|
46
|
+
elRef: {
|
|
47
|
+
type: import("vue").PropType<any>;
|
|
48
|
+
required: boolean;
|
|
49
|
+
};
|
|
50
|
+
inline: {
|
|
51
|
+
type: BooleanConstructor;
|
|
52
|
+
default: boolean;
|
|
53
|
+
};
|
|
54
|
+
readonly: {
|
|
55
|
+
type: BooleanConstructor;
|
|
56
|
+
default: undefined;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export declare const emits: {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { _VkfFormItemCtx } from '@vunk/form/components/form-item';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
|
+
const props = __spreadProps(__spreadValues({}, _VkfFormItemCtx.props), {
|
|
23
|
+
size: {
|
|
24
|
+
type: Number,
|
|
25
|
+
default: 1024 / (16 * 16) * 1024 * 1024
|
|
26
|
+
},
|
|
27
|
+
dictId: {
|
|
28
|
+
type: String,
|
|
29
|
+
default: ""
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
const emits = {};
|
|
33
|
+
|
|
34
|
+
export { emits, props };
|