cashier_app/commons/utils/safe-bottom.js

35 lines
843 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}