|
|
@@ -10,7 +10,7 @@ export default {
|
|
|
uploadFileList: [],
|
|
|
fileUploadCallBackParams: {return_data: {data: {}, status: 0}, upload_id: ""},
|
|
|
tempCheckpoint: {},
|
|
|
- uploadPercentage: "0",
|
|
|
+ uploadPercentage: 0,
|
|
|
oosClient: null,
|
|
|
isUploading: false
|
|
|
}
|
|
|
@@ -27,17 +27,21 @@ export default {
|
|
|
this.prepareUpload(file);
|
|
|
},
|
|
|
|
|
|
+ initUpload(file) {
|
|
|
+ if (this.isUploading) {
|
|
|
+ this.oosClient.cancel();
|
|
|
+ }
|
|
|
+ this.uploadPercentage = 0;
|
|
|
+ this.uploadFileList = [];
|
|
|
+ if (file)
|
|
|
+ this.uploadFileList.push({name: file.name, url: ""});
|
|
|
+ },
|
|
|
+
|
|
|
uploadFileOnProgress(event, file, fileList) {
|
|
|
|
|
|
},
|
|
|
uploadFileDelete(file = null) {
|
|
|
-
|
|
|
- this.uploadFileList = [];
|
|
|
- console.log(this.uploadFileList);
|
|
|
- if (this.isUploading) {
|
|
|
- this.oosClient.cancel();
|
|
|
- this.uploadPercentage = 0;
|
|
|
- }
|
|
|
+ this.initUpload();
|
|
|
},
|
|
|
/**
|
|
|
* 上传文件出错
|
|
|
@@ -51,8 +55,9 @@ export default {
|
|
|
* @param callback
|
|
|
*/
|
|
|
prepareUpload(file) {
|
|
|
+ //初始化上传状态
|
|
|
+ this.initUpload(file);
|
|
|
const formData = new FormData();
|
|
|
- this.uploadFileList.push({name: file.name, url: ""});
|
|
|
let wid = this.$route.query.wid;
|
|
|
formData.append("target", `{ "type": 5 ,"work_id":${wid || -1}}`);
|
|
|
formData.append("filename", file.name);
|
|
|
@@ -86,7 +91,7 @@ export default {
|
|
|
this.oosClient.put(data.post_params.policy['save-key'], file.raw).then(res => {
|
|
|
console.log("*******", res);
|
|
|
if (res.res.status === 200) {
|
|
|
- this.setUploadComplete(res);
|
|
|
+ this.setUploadComplete(res, file);
|
|
|
}
|
|
|
}).catch(err => {
|
|
|
console.log(err);
|
|
|
@@ -96,7 +101,7 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- async _ossMultipartUpload(data, file) {
|
|
|
+ _ossMultipartUpload(data, file) {
|
|
|
try {
|
|
|
this.oosClient = OSS({
|
|
|
region: "oss-cn-beijing",
|
|
|
@@ -120,7 +125,7 @@ export default {
|
|
|
mime: file.type,
|
|
|
}).then(res => {
|
|
|
console.log("multipartUpload res", res);
|
|
|
- this.setUploadComplete(res);
|
|
|
+ this.setUploadComplete(res, file);
|
|
|
}).catch(err => {
|
|
|
console.log("multipartUpload err", err);
|
|
|
})
|
|
|
@@ -129,7 +134,7 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- setUploadComplete(res) {
|
|
|
+ setUploadComplete(res, file) {
|
|
|
this.fileUploadCallBackParams.return_data.status = 1;
|
|
|
this.fileUploadCallBackParams.return_data.data.url = "https:\/\/filescdn.proginn.com/" + res.name;
|
|
|
this.fileUploadCallBackParams.return_data.data.path = res.name;
|