App.vue 6.1 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('app/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. console.log(reg)
  23. if (
  24. modelmes.search('iPhone 11') != -1 ||
  25. modelmes.search('iPhone 11 Pro Max') != -1 ||
  26. modelmes.search('iPhone 12') != -1 ||
  27. modelmes.search('iPhone X') != -1
  28. ) {
  29. //XS,XR,XS MAX均可以适配
  30. self.$store.dispatch('app/setVariableFun', true)
  31. } else {
  32. self.$store.dispatch('app/setVariableFun', false)
  33. }
  34. // #ifndef MP
  35. Vue.prototype.StatusBar = e.statusBarHeight
  36. if (e.platform == 'android') {
  37. Vue.prototype.CustomBar = e.statusBarHeight + 50
  38. Vue.prototype.platformClass = true
  39. } else {
  40. Vue.prototype.CustomBar = e.statusBarHeight + 45
  41. Vue.prototype.platformClass = false
  42. }
  43. // #endif
  44. // #ifdef MP-WEIXIN || MP-QQ
  45. console.log(e.platform)
  46. if (e.platform == 'android') {
  47. Vue.prototype.platformClass = 'left'
  48. self.$store.dispatch('app/setVariableFun', false)
  49. } else {
  50. Vue.prototype.platformClass = 'center'
  51. self.$store.dispatch('app/setIsIphoneFun', true)
  52. }
  53. Vue.prototype.StatusBar = e.statusBarHeight
  54. Vue.prototype.fontSizeSetting = e.fontSizeSetting
  55. Vue.prototype.screenWidth = e.screenWidth
  56. let capsule = wx.getMenuButtonBoundingClientRect()
  57. Vue.prototype.capsule = capsule
  58. if (capsule) {
  59. Vue.prototype.Custom = capsule
  60. // Vue.prototype.capsuleSafe = uni.upx2px(750) - capsule.left + uni.upx2px(750) - capsule.right;
  61. Vue.prototype.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight
  62. } else {
  63. Vue.prototype.CustomBar = e.statusBarHeight + 50
  64. }
  65. // #endif
  66. // #ifdef MP-ALIPAY
  67. Vue.prototype.StatusBar = e.statusBarHeight
  68. Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight
  69. // #endif
  70. }
  71. })
  72. this.refresh()
  73. if (uni.getStorageSync('isActivityStatus')) {
  74. const lockTime = uni.getStorageSync('lockTime')
  75. const eTime = this.diffTime(lockTime)
  76. this.$store.dispatch('app/setActivityFn', eTime)
  77. } else {
  78. this.$store.dispatch('app/setActivityFn', true)
  79. }
  80. },
  81. methods: {
  82. ...mapMutations('app', ['login', 'logout', 'updateStatus']),
  83. async getWxAuthorize() {
  84. const wechatCode = await authorize.getCode('weixin')
  85. this.UserService.userInfoLogin({
  86. code: wechatCode
  87. })
  88. .then(response => {
  89. this.login(response.data)
  90. this.updateStatus(response.data)
  91. })
  92. .catch(error => {
  93. uni.setStorage({
  94. //缓存游客用户openid
  95. key: 'openid',
  96. data: error.data.openid
  97. })
  98. this.logout()
  99. })
  100. },
  101. refresh() {
  102. let TIME = 20 * 60 * 1000
  103. setInterval(() => {
  104. authorize
  105. .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>