UNPKG

@tplc/business

Version:

29 lines (27 loc) 1.04 kB
import { getRect, isH5 } from '@tplc/wot/components/common/util' import { getCurrentInstance, onMounted, ref } from 'vue' import { getCurrentPage } from '../utils/utils' const useAutoHeight = (id = 'pagingTop', timeOut = 200, fullScreen = false) => { const { proxy } = getCurrentInstance() as any const route = getCurrentPage().route const isTabBar = uni.$lcb.getIsTabbar(route) const viewPageHeight = isH5 ? window.innerHeight : (uni.getWindowInfo ? uni.getWindowInfo() : uni.getSystemInfoSync()).screenHeight const height = ref('') const top = ref(0) onMounted(() => { setTimeout(() => { getRect(`#${id}`, false, proxy).then((res) => { top.value = res.top || 0 if (!isTabBar || fullScreen) { height.value = `${viewPageHeight - (res.top || 0)}px` } else { height.value = `calc(${viewPageHeight - (res.top || 0)}px - var(--window-bottom) - env(safe-area-inset-bottom))` } }) }, timeOut) }) return { height, top } } export default useAutoHeight