图片上传组件增加压缩功能支持,可自行开关

This commit is contained in:
数据小王子 2024-03-05 16:46:22 +08:00
parent ce275d9590
commit 0112faf3ba

View File

@ -44,6 +44,7 @@ import { listByIds, delOss } from '@/api/system/oss';
import { OssVO } from '@/api/system/oss/types';
import { propTypes } from '@/utils/propTypes';
import { globalHeaders } from '@/utils/request';
import { compressAccurately } from 'image-conversion';
const props = defineProps({
modelValue: {
@ -60,7 +61,14 @@ const props = defineProps({
isShowTip: {
type: Boolean,
default: true
}
},
//
compressSupport: {
type: Boolean,
default: false
},
// KB300KB300KB
compressTargetSize: propTypes.number.def(300)
});
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
@ -138,8 +146,16 @@ const handleBeforeUpload = (file: any) => {
return false;
}
}
proxy?.$modal.loading('正在上传图片,请稍候...');
number.value++;
//
if (props.compressSupport && file.size / 1024 > props.compressTargetSize) {
proxy?.$modal.loading('正在上传图片,请稍候...');
number.value++;
return compressAccurately(file, props.compressTargetSize);
} else {
proxy?.$modal.loading('正在上传图片,请稍候...');
number.value++;
}
};
//