Skip to content

Commit 7da1962

Browse files
author
piexlmax
committed
1 parent 4ef717f commit 7da1962

File tree

6 files changed

+41
-16
lines changed

6 files changed

+41
-16
lines changed

server/api/v1/example/exa_breakpoint_continue.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package example
22

33
import (
44
"fmt"
5+
"github.com/flipped-aurora/gin-vue-admin/server/model/example"
56
"io/ioutil"
67
"mime/multipart"
78
"strconv"
@@ -123,11 +124,17 @@ func (b *FileUploadAndDownloadApi) BreakpointContinueFinish(c *gin.Context) {
123124
// @Success 200 {string} string "{"success":true,"data":{},"msg":"缓存切片删除成功"}"
124125
// @Router /fileUploadAndDownload/removeChunk [post]
125126
func (u *FileUploadAndDownloadApi) RemoveChunk(c *gin.Context) {
126-
fileMd5 := c.Query("fileMd5")
127-
err := utils.RemoveChunk(fileMd5)
127+
var file example.ExaFile
128+
c.ShouldBindJSON(&file)
129+
err := utils.RemoveChunk(file.FileMd5)
128130
if err != nil {
129131
global.GVA_LOG.Error("缓存切片删除失败!", zap.Error(err))
130-
response.FailWithMessage("缓存切片删除失败", c)
132+
return
133+
}
134+
err = fileUploadAndDownloadService.DeleteFileChunk(file.FileMd5, file.FileName, file.FilePath)
135+
if err != nil {
136+
global.GVA_LOG.Error(err.Error(), zap.Error(err))
137+
response.FailWithMessage(err.Error(), c)
131138
} else {
132139
response.OkWithMessage("缓存切片删除成功", c)
133140
}

server/model/example/exa_breakpoint_continue.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
// file struct, 文件结构体
88
type ExaFile struct {
99
global.GVA_MODEL
10-
FileName string
11-
FileMd5 string
12-
FilePath string
10+
FileName string `json:"fileName"`
11+
FileMd5 string `json:"fileMd5"`
12+
FilePath string `json:"filePath"`
1313
ExaFileChunk []ExaFileChunk
1414
ChunkTotal int
1515
IsFinish bool

server/service/example/exa_breakpoint_continue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (e *FileUploadAndDownloadService) CreateFileChunk(id uint, fileChunkPath st
5656
func (e *FileUploadAndDownloadService) DeleteFileChunk(fileMd5 string, fileName string, filePath string) error {
5757
var chunks []example.ExaFileChunk
5858
var file example.ExaFile
59-
err := global.GVA_DB.Where("file_md5 = ? AND file_name = ?", fileMd5, fileName).First(&file).Update("IsFinish", true).Update("file_path", filePath).Error
59+
err := global.GVA_DB.Where("file_md5 = ? ", fileMd5).First(&file).Update("IsFinish", true).Update("file_path", filePath).Error
6060
if err != nil {
6161
return err
6262
}

web/src/api/breakpoint.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ export const findFile = (params) => {
1616
})
1717
}
1818

19+
export const breakpointContinue = (data) => {
20+
return service({
21+
url: '/fileUploadAndDownload/breakpointContinue',
22+
method: 'post',
23+
headers: { 'Content-Type': 'multipart/form-data' },
24+
data
25+
})
26+
}
27+
1928
export const breakpointContinueFinish = (params) => {
2029
return service({
2130
url: '/fileUploadAndDownload/breakpointContinueFinish',

web/src/utils/request.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ service.interceptors.request.use(
3636
}
3737
const token = store.getters['user/token']
3838
const user = store.getters['user/userInfo']
39-
config.data = JSON.stringify(config.data)
4039
config.headers = {
4140
'Content-Type': 'application/json',
4241
'x-token': token,
43-
'x-user-id': user.ID
42+
'x-user-id': user.ID,
43+
...config.headers
4444
}
4545
return config
4646
},
@@ -70,7 +70,7 @@ service.interceptors.response.use(
7070
} else {
7171
ElMessage({
7272
showClose: true,
73-
message: response.data.msg||decodeURI(response.headers.msg),
73+
message: response.data.msg || decodeURI(response.headers.msg),
7474
type: 'error'
7575
})
7676
if (response.data.data && response.data.data.reload) {

web/src/view/example/breakpoint/breakpoint.vue

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333

3434
<script>
3535
import SparkMD5 from 'spark-md5'
36-
import axios from 'axios'
3736
import {
3837
findFile,
3938
breakpointContinueFinish,
40-
removeChunk
39+
removeChunk,
40+
breakpointContinue
4141
} from '@/api/breakpoint'
4242
export default {
4343
name: 'BreakPoint',
@@ -47,13 +47,18 @@ export default {
4747
fileMd5: '',
4848
formDataList: [],
4949
waitUpLoad: [],
50-
waitNum: 0,
50+
waitNum: NaN,
5151
limitFileSize: false,
5252
percentage: 0,
5353
percentageFlage: true,
5454
customColor: '#409eff'
5555
}
5656
},
57+
watch: {
58+
waitNum() {
59+
this.percentage = Math.floor(((this.formDataList.length - this.waitNum) / this.formDataList.length) * 100)
60+
}
61+
},
5762
methods: {
5863
// 选中文件的函数
5964
async choseFile(e) {
@@ -107,6 +112,7 @@ export default {
107112
})
108113
} else {
109114
this.waitUpLoad = [] // 秒传则没有需要上传的切片
115+
this.$message.success('文件已秒传')
110116
}
111117
this.waitNum = this.waitUpLoad.length // 记录长度用于百分比展示
112118
}
@@ -121,7 +127,6 @@ export default {
121127
this.$message('请先上传文件')
122128
return
123129
}
124-
this.percentage = Math.floor(((this.formDataList.length - this.waitNum) / this.formDataList.length) * 100)
125130
if (this.percentage === 100) {
126131
this.percentageFlage = false
127132
}
@@ -145,7 +150,10 @@ export default {
145150
},
146151
async upLoadFileSlice(item) {
147152
// 切片上传
148-
await axios.post(import.meta.env.VITE_BASE_API + '/fileUploadAndDownload/breakpointContinue', item.formData)
153+
const fileRe = await breakpointContinue(item.formData)
154+
if (fileRe.code !== 0) {
155+
return
156+
}
149157
this.waitNum-- // 百分数增加
150158
if (this.waitNum === 0) {
151159
// 切片传完以后 合成文件
@@ -154,13 +162,14 @@ export default {
154162
fileMd5: this.fileMd5
155163
}
156164
const res = await breakpointContinueFinish(params)
157-
if (res.success) {
165+
if (res.code === 0) {
158166
// 合成文件过后 删除缓存切片
159167
const params = {
160168
fileName: this.file.name,
161169
fileMd5: this.fileMd5,
162170
filePath: res.data.filePath
163171
}
172+
this.$message.success('上传成功')
164173
await removeChunk(params)
165174
}
166175
}

0 commit comments

Comments
 (0)