update:切片上传

This commit is contained in:
lan
2023-02-28 18:34:15 +08:00
parent d8de60a1db
commit db6064330e
2 changed files with 61 additions and 32 deletions
+48 -23
View File
@@ -150,17 +150,17 @@
<el-button v-else slot="append" disabled></el-button>
</el-input>
</el-tooltip>
<el-radio-group style="margin-left: 18px" v-model="uploadData.type">
<el-radio-group style="margin-left: 18px" v-model="uploadData.is_file">
<el-radio label="1">
文件
</el-radio>
<el-radio label="2">
<el-radio label="0">
文本
</el-radio>
</el-radio-group>
</el-row>
<el-upload
v-if="uploadData.type === '1'"
v-if="uploadData.is_file === '1'"
drag
action="/share"
multiple
@@ -193,7 +193,7 @@
<div class="el-icon-takeaway-box"></div>
我的文件
</el-button>
<el-button round v-if="uploadData.type === '2'" @click="toUploadData">
<el-button round v-if="uploadData.is_file === '0'" @click="toUploadData">
<div class="el-icon-upload2"></div>
存入
</el-button>
@@ -280,9 +280,10 @@
enableUpload: false,
uploadData: {
style: '2',
type: '1',
type: 'text',
value: 1,
file: null,
is_file: '1',
text: ''
},
};
@@ -372,24 +373,48 @@
await this.http('post', `/file/upload/${file_key}/`, formData)
},
uploadFile: async function (e) {
this.http('post', '/file/create/').then(async res => {
const file = e.file;
let chunk_index = 0;
const shardSize = 1024 * 1024 * 5;
const {name, size} = file;
const total_chunks = Math.ceil(size / shardSize);
while (chunk_index < total_chunks) {
const start = chunk_index * shardSize
const end = Math.min(start + shardSize, size)
chunk_index += 1;
await this.uploadChunk(file.slice(start, end), res.data, chunk_index, total_chunks);
}
this.http('get', `/file/merge/${res.data}/?file_name=${file.name}&total_chunks=${total_chunks}`).then(res => {
console.log(res)
})
console.log(chunk_index, name, size, total_chunks);
})
if (this.checkFile(e.file)) {
this.http('post', '/file/create/').then(async res => {
const file = e.file;
let chunk_index = 0;
const shardSize = 1024 * 1024 * 5;
const {name, size, type} = file;
const total_chunks = Math.ceil(size / shardSize);
while (chunk_index < total_chunks) {
const start = chunk_index * shardSize
const end = Math.min(start + shardSize, size)
chunk_index += 1;
await this.uploadChunk(file.slice(start, end), res.data, chunk_index, total_chunks);
}
this.http('get', `/file/merge/${res.data}/?file_name=${name}&total_chunks=${total_chunks}`).then(text => {
this.http('post', '/share', {
file_key: res.data,
text: text.data,
size: size,
style: this.uploadData.style,
type: type,
name: name,
value: this.uploadData.value,
pwd: this.pwd
}, {
headers: {
'Content-Type': 'multipart/form-data',
'pwd': this.pwd
}
}).then(res => {
console.log(res.data)
this.jiFiles.unshift(res.data);
this.jiDrawer = true;
this.uploadData.text = '';
this.uploadData.file = null;
this.$message({
message: '上传成功',
type: 'success'
});
})
})
});
}
},
copyText: function (value, style = 1) {
if (style === 0) {