34 lines
842 B
JavaScript
34 lines
842 B
JavaScript
|
||
import { getCurrentInstance } from 'vue';
|
||
export async function getElRect(elClass, instance,option) {
|
||
instance = instance ? instance : getCurrentInstance();
|
||
const query = uni.createSelectorQuery().in(instance.proxy);
|
||
try{
|
||
const res= await getEle(query,elClass,option)
|
||
return res
|
||
}catch(e){
|
||
console.log(e);
|
||
}
|
||
}
|
||
async function getEle(query,elClass,option){
|
||
return new Promise((resolve, reject)=>{
|
||
query.select('.' + elClass).fields({
|
||
size: true,
|
||
...option
|
||
}, res => {
|
||
// 如果节点尚未生成,res值为null,循环调用执行
|
||
if (!res) {
|
||
return setTimeout(() => {
|
||
getEle(query,elClass,option);
|
||
}, 10);
|
||
}
|
||
resolve(res);
|
||
}).exec();
|
||
})
|
||
|
||
}
|
||
|
||
export async function getSafeBottomHeight(className, height = 16) {
|
||
const bottomEle = await getElRect(className)
|
||
return bottomEle.height + height
|
||
} |