App.vue 4.8 KB

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