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

bug修改

parent 9af070a5
...@@ -66,3 +66,12 @@ export function uploadCommon(data) { ...@@ -66,3 +66,12 @@ export function uploadCommon(data) {
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 @@ ...@@ -12,6 +12,7 @@
ref="imageUpload" ref="imageUpload"
multiple multiple
action action
:accept="['.jpg', '.png', 'jpeg']"
list-type="picture-card" list-type="picture-card"
:on-success="handleUploadSuccess" :on-success="handleUploadSuccess"
:before-upload="handleBeforeUpload" :before-upload="handleBeforeUpload"
...@@ -84,7 +85,7 @@ ...@@ -84,7 +85,7 @@
import ImageCropperModal from '@/components/imageCropper/index' import ImageCropperModal from '@/components/imageCropper/index'
import { getToken } from '@/utils/auth' import { getToken } from '@/utils/auth'
import { uploadCommon } from '@/api/system/config' import { uploadMino } from '@/api/system/config'
export default { export default {
components: { components: {
...@@ -129,7 +130,7 @@ export default { ...@@ -129,7 +130,7 @@ export default {
dialogVisible: false, dialogVisible: false,
hideUpload: false, hideUpload: false,
baseUrl: process.env.VUE_APP_TEST_API, 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: { headers: {
Authorization: 'Bearer ' + getToken() Authorization: 'Bearer ' + getToken()
}, },
...@@ -175,9 +176,16 @@ export default { ...@@ -175,9 +176,16 @@ export default {
var img = file.name.substring(file.name.lastIndexOf('.') + 1) var img = file.name.substring(file.name.lastIndexOf('.') + 1)
const suffix = img === 'jpg' || img === 'png' || img === 'jpeg' const suffix = img === 'jpg' || img === 'png' || img === 'jpeg'
if (!suffix) { if (!suffix) {
this.$message.error(`文件格式不正确, 请上传${this.fileType.join('/')}图片格式文件`) this.$message.error('文件格式不正确, 请上传png/jpg/jpeg图片格式文件!')
return false 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类型 // URL.createObjectURL的参数只能是blob或者file类型
// 第一种方法用FileReader,URL.createObjectURL接收blob类型 // 第一种方法用FileReader,URL.createObjectURL接收blob类型
const reader = new FileReader() const reader = new FileReader()
...@@ -207,22 +215,25 @@ export default { ...@@ -207,22 +215,25 @@ export default {
// 第三个参数可以设定一些文件的属性,比如文件的MIME,最后更新时间等 // 第三个参数可以设定一些文件的属性,比如文件的MIME,最后更新时间等
const file = new File([blob], this.fileName, { type: blob.type, lastModified: Date.now() }) const file = new File([blob], this.fileName, { type: blob.type, lastModified: Date.now() })
file.uid = Date.now() file.uid = Date.now()
form.append('file', file) form.append('multipartFile', file)
// 如果想在这里打印查看form的值,会发现它是空对象 // 如果想在这里打印查看form的值,会发现它是空对象
// 解决办法,需要用form.get('键')的方法获取值 // 解决办法,需要用form.get('键')的方法获取值
// console.log(form.get('file')) // console.log(form.get('file'))
// 这里调用接口,获取后端返给的图片地址 // 这里调用接口,获取后端返给的图片地址
this.number++ this.number++
uploadCommon(form).then(res => { uploadMino(form).then(res => {
console.log('moni', res)
this.cropperVisible = false this.cropperVisible = false
if (res.code === 200) { if (res) {
this.uploadList.push({ name: res.fileName, url: res.fileName }) this.uploadList.push({ name: res, url: res })
console.log('111')
this.uploadedSuccessfully() this.uploadedSuccessfully()
} else { } else {
this.number-- this.number--
// this.$modal.closeLoading() // this.$modal.closeLoading()
this.$modal.msgError(res.msg) // this.$modal.msgError(res.msg)
this.$refs.imageUpload.handleRemove(file) this.$refs.imageUpload.handleRemove(file)
console.log('222')
this.uploadedSuccessfully() this.uploadedSuccessfully()
} }
}).catch(err => { }).catch(err => {
...@@ -257,13 +268,13 @@ export default { ...@@ -257,13 +268,13 @@ export default {
} }
if (!isImg) { if (!isImg) {
this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join('/')}图片格式文件!`) this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join('/')}图片格式文件`)
return false return false
} }
if (this.fileSize) { if (this.fileSize) {
const isLt = file.size / 1024 / 1024 <= this.fileSize const isLt = file.size / 1024 / 1024 < this.fileSize
if (!isLt) { if (!isLt) {
this.$modal.msgError(`上传图片大小不能超过 ${this.fileSize} MB!`) this.$modal.msgError(`上传图片大小不能超过 ${this.fileSize} MB`)
return false return false
} }
} }
...@@ -272,7 +283,7 @@ export default { ...@@ -272,7 +283,7 @@ export default {
}, },
// 文件个数超出 // 文件个数超出
handleExceed() { handleExceed() {
this.$modal.msgError(`上传文件数量不能超过 ${this.limit}!`) this.$modal.msgError(`上传文件数量不能超过 ${this.limit} 个`)
}, },
// 上传成功回调 // 上传成功回调
handleUploadSuccess(res, file) { handleUploadSuccess(res, file) {
...@@ -351,17 +362,17 @@ export default { ...@@ -351,17 +362,17 @@ export default {
// .el-upload--picture-card 控制加号部分 // .el-upload--picture-card 控制加号部分
::v-deep.hide .el-upload--picture-card { ::v-deep.hide .el-upload--picture-card {
display: none; display: none;
} }
// 去掉动画效果 // 去掉动画效果
::v-deep .el-list-enter-active, ::v-deep .el-list-enter-active,
::v-deep .el-list-leave-active { ::v-deep .el-list-leave-active {
transition: all 0s; transition: all 0s;
} }
::v-deep .el-list-enter, .el-list-leave-active { ::v-deep .el-list-enter, .el-list-leave-active {
opacity: 0; opacity: 0;
transform: translateY(0); transform: translateY(0);
} }
::v-deep .el-upload-list--picture-card { ::v-deep .el-upload-list--picture-card {
line-height: 0; line-height: 0;
......
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