App.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 '@/common/config/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') ||
  18. modelmes.search('iPhone 11 Pro Max') ||
  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. async getWxAuthorize() {
  75. const wechatCode = await authorize.getCode('weixin')
  76. this.UserService.userInfoLogin({ code: wechatCode })
  77. .then(response => {
  78. this.login(response.data)
  79. this.$store.commit('updateStatus', response.data)
  80. })
  81. .catch(error => {
  82. uni.setStorage({
  83. //缓存游客用户openid
  84. key: 'openid',
  85. data: error.data.openid
  86. })
  87. this.logout()
  88. })
  89. },
  90. refresh() {
  91. let TIME = 20 * 60 * 1000
  92. setInterval(() => {
  93. authorize
  94. .getSetting()
  95. .then(res => {
  96. // console.log('是否已授权',res);//0:为取消授权 1:为已授权 2:为未操作
  97. if (res == 1) {
  98. this.getWxAuthorize()
  99. } else {
  100. console.log('授权失败============>:' + '用户取消授权或者未操作')
  101. }
  102. })
  103. .catch(error => {
  104. console.log('授权失败============>:' + '用户授权失败,提醒用户重新授权')
  105. })
  106. }, TIME)
  107. },
  108. diffTime(t) {
  109. let date = Date.now()
  110. return date - t < 2 * 60 * 1000 ? false : true
  111. }
  112. }
  113. }
  114. </script>
  115. <style lang="scss">
  116. /*每个页面公共css */
  117. @import '@/common/css/common.scss';
  118. @import '@/common/css/iconfont.scss';
  119. @import '@/common/css/style/thorui.css';
  120. @import '@/common/css/style/icon.css';
  121. view,
  122. scroll-view,
  123. swiper,
  124. swiper-item,
  125. cover-view,
  126. cover-image,
  127. icon,
  128. text,
  129. rich-text,
  130. progress,
  131. button,
  132. checkbox,
  133. form,
  134. input,
  135. label,
  136. radio,
  137. slider,
  138. switch,
  139. textarea,
  140. navigator,
  141. audio,
  142. camera,
  143. image,
  144. video {
  145. // box-sizing: border-box;
  146. }
  147. // page {
  148. // width: 100%;
  149. // height: 100%;
  150. // background: #fff;
  151. // filter: grayscale(100%);
  152. // filter: gray;
  153. // filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
  154. // --toast-default-width: 114px;
  155. // }
  156. page {
  157. height: 100%;
  158. background-color: #ffffff;
  159. }
  160. /* 骨架屏替代方案 */
  161. .Skeleton {
  162. background: #f3f3f3;
  163. padding: 20upx 0;
  164. border-radius: 8upx;
  165. }
  166. .clamp {
  167. overflow: hidden;
  168. text-overflow: ellipsis;
  169. white-space: nowrap;
  170. display: block;
  171. }
  172. .common-hover {
  173. background: #f5f5f5;
  174. }
  175. /* input 样式 */
  176. .input-placeholder {
  177. color: #999999;
  178. }
  179. .placeholder {
  180. color: #999999;
  181. }
  182. </style>