|
150 | 150 | <el-button v-else slot="append" disabled>天</el-button> |
151 | 151 | </el-input> |
152 | 152 | </el-tooltip> |
153 | | - <el-radio-group style="margin-left: 18px" v-model="uploadData.type"> |
| 153 | + <el-radio-group style="margin-left: 18px" v-model="uploadData.is_file"> |
154 | 154 | <el-radio label="1"> |
155 | 155 | 文件 |
156 | 156 | </el-radio> |
157 | | - <el-radio label="2"> |
| 157 | + <el-radio label="0"> |
158 | 158 | 文本 |
159 | 159 | </el-radio> |
160 | 160 | </el-radio-group> |
161 | 161 | </el-row> |
162 | 162 | <el-upload |
163 | | - v-if="uploadData.type === '1'" |
| 163 | + v-if="uploadData.is_file === '1'" |
164 | 164 | drag |
165 | 165 | action="/share" |
166 | 166 | multiple |
|
193 | 193 | <div class="el-icon-takeaway-box"></div> |
194 | 194 | 我的文件 |
195 | 195 | </el-button> |
196 | | - <el-button round v-if="uploadData.type === '2'" @click="toUploadData"> |
| 196 | + <el-button round v-if="uploadData.is_file === '0'" @click="toUploadData"> |
197 | 197 | <div class="el-icon-upload2"></div> |
198 | 198 | 存入 |
199 | 199 | </el-button> |
@@ -280,9 +280,10 @@ <h1 @click="copyText(file.code,0)" style="margin: 0;display: inline;cursor: poin |
280 | 280 | enableUpload: false, |
281 | 281 | uploadData: { |
282 | 282 | style: '2', |
283 | | - type: '1', |
| 283 | + type: 'text', |
284 | 284 | value: 1, |
285 | 285 | file: null, |
| 286 | + is_file: '1', |
286 | 287 | text: '' |
287 | 288 | }, |
288 | 289 | }; |
@@ -372,24 +373,48 @@ <h1 @click="copyText(file.code,0)" style="margin: 0;display: inline;cursor: poin |
372 | 373 | await this.http('post', `/file/upload/${file_key}/`, formData) |
373 | 374 | }, |
374 | 375 | uploadFile: async function (e) { |
375 | | - this.http('post', '/file/create/').then(async res => { |
376 | | - const file = e.file; |
377 | | - let chunk_index = 0; |
378 | | - const shardSize = 1024 * 1024 * 5; |
379 | | - const {name, size} = file; |
380 | | - const total_chunks = Math.ceil(size / shardSize); |
381 | | - while (chunk_index < total_chunks) { |
382 | | - const start = chunk_index * shardSize |
383 | | - const end = Math.min(start + shardSize, size) |
384 | | - chunk_index += 1; |
385 | | - await this.uploadChunk(file.slice(start, end), res.data, chunk_index, total_chunks); |
386 | | - } |
387 | | - this.http('get', `/file/merge/${res.data}/?file_name=${file.name}&total_chunks=${total_chunks}`).then(res => { |
388 | | - console.log(res) |
389 | | - }) |
390 | | - console.log(chunk_index, name, size, total_chunks); |
391 | | - }) |
392 | | - |
| 376 | + if (this.checkFile(e.file)) { |
| 377 | + this.http('post', '/file/create/').then(async res => { |
| 378 | + const file = e.file; |
| 379 | + let chunk_index = 0; |
| 380 | + const shardSize = 1024 * 1024 * 5; |
| 381 | + const {name, size, type} = file; |
| 382 | + const total_chunks = Math.ceil(size / shardSize); |
| 383 | + while (chunk_index < total_chunks) { |
| 384 | + const start = chunk_index * shardSize |
| 385 | + const end = Math.min(start + shardSize, size) |
| 386 | + chunk_index += 1; |
| 387 | + await this.uploadChunk(file.slice(start, end), res.data, chunk_index, total_chunks); |
| 388 | + } |
| 389 | + this.http('get', `/file/merge/${res.data}/?file_name=${name}&total_chunks=${total_chunks}`).then(text => { |
| 390 | + this.http('post', '/share', { |
| 391 | + file_key: res.data, |
| 392 | + text: text.data, |
| 393 | + size: size, |
| 394 | + style: this.uploadData.style, |
| 395 | + type: type, |
| 396 | + name: name, |
| 397 | + value: this.uploadData.value, |
| 398 | + pwd: this.pwd |
| 399 | + }, { |
| 400 | + headers: { |
| 401 | + 'Content-Type': 'multipart/form-data', |
| 402 | + 'pwd': this.pwd |
| 403 | + } |
| 404 | + }).then(res => { |
| 405 | + console.log(res.data) |
| 406 | + this.jiFiles.unshift(res.data); |
| 407 | + this.jiDrawer = true; |
| 408 | + this.uploadData.text = ''; |
| 409 | + this.uploadData.file = null; |
| 410 | + this.$message({ |
| 411 | + message: '上传成功', |
| 412 | + type: 'success' |
| 413 | + }); |
| 414 | + }) |
| 415 | + }) |
| 416 | + }); |
| 417 | + } |
393 | 418 | }, |
394 | 419 | copyText: function (value, style = 1) { |
395 | 420 | if (style === 0) { |
|
0 commit comments