CNCEC_APP/uni_modules/uview-pro/libs/function/getRect.ts

27 lines
869 B
TypeScript
Raw Normal View History

2026-03-25 14:54:15 +08:00
/**
*
* @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();
});
}