mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
[improvement] Swipe: jsx (#2626)
This commit is contained in:
parent
4e6d0b9c79
commit
fab090bef9
@ -9,7 +9,6 @@ exports[`render image 1`] = `
|
|||||||
<div class="van-swipe-item" style="width: 0px; height: 100%; transform: translateX(0px);"><img src="https://img.yzcdn.cn/2.png" class="van-image-preview__image"></div>
|
<div class="van-swipe-item" style="width: 0px; height: 100%; transform: translateX(0px);"><img src="https://img.yzcdn.cn/2.png" class="van-image-preview__image"></div>
|
||||||
<div class="van-swipe-item" style="width: 0px; height: 100%; transform: translateX(0px);"><img src="https://img.yzcdn.cn/3.png" class="van-image-preview__image"></div>
|
<div class="van-swipe-item" style="width: 0px; height: 100%; transform: translateX(0px);"><img src="https://img.yzcdn.cn/3.png" class="van-image-preview__image"></div>
|
||||||
</div>
|
</div>
|
||||||
<!---->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
@ -23,7 +22,6 @@ exports[`zoom 1`] = `
|
|||||||
<div class="van-swipe-item" style="width: 100px; height: 100%; transform: translateX(0px);"><img src="https://img.yzcdn.cn/2.png" class="van-image-preview__image"></div>
|
<div class="van-swipe-item" style="width: 100px; height: 100%; transform: translateX(0px);"><img src="https://img.yzcdn.cn/2.png" class="van-image-preview__image"></div>
|
||||||
<div class="van-swipe-item" style="width: 100px; height: 100%; transform: translateX(0px);"><img src="https://img.yzcdn.cn/3.png" class="van-image-preview__image"></div>
|
<div class="van-swipe-item" style="width: 100px; height: 100%; transform: translateX(0px);"><img src="https://img.yzcdn.cn/3.png" class="van-image-preview__image"></div>
|
||||||
</div>
|
</div>
|
||||||
<!---->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { use } from '../utils';
|
import { use } from '../utils';
|
||||||
|
import { stop } from '../utils/event';
|
||||||
import Key from './Key';
|
import Key from './Key';
|
||||||
|
|
||||||
const [sfc, bem, t] = use('number-keyboard');
|
const [sfc, bem, t] = use('number-keyboard');
|
||||||
@ -140,9 +141,7 @@ export default sfc({
|
|||||||
v-show={this.show}
|
v-show={this.show}
|
||||||
style={{ zIndex: this.zIndex }}
|
style={{ zIndex: this.zIndex }}
|
||||||
class={bem([theme])}
|
class={bem([theme])}
|
||||||
onTouchstart={event => {
|
onTouchstart={stop}
|
||||||
event.stopPropagation();
|
|
||||||
}}
|
|
||||||
onAnimationend={this.onAnimationEnd}
|
onAnimationend={this.onAnimationEnd}
|
||||||
onWebkitAnimationEnd={this.onAnimationEnd}
|
onWebkitAnimationEnd={this.onAnimationEnd}
|
||||||
>
|
>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import { use } from '../utils';
|
import { use } from '../utils';
|
||||||
|
import { prevent } from '../utils/event';
|
||||||
import Loading from '../loading';
|
import Loading from '../loading';
|
||||||
import PickerColumn from './PickerColumn';
|
import PickerColumn from './PickerColumn';
|
||||||
import deepClone from '../utils/deep-clone';
|
import deepClone from '../utils/deep-clone';
|
||||||
@ -171,9 +172,7 @@ export default sfc({
|
|||||||
<div
|
<div
|
||||||
class={bem('columns')}
|
class={bem('columns')}
|
||||||
style={columnsStyle}
|
style={columnsStyle}
|
||||||
onTouchmove={event => {
|
onTouchmove={prevent}
|
||||||
event.preventDefault();
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
{columns.map((item, index) => (
|
{columns.map((item, index) => (
|
||||||
<PickerColumn
|
<PickerColumn
|
||||||
|
@ -1,40 +1,10 @@
|
|||||||
<template>
|
import { use } from '../utils';
|
||||||
<div :class="b()">
|
|
||||||
<div
|
|
||||||
:style="trackStyle"
|
|
||||||
:class="b('track')"
|
|
||||||
@touchstart="onTouchStart"
|
|
||||||
@touchmove="onTouchMove"
|
|
||||||
@touchend="onTouchEnd"
|
|
||||||
@touchcancel="onTouchEnd"
|
|
||||||
@transitionend.stop="$emit('change', activeIndicator)"
|
|
||||||
>
|
|
||||||
<slot />
|
|
||||||
</div>
|
|
||||||
<slot name="indicator">
|
|
||||||
<div
|
|
||||||
v-if="showIndicators && count > 1"
|
|
||||||
:class="b('indicators', { vertical })"
|
|
||||||
@transitionend.stop
|
|
||||||
>
|
|
||||||
<i
|
|
||||||
v-for="index in count"
|
|
||||||
:class="b('indicator', { active: index - 1 === activeIndicator })"
|
|
||||||
:style="index - 1 === activeIndicator ? indicatorStyle : null"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</slot>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import create from '../utils/create';
|
|
||||||
import Touch from '../mixins/touch';
|
import Touch from '../mixins/touch';
|
||||||
import { on, off } from '../utils/event';
|
import { on, off, stop } from '../utils/event';
|
||||||
|
|
||||||
export default create({
|
const [sfc, bem] = use('swipe');
|
||||||
name: 'swipe',
|
|
||||||
|
|
||||||
|
export default sfc({
|
||||||
mixins: [Touch],
|
mixins: [Touch],
|
||||||
|
|
||||||
props: {
|
props: {
|
||||||
@ -222,8 +192,7 @@ export default create({
|
|||||||
const atLast = active === count - 1;
|
const atLast = active === count - 1;
|
||||||
const outOfBounds =
|
const outOfBounds =
|
||||||
!this.loop &&
|
!this.loop &&
|
||||||
((atFirst && (offset > 0 || move < 0)) ||
|
((atFirst && (offset > 0 || move < 0)) || (atLast && (offset < 0 || move > 0)));
|
||||||
(atLast && (offset < 0 || move > 0)));
|
|
||||||
|
|
||||||
if (outOfBounds || count <= 1) {
|
if (outOfBounds || count <= 1) {
|
||||||
return;
|
return;
|
||||||
@ -284,7 +253,45 @@ export default create({
|
|||||||
}, 30);
|
}, 30);
|
||||||
}, autoplay);
|
}, autoplay);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
onTransitionend(event) {
|
||||||
|
event.stopPropagation();
|
||||||
|
this.$emit('change', this.activeIndicator);
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
render(h) {
|
||||||
|
const { count, activeIndicator } = this;
|
||||||
|
|
||||||
|
const Indicator =
|
||||||
|
this.$slots.indicator ||
|
||||||
|
(this.showIndicators && count > 1 && (
|
||||||
|
<div class={bem('indicators', { vertical: this.vertical })} onTransitionend={stop}>
|
||||||
|
{Array(...Array(count)).map((empty, index) => (
|
||||||
|
<i
|
||||||
|
class={bem('indicator', { active: index === activeIndicator })}
|
||||||
|
style={index === activeIndicator ? this.indicatorStyle : null}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div class={bem()}>
|
||||||
|
<div
|
||||||
|
style={this.trackStyle}
|
||||||
|
class={bem('track')}
|
||||||
|
onTouchstart={this.onTouchStart}
|
||||||
|
onTouchmove={this.onTouchMove}
|
||||||
|
onTouchend={this.onTouchEnd}
|
||||||
|
onTouchcancel={this.onTouchEnd}
|
||||||
|
onTransitionend={this.onTransitionend}
|
||||||
|
>
|
||||||
|
{this.$slots.default}
|
||||||
|
</div>
|
||||||
|
{Indicator}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
|
@ -10,7 +10,6 @@ exports[`renders demo correctly 1`] = `
|
|||||||
<div class="van-swipe-item" style="width:0px;height:100%;transform:translateX(0px);">3</div>
|
<div class="van-swipe-item" style="width:0px;height:100%;transform:translateX(0px);">3</div>
|
||||||
<div class="van-swipe-item" style="width:0px;height:100%;transform:translateX(0px);">4</div>
|
<div class="van-swipe-item" style="width:0px;height:100%;transform:translateX(0px);">4</div>
|
||||||
</div>
|
</div>
|
||||||
<!---->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@ -21,7 +20,6 @@ exports[`renders demo correctly 1`] = `
|
|||||||
<div class="van-swipe-item" style="width:0px;height:100%;transform:translateX(0px);"><img></div>
|
<div class="van-swipe-item" style="width:0px;height:100%;transform:translateX(0px);"><img></div>
|
||||||
<div class="van-swipe-item" style="width:0px;height:100%;transform:translateX(0px);"><img></div>
|
<div class="van-swipe-item" style="width:0px;height:100%;transform:translateX(0px);"><img></div>
|
||||||
</div>
|
</div>
|
||||||
<!---->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@ -32,7 +30,6 @@ exports[`renders demo correctly 1`] = `
|
|||||||
<div class="van-swipe-item" style="width:0px;height:100%;transform:translateX(0px);">3</div>
|
<div class="van-swipe-item" style="width:0px;height:100%;transform:translateX(0px);">3</div>
|
||||||
<div class="van-swipe-item" style="width:0px;height:100%;transform:translateX(0px);">4</div>
|
<div class="van-swipe-item" style="width:0px;height:100%;transform:translateX(0px);">4</div>
|
||||||
</div>
|
</div>
|
||||||
<!---->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@ -43,7 +40,6 @@ exports[`renders demo correctly 1`] = `
|
|||||||
<div class="van-swipe-item" style="width:0px;height:0px;transform:translateY(0px);">3</div>
|
<div class="van-swipe-item" style="width:0px;height:0px;transform:translateY(0px);">3</div>
|
||||||
<div class="van-swipe-item" style="width:0px;height:0px;transform:translateY(0px);">4</div>
|
<div class="van-swipe-item" style="width:0px;height:0px;transform:translateY(0px);">4</div>
|
||||||
</div>
|
</div>
|
||||||
<!---->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
@ -54,7 +50,6 @@ exports[`renders demo correctly 1`] = `
|
|||||||
<div class="van-swipe-item" style="width:0px;height:100%;transform:translateX(0px);">3</div>
|
<div class="van-swipe-item" style="width:0px;height:100%;transform:translateX(0px);">3</div>
|
||||||
<div class="van-swipe-item" style="width:0px;height:100%;transform:translateX(0px);">4</div>
|
<div class="van-swipe-item" style="width:0px;height:100%;transform:translateX(0px);">4</div>
|
||||||
</div>
|
</div>
|
||||||
<!---->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
@ -30,3 +30,11 @@ export function on(target, event, handler, passive = false) {
|
|||||||
export function off(target, event, handler) {
|
export function off(target, event, handler) {
|
||||||
!isServer && target.removeEventListener(event, handler);
|
!isServer && target.removeEventListener(event, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function stop(event) {
|
||||||
|
event.stopPropagation();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function prevent(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user