Browse Source
fit: 增加CropperAvatar组件图片上传大小限制默认最大5M (#2928)
Co-authored-by: doverlee <doverlee@fox.mail.com>
pull/2935/head
DoverDee
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
10 additions and
1 deletions
-
src/components/Cropper/src/CropperAvatar.vue
-
src/components/Cropper/src/CropperModal.vue
-
src/locales/lang/en/component.ts
-
src/locales/lang/zh-CN/component.ts
|
|
|
@ -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: '重置', |
|
|
|
|