App.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <script>
  2. export default {
  3. onLoad() {
  4. console.log("onLoad")
  5. },
  6. onLaunch() {
  7. //更新提示
  8. const updateManager = wx.getUpdateManager()
  9. updateManager.onCheckForUpdate(function(res) {
  10. // 请求完新版本信息的回调
  11. // console.log(res.hasUpdate)
  12. if (res.hasUpdate) {
  13. updateManager.onUpdateReady(function(ress) {
  14. updateManager.applyUpdate()
  15. // console.log("===强制更新重启")
  16. })
  17. } else {
  18. updateManager.onUpdateFailed(function() {
  19. // 新版本下载失败
  20. })
  21. }
  22. })
  23. },
  24. onShow: function() {
  25. console.log('App Show')
  26. uni.getSystemInfo({
  27. success: (result) => {
  28. // 获取手机系统的状态栏高度(不同手机的状态栏高度不同) ( 不要使用uni-app官方文档的var(--status-bar-height) 官方这个是固定的20px 不对的 )
  29. // console.log('当前手机的状态栏高度',result.statusBarHeight)
  30. let statusBarHeight = result.statusBarHeight + 'px'
  31. // 获取右侧胶囊的信息 单位px
  32. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  33. //bottom: 胶囊底部距离屏幕顶部的距离
  34. //height: 胶囊高度
  35. //left: 胶囊左侧距离屏幕左侧的距离
  36. //right: 胶囊右侧距离屏幕左侧的距离
  37. //top: 胶囊顶部距离屏幕顶部的距离
  38. //width: 胶囊宽度
  39. // console.log(menuButtonInfo.width, menuButtonInfo.height, menuButtonInfo.top)
  40. // console.log('计算胶囊右侧距离屏幕右边距离', result.screenWidth - menuButtonInfo.right)
  41. let menuWidth = menuButtonInfo.width + 40 + 'px'
  42. let menuHeight = menuButtonInfo.height + 'px'
  43. let menuBorderRadius = menuButtonInfo.height / 2 + 'px'
  44. let menuRight = result.screenWidth - menuButtonInfo.right + 'px'
  45. let menuTop = menuButtonInfo.top + 'px'
  46. let contentTop = result.statusBarHeight + 44 + 'px'
  47. let menuInfo = {
  48. statusBarHeight: statusBarHeight, //状态栏高度----用来给自定义导航条页面的顶部导航条设计padding-top使用:目的留出系统的状态栏区域
  49. menuWidth: menuWidth, //右侧的胶囊宽度--用来给自定义导航条页面的左侧胶囊设置使用
  50. menuHeight: menuHeight, //右侧的胶囊高度--用来给自定义导航条页面的左侧胶囊设置使用
  51. menuBorderRadius: menuBorderRadius, //一半的圆角--用来给自定义导航条页面的左侧胶囊设置使用
  52. menuRight: menuRight, //右侧的胶囊距离右侧屏幕距离--用来给自定义导航条页面的左侧胶囊设置使用
  53. menuTop: menuTop, //右侧的胶囊顶部距离屏幕顶部的距离--用来给自定义导航条页面的左侧胶囊设置使用
  54. contentTop: contentTop, //内容区距离页面最上方的高度--用来给自定义导航条页面的内容区定位距离使用
  55. }
  56. uni.setStorageSync('menuInfo', menuInfo)
  57. },
  58. fail: (error) => {
  59. console.log(error)
  60. }
  61. })
  62. },
  63. onHide: function() {
  64. uni.hideTabBar()
  65. }
  66. }
  67. </script>
  68. <style lang="scss">
  69. /*每个页面公共css */
  70. @import "@/uni_modules/uview-ui/index.scss";
  71. @import "common/demo.scss";
  72. @import './common/uni.css';
  73. @font-face {
  74. font-family: hsUniAppFont; //字体
  75. src: url('static/font/SourceHanSansCN-Regular.otf'); //包路径
  76. }
  77. page {
  78. font-family: hsUniAppFont;
  79. letter-spacing: 2rpx;
  80. }
  81. </style>