refactor: 背景图片直接存储在服务器

refactor: 背景图片直接存储在服务器
This commit is contained in:
王嘉豪
2022-04-25 12:13:05 +08:00
committed by GitHub
parent dbb8a7a76d
commit f55749417d
11 changed files with 270 additions and 27 deletions

View File

@@ -0,0 +1,26 @@
import request from '@/utils/request'
import { uuid } from 'vue-uuid'
import store from '@/store'
export function uploadFile(fileId, file) {
const param = new FormData()
param.append('file', file.file)
return request({
url: '/static/resource/upload/' + fileId,
method: 'post',
headers: { 'Content-Type': 'multipart/form-data' },
data: param,
loading: false
})
}
export function uploadFileResult(file, callback) {
const fileId = uuid.v1()
const fileName = file.file.name
const newFileName = fileId + fileName.substr(fileName.lastIndexOf('.'), fileName.length)
const fileUrl = store.state.staticResourcePath + newFileName
uploadFile(fileId, file).then(() => {
callback(fileUrl)
})
}