App.vue 4.4 KB

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