Commit 1dd914dd authored by 以墨为白's avatar 以墨为白 🎧

1

parent 95a6cf16
...@@ -24,7 +24,14 @@ import WebUploader from "webuploader"; ...@@ -24,7 +24,14 @@ import WebUploader from "webuploader";
import "webuploader/dist/webuploader.css"; import "webuploader/dist/webuploader.css";
import { ACCESS_TOKEN, ACCESS_USER, HTTP_STATUS } from "../../constant/user"; import { ACCESS_TOKEN, ACCESS_USER, HTTP_STATUS } from "../../constant/user";
export default { export default {
props: ['fileType'], props: {
addFileInfo: {
type: Function
},
checkFileExist: {
type: Function
}
},
data() { data() {
return { return {
fileList: [], fileList: [],
...@@ -63,6 +70,31 @@ export default { ...@@ -63,6 +70,31 @@ export default {
file.md5 = val; file.md5 = val;
file.uid = WebUploader.Base.guid(); file.uid = WebUploader.Base.guid();
// 判断文件是否上传过,是否存在分片,断点续传 // 判断文件是否上传过,是否存在分片,断点续传
// fetch(`api/rest/file/bigFile/check?fileMd5=${val}`, {
// method: "POST",
// headers: new Headers(headers_target)
// }).then(res => {
// if (res.status == 200) {
// return res.json();
// } else {
// return Promise.reject(HTTP_STATUS);
// }
// })
// .then(res => {
// if (res.code == 9000 && res.data == 1) {
// if (_self.checkFileExist) {
// return _self.checkFileExist(val);
// } else {
// return Promise.resolve(true);
// }
// } else {
// Promise.reject({message: res.code == 9000 ? res.message : "文件已存在"});
// }
// }).then(res => {
// return Promise.resolve();
// }).catch(err => {
// deferred.reject(data.message);
// });
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "api/rest/file/bigFile/check", url: "api/rest/file/bigFile/check",
...@@ -120,26 +152,45 @@ export default { ...@@ -120,26 +152,45 @@ export default {
//该方法的在uploader.on("success")方法前执行。 //该方法的在uploader.on("success")方法前执行。
afterSendFile: function (file) { afterSendFile: function (file) {
var deferred = WebUploader.Deferred(); var deferred = WebUploader.Deferred();
if (!file.pass) {//文件不存在 Promise.resolve(file.pass)
$.ajax({ .then(res => {
type: "POST", if (res) {
url: "api/rest/file/bigFile/merge", return Promise.resolve({ code: 9000 });
headers: headers_target, } else {
data: { return fetch(`api/rest/file/bigFile/merge?fileName=${file.name}&fileMd5=${file.md5}`, {
fileName: file.name, method: "POST",
fileMd5: file.md5, headers: new Headers(headers_target)
fileType: _self.fileType }).then(res => {
}, if (res.status == 200) {
success: function (data) { return res.json();
if (data.code != 9000) {//触发error事件 } else {
deferred.reject(data.message); return Promise.reject(HTTP_STATUS);
} }
}, });
error: function (XMLHttpRequest, textStatus, errorThrown) { }
deferred.reject(textStatus); })
}, .then(res => {
if (res.code == 9000 && _self.addFileInfo) {
return _self.addFileInfo({
md5: file.md5,
file: {
name: file.name,
size: file.size,
type: file.ext,
uuid: file.uid + "." + file.ext,
}
});
} else if (res.code == 9000) {
return Promise.resolve();
} else {
return Promise.reject(res);
}
}).then(res => {
deferred.resolve();
}).catch(err => {
deferred.reject(err.message);
}); });
} return deferred.promise();
}, },
} }
); );
...@@ -226,6 +277,7 @@ export default { ...@@ -226,6 +277,7 @@ export default {
}); });
//所有文件上传结束 //所有文件上传结束
uploader.on("uploadFinished", () => { uploader.on("uploadFinished", () => {
_self.$emit("Finished", {});
console.log("uploadFinished"); console.log("uploadFinished");
}); });
//设置全局变量 //设置全局变量
......
...@@ -265,7 +265,8 @@ ...@@ -265,7 +265,8 @@
</el-dialog> </el-dialog>
<el-dialog title="大文件上传" :visible.sync="centerDialogVisible_bigFile" width="30%" center class="xzwd"> <el-dialog title="大文件上传" :visible.sync="centerDialogVisible_bigFile" width="30%" center class="xzwd">
<BigfileUpload @Success="completeUploadBigFile"></BigfileUpload> <BigfileUpload :checkFileExist="checkFileExist" :addFileInfo="addFileInfo" @Finished="bigFileUploadFinished">
</BigfileUpload>
</el-dialog> </el-dialog>
<el-dialog :title="title" :visible.sync="centerDialogVisible_video" center width="800px"> <el-dialog :title="title" :visible.sync="centerDialogVisible_video" center width="800px">
...@@ -636,7 +637,7 @@ export default { ...@@ -636,7 +637,7 @@ export default {
}, 200) }, 200)
}, },
bigFileUploadAdd() { bigFileUploadAdd() {//弹出
if (this.clientDetails_type[0] == 1 || this.clientDetails_type[0] == 2 || this.clientDetails_type[0] == 3 || this.clientDetails_type[0] == 4) { if (this.clientDetails_type[0] == 1 || this.clientDetails_type[0] == 2 || this.clientDetails_type[0] == 3 || this.clientDetails_type[0] == 4) {
this.$message({ this.$message({
type: "warning", type: "warning",
...@@ -648,7 +649,11 @@ export default { ...@@ -648,7 +649,11 @@ export default {
_this.centerDialogVisible_bigFile = true; _this.centerDialogVisible_bigFile = true;
}, },
completeUploadBigFile(evt) { bigFileUploadFinished(evt) {//所有文件上传完成,不一定都成功
this.handleCurrentChange_lb(1);
},
addFileInfo(evt) {//文件信息的上传,在文件上传后执行
let fd = new FormData(); let fd = new FormData();
let fileInfo = { let fileInfo = {
createId: this.$store.getters.userInfo.account, createId: this.$store.getters.userInfo.account,
...@@ -662,17 +667,11 @@ export default { ...@@ -662,17 +667,11 @@ export default {
fd.append("info", JSON.stringify(fileInfo)); fd.append("info", JSON.stringify(fileInfo));
fd.append("destFilename", evt.file.uuid); fd.append("destFilename", evt.file.uuid);
fd.append("md5", evt.md5); fd.append("md5", evt.md5);
fileUpload_PUT("api/rest/3z/document/upload", fd).then((data) => { return fileUpload_PUT("api/rest/3z/document/upload", fd);
this.$message({ },
type: "success",
message: "文件上传成功!", checkFileExist(md5) {
}); return get(`api/rest/3z/document/checkFileInfoExist?md5=${md5}&bucket=Document`);
this.centerDialogVisible_add = false;
this.handleCurrentChange_lb(1);
})
.catch((err) => {
this.$message.warning(err.message);
})
}, },
//编辑弹出框确定 //编辑弹出框确定
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment