App.vue 4.7 KB

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