App.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. <script>
  2. /**
  3. * vuex管理登陆状态,具体可以参考官方登陆模板示例
  4. */
  5. import Vue from 'vue'
  6. import { mapState, mapMutations } from 'vuex'
  7. import authorize from '@/common/authorize.js'
  8. import wxLogin from '@/services/wxLogin.js'
  9. export default {
  10. onLaunch: function() {
  11. let self = this
  12. uni.getSystemInfo({
  13. success: function(e) {
  14. let modelmes = e.model
  15. self.$store.commit('app/setWindowHeight', e.windowHeight)
  16. // iphone x以上的版本都要控制下巴高度
  17. if (/iphone [1|x]\s?/i.test(modelmes)) {
  18. self.$store.dispatch('app/setVariableFun', true)
  19. } else {
  20. self.$store.dispatch('app/setVariableFun', false)
  21. }
  22. // #ifndef MP
  23. Vue.prototype.StatusBar = e.statusBarHeight
  24. if (e.platform == 'android') {
  25. Vue.prototype.CustomBar = e.statusBarHeight + 50
  26. Vue.prototype.platformClass = true
  27. } else {
  28. Vue.prototype.CustomBar = e.statusBarHeight + 45
  29. Vue.prototype.platformClass = false
  30. }
  31. // #endif
  32. // #ifdef MP-WEIXIN || MP-QQ
  33. console.log(e.platform)
  34. if (e.platform == 'android') {
  35. Vue.prototype.platformClass = 'left'
  36. self.$store.dispatch('app/setVariableFun', false)
  37. } else {
  38. Vue.prototype.platformClass = 'center'
  39. self.$store.dispatch('app/setIsIphoneFun', true)
  40. }
  41. Vue.prototype.StatusBar = e.statusBarHeight
  42. Vue.prototype.fontSizeSetting = e.fontSizeSetting
  43. Vue.prototype.screenWidth = e.screenWidth
  44. let capsule = wx.getMenuButtonBoundingClientRect()
  45. Vue.prototype.capsule = capsule
  46. if (capsule) {
  47. Vue.prototype.Custom = capsule
  48. // Vue.prototype.capsuleSafe = uni.upx2px(750) - capsule.left + uni.upx2px(750) - capsule.right;
  49. Vue.prototype.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight
  50. } else {
  51. Vue.prototype.CustomBar = e.statusBarHeight + 50
  52. }
  53. // #endif
  54. // #ifdef MP-ALIPAY
  55. Vue.prototype.StatusBar = e.statusBarHeight
  56. Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight
  57. // #endif
  58. }
  59. })
  60. this.refresh()
  61. if (uni.getStorageSync('isActivityStatus')) {
  62. const lockTime = uni.getStorageSync('lockTime')
  63. const eTime = this.diffTime(lockTime)
  64. this.$store.dispatch('app/setActivityFn', eTime)
  65. } else {
  66. this.$store.dispatch('app/setActivityFn', true)
  67. }
  68. },
  69. methods: {
  70. ...mapMutations('app', ['login', 'logout', 'updateStatus']),
  71. async getWxAuthorize() {
  72. const wechatCode = await authorize.getCode('weixin')
  73. this.UserService.userInfoLogin({
  74. code: wechatCode
  75. })
  76. .then(response => {
  77. this.login(response.data)
  78. this.updateStatus(response.data)
  79. })
  80. .catch(error => {
  81. uni.setStorage({
  82. //缓存游客用户openid
  83. key: 'openid',
  84. data: error.data.openid
  85. })
  86. this.logout()
  87. })
  88. },
  89. refresh() {
  90. let TIME = 20 * 60 * 1000
  91. setInterval(() => {
  92. authorize
  93. .getSetting()
  94. .then(res => {
  95. // console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
  96. if (res == 1) {
  97. this.getWxAuthorize()
  98. } else {
  99. console.log('授权失败============>:' + '用户取消授权或者未操作')
  100. }
  101. })
  102. .catch(error => {
  103. console.log('授权失败============>:' + '用户授权失败,提醒用户重新授权')
  104. })
  105. }, TIME)
  106. },
  107. diffTime(t) {
  108. let date = Date.now()
  109. return date - t < 2 * 60 * 1000 ? false : true
  110. }
  111. }
  112. }
  113. </script>
  114. <style lang="scss">
  115. /*每个页面公共css */
  116. @import '@/common/css/common.scss';
  117. @import '@/common/css/iconfont.scss';
  118. @import '@/common/css/style/thorui.css';
  119. @import '@/common/css/style/icon.css';
  120. view,
  121. scroll-view,
  122. swiper,
  123. swiper-item,
  124. cover-view,
  125. cover-image,
  126. icon,
  127. text,
  128. rich-text,
  129. progress,
  130. button,
  131. checkbox,
  132. form,
  133. input,
  134. label,
  135. radio,
  136. slider,
  137. switch,
  138. textarea,
  139. navigator,
  140. audio,
  141. camera,
  142. image,
  143. video {
  144. // box-sizing: border-box;
  145. }
  146. // page {
  147. // width: 100%;
  148. // height: 100%;
  149. // background: #fff;
  150. // filter: grayscale(100%);
  151. // filter: gray;
  152. // filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
  153. // --toast-default-width: 114px;
  154. // }
  155. page {
  156. height: 100%;
  157. background-color: #ffffff;
  158. }
  159. /* 骨架屏替代方案 */
  160. .Skeleton {
  161. background: #f3f3f3;
  162. padding: 20upx 0;
  163. border-radius: 8upx;
  164. }
  165. .clamp {
  166. overflow: hidden;
  167. text-overflow: ellipsis;
  168. white-space: nowrap;
  169. display: block;
  170. }
  171. .common-hover {
  172. background: #f5f5f5;
  173. }
  174. /* input 样式 */
  175. .input-placeholder {
  176. color: #999999;
  177. }
  178. .placeholder {
  179. color: #999999;
  180. }
  181. .uni-swiper__dots-box{display: none !important;}
  182. </style>