Skip to content

Commit 9645921

Browse files
committed
chore: 同步更改 index.vue
1 parent 287ab78 commit 9645921

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

src/packages/__VUE/elevator/index.vue

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@
2121
<view class="nut-elevator__list__fixed-title">{{ indexList?.[currentIndex]?.[acceptKey] }}</view>
2222
</view>
2323
<view v-show="scrollStart" v-if="indexList.length" class="nut-elevator__code--current">
24-
{{
25-
indexList[codeIndex][acceptKey]
26-
}}
24+
{{ indexList[codeIndex][acceptKey] }}
2725
</view>
2826
<view class="nut-elevator__bars" @touchstart="touchStart" @touchmove.stop.prevent="touchMove" @touchend="touchEnd">
2927
<view class="nut-elevator__bars__inner">
@@ -36,8 +34,7 @@
3634
@click="handleClickIndex(item[acceptKey])"
3735
>
3836
{{ item[acceptKey] }}
39-
</view
40-
>
37+
</view>
4138
</view>
4239
</view>
4340
</view>
@@ -96,29 +93,25 @@ export default create({
9693
fixedTop: 0
9794
})
9895
99-
const clientHeight = computed(() => {
100-
return listview.value.clientHeight
101-
})
96+
const clientHeight = computed(() => listview.value.clientHeight)
10297
10398
const getData = (el: HTMLElement, name: string): string | void => {
10499
const prefix = 'data-'
105100
return el.getAttribute(prefix + name) as string
106101
}
107102
108103
const setListGroup = (el: any) => {
109-
nextTick(() => {
110-
if (!state.listGroup.includes(el) && el != null) {
111-
state.listGroup.push(el)
112-
}
113-
})
104+
if (!state.listGroup.includes(el) && el != null) {
105+
state.listGroup.push(el)
106+
}
114107
}
115108
116109
const calculateHeight = () => {
117110
let height = 0
118111
state.listHeight.push(height)
119112
for (let i = 0; i < state.listGroup.length; i++) {
120113
let item = state.listGroup[i]
121-
height += Math.floor(item.clientHeight)
114+
height += Math.round(item.clientHeight)
122115
state.listHeight.push(height)
123116
}
124117
}
@@ -166,20 +159,18 @@ export default create({
166159
}
167160
168161
const listViewScroll = (e: Event) => {
169-
let target = e.target as Element
170-
let scrollTop = target.scrollTop
162+
const target = e.target as Element
163+
const scrollTop = target.scrollTop
171164
const listHeight = state.listHeight
172-
state.scrollY = scrollTop
165+
state.scrollY = Math.round(scrollTop)
173166
for (let i = 0; i < listHeight.length - 1; i++) {
174-
let height1 = listHeight[i]
175-
let height2 = listHeight[i + 1]
176-
if (state.scrollY >= height1 && state.scrollY < height2) {
167+
const [startHeight, endHeight] = [listHeight[i], listHeight[i + 1]]
168+
if (state.scrollY >= startHeight && state.scrollY < endHeight) {
177169
state.currentIndex = i
178-
state.diff = height2 - state.scrollY
170+
state.diff = endHeight - state.scrollY
179171
return
180172
}
181173
}
182-
183174
state.currentIndex = listHeight.length - 2
184175
}
185176

0 commit comments

Comments
 (0)