useListHeight.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { ref, nextTick, computed } from 'vue'
  2. import { onReady } from "@dcloudio/uni-app"
  3. import { query, systemInfo } from "@/utils"
  4. function useListHeight() {
  5. const navbarNodeInfo = ref(null)
  6. const footerHeightInfo = ref({
  7. height: 0,
  8. keyboardHeight: 0,
  9. bottomSafeDistance: 0
  10. })
  11. const sysInfo = ref(systemInfo())
  12. // 计算列表高度
  13. const listHeight = computed(() => {
  14. const { windowHeight } = sysInfo.value
  15. const navbarHeight = navbarNodeInfo.value ? navbarNodeInfo.value.height : 0
  16. let footerHeight = 0
  17. if (footerHeightInfo.value) {
  18. const { height = 0, keyboardHeight = 0, bottomSafeDistance = 0 } = footerHeightInfo.value
  19. footerHeight = height + keyboardHeight
  20. const isIOS = uni.getSystemInfoSync().platform === 'ios';
  21. if (isIOS) {
  22. footerHeight += bottomSafeDistance;
  23. }
  24. }
  25. return windowHeight - navbarHeight - footerHeight
  26. })
  27. onReady(() => {
  28. nextTick(() => {
  29. query(".user-chat__navbar")
  30. .then(result => {
  31. navbarNodeInfo.value = result
  32. })
  33. })
  34. })
  35. return {
  36. navbarNodeInfo,
  37. footerHeightInfo,
  38. sysInfo,
  39. listHeight
  40. }
  41. }
  42. export default useListHeight