48
48
@click =" handleClickIndex(item[acceptKey])"
49
49
>
50
50
{{ item[acceptKey] }}
51
- </view
52
- >
51
+ </view >
53
52
</view >
54
53
</view >
55
54
</view >
56
55
</template >
57
56
<script lang="ts">
58
- import { computed , reactive , toRefs , nextTick , ref , Ref , watch , PropType } from ' vue'
57
+ import { computed , reactive , toRefs , ref , Ref , watch , PropType } from ' vue'
59
58
import { createComponent } from ' @/packages/utils/create'
60
59
import { ElevatorData } from ' ./type'
61
60
const { create } = createComponent (' elevator' )
@@ -117,9 +116,7 @@ export default create({
117
116
scrollY: 0
118
117
})
119
118
120
- const clientHeight = computed (() => {
121
- return listview .value .clientHeight
122
- })
119
+ const clientHeight = computed (() => listview .value .clientHeight )
123
120
124
121
const fixedStyle = computed (() => {
125
122
return {
@@ -135,11 +132,9 @@ export default create({
135
132
}
136
133
137
134
const setListGroup = (el : any ) => {
138
- nextTick (() => {
139
- if (! state .listGroup .includes (el ) && el != null ) {
140
- state .listGroup .push (el )
141
- }
142
- })
135
+ if (! state .listGroup .includes (el ) && el != null ) {
136
+ state .listGroup .push (el )
137
+ }
143
138
}
144
139
145
140
const calculateHeight = () => {
@@ -149,7 +144,7 @@ export default create({
149
144
for (let i = 0 ; i < state .listGroup .length ; i ++ ) {
150
145
state .query .selectAll (` .elevator__item__${i } ` ).boundingClientRect ()
151
146
state .query .exec ((res ) => {
152
- height += Math .floor (res [i ][0 ].height )
147
+ height += Math .round (res [i ][0 ].height )
153
148
state .listHeight .push (height )
154
149
})
155
150
}
@@ -167,8 +162,8 @@ export default create({
167
162
168
163
const touchStart = (e : TouchEvent ) => {
169
164
state .scrollStart = true
170
- let index = getData (e .target as HTMLElement )
171
- let firstTouch = e .touches [0 ]
165
+ const index = getData (e .target as HTMLElement )
166
+ const firstTouch = e .touches [0 ]
172
167
state .touchState .y1 = firstTouch .pageY
173
168
state .anchorIndex = + index
174
169
state .codeIndex = + index
@@ -198,14 +193,15 @@ export default create({
198
193
}
199
194
200
195
const listViewScroll = (e : Event ) => {
201
- let target = e .target as Element
202
- let scrollTop = target .scrollTop
196
+ const target = e .target as Element
197
+ const scrollTop = target .scrollTop
203
198
const listHeight = state .listHeight
204
- state .scrollY = Math .floor (scrollTop )
205
- for (let i = 0 ; i < listHeight .length - 1 ; i ++ ) {
206
- let height1 = listHeight [i ]
207
- let height2 = listHeight [i + 1 ]
208
- if (state .scrollY >= height1 && state .scrollY < height2 ) {
199
+ const listTotal = listHeight .length
200
+ state .scrollY = Math .round (scrollTop )
201
+
202
+ for (let i = 0 ; i < listTotal - 1 ; i ++ ) {
203
+ const [startHeight, endHeight] = [listHeight [i ], listHeight [i + 1 ]]
204
+ if (state .scrollY >= startHeight && state .scrollY < endHeight ) {
209
205
state .currentIndex = i
210
206
return
211
207
}
0 commit comments