App.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <script>
  2. import Vue from 'vue'
  3. // import TIM from 'tim-wx-sdk';
  4. // import COS from 'cos-wx-sdk-v5';
  5. export default {
  6. globalData: {
  7. appId: 'wx19c8813ffc33d1cb',
  8. wsUrl: 'wss://websocket.cdwjyyh.com',
  9. },
  10. onLaunch: function() {
  11. this.checkUpdate()
  12. // uni.$TUIKit = TIM.create({
  13. // SDKAppID: 1400693126
  14. // });
  15. // uni.$TUIKit.registerPlugin({
  16. // 'cos-wx-sdk': COS
  17. // });
  18. // uni.$TUIKitTIM = TIM;
  19. // uni.$TUIKitEvent = TIM.EVENT;
  20. // uni.$TUIKitVersion = TIM.VERSION;
  21. // uni.$TUIKitTypes = TIM.TYPES; // 监听系统级事件
  22. // uni.$resetLoginData = this.resetLoginData();
  23. // uni.$TUIKit.on(uni.$TUIKitEvent.SDK_READY, this.onSDKReady);
  24. // uni.$TUIKit.on(uni.$TUIKitEvent.SDK_NOT_READY, this.onSdkNotReady);
  25. // uni.$TUIKit.on(uni.$TUIKitEvent.KICKED_OUT, this.onKickedOut);
  26. // uni.$TUIKit.on(uni.$TUIKitEvent.ERROR, this.onTIMError);
  27. // uni.$TUIKit.on(uni.$TUIKitEvent.NET_STATE_CHANGE, this.onNetStateChange);
  28. // uni.$TUIKit.on(uni.$TUIKitEvent.SDK_RELOAD, this.onSDKReload);
  29. console.log('IM')
  30. },
  31. onShow: function () {
  32. console.log('App Show')
  33. uni.getSystemInfo({
  34. success: (result) => {
  35. // 获取手机系统的状态栏高度(不同手机的状态栏高度不同)
  36. // console.log('当前手机的状态栏高度',result.statusBarHeight)
  37. let statusBarHeight = result.statusBarHeight + 'px'
  38. // 获取右侧胶囊的信息 单位px
  39. //#ifndef H5 || APP-PLUS
  40. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  41. //bottom: 胶囊底部距离屏幕顶部的距离
  42. //height: 胶囊高度
  43. //left: 胶囊左侧距离屏幕左侧的距离
  44. //right: 胶囊右侧距离屏幕左侧的距离
  45. //top: 胶囊顶部距离屏幕顶部的距离
  46. //width: 胶囊宽度
  47. // console.log(menuButtonInfo.width, menuButtonInfo.height, menuButtonInfo.top)
  48. // console.log('计算胶囊右侧距离屏幕右边距离', result.screenWidth - menuButtonInfo.right)
  49. let menuWidth = menuButtonInfo.width + 'px'
  50. let menuHeight = menuButtonInfo.height + 'px'
  51. let menuBorderRadius = menuButtonInfo.height / 2 + 'px'
  52. let menuRight = result.screenWidth - menuButtonInfo.right + 'px'
  53. let menuTop = menuButtonInfo.top + 'px'
  54. let contentTop = result.statusBarHeight + 44 + 'px'
  55. let menuInfo = {
  56. statusBarHeight: statusBarHeight,//状态栏高度----用来给自定义导航条页面的顶部导航条设计padding-top使用:目的留出系统的状态栏区域
  57. menuWidth: menuWidth,//右侧的胶囊宽度--用来给自定义导航条页面的左侧胶囊设置使用
  58. menuHeight: menuHeight,//右侧的胶囊高度--用来给自定义导航条页面的左侧胶囊设置使用
  59. menuBorderRadius: menuBorderRadius,//一半的圆角--用来给自定义导航条页面的左侧胶囊设置使用
  60. menuRight: menuRight,//右侧的胶囊距离右侧屏幕距离--用来给自定义导航条页面的左侧胶囊设置使用
  61. menuTop: menuTop,//右侧的胶囊顶部距离屏幕顶部的距离--用来给自定义导航条页面的左侧胶囊设置使用
  62. contentTop: contentTop,//内容区距离页面最上方的高度--用来给自定义导航条页面的内容区定位距离使用
  63. }
  64. uni.setStorageSync('menuInfo', menuInfo)
  65. //#endif
  66. },
  67. fail: (error) => {
  68. console.log(error)
  69. }
  70. })
  71. },
  72. onHide: function() {
  73. console.log('App Hide')
  74. },
  75. methods: {
  76. checkUpdate() {
  77. const updateManager = uni.getUpdateManager();
  78. updateManager.onCheckForUpdate(function(res) {
  79. // 请求完新版本信息的回调
  80. console.log('是否有新版本:', res.hasUpdate);
  81. });
  82. updateManager.onUpdateReady(function() {
  83. uni.showModal({
  84. title: '更新提示',
  85. content: '新版本已经准备好,是否重启小程序?',
  86. confirmText: '立即重启',
  87. confirmColor: '#2179f5',
  88. showCancel: false,
  89. success(res) {
  90. if (res.confirm) {
  91. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  92. updateManager.applyUpdate();
  93. }
  94. }
  95. });
  96. });
  97. updateManager.onUpdateFailed(function() {
  98. // 新的版本下载失败
  99. uni.showModal({
  100. title: '更新提示',
  101. content: '新版本下载失败,请检查网络后重试。',
  102. showCancel: false
  103. });
  104. });
  105. },
  106. // TODO:
  107. resetLoginData() {
  108. // this.globalData.expiresIn = '';
  109. // this.globalData.sessionID = '';
  110. // this.globalData.userInfo = {
  111. // userID: '',
  112. // userSig: '',
  113. // token: '',
  114. // phone: ''
  115. // };
  116. // this.globalData.userProfile = null;
  117. // logger.log(`| app | resetLoginData | globalData: ${this.globalData}`);
  118. },
  119. onTIMError() {},
  120. onSDKReady({name}) {
  121. console.log("im注册:"+name)
  122. const isSDKReady = name === uni.$TUIKitEvent.SDK_READY ? true : false
  123. console.log("im注册:"+isSDKReady)
  124. uni.$emit('isSDKReady', {
  125. isSDKReady: true
  126. });
  127. },
  128. onNetStateChange() {},
  129. onSDKReload() {},
  130. onSdkNotReady() {},
  131. onKickedOut() {
  132. uni.showToast({
  133. title: '您被踢下线',
  134. icon: 'error'
  135. });
  136. }
  137. }
  138. }
  139. </script>
  140. <style lang="less">
  141. /*每个页面公共css */
  142. // @import 'animate.css';
  143. @import './assets/iconfont/iconfont.css';
  144. @import './assets/css/common.less';
  145. page{
  146. background-color: #f6f6f6;
  147. }
  148. ::-webkit-scrollbar{
  149. width: 0 !important;
  150. height: 0 !important;
  151. }
  152. </style>
  153. <style lang="scss">
  154. /* 注意要写在第一行,同时给style标签加入lang="scss"属性 */
  155. @import "@/uni_modules/uview-ui/index.scss";
  156. /*每个页面公共css */
  157. /* 解决小程序和app滚动条的问题 */
  158. /* #ifdef MP-WEIXIN || APP-PLUS */
  159. ::v-deep ::-webkit-scrollbar {
  160. display: none !important;
  161. width: 0 !important;
  162. height: 0 !important;
  163. -webkit-appearance: none;
  164. background: transparent;
  165. color: transparent;
  166. }
  167. /* #endif */
  168. /* 解决H5 的问题 */
  169. /* #ifdef H5 */
  170. uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
  171. /* 隐藏滚动条,但依旧具备可以滚动的功能 */
  172. display: none;
  173. width: 0 !important;
  174. height: 0 !important;
  175. -webkit-appearance: none;
  176. background: transparent;
  177. color: transparent;
  178. }
  179. /* #endif */
  180. </style>