1
1
<template >
2
2
<view class =" nut-picker__list" @touchstart =" onTouchStart" @touchmove =" onTouchMove" @touchend =" onTouchEnd" >
3
- <view class =" nut-picker-roller" ref =" roller" :style =" touchTileStyle" @transitionend =" stopMomentum" >
4
- <!-- 3D 效果 -->
5
- <view
6
- class =" nut-picker-roller-item"
7
- :class =" { 'nut-picker-roller-item-hidden': isHidden(index + 1) }"
8
- v-for =" (item, index) in column"
9
- :style =" setRollerStyle(index + 1)"
10
- :key =" item.value ? item.value : index"
11
- >
12
- {{ item.text }}
13
- </view >
3
+ <view
4
+ class =" nut-picker-roller"
5
+ ref =" roller"
6
+ :id =" 'roller' + refRandomId"
7
+ :style =" threeDimensional ? touchRollerStyle : touchTileStyle"
8
+ @transitionend =" stopMomentum"
9
+ >
10
+ <template v-for =" (item , index ) in column " :key =" item .value ? item .value : index " >
11
+ <!-- 3D 效果 -->
12
+ <view
13
+ class =" nut-picker-roller-item"
14
+ :class =" { 'nut-picker-roller-item-hidden': isHidden(index + 1) }"
15
+ :style =" setRollerStyle(index + 1)"
16
+ v-if =" item && item.text && threeDimensional"
17
+ >
18
+ {{ item.text }}
19
+ </view >
20
+ <!-- 平铺 -->
21
+ <view class =" nut-picker-roller-item-tile" v-if =" item && item.text && !threeDimensional" >
22
+ {{ item.text }}
23
+ </view >
24
+ </template >
14
25
</view >
15
26
<view class =" nut-picker-roller-mask" ></view >
16
- <view class =" nut-picker-content" >
17
- <view class =" nut-picker-list-panel" ref =" list" :id =" 'list' + refRandomId" :style =" touchListStyle " > </view >
27
+ <view class =" nut-picker-content" ref = " listbox " :id = " 'listbox' + refRandomId " v-if = " threeDimensional " >
28
+ <view class =" nut-picker-list-panel" ref =" list" :id =" 'list' + refRandomId" :style =" touchTileStyle " > </view >
18
29
</view >
19
30
</view >
20
31
</template >
@@ -76,6 +87,7 @@ export default create({
76
87
const roller = ref (null );
77
88
const list = ref (null );
78
89
const listitem = ref (null );
90
+ const listbox = ref (null );
79
91
80
92
const moving = ref (false ); // 是否处于滚动中
81
93
const touchDeg = ref (0 );
@@ -88,14 +100,14 @@ export default create({
88
100
const INERTIA_TIME = 300 ;
89
101
const INERTIA_DISTANCE = 15 ;
90
102
91
- const touchListStyle = computed (() => {
103
+ const touchTileStyle = computed (() => {
92
104
return {
93
105
transition: ` transform ${touchTime .value }ms cubic-bezier(0.17, 0.89, 0.45, 1) ` ,
94
106
transform: ` translate3d(0, ${state .scrollDistance }px, 0) `
95
107
};
96
108
});
97
109
98
- const touchTileStyle = computed (() => {
110
+ const touchRollerStyle = computed (() => {
99
111
return {
100
112
transition: ` transform ${touchTime .value }ms cubic-bezier(0.17, 0.89, 0.45, 1) ` ,
101
113
transform: ` rotate3d(1, 0, 0, ${touchDeg .value }) `
@@ -108,8 +120,12 @@ export default create({
108
120
const onTouchStart = (event : TouchEvent ) => {
109
121
touch .start (event );
110
122
if (moving .value ) {
111
- const { transform } = window .getComputedStyle (list .value as any );
123
+ let dom = list .value as any ;
124
+ if (! props .threeDimensional ) {
125
+ dom = roller .value as any ;
126
+ }
112
127
128
+ const { transform } = window .getComputedStyle (dom );
113
129
state .scrollDistance = + parseInt (transform .split (' , ' )[1 ]);
114
130
}
115
131
@@ -255,11 +271,12 @@ export default create({
255
271
// 惯性滚动结束
256
272
const stopMomentum = () => {
257
273
moving .value = false ;
258
- console .log (' 滚动结束' );
259
274
setChooseValue ();
260
275
};
261
276
262
277
const getReference = async () => {
278
+ const refe = await useTaroRect (listbox , Taro );
279
+ state .lineSpacing = refe .height ? refe .height : 36 ;
263
280
modifyStatus (true );
264
281
};
265
282
@@ -319,11 +336,12 @@ export default create({
319
336
roller ,
320
337
list ,
321
338
listitem ,
339
+ listbox ,
322
340
onTouchStart ,
323
341
onTouchMove ,
324
342
onTouchEnd ,
325
343
touchTileStyle ,
326
- touchListStyle ,
344
+ touchRollerStyle ,
327
345
setMove ,
328
346
refRandomId ,
329
347
stopMomentum
0 commit comments