Commit 1ce859af authored by 陈明豪's avatar 陈明豪

bug修改

parent 9af070a5
......@@ -66,3 +66,12 @@ export function uploadCommon(data) {
data
})
}
export function uploadMino(data) {
return request({
headers: { 'Content-Type': 'multipart/form-data' },
url: '/business/common/uploadMinioPublic',
method: 'post',
data
})
}
......@@ -12,6 +12,7 @@
ref="imageUpload"
multiple
action
:accept="['.jpg', '.png', 'jpeg']"
list-type="picture-card"
:on-success="handleUploadSuccess"
:before-upload="handleBeforeUpload"
......@@ -84,7 +85,7 @@
import ImageCropperModal from '@/components/imageCropper/index'
import { getToken } from '@/utils/auth'
import { uploadCommon } from '@/api/system/config'
import { uploadMino } from '@/api/system/config'
export default {
components: {
......@@ -129,7 +130,7 @@ export default {
dialogVisible: false,
hideUpload: false,
baseUrl: process.env.VUE_APP_TEST_API,
uploadImgUrl: process.env.VUE_APP_BASE_API + '/common/upload', // 上传的图片服务器地址
uploadImgUrl: process.env.VUE_APP_BASE_API + '/business/common/uploadMinioPublic', // 上传的图片服务器地址
headers: {
Authorization: 'Bearer ' + getToken()
},
......@@ -175,9 +176,16 @@ export default {
var img = file.name.substring(file.name.lastIndexOf('.') + 1)
const suffix = img === 'jpg' || img === 'png' || img === 'jpeg'
if (!suffix) {
this.$message.error(`文件格式不正确, 请上传${this.fileType.join('/')}图片格式文件`)
this.$message.error('文件格式不正确, 请上传png/jpg/jpeg图片格式文件!')
return false
}
if (this.fileSize) {
const isLt = file.size / 1024 / 1024 < this.fileSize
if (!isLt) {
this.$modal.msgError(`上传图片大小不能超过 ${this.fileSize} MB`)
return false
}
}
// URL.createObjectURL的参数只能是blob或者file类型
// 第一种方法用FileReader,URL.createObjectURL接收blob类型
const reader = new FileReader()
......@@ -207,22 +215,25 @@ export default {
// 第三个参数可以设定一些文件的属性,比如文件的MIME,最后更新时间等
const file = new File([blob], this.fileName, { type: blob.type, lastModified: Date.now() })
file.uid = Date.now()
form.append('file', file)
form.append('multipartFile', file)
// 如果想在这里打印查看form的值,会发现它是空对象
// 解决办法,需要用form.get('键')的方法获取值
// console.log(form.get('file'))
// 这里调用接口,获取后端返给的图片地址
this.number++
uploadCommon(form).then(res => {
uploadMino(form).then(res => {
console.log('moni', res)
this.cropperVisible = false
if (res.code === 200) {
this.uploadList.push({ name: res.fileName, url: res.fileName })
if (res) {
this.uploadList.push({ name: res, url: res })
console.log('111')
this.uploadedSuccessfully()
} else {
this.number--
// this.$modal.closeLoading()
this.$modal.msgError(res.msg)
// this.$modal.msgError(res.msg)
this.$refs.imageUpload.handleRemove(file)
console.log('222')
this.uploadedSuccessfully()
}
}).catch(err => {
......@@ -257,13 +268,13 @@ export default {
}
if (!isImg) {
this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join('/')}图片格式文件!`)
this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join('/')}图片格式文件`)
return false
}
if (this.fileSize) {
const isLt = file.size / 1024 / 1024 <= this.fileSize
const isLt = file.size / 1024 / 1024 < this.fileSize
if (!isLt) {
this.$modal.msgError(`上传图片大小不能超过 ${this.fileSize} MB!`)
this.$modal.msgError(`上传图片大小不能超过 ${this.fileSize} MB`)
return false
}
}
......@@ -272,7 +283,7 @@ export default {
},
// 文件个数超出
handleExceed() {
this.$modal.msgError(`上传文件数量不能超过 ${this.limit}!`)
this.$modal.msgError(`上传文件数量不能超过 ${this.limit} 个`)
},
// 上传成功回调
handleUploadSuccess(res, file) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment