App.vue 4.7 KB

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