App.vue 4.7 KB

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