Skip to content

Commit 2863f18

Browse files
author
piexlmax
committed
修复断点续传前端部分
1 parent 350bb95 commit 2863f18

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

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/view/example/breakpoint/breakpoint.vue

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@ import axios from 'axios'
3434
import {
3535
findFile,
3636
breakpointContinueFinish,
37-
removeChunk
37+
removeChunk,
38+
breakpointContinue
3839
} from '@/api/breakpoint'
39-
import { ref } from 'vue'
40+
import { computed, ref, watch } from 'vue'
4041
import { ElMessage } from 'element-plus'
4142
4243
const file = ref(null)
4344
const fileMd5 = ref('')
4445
const formDataList = ref([])
4546
const waitUpLoad = ref([])
46-
const waitNum = ref(0)
47+
const waitNum = ref(NaN)
4748
const limitFileSize = ref(false)
4849
const percentage = ref(0)
4950
const percentageFlage = ref(true)
@@ -100,8 +101,10 @@ const choseFile = async(e) => {
100101
})
101102
} else {
102103
waitUpLoad.value = [] // 秒传则没有需要上传的切片
104+
ElMessage.success("文件已秒传")
103105
}
104106
waitNum.value = waitUpLoad.value.length // 记录长度用于百分比展示
107+
console.log(waitNum.value)
105108
}
106109
} else {
107110
limitFileSize.value = true
@@ -115,7 +118,6 @@ const getFile = () => {
115118
ElMessage('请先上传文件')
116119
return
117120
}
118-
percentage.value = Math.floor(((formDataList.value.length - waitNum.value) / formDataList.value.length) * 100)
119121
if (percentage.value === 100) {
120122
percentageFlage.value = false
121123
}
@@ -139,9 +141,14 @@ const sliceFile = () => {
139141
})
140142
}
141143
144+
watch(waitNum,()=>{percentage.value = Math.floor(((formDataList.value.length - waitNum.value) / formDataList.value.length) * 100)})
145+
142146
const upLoadFileSlice = async(item) => {
143147
// 切片上传
144-
await axios.post(import.meta.env.VITE_BASE_API + '/fileUploadAndDownload/breakpointContinue', item.formData)
148+
const fileRe = await breakpointContinue(item.formData)
149+
if (fileRe.code !== 0) {
150+
return
151+
}
145152
waitNum.value-- // 百分数增加
146153
if (waitNum.value === 0) {
147154
// 切片传完以后 合成文件
@@ -150,13 +157,12 @@ const upLoadFileSlice = async(item) => {
150157
fileMd5: fileMd5.value
151158
}
152159
const res = await breakpointContinueFinish(params)
153-
if (res.success) {
160+
if (res.code === 0) {
154161
// 合成文件过后 删除缓存切片
155162
const params = {
156-
fileName: file.value.name,
157163
fileMd5: fileMd5.value,
158-
filePath: res.data.filePath
159164
}
165+
ElMessage.success(上传成功)
160166
await removeChunk(params)
161167
}
162168
}
@@ -171,15 +177,7 @@ const inputChange = () => {
171177
<script>
172178
173179
export default {
174-
name: 'BreakPoint',
175-
data() {
176-
return {
177-
178-
}
179-
},
180-
methods: {
181-
182-
}
180+
name: 'BreakPoint'
183181
}
184182
</script>
185183

0 commit comments

Comments
 (0)