mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[new feature] ImagePreview: add closeOnPopstate prop
This commit is contained in:
parent
30ddcb5daa
commit
b572c76245
@ -1,4 +1,4 @@
|
|||||||
import { use, range } from '../utils';
|
import { use, range, isServer } from '../utils';
|
||||||
import { preventDefault } from '../utils/event';
|
import { preventDefault } from '../utils/event';
|
||||||
import { PopupMixin } from '../mixins/popup';
|
import { PopupMixin } from '../mixins/popup';
|
||||||
import { TouchMixin } from '../mixins/touch';
|
import { TouchMixin } from '../mixins/touch';
|
||||||
@ -26,6 +26,7 @@ export default sfc({
|
|||||||
asyncClose: Boolean,
|
asyncClose: Boolean,
|
||||||
startPosition: Number,
|
startPosition: Number,
|
||||||
showIndicators: Boolean,
|
showIndicators: Boolean,
|
||||||
|
closeOnPopstate: Boolean,
|
||||||
loop: {
|
loop: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true
|
default: true
|
||||||
@ -57,6 +58,8 @@ export default sfc({
|
|||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
|
this.bindStatus = false;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
scale: 1,
|
scale: 1,
|
||||||
moveX: 0,
|
moveX: 0,
|
||||||
@ -90,10 +93,30 @@ export default sfc({
|
|||||||
|
|
||||||
startPosition(active) {
|
startPosition(active) {
|
||||||
this.active = active;
|
this.active = active;
|
||||||
|
},
|
||||||
|
|
||||||
|
closeOnPopstate: {
|
||||||
|
handler(val) {
|
||||||
|
this.handlePopstate(val);
|
||||||
|
},
|
||||||
|
immediate: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
handlePopstate(bind) {
|
||||||
|
/* istanbul ignore if */
|
||||||
|
if (isServer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.bindStatus !== bind) {
|
||||||
|
this.bindStatus = bind;
|
||||||
|
const action = bind ? 'add' : 'remove';
|
||||||
|
window[`${action}EventListener`]('popstate', this.close);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
onWrapperTouchStart() {
|
onWrapperTouchStart() {
|
||||||
this.touchStartTime = new Date();
|
this.touchStartTime = new Date();
|
||||||
},
|
},
|
||||||
|
@ -94,6 +94,7 @@ export default {
|
|||||||
const instance = ImagePreview({
|
const instance = ImagePreview({
|
||||||
images,
|
images,
|
||||||
asyncClose: !!timer,
|
asyncClose: !!timer,
|
||||||
|
closeOnPopstate: true,
|
||||||
startPosition: typeof position === 'number' ? position : 0
|
startPosition: typeof position === 'number' ? position : 0
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -95,6 +95,7 @@ export default {
|
|||||||
| showIndicators | Whether to show indicators | `Boolean` | `false` |
|
| showIndicators | Whether to show indicators | `Boolean` | `false` |
|
||||||
| loop | Whether to enable loop | `Boolean` | `true` |
|
| loop | Whether to enable loop | `Boolean` | `true` |
|
||||||
| onClose | Close callback | `Function` | - |
|
| onClose | Close callback | `Function` | - |
|
||||||
|
| closeOnPopstate | Whether to close when popstate | `Boolean` | `false` |
|
||||||
| asyncClose | Whether to enable async close | `Boolean` | `false` |
|
| asyncClose | Whether to enable async close | `Boolean` | `false` |
|
||||||
| className | Custom className | `String | Array | Object` | - |
|
| className | Custom className | `String | Array | Object` | - |
|
||||||
| lazyLoad | Whether to enable thumb lazy load,should register [Lazyload](#/en-US/lazyload) component | `Boolean` | `false` |
|
| lazyLoad | Whether to enable thumb lazy load,should register [Lazyload](#/en-US/lazyload) component | `Boolean` | `false` |
|
||||||
@ -111,6 +112,7 @@ export default {
|
|||||||
| show-indicators | Whether to show indicators | `Boolean` | `false` |
|
| show-indicators | Whether to show indicators | `Boolean` | `false` |
|
||||||
| loop | Whether to enable loop | `Boolean` | `true` |
|
| loop | Whether to enable loop | `Boolean` | `true` |
|
||||||
| async-close | Whether to enable async close | `Boolean` | `false` |
|
| async-close | Whether to enable async close | `Boolean` | `false` |
|
||||||
|
| close-on-popstate | Whether to close when popstate | `Boolean` | `false` |
|
||||||
| class-name | Custom className | `String | Array | Object` | - |
|
| class-name | Custom className | `String | Array | Object` | - |
|
||||||
| lazy-load | Whether to enable thumb lazy load,should register [Lazyload](#/en-US/lazyload) component | `Boolean` | `false` |
|
| lazy-load | Whether to enable thumb lazy load,should register [Lazyload](#/en-US/lazyload) component | `Boolean` | `false` |
|
||||||
| max-zoom | Max zoom | `Number` | `3` |
|
| max-zoom | Max zoom | `Number` | `3` |
|
||||||
|
@ -15,7 +15,8 @@ const defaultConfig = {
|
|||||||
showIndex: true,
|
showIndex: true,
|
||||||
asyncClose: false,
|
asyncClose: false,
|
||||||
startPosition: 0,
|
startPosition: 0,
|
||||||
showIndicators: false
|
showIndicators: false,
|
||||||
|
closeOnPopstate: false
|
||||||
};
|
};
|
||||||
|
|
||||||
const initInstance = () => {
|
const initInstance = () => {
|
||||||
|
@ -116,3 +116,24 @@ test('index slot', () => {
|
|||||||
|
|
||||||
expect(wrapper).toMatchSnapshot();
|
expect(wrapper).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('closeOnPopstate', () => {
|
||||||
|
const wrapper = mount(ImagePreviewVue, {
|
||||||
|
propsData: {
|
||||||
|
images,
|
||||||
|
value: true,
|
||||||
|
closeOnPopstate: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
trigger(window, 'popstate');
|
||||||
|
expect(wrapper.emitted('input')[0][0]).toBeFalsy();
|
||||||
|
|
||||||
|
wrapper.setProps({
|
||||||
|
value: true,
|
||||||
|
closeOnPopstate: false
|
||||||
|
});
|
||||||
|
|
||||||
|
trigger(window, 'popstate');
|
||||||
|
expect(wrapper.emitted('input')[1]).toBeFalsy();
|
||||||
|
});
|
||||||
|
@ -108,6 +108,7 @@ export default {
|
|||||||
| loop | 是否开启循环播放 | `Boolean` | `true` | 1.4.4 |
|
| loop | 是否开启循环播放 | `Boolean` | `true` | 1.4.4 |
|
||||||
| onClose | 关闭时的回调函数 | `Function` | - | 1.1.16 |
|
| onClose | 关闭时的回调函数 | `Function` | - | 1.1.16 |
|
||||||
| asyncClose | 是否开启异步关闭 | `Boolean` | `false` | 1.4.8 |
|
| asyncClose | 是否开启异步关闭 | `Boolean` | `false` | 1.4.8 |
|
||||||
|
| closeOnPopstate | 是否在页面回退时自动关闭 | `Boolean` | `false` | 2.0.0 |
|
||||||
| className | 自定义类名 | `String | Array | Object` | - | 1.5.2 |
|
| className | 自定义类名 | `String | Array | Object` | - | 1.5.2 |
|
||||||
| lazyLoad | 是否开启图片懒加载,须配合 [Lazyload](#/zh-CN/lazyload) 组件使用 | `Boolean` | `false` | 1.5.3 |
|
| lazyLoad | 是否开启图片懒加载,须配合 [Lazyload](#/zh-CN/lazyload) 组件使用 | `Boolean` | `false` | 1.5.3 |
|
||||||
| maxZoom | 手势缩放时,最大缩放比例 | `Number` | `3` | 1.6.14 |
|
| maxZoom | 手势缩放时,最大缩放比例 | `Number` | `3` | 1.6.14 |
|
||||||
@ -125,6 +126,7 @@ export default {
|
|||||||
| show-indicators | 是否显示轮播指示器 | `Boolean` | `false` | 1.3.10 |
|
| show-indicators | 是否显示轮播指示器 | `Boolean` | `false` | 1.3.10 |
|
||||||
| loop | 是否开启循环播放 | `Boolean` | `true` | 1.4.4 |
|
| loop | 是否开启循环播放 | `Boolean` | `true` | 1.4.4 |
|
||||||
| async-close | 是否开启异步关闭 | `Boolean` | `false` | 1.4.8 |
|
| async-close | 是否开启异步关闭 | `Boolean` | `false` | 1.4.8 |
|
||||||
|
| close-on-popstate | 是否在页面回退时自动关闭 | `Boolean` | `false` |
|
||||||
| class-name | 自定义类名 | `String | Array | Object` | - | 1.5.2 |
|
| class-name | 自定义类名 | `String | Array | Object` | - | 1.5.2 |
|
||||||
| lazy-load | 是否开启图片懒加载,须配合 [Lazyload](#/zh-CN/lazyload) 组件使用 | `Boolean` | `false` | 1.5.3 |
|
| lazy-load | 是否开启图片懒加载,须配合 [Lazyload](#/zh-CN/lazyload) 组件使用 | `Boolean` | `false` | 1.5.3 |
|
||||||
| max-zoom | 手势缩放时,最大缩放比例 | `Number` | `3` | 1.6.14 |
|
| max-zoom | 手势缩放时,最大缩放比例 | `Number` | `3` | 1.6.14 |
|
||||||
|
1
types/image-preview.d.ts
vendored
1
types/image-preview.d.ts
vendored
@ -11,6 +11,7 @@ export type ImagePreviewOptions = string[] | {
|
|||||||
showIndex?: boolean;
|
showIndex?: boolean;
|
||||||
asyncClose?: boolean;
|
asyncClose?: boolean;
|
||||||
showIndicators?: boolean;
|
showIndicators?: boolean;
|
||||||
|
closeOnPopstate?: boolean;
|
||||||
onClose?: () => any;
|
onClose?: () => any;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user