未验证 提交 fbf99266 编写于 作者: Mr.奇淼('s avatar Mr.奇淼( 提交者: GitHub

Merge branch 'master' into gva-2.4.6+

......@@ -2,6 +2,7 @@ package example
import (
"fmt"
"github.com/flipped-aurora/gin-vue-admin/server/model/example"
"io/ioutil"
"mime/multipart"
"strconv"
......@@ -123,18 +124,18 @@ func (b *FileUploadAndDownloadApi) BreakpointContinueFinish(c *gin.Context) {
// @Success 200 {string} string "{"success":true,"data":{},"msg":"缓存切片删除成功"}"
// @Router /fileUploadAndDownload/removeChunk [post]
func (u *FileUploadAndDownloadApi) RemoveChunk(c *gin.Context) {
fileMd5 := c.Query("fileMd5")
fileName := c.Query("fileName")
filePath := c.Query("filePath")
err := utils.RemoveChunk(fileMd5)
var file example.ExaFile
c.ShouldBindJSON(&file)
err := utils.RemoveChunk(file.FileMd5)
if err != nil {
global.GVA_LOG.Error("缓存切片删除失败!", zap.Error(err))
return
}
err = fileUploadAndDownloadService.DeleteFileChunk(fileMd5, fileName, filePath)
err = fileUploadAndDownloadService.DeleteFileChunk(file.FileMd5, file.FileName, file.FilePath)
if err != nil {
global.GVA_LOG.Error("缓存切片删除失败!", zap.Error(err))
response.FailWithDetailed(exampleRes.FilePathResponse{FilePath: filePath}, "缓存切片删除失败", c)
global.GVA_LOG.Error(err.Error(), zap.Error(err))
response.FailWithMessage(err.Error(), c)
} else {
response.OkWithDetailed(exampleRes.FilePathResponse{FilePath: filePath}, "缓存切片删除成功", c)
response.OkWithMessage("缓存切片删除成功", c)
}
}
......@@ -7,9 +7,9 @@ import (
// file struct, 文件结构体
type ExaFile struct {
global.GVA_MODEL
FileName string
FileMd5 string
FilePath string
FileName string `json:"fileName"`
FileMd5 string `json:"fileMd5"`
FilePath string `json:"filePath"`
ExaFileChunk []ExaFileChunk
ChunkTotal int
IsFinish bool
......
......@@ -56,7 +56,7 @@ func (e *FileUploadAndDownloadService) CreateFileChunk(id uint, fileChunkPath st
func (e *FileUploadAndDownloadService) DeleteFileChunk(fileMd5 string, fileName string, filePath string) error {
var chunks []example.ExaFileChunk
var file example.ExaFile
err := global.GVA_DB.Where("file_md5 = ? AND file_name = ?", fileMd5, fileName).First(&file).Update("IsFinish", true).Update("file_path", filePath).Error
err := global.GVA_DB.Where("file_md5 = ? ", fileMd5).First(&file).Update("IsFinish", true).Update("file_path", filePath).Error
if err != nil {
return err
}
......
......@@ -60,8 +60,9 @@ func (a *api) Initialize() error {
{ApiGroup: "菜单", Method: "POST", Path: "/menu/addMenuAuthority", Description: "增加menu和角色关联关系"},
{ApiGroup: "分片上传", Method: "POST", Path: "/fileUploadAndDownload/findFile", Description: "寻找目标文件(秒传)"},
{ApiGroup: "分片上传", Method: "POST", Path: "/fileUploadAndDownload/breakpointContinueFinish", Description: "断点续传"},
{ApiGroup: "分片上传", Method: "POST", Path: "/fileUploadAndDownload/removeChunk", Description: "上传完成"},
{ApiGroup: "分片上传", Method: "POST", Path: "/fileUploadAndDownload/breakpointContinue", Description: "断点续传"},
{ApiGroup: "分片上传", Method: "POST", Path: "/fileUploadAndDownload/breakpointContinueFinish", Description: "断点续传完成"},
{ApiGroup: "分片上传", Method: "POST", Path: "/fileUploadAndDownload/removeChunk", Description: "上传完成移除文件"},
{ApiGroup: "文件上传与下载", Method: "POST", Path: "/fileUploadAndDownload/upload", Description: "文件上传示例"},
{ApiGroup: "文件上传与下载", Method: "POST", Path: "/fileUploadAndDownload/deleteFile", Description: "删除文件"},
......
......@@ -56,6 +56,7 @@ func (c *casbin) Initialize() error {
{PType: "p", V0: "888", V1: "/fileUploadAndDownload/findFile", V2: "GET"},
{PType: "p", V0: "888", V1: "/fileUploadAndDownload/breakpointContinueFinish", V2: "POST"},
{PType: "p", V0: "888", V1: "/fileUploadAndDownload/breakpointContinue", V2: "POST"},
{PType: "p", V0: "888", V1: "/fileUploadAndDownload/removeChunk", V2: "POST"},
{PType: "p", V0: "888", V1: "/fileUploadAndDownload/upload", V2: "POST"},
......
......@@ -16,6 +16,15 @@ export const findFile = (params) => {
})
}
export const breakpointContinue = (data) => {
return service({
url: '/fileUploadAndDownload/breakpointContinue',
method: 'post',
headers: { 'Content-Type': 'multipart/form-data' },
data
})
}
export const breakpointContinueFinish = (params) => {
return service({
url: '/fileUploadAndDownload/breakpointContinueFinish',
......
......@@ -19,7 +19,7 @@
</template>
<script>
const path = process.env.VUE_APP_BASE_API
const path = import.meta.env.VITE_BASE_API
import { getFileList } from '@/api/fileUploadAndDownload'
export default {
props: {
......
......@@ -36,11 +36,11 @@ service.interceptors.request.use(
}
const token = store.getters['user/token']
const user = store.getters['user/userInfo']
config.data = JSON.stringify(config.data)
config.headers = {
'Content-Type': 'application/json',
'x-token': token,
'x-user-id': user.ID
'x-user-id': user.ID,
...config.headers
}
return config
},
......@@ -70,7 +70,7 @@ service.interceptors.response.use(
} else {
ElMessage({
showClose: true,
message: response.data.msg||decodeURI(response.headers.msg),
message: response.data.msg || decodeURI(response.headers.msg),
type: 'error'
})
if (response.data.data && response.data.data.reload) {
......
......@@ -33,11 +33,11 @@
<script>
import SparkMD5 from 'spark-md5'
import axios from 'axios'
import {
findFile,
breakpointContinueFinish,
removeChunk
removeChunk,
breakpointContinue
} from '@/api/breakpoint'
export default {
name: 'BreakPoint',
......@@ -47,13 +47,18 @@ export default {
fileMd5: '',
formDataList: [],
waitUpLoad: [],
waitNum: 0,
waitNum: NaN,
limitFileSize: false,
percentage: 0,
percentageFlage: true,
customColor: '#409eff'
}
},
watch: {
waitNum() {
this.percentage = Math.floor(((this.formDataList.length - this.waitNum) / this.formDataList.length) * 100)
}
},
methods: {
// 选中文件的函数
async choseFile(e) {
......@@ -107,6 +112,7 @@ export default {
})
} else {
this.waitUpLoad = [] // 秒传则没有需要上传的切片
this.$message.success('文件已秒传')
}
this.waitNum = this.waitUpLoad.length // 记录长度用于百分比展示
}
......@@ -121,7 +127,6 @@ export default {
this.$message('请先上传文件')
return
}
this.percentage = Math.floor(((this.formDataList.length - this.waitNum) / this.formDataList.length) * 100)
if (this.percentage === 100) {
this.percentageFlage = false
}
......@@ -145,7 +150,10 @@ export default {
},
async upLoadFileSlice(item) {
// 切片上传
await axios.post(import.meta.env.VITE_BASE_API + '/fileUploadAndDownload/breakpointContinue', item.formData)
const fileRe = await breakpointContinue(item.formData)
if (fileRe.code !== 0) {
return
}
this.waitNum-- // 百分数增加
if (this.waitNum === 0) {
// 切片传完以后 合成文件
......@@ -154,13 +162,14 @@ export default {
fileMd5: this.fileMd5
}
const res = await breakpointContinueFinish(params)
if (res.success) {
if (res.code === 0) {
// 合成文件过后 删除缓存切片
const params = {
fileName: this.file.name,
fileMd5: this.fileMd5,
filePath: res.data.filePath
}
this.$message.success('上传成功')
await removeChunk(params)
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册