Skip to content
This repository was archived by the owner on Oct 27, 2021. It is now read-only.

Commit 08880e8

Browse files
author
pengshanglong
committed
fix(taro-ui-vue): H5 calendar swipe event
1 parent 18cd9c6 commit 08880e8

File tree

2 files changed

+96
-20
lines changed

2 files changed

+96
-20
lines changed

packages/taro-ui-vue/src/components/calendar/body/index.js

+44-12
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,11 @@ import classnames from 'classnames'
33
import dayjs from 'dayjs'
44
import { delayQuerySelector } from '../../../utils/common'
55
import generateCalendarGroup from '../common/helper'
6-
import AtCalendarDateList from '../ui/date-list/index.vue'
7-
import AtCalendarDayList from '../ui/day-list/index.vue'
86
import mixins from '../../mixins'
97

108
const ANIMTE_DURATION = 300
119

1210
const AtCalendarBody = Vue.extend({
13-
name: 'AtCalendarBody',
14-
components: {
15-
AtCalendarDateList,
16-
AtCalendarDayList,
17-
},
1811
mixins: [mixins],
1912
props: {
2013
marks: {
@@ -62,12 +55,22 @@ const AtCalendarBody = Vue.extend({
6255
},
6356
onDayClick: {
6457
type: Function,
65-
default: () => () => {},
58+
default: function() {
59+
return () => {}
60+
},
6661
},
6762
onLongClick: {
6863
type: Function,
69-
default: () => () => {},
64+
default: function() {
65+
return () => {}
66+
},
7067
},
68+
onSwipeMonth: {
69+
type: Function,
70+
default: function() {
71+
return () => {}
72+
}
73+
}
7174
},
7275
data() {
7376
const { validDates, marks, format, minDate, maxDate, selectedDates } = this
@@ -93,6 +96,7 @@ const AtCalendarBody = Vue.extend({
9396
offsetSize: 0,
9497
isAnimate: false,
9598
},
99+
isH5: process.env.TARO_ENV === 'h5',
96100
}
97101
},
98102
computed: {
@@ -118,6 +122,32 @@ const AtCalendarBody = Vue.extend({
118122
selectedDates,
119123
}
120124
},
125+
h5CalendarBody() {
126+
return classnames(
127+
'main',
128+
'at-calendar-slider__main',
129+
`at-calendar-slider__main--${process.env.TARO_ENV}`
130+
)
131+
},
132+
h5CalendarMainBodyCls() {
133+
const { isSwiper, isAnimate } = this
134+
return classnames('main__body body', {
135+
'main__body--slider': isSwiper,
136+
'main__body--animate': isAnimate
137+
})
138+
},
139+
h5CalendarMainBodyStyle() {
140+
const { isSwiper } = this
141+
const { offsetSize } = this.state
142+
return {
143+
transform: isSwiper
144+
? `translateX(-100%) translate3d(${offsetSize},0,0)`
145+
: '',
146+
WebkitTransform: isSwiper
147+
? `translateX(-100%) translate3d(${offsetSize}px,0,0)`
148+
: ''
149+
}
150+
}
121151
},
122152
watch: {
123153
nextProps(val) {
@@ -155,7 +185,9 @@ const AtCalendarBody = Vue.extend({
155185
},
156186
mounted() {
157187
delayQuerySelector(this, '.at-calendar-slider__main').then((res) => {
158-
this.maxWidth = res[0].width
188+
if (res[0]) {
189+
this.maxWidth = res[0].width
190+
}
159191
})
160192
},
161193
methods: {
@@ -241,7 +273,7 @@ const AtCalendarBody = Vue.extend({
241273
if (absOffsetSize > breakpoint) {
242274
const res = isRight ? this.maxWidth : -this.maxWidth
243275
return this.animateMoveSlide(res, () => {
244-
this.atSwipeMonth(isRight ? -1 : 1)
276+
this.onSwipeMonth(isRight ? -1 : 1)
245277
})
246278
}
247279
this.animateMoveSlide(0)
@@ -256,7 +288,7 @@ const AtCalendarBody = Vue.extend({
256288
},
257289
handleAnimateFinish() {
258290
if (this.changeCount > 0) {
259-
this.atSwipeMonth(this.isPreMonth ? -this.changeCount : this.changeCount)
291+
this.onSwipeMonth(this.isPreMonth ? -this.changeCount : this.changeCount)
260292
this.changeCount = 0
261293
}
262294
},

packages/taro-ui-vue/src/components/calendar/body/index.vue

+52-8
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,46 @@
1010
:list="state.listGroup[1].list"
1111
:on-click="onDayClick"
1212
:on-long-click="onLongClick"
13+
></AtCalendarDateList>
14+
</view>
15+
</view>
16+
</view>
17+
<view
18+
v-if="isH5"
19+
:class="h5CalendarBody"
20+
@touchend="handleTouchEnd"
21+
@touchmove="handleTouchMove"
22+
@touchstart="handleTouchStart"
23+
>
24+
<AtCalendarDayList />
25+
<view
26+
:class="h5CalendarMainBodyCls"
27+
:style="h5CalendarMainBodyStyle"
28+
>
29+
<view class='body__slider body__slider--pre'>
30+
<AtCalendarDateList
31+
:key="state.listGroup[0].value"
32+
:list="state.listGroup.length ? state.listGroup[0].list : []"
33+
/>
34+
</view>
35+
<view class='body__slider body__slider--now'>
36+
<AtCalendarDateList
37+
:key="state.listGroup[1].value"
38+
:list="state.listGroup.length ? state.listGroup[1].list : []"
39+
:on-click="onDayClick"
40+
:on-long-click="onLongClick"
41+
/>
42+
</view>
43+
<view class='body__slider body__slider--next'>
44+
<AtCalendarDateList
45+
:key="state.listGroup[2].value"
46+
:list="state.listGroup.length ? state.listGroup[2].list : []"
1347
/>
1448
</view>
1549
</view>
1650
</view>
1751
<view
18-
v-else
52+
v-if="isSwiper && !isH5"
1953
:class="getCls">
2054
<AtCalendarDayList />
2155
<swiper
@@ -24,16 +58,17 @@
2458
skipHiddenItemLayout
2559
class="main__body"
2660
:vertical="isVertical"
27-
:on-change="handleChange"
28-
:on-animation-finish="handleAnimateFinish"
29-
:on-touch-end="handleSwipeTouchEnd"
30-
:on-touch-start="handleSwipeTouchStart"
61+
@change="handleChange"
62+
@animationfinish="handleAnimateFinish"
63+
@touchend="handleSwipeTouchEnd"
64+
@touchstart="handleSwipeTouchStart"
3165
>
3266
<swiper-item
33-
v-for="(item, key) in state.listGroup"
34-
:key="item.value"
67+
v-for="(item, key) in state.listGroup"
68+
:key="key.toString()"
3569
:itemId="key.toString()">
3670
<AtCalendarDateList
71+
:key="item.value"
3772
:list="item.list"
3873
:on-click="onDayClick"
3974
:on-long-click="onLongClick"
@@ -45,5 +80,14 @@
4580
</template>
4681
<script>
4782
import AtCalendarBody from './index';
48-
export default AtCalendarBody
83+
import AtCalendarDateList from '../ui/date-list/index.vue'
84+
import AtCalendarDayList from '../ui/day-list/index.vue'
85+
export default {
86+
name: 'AtCalendarBody',
87+
mixins: [AtCalendarBody],
88+
components: {
89+
AtCalendarDateList,
90+
AtCalendarDayList,
91+
},
92+
}
4993
</script>

0 commit comments

Comments
 (0)