[new feature] ImagePreview support manually close (#346)

* fix: Tabbar icon line-height

* [new feature] progress add showPivot prop

* [new feature] TabItem support vue-router

* [new feature] update document header style

* [Doc] add toast english ducoment

* [bugfix] Search box-sizing wrong

* [Doc] update vant-demo respo

* [Doc] translate theme & demo pages

* [Doc] add Internationalization document

* [bugfix] remove unnecessary props

* [fix] optimize clickoutside

* [new feature] optimize find-parent

* [new feature]: change document title accordinng to language

* [new feature] Pagination code review

* [improvement] adjust icon-font unicode

* [improvement] Icon spinner color inherit

* [improvement] icon default width

* [bugfix] DateTimePicker validate date props

* [bugfix] Tab item text ellipsis

* [improvement] optimize single line ellipsis

* [Improvement] optimzie staticClass

* [Improvement] Button: use sfc instread of jsx

* [Improvement] update actionsheet close icon style

* fix: yarn.lock

* fix: icon test cases

* [bugfix] errors during ssr

* [Improvement] SubmitBar add left slot

* [new feature] ImagePreview support manually close

* fix: ImagePreview test case
This commit is contained in:
neverland 2017-11-23 21:50:10 +08:00 committed by GitHub
parent 493371c7a1
commit 4ff7987cde
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 52 additions and 6 deletions

View File

@ -7,6 +7,10 @@
<demo-block :title="$t('button2')">
<van-button @click="showImagePreview(1)">{{ $t('button2') }}</van-button>
</demo-block>
<demo-block :title="$t('button3')">
<van-button @click="showImagePreview(0, 1000)">{{ $t('button3') }}</van-button>
</demo-block>
</demo-section>
</template>
@ -17,21 +21,29 @@ export default {
i18n: {
'zh-CN': {
button1: '预览图片',
button2: '指定初始位置'
button2: '指定初始位置',
button3: '手动关闭'
},
'en-US': {
button1: 'Show Images',
button2: 'Custom Start Position'
button2: 'Custom Start Position',
button3: 'Close Manually'
}
},
methods: {
showImagePreview(position) {
ImagePreview([
showImagePreview(position, timer) {
const instance = ImagePreview([
'https://img.yzcdn.cn/upload_files/2017/03/15/FkubrzN7AgGwLlTeb1E89-T_ZjBg.png',
'https://img.yzcdn.cn/upload_files/2017/03/14/FmTPs0SeyQaAOSK1rRe1sL8RcwSY.jpeg',
'https://img.yzcdn.cn/upload_files/2017/03/15/FvexrWlG_WxtCE9Omo5l27n_mAG_.jpeg'
], typeof position === 'number' ? position : 0);
if (timer) {
setTimeout(() => {
instance.close();
}, timer);
}
}
}
};

View File

@ -25,6 +25,19 @@ ImagePreview([
], 1);
```
#### Close Manually
```javascript
const instance = ImagePreview([
'https://img.yzcdn.cn/1.jpg',
'https://img.yzcdn.cn/2.jpg'
]);
setTimeout(() => {
instance.close();
}, 1000);
```
### Arguments
| Attribute | Description | Type |

View File

@ -28,6 +28,19 @@ ImagePreview([
], 1);
```
#### 手动关闭
```javascript
const instance = ImagePreview([
'https://img.yzcdn.cn/1.jpg',
'https://img.yzcdn.cn/2.jpg'
]);
setTimeout(() => {
instance.close();
}, 1000);
```
### 方法参数
| 参数名 | 说明 | 类型 |

View File

@ -66,7 +66,7 @@ export default {
// prevent long tap to close component
const deltaTime = new Date() - this.touchStartTime;
if (deltaTime < 100 && Math.abs(this.deltaX) < 20 && Math.abs(this.deltaY) < 20) {
this.value = false;
this.close();
}
}
}

View File

@ -20,6 +20,11 @@ const ImagePreviewBox = (images, startPosition = 0) => {
instance.images = images;
instance.startPosition = startPosition;
instance.value = true;
instance.$on('input', show => {
instance.value = show;
});
return instance;
};
export default ImagePreviewBox;

View File

@ -32,7 +32,7 @@ const PopupManager = {
}
},
openModal({id, zIndex, dom, extraClass, extraStyle}) {
openModal({ id, zIndex, dom, extraClass, extraStyle }) {
const { modalStack } = context;
const exist = modalStack.some(item => item.id === id);

View File

@ -34,6 +34,9 @@ describe('ImagePreview', () => {
wrapper = mount(ImagePreviewVue);
wrapper.vm.images = images;
wrapper.vm.value = true;
wrapper.vm.$on('input', val => {
wrapper.vm.value = val;
});
expect(wrapper.hasClass('van-image-preview')).to.be.true;