App.vue 6.6 KB

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