App.vue 4.4 KB

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