rect.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { config } from "@/config";
  2. import { router } from "../router";
  3. import { isH5, isHarmony } from "./comm";
  4. import { ctx } from "../ctx";
  5. import { getPx } from "./parse";
  6. /**
  7. * 是否需要计算 tabBar 高度
  8. * @returns boolean
  9. */
  10. export function hasCustomTabBar() {
  11. if (router.isTabPage()) {
  12. if (isHarmony()) {
  13. return false;
  14. }
  15. return config.isCustomTabBar || isH5();
  16. }
  17. return false;
  18. }
  19. /**
  20. * 是否存在自定义 topbar
  21. * @returns boolean
  22. */
  23. export function hasCustomTopbar() {
  24. return router.route()?.isCustomNavbar ?? false;
  25. }
  26. /**
  27. * 获取安全区域高度
  28. * @param type 类型
  29. * @returns 安全区域高度
  30. */
  31. export function getSafeAreaHeight(type: "top" | "bottom") {
  32. const { safeAreaInsets } = uni.getWindowInfo();
  33. let h: number;
  34. if (type == "top") {
  35. h = safeAreaInsets.top;
  36. } else {
  37. h = safeAreaInsets.bottom;
  38. // #ifdef APP-ANDROID
  39. if (h == 0) {
  40. h = 16;
  41. }
  42. // #endif
  43. }
  44. return h;
  45. }
  46. /**
  47. * 获取 tabBar 高度
  48. * @returns tabBar 高度
  49. */
  50. export function getTabBarHeight() {
  51. let h = ctx.tabBar.height == null ? 50 : getPx(ctx.tabBar.height!);
  52. if (hasCustomTabBar()) {
  53. h += getSafeAreaHeight("bottom");
  54. }
  55. return h;
  56. }