App.vue 4.9 KB

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