Skip to content

Commit 9620a32

Browse files
committed
update(uni-ui): 修复索引列表非全屏显示时索引位置不正确的Bug
1 parent ac65055 commit 9620a32

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

components/uni-indexed-list/uni-indexed-list.vue

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
5050
function touchMove(e) {
5151
let pageY = e.touches[0].pageY
52-
let index = Math.floor(pageY / this.itemHeight)
52+
let index = Math.floor((pageY - this.winOffsetY) / this.itemHeight)
5353
if (this.touchmoveIndex === index) {
5454
return false
5555
}
@@ -71,7 +71,7 @@
7171
// #endif
7272
7373
/**
74-
* IndexedList 索引列表
74+
* IndexedList 索引列表
7575
* @description 用于展示索引列表
7676
* @tutorial https://ext.dcloud.net.cn/plugin?id=375
7777
* @property {Boolean} showSelect = [true|false] 展示模式
@@ -104,6 +104,7 @@
104104
lists: [],
105105
winHeight: 0,
106106
itemHeight: 0,
107+
winOffsetY: 0,
107108
touchmove: false,
108109
touchmoveIndex: -1,
109110
scrollViewId: '',
@@ -158,12 +159,14 @@
158159
.select('#list')
159160
.boundingClientRect()
160161
.exec(ret => {
162+
this.winOffsetY = ret[0].top
161163
this.winHeight = ret[0].height
162164
this.itemHeight = this.winHeight / this.lists.length
163165
})
164166
// #endif
165167
// #ifdef APP-NVUE
166168
dom.getComponentRect(this.$refs['list'], (res) => {
169+
this.winOffsetY = res.size.top
167170
this.winHeight = res.size.height
168171
this.itemHeight = this.winHeight / this.lists.length
169172
})
@@ -172,7 +175,7 @@
172175
touchStart(e) {
173176
this.touchmove = true
174177
let pageY = e.touches[0].pageY
175-
let index = Math.floor(pageY / this.itemHeight)
178+
let index = Math.floor((pageY - this.winOffsetY) / this.itemHeight)
176179
let item = this.lists[index]
177180
if (item) {
178181
this.scrollViewId = 'uni-indexed-list-' + index
@@ -187,7 +190,7 @@
187190
touchMove(e) {
188191
// #ifndef APP-PLUS
189192
let pageY = e.touches[0].pageY
190-
let index = Math.floor(pageY / this.itemHeight)
193+
let index = Math.floor((pageY - this.winOffsetY) / this.itemHeight)
191194
if (this.touchmoveIndex === index) {
192195
return false
193196
}

0 commit comments

Comments
 (0)