优化报废图片上传问题

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

View File

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

View File

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