App.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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') || modelmes.search('iPhone 11 Pro Max') ||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. // if(uni.getStorageSync('isActivityStatus')){
  60. // const lockTime = uni.getStorageSync('lockTime')
  61. // const eTime = this.diffTime(lockTime)
  62. // this.$store.dispatch('setActivityFn',eTime)
  63. // }else{
  64. // this.$store.dispatch('setActivityFn',true)
  65. // }
  66. },
  67. methods:{
  68. ...mapMutations(['login','logout']),
  69. async getWxAuthorize(){
  70. const wechatCode = await authorize.getCode('weixin');// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  71. const getUserInfo = await authorize.getUserInfo('weixin');
  72. this.UserService.UserLoginAuthApplets({
  73. code:wechatCode,
  74. encryptedData:getUserInfo.encryptedData,
  75. iv:getUserInfo.iv
  76. })
  77. .then(response =>{
  78. this.$store.commit('updateStatus',response.data)
  79. this.login(response.data);
  80. uni.setStorageSync('token',response.data.token)
  81. uni.setStorageSync('unionId',response.data.unionId)
  82. })
  83. .catch(error =>{
  84. this.logout(error.data)
  85. uni.setStorageSync('unionId',error.data.unionId)
  86. this.$store.commit('updateStatus',error.data)
  87. })
  88. },
  89. refresh(){
  90. let TIME = (20*60)*1000;
  91. setInterval(()=>{
  92. authorize.checkLogin().then(res => {
  93. this.getWxAuthorize()
  94. })
  95. .catch(err => {
  96. console.log(new Date +'用户未授权微信信息')
  97. })
  98. },TIME)
  99. },
  100. diffTime(t){
  101. let date = Date.now();
  102. return (date -t) < 2*60*1000 ? false : true
  103. }
  104. },
  105. onShow: function() {
  106. },
  107. onHide: function() {
  108. console.log('App Hide')
  109. },
  110. }
  111. </script>
  112. <style lang="scss">
  113. /*每个页面公共css */
  114. @import "@/common/css/common.scss";
  115. @import "@/common/css/iconfont.scss";
  116. @import "@/common/css/style/thorui.css";
  117. @import "@/common/css/style/icon.css";
  118. view,
  119. scroll-view,
  120. swiper,
  121. swiper-item,
  122. cover-view,
  123. cover-image,
  124. icon,
  125. text,
  126. rich-text,
  127. progress,
  128. button,
  129. checkbox,
  130. form,
  131. input,
  132. label,
  133. radio,
  134. slider,
  135. switch,
  136. textarea,
  137. navigator,
  138. audio,
  139. camera,
  140. image,
  141. video {
  142. // box-sizing: border-box;
  143. }
  144. // page {
  145. // width: 100%;
  146. // height: 100%;
  147. // background: #fff;
  148. // filter: grayscale(100%);
  149. // filter: gray;
  150. // filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
  151. // --toast-default-width: 114px;
  152. // }
  153. page{
  154. height: 100%;
  155. background-color: #FFFFFF;
  156. }
  157. /* 骨架屏替代方案 */
  158. .Skeleton {
  159. background: #f3f3f3;
  160. padding: 20upx 0;
  161. border-radius: 8upx;
  162. }
  163. .clamp {
  164. overflow: hidden;
  165. text-overflow: ellipsis;
  166. white-space: nowrap;
  167. display: block;
  168. }
  169. .common-hover {
  170. background: #f5f5f5;
  171. }
  172. /* input 样式 */
  173. .input-placeholder {
  174. color: #999999;
  175. }
  176. .placeholder {
  177. color: #999999;
  178. }
  179. </style>