mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-05 19:41:42 +08:00
feat(Uploader): add click-upload event (#9119)
This commit is contained in:
parent
728e28f80c
commit
354ab2db82
@ -322,6 +322,7 @@ export default {
|
||||
| Event | Description | Arguments |
|
||||
| --- | --- | --- |
|
||||
| oversize | Emitted when file size over limit | Same as after-read |
|
||||
| click-upload `v3.1.5` | Emitted when click upload area | _event: MouseEvent_ |
|
||||
| click-preview | Emitted when preview image is clicked | Same as after-read |
|
||||
| close-preview | Emitted when the full screen image preview is closed | - |
|
||||
| delete | Emitted when preview file is deleted | Same as after-read |
|
||||
|
@ -340,12 +340,13 @@ export default {
|
||||
|
||||
### Events
|
||||
|
||||
| 事件名 | 说明 | 回调参数 |
|
||||
| ------------- | ---------------------- | --------------- |
|
||||
| oversize | 文件大小超过限制时触发 | 同 `after-read` |
|
||||
| click-preview | 点击预览图时触发 | 同 `after-read` |
|
||||
| close-preview | 关闭全屏图片预览时触发 | - |
|
||||
| delete | 删除文件预览时触发 | 同 `after-read` |
|
||||
| 事件名 | 说明 | 回调参数 |
|
||||
| --------------------- | ---------------------- | ------------------- |
|
||||
| oversize | 文件大小超过限制时触发 | 同 `after-read` |
|
||||
| click-upload `v3.1.5` | 点击上传区域时触发 | _event: MouseEvent_ |
|
||||
| click-preview | 点击预览图时触发 | 同 `after-read` |
|
||||
| close-preview | 关闭全屏图片预览时触发 | - |
|
||||
| delete | 删除文件预览时触发 | 同 `after-read` |
|
||||
|
||||
### Slots
|
||||
|
||||
|
@ -109,6 +109,7 @@ export default defineComponent({
|
||||
emits: [
|
||||
'delete',
|
||||
'oversize',
|
||||
'click-upload',
|
||||
'close-preview',
|
||||
'click-preview',
|
||||
'update:modelValue',
|
||||
@ -307,6 +308,8 @@ export default defineComponent({
|
||||
}
|
||||
};
|
||||
|
||||
const onClickUpload = (event: MouseEvent) => emit('click-upload', event);
|
||||
|
||||
const renderUpload = () => {
|
||||
if (props.modelValue.length >= props.maxCount || !props.showUpload) {
|
||||
return;
|
||||
@ -327,7 +330,7 @@ export default defineComponent({
|
||||
|
||||
if (slots.default) {
|
||||
return (
|
||||
<div class={bem('input-wrapper')}>
|
||||
<div class={bem('input-wrapper')} onClick={onClickUpload}>
|
||||
{slots.default()}
|
||||
{Input}
|
||||
</div>
|
||||
@ -338,6 +341,7 @@ export default defineComponent({
|
||||
<div
|
||||
class={bem('upload', { readonly: props.readonly })}
|
||||
style={getSizeStyle(props.previewSize)}
|
||||
onClick={onClickUpload}
|
||||
>
|
||||
<Icon name={props.uploadIcon} class={bem('upload-icon')} />
|
||||
{props.uploadText && (
|
||||
|
@ -619,3 +619,9 @@ test('should not render upload input when using readonly prop', async () => {
|
||||
|
||||
expect(wrapper.html()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should emit click-upload event when upload area is clicked', async () => {
|
||||
const wrapper = mount(Uploader);
|
||||
wrapper.find('.van-uploader__upload').trigger('click');
|
||||
expect(wrapper.emitted('click-upload')).toBeTruthy();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user