mirror of
https://gitee.com/wot-design-uni/wot-design-uni.git
synced 2025-12-07 17:48:34 +08:00
refactor: ♻️ 重构SelectPicker滚动到选中值的逻辑
This commit is contained in:
parent
4246548552
commit
fbd1d8b36a
@ -261,7 +261,7 @@ const { proxy } = getCurrentInstance() as any
|
||||
|
||||
function setScrollIntoView() {
|
||||
let wraperSelector: string = ''
|
||||
let selectorPromise: Promise<UniApp.NodeInfo | UniApp.NodeInfo[]>[] = []
|
||||
let selectorPromise: Promise<UniApp.NodeInfo>[] = []
|
||||
if (isDef(selectList.value) && selectList.value !== '' && !isArray(selectList.value)) {
|
||||
wraperSelector = '#wd-radio-group'
|
||||
selectorPromise = [getRect(`#radio${selectList.value}`, false, proxy)]
|
||||
@ -274,28 +274,24 @@ function setScrollIntoView() {
|
||||
if (wraperSelector) {
|
||||
requestAnimationFrame().then(() => {
|
||||
requestAnimationFrame().then(() => {
|
||||
Promise.all([getRect('.wd-select-picker__wrapper', false, proxy), getRect(wraperSelector, false, proxy), ...selectorPromise])
|
||||
.then((res: any[]) => {
|
||||
if (isDef(res) && isArray(res)) {
|
||||
const scrollView = res[0]
|
||||
const wraper = res[1]
|
||||
const target = res.slice(2) || []
|
||||
if (isDef(wraper) && isDef(scrollView)) {
|
||||
const index = target.findIndex((item) => {
|
||||
return item.top >= scrollView.top && item.bottom <= scrollView.bottom
|
||||
Promise.all([getRect('.wd-select-picker__wrapper', false, proxy), getRect(wraperSelector, false, proxy), ...selectorPromise]).then((res) => {
|
||||
if (isDef(res) && isArray(res)) {
|
||||
const scrollView = res[0]
|
||||
const wraper = res[1]
|
||||
const target = res.slice(2) || []
|
||||
if (isDef(wraper) && isDef(scrollView)) {
|
||||
const index = target.findIndex((item) => {
|
||||
return item.bottom! > scrollView.top! && item.top! < scrollView.bottom!
|
||||
})
|
||||
if (index < 0) {
|
||||
scrollTop.value = -1
|
||||
nextTick(() => {
|
||||
scrollTop.value = Math.max(0, target[0].top! - wraper.top! - scrollView.height! / 2)
|
||||
})
|
||||
if (index < 0) {
|
||||
scrollTop.value = -1
|
||||
nextTick(() => {
|
||||
scrollTop.value = Math.max(0, target[0].top - wraper.top - scrollView.height / 2)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error)
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user