App.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <script>
  2. import Vue from 'vue'
  3. export default {
  4. globalData: {
  5. // confirm订单参数
  6. confirmParam: []
  7. },
  8. onLaunch: function() {
  9. // uni.$TUIKit = TIM.create({
  10. // SDKAppID: 1400693126
  11. // });
  12. // uni.$TUIKit.registerPlugin({
  13. // 'cos-wx-sdk': COS
  14. // });
  15. // uni.$TUIKitTIM = TIM;
  16. // uni.$TUIKitEvent = TIM.EVENT;
  17. // uni.$TUIKitVersion = TIM.VERSION;
  18. // uni.$TUIKitTypes = TIM.TYPES; // 监听系统级事件
  19. // uni.$resetLoginData = this.resetLoginData();
  20. // uni.$TUIKit.on(uni.$TUIKitEvent.SDK_READY, this.onSDKReady);
  21. // uni.$TUIKit.on(uni.$TUIKitEvent.SDK_NOT_READY, this.onSdkNotReady);
  22. // uni.$TUIKit.on(uni.$TUIKitEvent.KICKED_OUT, this.onKickedOut);
  23. // uni.$TUIKit.on(uni.$TUIKitEvent.ERROR, this.onTIMError);
  24. // uni.$TUIKit.on(uni.$TUIKitEvent.NET_STATE_CHANGE, this.onNetStateChange);
  25. // uni.$TUIKit.on(uni.$TUIKitEvent.SDK_RELOAD, this.onSDKReload);
  26. // console.log('IM')
  27. },
  28. onShow: function () {
  29. console.log('App Show');
  30. this.checkShowWatermark();
  31. uni.getSystemInfo({
  32. success: (result) => {
  33. // 获取手机系统的状态栏高度(不同手机的状态栏高度不同)
  34. // console.log('当前手机的状态栏高度',result.statusBarHeight)
  35. let statusBarHeight = result.statusBarHeight + 'px'
  36. // 获取右侧胶囊的信息 单位px
  37. //#ifndef H5 || APP-PLUS
  38. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  39. //bottom: 胶囊底部距离屏幕顶部的距离
  40. //height: 胶囊高度
  41. //left: 胶囊左侧距离屏幕左侧的距离
  42. //right: 胶囊右侧距离屏幕左侧的距离
  43. //top: 胶囊顶部距离屏幕顶部的距离
  44. //width: 胶囊宽度
  45. // console.log(menuButtonInfo.width, menuButtonInfo.height, menuButtonInfo.top)
  46. // console.log('计算胶囊右侧距离屏幕右边距离', result.screenWidth - menuButtonInfo.right)
  47. let menuWidth = menuButtonInfo.width + 'px'
  48. let menuHeight = menuButtonInfo.height + 'px'
  49. let menuBorderRadius = menuButtonInfo.height / 2 + 'px'
  50. let menuRight = result.screenWidth - menuButtonInfo.right + 'px'
  51. let menuTop = menuButtonInfo.top + 'px'
  52. let contentTop = result.statusBarHeight + 44 + 'px'
  53. let menuInfo = {
  54. statusBarHeight: statusBarHeight,//状态栏高度----用来给自定义导航条页面的顶部导航条设计padding-top使用:目的留出系统的状态栏区域
  55. menuWidth: menuWidth,//右侧的胶囊宽度--用来给自定义导航条页面的左侧胶囊设置使用
  56. menuHeight: menuHeight,//右侧的胶囊高度--用来给自定义导航条页面的左侧胶囊设置使用
  57. menuBorderRadius: menuBorderRadius,//一半的圆角--用来给自定义导航条页面的左侧胶囊设置使用
  58. menuRight: menuRight,//右侧的胶囊距离右侧屏幕距离--用来给自定义导航条页面的左侧胶囊设置使用
  59. menuTop: menuTop,//右侧的胶囊顶部距离屏幕顶部的距离--用来给自定义导航条页面的左侧胶囊设置使用
  60. contentTop: contentTop,//内容区距离页面最上方的高度--用来给自定义导航条页面的内容区定位距离使用
  61. }
  62. uni.setStorageSync('menuInfo', menuInfo)
  63. //#endif
  64. },
  65. fail: (error) => {
  66. console.log(error)
  67. }
  68. })
  69. },
  70. onHide: function() {
  71. console.log('App Hide')
  72. },
  73. methods: {
  74. checkShowWatermark() {
  75. const pages = getCurrentPages();
  76. if (!pages.length) return;
  77. const currentPage = pages[pages.length - 1];
  78. const pagePath = currentPage.route;
  79. const exclude = [
  80. 'pages/auth/login',
  81. 'pages/auth/register',
  82. 'pages/auth/registerUser'
  83. ];
  84. this.showWatermark = !exclude.includes(pagePath);
  85. const userInfo = uni.getStorageSync('userInfo') || {};
  86. console.log('userInfo:', userInfo);
  87. console.log('showWatermark:', this.showWatermark);
  88. console.log('userName:', this.userName);
  89. if (userInfo.userName) {
  90. this.userName = userInfo.userName;
  91. } else if (userInfo.nickName) {
  92. this.userName = userInfo.nickName;
  93. }
  94. console.log('final userName:', this.userName);
  95. },
  96. // TODO:
  97. resetLoginData() {
  98. // this.globalData.expiresIn = '';
  99. // this.globalData.sessionID = '';
  100. // this.globalData.userInfo = {
  101. // userID: '',
  102. // userSig: '',
  103. // token: '',
  104. // phone: ''
  105. // };
  106. // this.globalData.userProfile = null;
  107. // logger.log(`| app | resetLoginData | globalData: ${this.globalData}`);
  108. },
  109. onTIMError() {},
  110. onSDKReady({name}) {
  111. console.log("im注册:"+name)
  112. const isSDKReady = name === uni.$TUIKitEvent.SDK_READY ? true : false
  113. console.log("im注册:"+isSDKReady)
  114. uni.$emit('isSDKReady', {
  115. isSDKReady: true
  116. });
  117. },
  118. onNetStateChange() {},
  119. onSDKReload() {},
  120. onSdkNotReady() {},
  121. onKickedOut() {
  122. uni.showToast({
  123. title: '您被踢下线',
  124. icon: 'error'
  125. });
  126. }
  127. }
  128. }
  129. </script>
  130. <style lang="less">
  131. @import './assets/css/common.less';
  132. </style>
  133. <style lang="scss">
  134. /*每个页面公共css */
  135. // @import 'animate.css';
  136. @import "uview-ui/index.scss";
  137. @import './assets/iconfont/iconfont.css';
  138. @import './assets/css/common.scss';
  139. @import './assets/css/commonTheme.css';
  140. ::-webkit-scrollbar{
  141. width: 0 !important;
  142. height: 0 !important;
  143. }
  144. </style>
  145. <style>
  146. /*每个页面公共css */
  147. /* 解决小程序和app滚动条的问题 */
  148. /* #ifdef MP-WEIXIN || APP-PLUS */
  149. ::v-deep ::-webkit-scrollbar {
  150. display: none !important;
  151. width: 0 !important;
  152. height: 0 !important;
  153. -webkit-appearance: none;
  154. background: transparent;
  155. color: transparent;
  156. }
  157. /* #endif */
  158. /* 解决H5 的问题 */
  159. /* #ifdef H5 */
  160. uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
  161. /* 隐藏滚动条,但依旧具备可以滚动的功能 */
  162. display: none;
  163. width: 0 !important;
  164. height: 0 !important;
  165. -webkit-appearance: none;
  166. background: transparent;
  167. color: transparent;
  168. }
  169. /* #endif */
  170. </style>