App.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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','isWxAuthorize']),
  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. if(uni.getStorageSync('_WX_State')){
  93. this.getWxAuthorize()
  94. }else{
  95. console.log(new Date +'用户未授权微信信息')
  96. }
  97. },TIME)
  98. },
  99. diffTime(t){
  100. let date = Date.now();
  101. return (date -t) < 2*60*1000 ? false : true
  102. }
  103. },
  104. onShow: function() {
  105. },
  106. onHide: function() {
  107. console.log('App Hide')
  108. },
  109. }
  110. </script>
  111. <style lang="scss">
  112. /*每个页面公共css */
  113. @import "@/common/css/common.scss";
  114. @import "@/common/css/iconfont.scss";
  115. @import "@/common/css/style/thorui.css";
  116. @import "@/common/css/style/icon.css";
  117. view,
  118. scroll-view,
  119. swiper,
  120. swiper-item,
  121. cover-view,
  122. cover-image,
  123. icon,
  124. text,
  125. rich-text,
  126. progress,
  127. button,
  128. checkbox,
  129. form,
  130. input,
  131. label,
  132. radio,
  133. slider,
  134. switch,
  135. textarea,
  136. navigator,
  137. audio,
  138. camera,
  139. image,
  140. video {
  141. // box-sizing: border-box;
  142. }
  143. // page {
  144. // width: 100%;
  145. // height: 100%;
  146. // background: #fff;
  147. // filter: grayscale(100%);
  148. // filter: gray;
  149. // filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
  150. // --toast-default-width: 114px;
  151. // }
  152. page{
  153. height: 100%;
  154. background-color: #FFFFFF;
  155. }
  156. /* 骨架屏替代方案 */
  157. .Skeleton {
  158. background: #f3f3f3;
  159. padding: 20upx 0;
  160. border-radius: 8upx;
  161. }
  162. .clamp {
  163. overflow: hidden;
  164. text-overflow: ellipsis;
  165. white-space: nowrap;
  166. display: block;
  167. }
  168. .common-hover {
  169. background: #f5f5f5;
  170. }
  171. /* input 样式 */
  172. .input-placeholder {
  173. color: #999999;
  174. }
  175. .placeholder {
  176. color: #999999;
  177. }
  178. </style>