图片上传格式和大小更改

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

Loading…
Cancel
Save