@tplc/business
Version:
25 lines (23 loc) • 842 B
text/typescript
import { getRect, isH5 } from '@tplc/wot/components/common/util'
import { getCurrentInstance, onMounted, ref } from 'vue'
const useAutoHeight = (id = 'pagingTop') => {
const { proxy } = getCurrentInstance() as any
const isTabBar = uni.$lcb.getIsTabbar()
const viewPageHeight = isH5 ? window.innerHeight : uni.getWindowInfo().screenHeight
const height = ref('')
const top = ref(0)
onMounted(() => {
setTimeout(() => {
getRect(`#${id}`, false, proxy).then((res) => {
top.value = res.top || 0
if (!isTabBar) {
height.value = `${viewPageHeight - (res.top || 0)}px`
} else {
height.value = `calc(${viewPageHeight - (res.top || 0)}px - var(--window-bottom) - env(safe-area-inset-bottom))`
}
})
}, 200)
})
return { height, top }
}
export default useAutoHeight