mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
修复长按图片后,图片会隐藏问题 (#32)
* fix: 修复长按图片,图片隐藏问题 * fix: button style * fix: preview unit test * fix: init datetime-picker unit test
This commit is contained in:
parent
f4dc7982d9
commit
525a415aee
@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<transition name="image-fade">
|
||||
<div class="van-image-preview" ref="previewContainer" v-show="value" @click="handlePreviewClick">
|
||||
<div class="van-image-preview" ref="previewContainer" v-show="value">
|
||||
<van-swipe>
|
||||
<van-swipe-item v-for="item in images">
|
||||
<img class="van-image-preview__image" @load="handleLoad" :src="item" alt="">
|
||||
@ -11,6 +11,7 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Vue from 'vue';
|
||||
import Popup from 'src/mixins/popup';
|
||||
import VanSwipe from 'packages/swipe';
|
||||
import VanSwipeItem from 'packages/swipe-item';
|
||||
@ -47,12 +48,9 @@ export default {
|
||||
},
|
||||
|
||||
methods: {
|
||||
handlePreviewClick() {
|
||||
this.value = false;
|
||||
},
|
||||
|
||||
handleLoad(event) {
|
||||
const containerSize = this.$refs.previewContainer.getBoundingClientRect();
|
||||
const container = this.$refs.previewContainer;
|
||||
const containerSize = container.getBoundingClientRect();
|
||||
const ratio = containerSize.width / containerSize.height;
|
||||
const target = event.currentTarget;
|
||||
const targetRatio = target.width / target.height;
|
||||
@ -88,6 +86,28 @@ export default {
|
||||
this.opened = false;
|
||||
this.doAfterClose();
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
const supportTouch = !Vue.prototype.$isServer && 'ontouchstart' in window;
|
||||
const container = this.$refs.previewContainer;
|
||||
|
||||
if (supportTouch) {
|
||||
let touchStartTime;
|
||||
|
||||
container.addEventListener('touchstart', () => {
|
||||
touchStartTime = new Date();
|
||||
});
|
||||
container.addEventListener('touchend', () => {
|
||||
if (new Date() - touchStartTime < 1500) {
|
||||
this.value = false;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
container.addEventListener('click', () => {
|
||||
this.value = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
@ -18,7 +18,11 @@
|
||||
|
||||
&::after {
|
||||
content: " ";
|
||||
position: absolute 0 0 0 0;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: #000;
|
||||
opacity: 0;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ var travis = process.env.TRAVIS;
|
||||
|
||||
module.exports = function(config) {
|
||||
config.set({
|
||||
browsers: travis ? ['PhantomJS'] : ['Chrome'],
|
||||
browsers: travis ? ['PhantomJS'] : ['PhantomJS', 'Chrome'],
|
||||
frameworks: ['mocha', 'sinon-chai'],
|
||||
reporters: ['spec', 'coverage'],
|
||||
files: ['./index.js'],
|
||||
|
42
test/unit/specs/datetime-picker.spec.js
Normal file
42
test/unit/specs/datetime-picker.spec.js
Normal file
@ -0,0 +1,42 @@
|
||||
import DatetimePicker from 'packages/datetime-picker';
|
||||
import { mount } from 'avoriaz';
|
||||
|
||||
describe('DatetimePicker', () => {
|
||||
let wrapper;
|
||||
afterEach(() => {
|
||||
wrapper && wrapper.destroy();
|
||||
});
|
||||
|
||||
it('create a datetime picker', () => {
|
||||
const date = new Date();
|
||||
wrapper = mount(DatetimePicker, {
|
||||
propsData: {
|
||||
type: 'datetime',
|
||||
value: date
|
||||
}
|
||||
});
|
||||
expect(wrapper.data().innerValue.getTime()).to.equal(date.getTime());
|
||||
});
|
||||
|
||||
it('create a date picker', () => {
|
||||
const date = new Date();
|
||||
wrapper = mount(DatetimePicker, {
|
||||
propsData: {
|
||||
type: 'date',
|
||||
value: date
|
||||
}
|
||||
});
|
||||
expect(wrapper.data().innerValue.getTime()).to.equal(date.getTime());
|
||||
});
|
||||
|
||||
it('create a time picker', () => {
|
||||
const time = '10:00';
|
||||
wrapper = mount(DatetimePicker, {
|
||||
propsData: {
|
||||
type: 'time',
|
||||
value: time
|
||||
}
|
||||
});
|
||||
expect(wrapper.data().innerValue).to.equal(time);
|
||||
});
|
||||
});
|
@ -1,4 +1,5 @@
|
||||
import ImagePreview from 'packages/image-preview';
|
||||
import Wrapper from 'avoriaz/dist/Wrapper';
|
||||
|
||||
describe('ImagePreview', () => {
|
||||
beforeEach(() => {
|
||||
@ -22,7 +23,11 @@ describe('ImagePreview', () => {
|
||||
expect(document.querySelector('.van-image-preview')).to.exist;
|
||||
|
||||
setTimeout(() => {
|
||||
document.querySelector('.van-swipe-item').click();
|
||||
const image = document.querySelector('.van-image-preview');
|
||||
const avImage = new Wrapper({ elm: image }, () => {}, false);
|
||||
avImage.simulate('click');
|
||||
avImage.simulate('touchstart');
|
||||
avImage.simulate('touchend');
|
||||
setTimeout(() => {
|
||||
expect(document.querySelector('.van-image-preview').__vue__.$parent.value).to.be.false;
|
||||
expect(document.body.style.overflow).to.equal('');
|
||||
@ -42,7 +47,12 @@ describe('ImagePreview', () => {
|
||||
expect(document.querySelector('.van-image-preview')).to.exist;
|
||||
|
||||
setTimeout(() => {
|
||||
document.querySelector('.van-swipe-item').click();
|
||||
const image = document.querySelector('.van-image-preview');
|
||||
const avImage = new Wrapper({ elm: image }, () => {}, false);
|
||||
avImage.simulate('click');
|
||||
avImage.simulate('touchstart');
|
||||
avImage.simulate('touchend');
|
||||
|
||||
setTimeout(() => {
|
||||
expect(document.querySelector('.van-image-preview').__vue__.$parent.value).to.be.false;
|
||||
expect(document.body.style.overflow).to.equal('hidden');
|
||||
|
Loading…
x
Reference in New Issue
Block a user