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

大文件上传

parent e44c349f
...@@ -5,20 +5,16 @@ ...@@ -5,20 +5,16 @@
</div> </div>
<div id="thelist" class="uploader-list"> <div id="thelist" class="uploader-list">
<ul> <ul>
<li v-for="(item, index) in fileList"> <li v-for="(item, index) in fileList ">
<a @click="removeFile(item, index)"><span title="点击移除">{{item.name}}</span></a> <a @click="removeFile(item, index)"><span title="点击移除">{{ item.name }}</span></a>
<el-progress <span style="color: white;"
v-if="item.percentage!=0" :class="[item.state == 1 ? 'el-icon-loading' : item.state == 2 ? 'el-icon-check' : '']"></span>
:text-inside="true" <el-progress :text-inside="true" :stroke-width="14" :percentage="item.percentage"
:stroke-width="14" status="success"></el-progress>
:percentage="item.percentage"
status="success"
></el-progress>
</li> </li>
</ul> </ul>
</div> </div>
<el-button type="primary" @click="import_data_collect()">开始同步</el-button> <el-button type="primary" @click="upload()">开始上传</el-button>
<!-- <div class="button-discuss" @click="import_data_collect">开始同步</div> -->
</div> </div>
</template> </template>
<script> <script>
...@@ -50,6 +46,7 @@ export default { ...@@ -50,6 +46,7 @@ export default {
{ {
//时间点1:所有分块进行上存之前触发该方法,即当每个文件开始上传第一个分块前就调用该方法 //时间点1:所有分块进行上存之前触发该方法,即当每个文件开始上传第一个分块前就调用该方法
beforeSendFile: function (file) { beforeSendFile: function (file) {
_self.fileList.filter(e => e.id == file.id)[0].state = 1;
//定义一个异步对象 //定义一个异步对象
var deferred = WebUploader.Deferred(); var deferred = WebUploader.Deferred();
uploader uploader
...@@ -63,7 +60,7 @@ export default { ...@@ -63,7 +60,7 @@ export default {
// 判断文件是否上传过,是否存在分片,断点续传 // 判断文件是否上传过,是否存在分片,断点续传
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "api/rest/upload/check", url: "api/rest/file/bigFile/check",
async: false, async: false,
data: { data: {
fileMd5: val, fileMd5: val,
...@@ -80,7 +77,7 @@ export default { ...@@ -80,7 +77,7 @@ export default {
file.indexcode = resultCode; file.indexcode = resultCode;
} }
}, },
error: function () {}, error: function () { },
}); });
//获取文件信息后进入下一步 //获取文件信息后进入下一步
deferred.resolve(); deferred.resolve();
...@@ -110,50 +107,61 @@ export default { ...@@ -110,50 +107,61 @@ export default {
//时间点3:一个文件的所有分片上传成功后,调用该方法,让后台合并所有分片 //时间点3:一个文件的所有分片上传成功后,调用该方法,让后台合并所有分片
//该方法的在uploader.on("success")方法前执行。 //该方法的在uploader.on("success")方法前执行。
afterSendFile: function (file) { afterSendFile: function (file) {
//如果所有分块上传成功,则通知后台合并分块 let param = {
$.ajax({ success: file.pass,
type: "POST", md5: file.md5,
url: "api/rest/upload/merge", file: {
data: { name: file.name,
fileName: file.name, size: file.size,
fileMd5: file.md5, type: file.ext,
fileType: _self.fileType uuid: file.uid + "." + file.ext,
}, }
success: function (data) { };
if(data.code == 9000){ if (file.pass) {//文件已经存在
_self.$message.success("成功数据"+data.data + "条数据"); _self.$emit("Completed", param);
}else{ _self.fileList.filter(e => e.id == file.id)[0].state = 2;
_self.$message.warning(data.message); } else { //如果所有分块上传成功,则通知后台合并分块
} $.ajax({
}, type: "POST",
error: function () {}, url: "api/rest/file/bigFile/merge",
}); data: {
fileName: file.name,
fileMd5: file.md5,
fileType: _self.fileType
},
success: function (data) {
_self.fileList.filter(e => e.id == file.id)[0].state = 2;
param.success = data.code == 9000;
_self.$emit("Completed", param);
},
error: function () { },
});
}
}, },
} }
); );
//创建实例 //创建实例
var uploader = WebUploader.create({ var uploader = WebUploader.create({
pick: { pick: {
id: '#picker', id: '#picker',
label: '点击选择文件' label: '点击选择文件'
}, },
duplicate: true,//去重, 根据文件名字、文件大小和最后修改时间来生成hash Key duplicate: true,//去重, 根据文件名字、文件大小和最后修改时间来生成hash Key
swf: 'WebUploader/uploader.swf', swf: 'WebUploader/uploader.swf',
chunked: true, chunked: true,
chunkSize: 10 * 1024 * 1024, // 10M 每个分片的大小限制 chunkSize: 10 * 1024 * 1024, // 10M 每个分片的大小限制
threads: 3, threads: 3,
server: 'api/rest/upload/part', server: 'api/rest/file/bigFile/part',
// auto: true, // auto: true,
// 禁掉全局的拖拽功能。这样不会出现图片拖进页面的时候,把图片打开。 // 禁掉全局的拖拽功能。这样不会出现图片拖进页面的时候,把图片打开。
disableGlobalDnd: true, disableGlobalDnd: true,
fileNumLimit: 1024, fileNumLimit: 1024,
fileSizeLimit: 50 * 1024 * 1024 * 1024,//50G 验证文件总大小是否超出限制, 超出则不允许加入队列 fileSizeLimit: 50 * 1024 * 1024 * 1024,//50G 验证文件总大小是否超出限制, 超出则不允许加入队列
fileSingleSizeLimit: 10 * 1024 * 1024 * 1024 //10G 验证单个文件大小是否超出限制, 超出则不允许加入队列 fileSingleSizeLimit: 10 * 1024 * 1024 * 1024 //10G 验证单个文件大小是否超出限制, 超出则不允许加入队列
}); });
// 当有文件被添加进队列的时候触发 // 当有文件被添加进队列的时候触发
uploader.on("fileQueued", function (file) { uploader.on("fileQueued", function (file) {
console.log("添加", file); _self.fileList.push({ name: file.name, id: file.id, percentage: 0, state: 0 });
_self.fileList.push({name: file.name, id: file.id, percentage: 0});
}); });
/** /**
* 当某个文件的分块在发送前触发,主要用来询问是否要添加附带参数,大文件在开起分片上传的前提下此事件可能会触发多次。 * 当某个文件的分块在发送前触发,主要用来询问是否要添加附带参数,大文件在开起分片上传的前提下此事件可能会触发多次。
...@@ -173,79 +181,82 @@ export default { ...@@ -173,79 +181,82 @@ export default {
/** /**
* 文件上传成功后,就在该文件对应的位置上,显示上传成功,file.id,作为上传文件位置标签的id, * 文件上传成功后,就在该文件对应的位置上,显示上传成功,file.id,作为上传文件位置标签的id,
*/ */
uploader.on("uploadSuccess", (file) => {}); uploader.on("uploadSuccess", (file) => { });
/** /**
* 发生错误时 * 发生错误时
*/ */
uploader.on("uploadError", function (file) {}); uploader.on("uploadError", function (file) { });
/** /**
* 不管所有分片发送成功或者失败都会执行该方法 * 不管所有分片发送成功或者失败都会执行该方法
*/ */
uploader.on("uploadComplete", function (file) { uploader.on("uploadComplete", function (file) {
}); });
//设置全局变量 //设置全局变量
this.uploader = uploader; this.uploader = uploader;
}, },
methods: { methods: {
import_data_collect() { upload() {
this.uploader.upload(); this.uploader.upload();
}, },
removeFile(item, index) { removeFile(item, index) {
if (item.state == 1) {//上传中的文件无法删除
return;
}
this.uploader.removeFile(item.id); this.uploader.removeFile(item.id);
this.fileList.splice(index, 1); this.fileList.splice(index, 1);
}, },
getProgressBar(file, percentage) { getProgressBar(file, percentage) {
let item = this.fileList.find(e=>e.id == file.id); let item = this.fileList.find(e => e.id == file.id);
item && (item.percentage = Math.floor(percentage * 100 * 100) / 100); item && (item.percentage = Math.floor(percentage * 100 * 100) / 100);
} }
}, },
}; };
</script> </script>
<style lang="scss" scope> <style lang="scss" scope>
.uploadWrapper { .uploadWrapper {
height: 100%; height: 524px;
} }
#picker > div:nth-child(2){ #picker>div:nth-child(2) {
width: 126px !important; width: 126px !important;
height: 40px !important; height: 40px !important;
} }
.btnUpload{ .btnUpload {
height: 50px; height: 50px;
} }
#thelist{ #thelist {
height: auto; height: auto;
overflow-y: auto; overflow-y: auto;
max-height: calc(100% - 40px); max-height: calc(100% - 40px);
} }
#thelist a{ #thelist a {
text-decoration: underline; text-decoration: underline;
cursor: pointer; cursor: pointer;
font-size: 18px; font-size: 18px;
} }
#thelist li { #thelist li {
/* 去掉li前面的小圆点 */ /* 去掉li前面的小圆点 */
list-style: none; list-style: none;
margin: 10px 0px; margin: 10px 0px;
} }
.button-discuss { .button-discuss {
width: 100px; width: 100px;
height: 30px; height: 30px;
line-height: 30px; line-height: 30px;
float: left; float: left;
font-size: 14px; font-size: 14px;
margin-top: 5px; margin-top: 5px;
margin-left: 20px; margin-left: 20px;
text-align: center; text-align: center;
cursor: pointer; cursor: pointer;
background-image: url(../../assets/img/yqjc/40.png); background-image: url(../../assets/img/yqjc/40.png);
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: 100% 100%; background-size: 100% 100%;
} }
</style> </style>
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
circle></el-button> circle></el-button>
</el-tooltip> --> </el-tooltip> -->
<div class="button-discuss1" @click="handleAdd()">新增</div> <div class="button-discuss1" @click="handleAdd()">新增</div>
<div class="button-discuss1" @click="bigFileUploadAdd()">大文件新增</div>
</div> </div>
<div class="bottom-div"> <div class="bottom-div">
<transition name="el-zoom-in-top" v-on:after-leave="afterLeave_lb"> <transition name="el-zoom-in-top" v-on:after-leave="afterLeave_lb">
...@@ -262,6 +263,11 @@ ...@@ -262,6 +263,11 @@
<el-button type="primary" @click="submit_bj">确 定</el-button> <el-button type="primary" @click="submit_bj">确 定</el-button>
</span> </span>
</el-dialog> </el-dialog>
<el-dialog title="大文件上传" :visible.sync="centerDialogVisible_bigFile" width="30%" center class="xzwd">
<BigfileUpload @Completed="completeUploadBigFile"></BigfileUpload>
</el-dialog>
<el-dialog :title="title" :visible.sync="centerDialogVisible_video" center width="800px"> <el-dialog :title="title" :visible.sync="centerDialogVisible_video" center width="800px">
<div style="height: 400px; position: relative"> <div style="height: 400px; position: relative">
<video id="video" class="" preload="meta" controls width="100%" object-fit="fill" height="100%" <video id="video" class="" preload="meta" controls width="100%" object-fit="fill" height="100%"
...@@ -289,10 +295,12 @@ import { ...@@ -289,10 +295,12 @@ import {
arr_sound_format, //音频的文件格式 arr_sound_format, //音频的文件格式
} from "../../util/http_util"; } from "../../util/http_util";
import { uuid } from "../../util/data_util"; import { uuid } from "../../util/data_util";
import BigfileUpload from "../../components/common/bigfileUpload.vue";
export default { export default {
data() { data() {
return { return {
centerDialogVisible_add: false, centerDialogVisible_add: false,
centerDialogVisible_bigFile: false,
centerDialogVisible_edit: false, centerDialogVisible_edit: false,
centerDialogVisible_video: false, centerDialogVisible_video: false,
centerDialogVisible_sound: false, centerDialogVisible_sound: false,
...@@ -356,6 +364,9 @@ export default { ...@@ -356,6 +364,9 @@ export default {
} }
}; };
}, },
components: {
BigfileUpload
},
props: { props: {
clientDetails: { clientDetails: {
type: Object, type: Object,
...@@ -626,6 +637,51 @@ export default { ...@@ -626,6 +637,51 @@ export default {
}, 200) }, 200)
}, },
bigFileUploadAdd() {
if (this.clientDetails_type[0] == 1 || this.clientDetails_type[0] == 2 || this.clientDetails_type[0] == 3 || this.clientDetails_type[0] == 4) {
this.$message({
type: "warning",
message: "请选择文档列表子节点",
});
return;
}
let _this = this;
_this.centerDialogVisible_bigFile = true;
},
completeUploadBigFile(evt) {
if (!evt.success) {
this.$message({
type: "warning",
message: "上传失败!",
});
}
let fd = new FormData();
let fileInfo = {
createId: this.$store.getters.userInfo.account,
description: null,
file: evt.file,
treeId: this.clientDetails_type[0],
name: evt.file.name,
keyword: null,
module: this.module_name
};
fd.append("info", JSON.stringify(fileInfo));
fd.append("destFilename", evt.file.uuid);
fd.append("md5", evt.md5);
fileUpload_PUT("api/rest/3z/document/upload", fd).then((data) => {
this.$message({
type: "success",
message: "文件上传成功!",
});
this.centerDialogVisible_add = false;
this.handleCurrentChange_lb(1);
})
.catch((err) => {
this.$message.warning(err.message);
})
},
//编辑弹出框确定 //编辑弹出框确定
submit_bj() { submit_bj() {
let _this = this; let _this = this;
...@@ -1328,4 +1384,5 @@ export default { ...@@ -1328,4 +1384,5 @@ 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