App.vue 4.5 KB

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