图片上传格式和大小更改

main
xuechunyuan 2 years ago
parent bdbe986a19
commit ec2e27e5a2
  1. BIN
      dist20230824-01.zip
  2. 16
      src/views/product/index.vue

Binary file not shown.

@ -11,11 +11,11 @@
<el-input style="width:360px;" v-model="productDetail.price" placeholder="请输入价格" maxlength="10" @input="NumberCheck" />
</el-form-item>
<el-form-item label="商品介绍详情图片:">
<el-upload v-if="productDetail.imgPath == ''" class="avatar-uploader" action="/api/blade-resource/oss/endpoint/put-file" :show-file-list="false"
<el-upload v-if="productDetail.imgPath == ''" class="avatar-uploader" action="/api/blade-resource/oss/endpoint/put-file" :headers="headers" :show-file-list="false"
:on-success="handleAvatarSuccess" :before-upload="beforeAvatarUpload">
<template>
<i class="el-icon-plus avatar-uploader-icon"></i>
<div class="tip">图片宽度750 高度不限 文件大小5M</div>
<div class="tip">图片宽度750 高度不限 文件大小2M</div>
</template>
</el-upload>
<div v-else class="img-box">
@ -34,6 +34,7 @@
<script>
import { getGoodInfo, saveGoodInfo } from "@/api/product/product";
import { getToken } from "@/util/auth";
export default {
data() {
return {
@ -43,7 +44,8 @@ export default {
imgPath : '',
price: ''
},
loading: false
loading: false,
headers: {'Blade-Auth':"bearer " + getToken()}
};
},
@ -140,14 +142,14 @@ export default {
}
},
beforeAvatarUpload(file) {
const isJPG = file.type === 'image/jpeg';
const isLt2M = file.size / 1024 / 1024 < 5;
const isJPG = file.type === 'image/jpeg' || file.type === 'image/jpg' || file.type === 'image/png';
const isLt2M = file.size / 1024 / 1024 < 2;
if (!isJPG) {
this.$message.error('上传头像图片只能是 JPG 格式!');
}
if (!isLt2M) {
this.$message.error('上传头像图片大小不能超过 5MB!');
else if (!isLt2M) {
this.$message.error('上传头像图片大小不能超过 2MB!');
}
return isJPG && isLt2M;
}

Loading…
Cancel
Save