fit: 增加CropperAvatar组件图片上传大小限制默认最大5M (#2928)

Co-authored-by: doverlee <doverlee@fox.mail.com>
This commit is contained in:
DoverDee 2023-07-26 19:05:31 +08:00 committed by GitHub
parent c28224f3f8
commit 16b4b6d57c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 1 deletions

View File

@ -25,6 +25,7 @@
@upload-success="handleUploadSuccess"
:uploadApi="uploadApi"
:src="sourceValue"
:size="size"
/>
</div>
</template>
@ -54,6 +55,7 @@
btnProps: { type: Object as PropType<ButtonProps> },
btnText: { type: String, default: '' },
uploadApi: { type: Function as PropType<({ file: Blob, name: string }) => Promise<void>> },
size: { type: Number, default: 5 },
};
export default defineComponent({

View File

@ -130,13 +130,14 @@
type: Function as PropType<(params: apiFunParams) => Promise<any>>,
},
src: { type: String },
size: { type: Number },
};
export default defineComponent({
name: 'CropperModal',
components: { BasicModal, Space, CropperImage, Upload, Avatar, Tooltip },
props,
emits: ['uploadSuccess', 'register'],
emits: ['uploadSuccess', 'uploadError', 'register'],
setup(props, { emit }) {
let filename = '';
const src = ref(props.src || '');
@ -151,6 +152,10 @@
// Block upload
function handleBeforeUpload(file: File) {
if (props.size && file.size > 1024 * 1024 * props.size) {
emit('uploadError', { msg: t('component.cropper.imageTooBig') });
return;
}
const reader = new FileReader();
reader.readAsDataURL(file);
src.value = '';

View File

@ -11,6 +11,7 @@ export default {
cropper: {
selectImage: 'Select Image',
uploadSuccess: 'Uploaded success!',
imageTooBig: 'Image too big',
modalTitle: 'Avatar upload',
okText: 'Confirm and upload',
btn_reset: 'Reset',

View File

@ -11,6 +11,7 @@ export default {
cropper: {
selectImage: '选择图片',
uploadSuccess: '上传成功',
imageTooBig: '图片超限',
modalTitle: '头像上传',
okText: '确认并上传',
btn_reset: '重置',