This commit is contained in:
2026-03-25 14:54:15 +08:00
commit ab4646b43a
827 changed files with 123812 additions and 0 deletions
@@ -0,0 +1,26 @@
/**
* 获取元素的位置信息
* @param {any} selector 选择器
* @param {boolean} all 是否获取所有匹配元素
* @returns {Promise<any>} 返回一个 Promise,解析为元素的位置信息
*/
import { getCurrentInstance } from 'vue';
export default function (selector: any, _instance: any = null, all: boolean = false): Promise<any> {
const instance = _instance || getCurrentInstance();
return new Promise(resolve => {
uni.createSelectorQuery()
.in(instance?.proxy)
[all ? 'selectAll' : 'select'](selector)
.boundingClientRect((rect: any) => {
if (all && Array.isArray(rect) && rect.length) {
resolve(rect);
}
if (!all && rect) {
resolve(rect);
}
})
.exec();
});
}