e4ec2bfe by renchao@pashanhoo.com

style:图片上传

1 parent fcf0c30a
<!--
* @Description:
* @Autor: renchao
* @LastEditTime: 2023-07-28 14:59:55
* @LastEditTime: 2023-07-31 15:12:08
-->
<template>
<div class="rlPopup">
......@@ -223,28 +223,20 @@
clickImage () {
this.showViewer = true
},
// 上传
/**
* @description: 上传
* @param {*} file
* @author: renchao
*/
beforeUpload (file) {
const isJPEG = file.type === 'image/jpeg'
const isPNG = file.type === 'image/png'
const isJPG = file.type === 'image/jpg'
const isGIF = file.type === 'image/gif'
const isLt5M = file.size / 1024 / 1024 < 5
if (!isJPEG && !isGIF && !isPNG && !isJPG && !isGIF) {
this.$message.error('请选择jpeg/png/jpg/bmp/gif格式的图片后重试')
this.loading = false
}
const isLt5M = file.size / 1024 / 1024 < 5;
if (!isLt5M) {
this.$message.error('上传图片大小不能超过 5MB!')
this.loading = false
this.$message.error('上传图片大小不能超过 5MB!');
return false;
}
this.imgHidden = (isJPG || isJPEG || isPNG || isGIF) && isLt5M
return this.imgHidden
// 所有条件满足时返回 true
return true;
},
/**
* @description: handleChange
......@@ -253,17 +245,25 @@
* @author: renchao
*/
async handleChange (file, fileList) {
if (!this.beforeUpload(file)) return
let length = fileList.length;
this.maxFileLength = Math.max(length, this.maxFileLength)
console.log(fileList, this.maxFileLength, 'this.maxFileLength');
var formData = new FormData();
let num = 0
setTimeout(() => {
if (this.maxFileLength !== length) {
return
}
fileList.forEach(item => {
if (!['image/jpeg', 'image/png', 'image/jpg', 'image/gif'].includes(item.raw.type)) {
num++
}
formData.append('file', item.raw)
})
if (num >= 1) {
this.$message.error("请选择jpeg/png/jpg/bmp/gif格式的图片后重试")
return
}
formData.append("bsmSj", this.previewImg.bsmSj);
formData.append("bsmSlsq", this.previewImg.bsmSlsq);
uploadBatch(formData).then((res) => {
......