Commit a92ebafb authored by 以墨为白's avatar 以墨为白 🎧

文件上传采用直连oss方式

parent d301e904
...@@ -753,9 +753,11 @@ let httpSSERequest = (url, success, error) => { ...@@ -753,9 +753,11 @@ let httpSSERequest = (url, success, error) => {
* @param {*} url * @param {*} url
* @param {*} file * @param {*} file
*/ */
let uploadOSS = (url, file) => { let uploadOSS = (filename, bucket, file) => {
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
fetch(url).then(res => { fetch(`api/rest/file/presign?filename=${filename}&bucket=${bucket}`, {
headers: new Headers(addHeaders({}))
}).then(res => {
if (res.status == 200) { if (res.status == 200) {
return res.json(); return res.json();
} else { } else {
...@@ -783,7 +785,47 @@ let uploadOSS = (url, file) => { ...@@ -783,7 +785,47 @@ let uploadOSS = (url, file) => {
}) })
}) })
} }
let uploadOSSProgress = (filename, bucket, file, progressFunction) => {
return new Promise((resolve, reject) => {
fetch(`api/rest/file/presign?filename=${filename}&bucket=${bucket}`, {
headers: new Headers(addHeaders({}))
}).then(res => {
if (res.status == 200) {
return res.json();
} else {
console.log(res.statusText);
reject(HTTP_STATUS);
}
}).then(res => {
if (res.code == 9000) {
let xhr = new XMLHttpRequest(); // XMLHttpRequest 对象
xhr.open("put", res.data, true); //
xhr.onload = (e) => {
var info = xhr.responseText;
resolve();
}; //请求完成
xhr.onerror = (evt) => {
reject({ message: "错误" });
} //请求失败
xhr.upload.onprogress = (evt) => {
if (evt.lengthComputable) {//
progressFunction(Math.round(evt.loaded / evt.total * 100) + "%");
}
}//【上传进度调用方法实现】
xhr.upload.onloadstart = function () {//上传开始执行方法
console.log("started");
};
// xhr.setRequestHeader(ACCESS_TOKEN, token);
xhr.send(file); //开始上传,发送form数据
} else {
return Promise.reject({ err: res.message });
}
}).catch(err => {
reject({ err: err });
});
});
};
export { export {
get, get,
...@@ -825,5 +867,6 @@ export { ...@@ -825,5 +867,6 @@ export {
fileUploadProgress, fileUploadProgress,
post_machineWriting, post_machineWriting,
httpSSERequest, httpSSERequest,
uploadOSS uploadOSS,
uploadOSSProgress
} }
\ No newline at end of file
...@@ -63,7 +63,8 @@ ...@@ -63,7 +63,8 @@
title="编辑"></i>&nbsp; title="编辑"></i>&nbsp;
<!-- <i class="el-icon-delete-solid" @click="handleOpen(scope.$index, scope.row)" <!-- <i class="el-icon-delete-solid" @click="handleOpen(scope.$index, scope.row)"
title="打开软件" v-if="fl_type===2"></i>&nbsp; --> title="打开软件" v-if="fl_type===2"></i>&nbsp; -->
<div class="ht-div" @click="handleOpen(scope.$index, scope.row)" v-if="fl_type===2" title="打开软件"></div> <div class="ht-div" @click="handleOpen(scope.$index, scope.row)" v-if="fl_type === 2"
title="打开软件"></div>
<i class="el-icon-delete-solid" @click="handleDelete(scope.$index, scope.row)" <i class="el-icon-delete-solid" @click="handleDelete(scope.$index, scope.row)"
title="删除"></i> title="删除"></i>
</template> </template>
...@@ -183,8 +184,9 @@ ...@@ -183,8 +184,9 @@
title="编辑"></i>&nbsp; title="编辑"></i>&nbsp;
<!-- <i class="el-icon-delete-solid" @click="handleOpen(scope.$index, scope.row)" <!-- <i class="el-icon-delete-solid" @click="handleOpen(scope.$index, scope.row)"
title="打开软件" v-if="fl_type===2"></i>&nbsp; --> title="打开软件" v-if="fl_type===2"></i>&nbsp; -->
<div class="ht-div" @click="handleOpen(scope.$index, scope.row)" v-if="fl_type===2" title="打开软件"></div> <div class="ht-div" @click="handleOpen(scope.$index, scope.row)" v-if="fl_type === 2"
title="打开软件"></div>
<i class="el-icon-delete-solid" @click="handleDelete(scope.$index, scope.row)" <i class="el-icon-delete-solid" @click="handleDelete(scope.$index, scope.row)"
title="删除"></i> title="删除"></i>
</template> </template>
...@@ -298,6 +300,7 @@ import { ...@@ -298,6 +300,7 @@ import {
post, post,
fileUpload_PUT, fileUpload_PUT,
fileUploadProgress, fileUploadProgress,
uploadOSSProgress,
delete_util, delete_util,
startLoading, startLoading,
startLoadingProgress, startLoadingProgress,
...@@ -598,7 +601,7 @@ export default { ...@@ -598,7 +601,7 @@ export default {
download(path_srt, item.fileInfo.file.name); download(path_srt, item.fileInfo.file.name);
}, },
//打开软件 //打开软件
handleOpen(index,row){ handleOpen(index, row) {
let _this = this; let _this = this;
//用户判断此格式是否是视频格式 //用户判断此格式是否是视频格式
let video_type = false; let video_type = false;
...@@ -614,19 +617,19 @@ export default { ...@@ -614,19 +617,19 @@ export default {
img_type = true; img_type = true;
} }
}); });
if(video_type||img_type){ if (video_type || img_type) {
window.protocolCheck('UHD://',(fail) =>{ window.protocolCheck('UHD://', (fail) => {
// 安装则直接打开 // 安装则直接打开
_this.$message({ _this.$message({
type: "warning", type: "warning",
message: "未找到注册表,请安装相应注册表", message: "未找到注册表,请安装相应注册表",
}); });
},(succ) => { }, (succ) => {
// 安装则直接打开 // 安装则直接打开
console.log('succ', succ) console.log('succ', succ)
} }
) )
}else{ } else {
_this.$message({ _this.$message({
type: "warning", type: "warning",
message: "当前文件格式不支持本地软件操作", message: "当前文件格式不支持本地软件操作",
...@@ -846,7 +849,7 @@ export default { ...@@ -846,7 +849,7 @@ export default {
fd.append("file", file); fd.append("file", file);
fd.append("filename", md5); fd.append("filename", md5);
fd.append("bucket", "MERGE"); fd.append("bucket", "MERGE");
return fileUploadProgress("api/rest/file/upload", fd, res => {//文件上传 return uploadOSSProgress(md5, "MERGE", file, res => {//文件上传
load.text = "上传中:" + res; load.text = "上传中:" + res;
}); });
} else { } else {
...@@ -856,7 +859,7 @@ export default { ...@@ -856,7 +859,7 @@ export default {
.then(res => { .then(res => {
let fd1 = new FormData(); let fd1 = new FormData();
fd1.append("info", JSON.stringify(fileInfo)); fd1.append("info", JSON.stringify(fileInfo));
fd1.append("md5", res); fd1.append("md5", md5);
fd1.append("destFilename", fileInfo.file.uuid); fd1.append("destFilename", fileInfo.file.uuid);
load.text = "完成中"; load.text = "完成中";
return fileUpload_PUT("api/rest/3z/document/upload", fd1);//文件信息上传 return fileUpload_PUT("api/rest/3z/document/upload", fd1);//文件信息上传
...@@ -1187,7 +1190,8 @@ export default { ...@@ -1187,7 +1190,8 @@ export default {
.table-div { .table-div {
width: 100%; width: 100%;
height: calc(100% - 50px); height: calc(100% - 50px);
.ht-div{
.ht-div {
width: 26px; width: 26px;
height: 21px; height: 21px;
background-image: url(../../assets/img/setting/ht1.png); background-image: url(../../assets/img/setting/ht1.png);
...@@ -1197,6 +1201,7 @@ export default { ...@@ -1197,6 +1201,7 @@ export default {
float: left; float: left;
cursor: pointer; cursor: pointer;
} }
.el-table tr { .el-table tr {
background-color: transparent !important; background-color: transparent !important;
color: #ffffffc7; color: #ffffffc7;
...@@ -1489,5 +1494,4 @@ export default { ...@@ -1489,5 +1494,4 @@ export default {
padding: 25px 25px 0px; padding: 25px 25px 0px;
} }
} }
} }</style>
</style>
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