优化报废图片上传问题

This commit is contained in:
BianLzhaoMin 2024-06-17 17:13:51 +08:00
parent ee30623248
commit 6a64086767
3 changed files with 114 additions and 112 deletions

View File

@ -1,6 +1,6 @@
import request from '@/utils/request'
//资源图片上传
export function imgUpLoad(param){
export function imgUpLoad(param) {
const formData = new FormData()
formData.append('file', param.file)
formData.append('fileType', param.type)
@ -8,12 +8,12 @@ export function imgUpLoad(param){
url: '/system/sys/file/upload',
method: 'post',
data: formData,
header:'multipart/form-data'
header: 'multipart/form-data'
})
}
}
//资源文件上传
export function fileUpLoad(param){
export function fileUpLoad(param) {
const formData = new FormData()
formData.append('file', param.file)
return request({
@ -21,7 +21,7 @@ export function fileUpLoad(param){
method: 'post',
data: formData,
})
}
}

View File

@ -34,8 +34,6 @@ export default {
return
}
let real_src = this.src.split(',')[0]
console.log(this.src, '图片地址--')
return real_src
},
realSrcList() {

View File

@ -49,7 +49,8 @@ export default {
},
data() {
return {
uploadImgUrl: process.env.VUE_APP_BASE_API + '/dev-api' + this.actionUrl,
uploadImgUrl:
process.env.VUE_APP_BASE_API + '/dev-api' + this.actionUrl,
headers: {
Authorization: 'Bearer ' + getToken(),
},
@ -70,9 +71,9 @@ export default {
},
handleExceed(files, fileList) {
this.$message.warning(
`当前限制选择 ${this.limit} 个文件,本次选择了 ${files.length} 个文件,共选择了 ${
files.length + fileList.length
} 个文件`
`当前限制选择 ${this.limit} 个文件,本次选择了 ${
files.length
} 个文件共选择了 ${files.length + fileList.length} 个文件`,
)
this.$emit('exceed', files, fileList)
},
@ -85,7 +86,10 @@ export default {
},
beforeUpload(file) {
console.log('file', file)
const isJPGorPNG = file.type == 'image/png' || file.type == 'image/jpg' || file.type == 'image/jpeg'
const isJPGorPNG =
file.type == 'image/png' ||
file.type == 'image/jpg' ||
file.type == 'image/jpeg'
const isLt5M = file.size / 1024 / 1024 < 5 // 5MB
if (!isJPGorPNG) {
this.$message.error('只能上传 jpg、jpeg、png 格式的图片')