App.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. // confirm订单参数
  8. confirmParam: [],
  9. themecolor: 'beiliyou'
  10. },
  11. onLaunch: function() {
  12. // 在这里调用 onLaunch vuex 得 getTheme去请求接口
  13. this.$store.dispatch('getTheme')
  14. // console.log('App Launch')
  15. // uni.hideTabBar()
  16. // uni.removeStorageSync('selectedIndex');
  17. // uni.$TUIKit = TIM.create({
  18. // SDKAppID: 1400693126
  19. // });
  20. // uni.$TUIKit.registerPlugin({
  21. // 'cos-wx-sdk': COS
  22. // });
  23. // uni.$TUIKitTIM = TIM;
  24. // uni.$TUIKitEvent = TIM.EVENT;
  25. // uni.$TUIKitVersion = TIM.VERSION;
  26. // uni.$TUIKitTypes = TIM.TYPES; // 监听系统级事件
  27. // uni.$resetLoginData = this.resetLoginData();
  28. // uni.$TUIKit.on(uni.$TUIKitEvent.SDK_READY, this.onSDKReady);
  29. // uni.$TUIKit.on(uni.$TUIKitEvent.SDK_NOT_READY, this.onSdkNotReady);
  30. // uni.$TUIKit.on(uni.$TUIKitEvent.KICKED_OUT, this.onKickedOut);
  31. // uni.$TUIKit.on(uni.$TUIKitEvent.ERROR, this.onTIMError);
  32. // uni.$TUIKit.on(uni.$TUIKitEvent.NET_STATE_CHANGE, this.onNetStateChange);
  33. // uni.$TUIKit.on(uni.$TUIKitEvent.SDK_RELOAD, this.onSDKReload);
  34. // console.log('IM')
  35. // uni.$on('updateTabbar', this.updateTabbar);
  36. // this.updateTabbar();
  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. updateTabbar() {
  84. // 获取当前主题
  85. const theme = this.globalData.themecolor;
  86. // 设置tabbar的图标
  87. const tabbarList = [{
  88. iconPath: `/static/images/tabbar/${theme}/home.png`,
  89. selectedIconPath: `/static/images/tabbar/${theme}/home_on.png`
  90. },
  91. {
  92. iconPath: `/static/images/tabbar/${theme}/home.png`,
  93. selectedIconPath: `/static/images/tabbar/${theme}/home_on.png`
  94. },
  95. {
  96. iconPath: `/static/images/tabbar/${theme}/home.png`,
  97. selectedIconPath: `/static/images/tabbar/${theme}/home_on.png`
  98. },
  99. {
  100. iconPath: `/static/images/tabbar/${theme}/home.png`,
  101. selectedIconPath: `/static/images/tabbar/${theme}/home_on.png`
  102. },
  103. ];
  104. // 这个style不要用循环
  105. uni.setTabBarStyle({
  106. color: '#acafac',
  107. selectedColor: '#118e4a'
  108. })
  109. tabbarList.forEach((item, index) => {
  110. // 只能一项设置 所以循环
  111. uni.setTabBarItem({
  112. index,
  113. ...item
  114. })
  115. })
  116. },
  117. // TODO:
  118. resetLoginData() {
  119. // this.globalData.expiresIn = '';
  120. // this.globalData.sessionID = '';
  121. // this.globalData.userInfo = {
  122. // userID: '',
  123. // userSig: '',
  124. // token: '',
  125. // phone: ''
  126. // };
  127. // this.globalData.userProfile = null;
  128. // logger.log(`| app | resetLoginData | globalData: ${this.globalData}`);
  129. },
  130. onTIMError() {},
  131. onSDKReady({
  132. name
  133. }) {
  134. console.log("im注册:" + name)
  135. const isSDKReady = name === uni.$TUIKitEvent.SDK_READY ? true : false
  136. console.log("im注册:" + isSDKReady)
  137. uni.$emit('isSDKReady', {
  138. isSDKReady: true
  139. });
  140. },
  141. onNetStateChange() {},
  142. onSDKReload() {},
  143. onSdkNotReady() {},
  144. onKickedOut() {
  145. uni.showToast({
  146. title: '您被踢下线',
  147. icon: 'error'
  148. });
  149. }
  150. }
  151. }
  152. </script>
  153. <style lang="scss">
  154. /*每个页面公共css */
  155. // @import 'animate.css';
  156. @import "uview-ui/index.scss";
  157. @import './assets/iconfont/iconfont.css';
  158. @import './assets/css/common.less';
  159. @import '@/assets/css/common.scss';
  160. @import '@/assets/css/commonTheme.css';
  161. @import '@/assets/css/theme.scss';
  162. page {
  163. background-color: #f6f6f6;
  164. }
  165. ::-webkit-scrollbar {
  166. width: 0 !important;
  167. height: 0 !important;
  168. }
  169. </style>
  170. <style>
  171. /*每个页面公共css */
  172. /* 解决小程序和app滚动条的问题 */
  173. /* #ifdef MP-WEIXIN || APP-PLUS */
  174. /deep/ ::-webkit-scrollbar {
  175. display: none !important;
  176. width: 0 !important;
  177. height: 0 !important;
  178. -webkit-appearance: none;
  179. background: transparent;
  180. color: transparent;
  181. }
  182. /* #endif */
  183. /* 解决H5 的问题 */
  184. /* #ifdef H5 */
  185. uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
  186. /* 隐藏滚动条,但依旧具备可以滚动的功能 */
  187. display: none;
  188. width: 0 !important;
  189. height: 0 !important;
  190. -webkit-appearance: none;
  191. background: transparent;
  192. color: transparent;
  193. }
  194. /* #endif */
  195. </style>