!84 图片上传组件增加压缩支持

Merge pull request !84 from 缝合怪/dev
This commit is contained in:
疯狂的狮子Li 2024-02-23 07:24:31 +00:00 committed by Gitee
commit 26cfa7afc4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 20 additions and 3 deletions

View File

@ -30,6 +30,7 @@
"element-plus": "2.4.4",
"file-saver": "2.0.5",
"fuse.js": "7.0.0",
"image-conversion": "^2.1.1",
"js-cookie": "3.0.5",
"jsencrypt": "3.3.2",
"nprogress": "0.2.0",

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++;
}
};
//