App.vue 4.5 KB

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