utils.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. export const getPlatform = function() {
  2. let platForm = undefined
  3. // #ifdef H5
  4. platForm = 'H5'
  5. //#endif
  6. // #ifdef APP-PLUS
  7. platForm = 'APP'
  8. //#endif
  9. // #ifdef APP-PLUS-NVUE
  10. platForm = 'APP'
  11. //#endif
  12. // #ifdef APP-NVUE
  13. platForm = 'APP'
  14. //#endif
  15. // #ifdef MP-WEIXIN
  16. platForm = 'MP-WEIXIN'
  17. //#endif
  18. // #ifdef MP-ALIPAY
  19. platForm = 'MP-ALIPAY'
  20. //#endif
  21. // #ifdef MP-BAIDU
  22. platForm = 'MP-BAIDU'
  23. //#endif
  24. // #ifdef MP-TOUTIAO
  25. platForm = 'MP-TOUTIAO'
  26. //#endif
  27. return platForm
  28. }
  29. export const isWx = function() {
  30. //#ifdef H5
  31. let ua = window.navigator.userAgent.toLowerCase()
  32. if (ua.indexOf('micromessenger') !== -1) {
  33. return true
  34. } else {
  35. return false
  36. }
  37. //#endif
  38. // #ifndef H5
  39. return false
  40. // #endif
  41. }
  42. /**
  43. * 获取小程序胶囊居中对齐的高度
  44. */
  45. export const getNavHeight = function () {
  46. let platForm = getPlatform();
  47. if (platForm === 'MP-WEIXIN') {
  48. let res = uni.getSystemInfoSync();
  49. let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
  50. let navHeight =
  51. menuButtonInfo.height + (menuButtonInfo.top - res.statusBarHeight) * 2;
  52. return navHeight
  53. } else {
  54. return 44;
  55. }
  56. }
  57. /**
  58. * 手机顶部高度
  59. */
  60. export const getPhoneTopHeight = function () {
  61. let platForm = getPlatform();
  62. if (platForm === 'MP-WEIXIN') {
  63. let height = uni.getSystemInfoSync().statusBarHeight;
  64. return height
  65. } else {
  66. return 0;
  67. }
  68. }