|
@@ -6,11 +6,13 @@
|
|
|
:accept="api.accept.value"
|
|
|
:show-file-list="true"
|
|
|
:http-request="() => {}"
|
|
|
+ @remove="api.file.value = undefined"
|
|
|
:file-list="api.fileList.value"
|
|
|
+ @exceed="() => ElMessage.error('只能上传一个文件')"
|
|
|
:disable="api.percentage.value || disabled"
|
|
|
:before-upload="api.upload"
|
|
|
>
|
|
|
- <el-button v-pdpath="'sync'" type="primary">
|
|
|
+ <el-button v-pdpath="'sync'" type="primary" class="upload-button">
|
|
|
<el-icon><Upload /></el-icon>{{ api.percentage.value ? "文件上传中" : "上传数据" }}
|
|
|
</el-button>
|
|
|
</el-upload>
|
|
@@ -27,7 +29,7 @@
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
import { useUpload } from "@/hook/upload";
|
|
|
-import { computed } from "vue";
|
|
|
+import { computed, reactive } from "vue";
|
|
|
import { uploadIngs } from "./uploading";
|
|
|
import SparkMD5 from "spark-md5";
|
|
|
import { axios, initChunkUpload, mergeChunkUpload } from "@/request";
|
|
@@ -142,7 +144,11 @@ const chunksUpload = async (
|
|
|
i * parallelCount,
|
|
|
Math.min((i + 1) * parallelCount, chunks.length)
|
|
|
);
|
|
|
- await Promise.all(uploadChunks(chunkGroup, i * parallelCount));
|
|
|
+ try {
|
|
|
+ await Promise.all(uploadChunks(chunkGroup, i * parallelCount));
|
|
|
+ } catch (e) {
|
|
|
+ i--;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
setPercentage();
|
|
@@ -159,10 +165,10 @@ const chunksUpload = async (
|
|
|
emit("success");
|
|
|
};
|
|
|
|
|
|
-const expose = {
|
|
|
- file: null,
|
|
|
+const expose = reactive({
|
|
|
+ file: computed(() => api.value.file.value),
|
|
|
upload: () => {},
|
|
|
-} as any;
|
|
|
+}) as any;
|
|
|
const api = computed(() =>
|
|
|
useUpload({
|
|
|
maxSize: props.maxSize,
|
|
@@ -171,7 +177,6 @@ const api = computed(() =>
|
|
|
if (!props.customUpload) {
|
|
|
return chunksUpload(file, props.attach || {}, onPercentage);
|
|
|
} else {
|
|
|
- expose.file = file;
|
|
|
return new Promise<string>((resolve, reject) => {
|
|
|
expose.upload = async () => {
|
|
|
try {
|
|
@@ -180,8 +185,7 @@ const api = computed(() =>
|
|
|
reject(e);
|
|
|
throw e;
|
|
|
}
|
|
|
-
|
|
|
- delete expose.file;
|
|
|
+ api.value.file.value = undefined;
|
|
|
delete expose.upload;
|
|
|
resolve("success");
|
|
|
};
|
|
@@ -193,3 +197,16 @@ const api = computed(() =>
|
|
|
|
|
|
defineExpose(expose);
|
|
|
</script>
|
|
|
+
|
|
|
+<style lang="scss">
|
|
|
+.upload-demo {
|
|
|
+ width: 100%;
|
|
|
+}
|
|
|
+.el-upload-list {
|
|
|
+ width: 100%;
|
|
|
+
|
|
|
+ .el-icon--close-tip {
|
|
|
+ display: none !important;
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|