Skip to content

Commit 287ab78

Browse files
committed
fix(elevator): 修复点击楼层未准确高亮对应的楼层位置信息
1 parent a415d0b commit 287ab78

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

src/packages/__VUE/elevator/index.taro.vue

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,13 @@
4848
@click="handleClickIndex(item[acceptKey])"
4949
>
5050
{{ item[acceptKey] }}
51-
</view
52-
>
51+
</view>
5352
</view>
5453
</view>
5554
</view>
5655
</template>
5756
<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'
5958
import { createComponent } from '@/packages/utils/create'
6059
import { ElevatorData } from './type'
6160
const { create } = createComponent('elevator')
@@ -117,9 +116,7 @@ export default create({
117116
scrollY: 0
118117
})
119118
120-
const clientHeight = computed(() => {
121-
return listview.value.clientHeight
122-
})
119+
const clientHeight = computed(() => listview.value.clientHeight)
123120
124121
const fixedStyle = computed(() => {
125122
return {
@@ -135,11 +132,9 @@ export default create({
135132
}
136133
137134
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+
}
143138
}
144139
145140
const calculateHeight = () => {
@@ -149,7 +144,7 @@ export default create({
149144
for (let i = 0; i < state.listGroup.length; i++) {
150145
state.query.selectAll(`.elevator__item__${i}`).boundingClientRect()
151146
state.query.exec((res) => {
152-
height += Math.floor(res[i][0].height)
147+
height += Math.round(res[i][0].height)
153148
state.listHeight.push(height)
154149
})
155150
}
@@ -167,8 +162,8 @@ export default create({
167162
168163
const touchStart = (e: TouchEvent) => {
169164
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]
172167
state.touchState.y1 = firstTouch.pageY
173168
state.anchorIndex = +index
174169
state.codeIndex = +index
@@ -198,14 +193,15 @@ export default create({
198193
}
199194
200195
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
203198
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) {
209205
state.currentIndex = i
210206
return
211207
}

0 commit comments

Comments
 (0)