mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-24 18:40:22 +08:00
fit: 增加CropperAvatar组件图片上传大小限制默认最大5M (#2928)
Co-authored-by: doverlee <doverlee@fox.mail.com>
This commit is contained in:
parent
c28224f3f8
commit
16b4b6d57c
@ -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({
|
||||
|
@ -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 = '';
|
||||
|
@ -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',
|
||||
|
@ -11,6 +11,7 @@ export default {
|
||||
cropper: {
|
||||
selectImage: '选择图片',
|
||||
uploadSuccess: '上传成功',
|
||||
imageTooBig: '图片超限',
|
||||
modalTitle: '头像上传',
|
||||
okText: '确认并上传',
|
||||
btn_reset: '重置',
|
||||
|
Loading…
Reference in New Issue
Block a user