App.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. //小程序热更新代码
  12. // if (wx.canIUse('getUpdateManager')) {
  13. // const updateManager = wx.getUpdateManager()
  14. // updateManager.onCheckForUpdate(function (res) {
  15. // console.log('onCheckForUpdate====', res)
  16. // // 请求完新版本信息的回调
  17. // if (res.hasUpdate) {
  18. // console.log('res.hasUpdate====')
  19. // updateManager.onUpdateReady(function () {// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  20. // self.$util.modal('更新提示','新版本已经准备好,是否重启应用?','确定','取消',true,() =>{
  21. // updateManager.applyUpdate()
  22. // })
  23. // })
  24. // updateManager.onUpdateFailed(function () { // 新的版本下载失败
  25. // self.$util.modal('已经有新版本了哟~','新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~','确定','取消',true,() =>{
  26. // // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  27. // updateManager.applyUpdate()
  28. // })
  29. // })
  30. // }
  31. // })
  32. // }
  33. uni.getSystemInfo({
  34. success: function(e) {
  35. let modelmes = e.model;
  36. console.log(e);
  37. if (modelmes.search('iPhone 11') || modelmes.search('iPhone 11 Pro Max') ||modelmes.search('iPhone X') != -1) { //XS,XR,XS MAX均可以适配
  38. self.$store.dispatch('setVariableFun',true)
  39. }else{
  40. self.$store.dispatch('setVariableFun',false)
  41. }
  42. // #ifndef MP
  43. Vue.prototype.StatusBar = e.statusBarHeight;
  44. if (e.platform == 'android') {
  45. Vue.prototype.CustomBar = e.statusBarHeight + 50;
  46. Vue.prototype.platformClass = true
  47. } else {
  48. Vue.prototype.CustomBar = e.statusBarHeight + 45;
  49. Vue.prototype.platformClass = false
  50. };
  51. // #endif
  52. // #ifdef MP-WEIXIN || MP-QQ
  53. console.log(e.platform)
  54. if (e.platform == 'android') {
  55. Vue.prototype.platformClass = 'left'
  56. self.$store.dispatch('setVariableFun',false)
  57. } else {
  58. Vue.prototype.platformClass = 'center'
  59. self.$store.dispatch('setIsIphoneFun',true)
  60. }
  61. Vue.prototype.StatusBar = e.statusBarHeight;
  62. Vue.prototype.fontSizeSetting = e.fontSizeSetting
  63. Vue.prototype.screenWidth = e.screenWidth
  64. let capsule = wx.getMenuButtonBoundingClientRect();
  65. Vue.prototype.capsule = capsule
  66. if (capsule) {
  67. Vue.prototype.Custom = capsule;
  68. // Vue.prototype.capsuleSafe = uni.upx2px(750) - capsule.left + uni.upx2px(750) - capsule.right;
  69. Vue.prototype.CustomBar = capsule.bottom + capsule.top - e.statusBarHeight;
  70. } else {
  71. Vue.prototype.CustomBar = e.statusBarHeight + 50;
  72. }
  73. // #endif
  74. // #ifdef MP-ALIPAY
  75. Vue.prototype.StatusBar = e.statusBarHeight;
  76. Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
  77. // #endif
  78. }
  79. })
  80. this.refresh()
  81. },
  82. computed: {
  83. ...mapState(['hasLogin'])
  84. },
  85. methods:{
  86. ...mapMutations(['login','logout','isWxAuthorize']),
  87. async getWxAuthorize(){
  88. const wechatCode = await authorize.getCode('weixin');// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  89. const getUserInfo = await authorize.getUserInfo('weixin');
  90. this.UserService.UserLoginAuthApplets({
  91. code:wechatCode,
  92. encryptedData:getUserInfo.encryptedData,
  93. iv:getUserInfo.iv
  94. })
  95. .then(response =>{
  96. this.$store.commit('updateStatus',response.data)
  97. this.login(response.data);
  98. uni.setStorageSync('token',response.data.token)
  99. uni.setStorageSync('unionId',response.data.unionId)
  100. })
  101. .catch(error =>{
  102. this.logout(error.data)
  103. uni.setStorageSync('unionId',error.data.unionId)
  104. this.$store.commit('updateStatus',error.data)
  105. if(!this.hasLogin){
  106. if(uni.getStorageSync('isActivitySwitch')){
  107. const lockTime = uni.getStorageSync('lockTime')
  108. const eTime = this.diffTime(lockTime)
  109. this.$store.dispatch('setActivityFn',eTime)
  110. }else{
  111. this.$store.dispatch('setActivityFn',true)
  112. }
  113. }
  114. })
  115. },
  116. refresh(){
  117. let TIME = (20*60)*1000;
  118. setInterval(()=>{
  119. this.getWxAuthorize()
  120. },TIME)
  121. },
  122. diffTime(t){
  123. let date = Date.now();
  124. return (date -t) < 2*60*1000 ? false : true
  125. }
  126. },
  127. onShow: function() {
  128. },
  129. onHide: function() {
  130. console.log('App Hide')
  131. },
  132. }
  133. </script>
  134. <style lang="scss">
  135. /*每个页面公共css */
  136. @import "@/common/css/common.scss";
  137. @import "@/common/css/iconfont.scss";
  138. @import "@/common/css/style/thorui.css";
  139. @import "@/common/css/style/icon.css";
  140. view,
  141. scroll-view,
  142. swiper,
  143. swiper-item,
  144. cover-view,
  145. cover-image,
  146. icon,
  147. text,
  148. rich-text,
  149. progress,
  150. button,
  151. checkbox,
  152. form,
  153. input,
  154. label,
  155. radio,
  156. slider,
  157. switch,
  158. textarea,
  159. navigator,
  160. audio,
  161. camera,
  162. image,
  163. video {
  164. // box-sizing: border-box;
  165. }
  166. // page {
  167. // width: 100%;
  168. // height: 100%;
  169. // background: #fff;
  170. // filter: grayscale(100%);
  171. // filter: gray;
  172. // filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
  173. // --toast-default-width: 114px;
  174. // }
  175. page{
  176. height: 100%;
  177. background-color: #FFFFFF;
  178. }
  179. /* 骨架屏替代方案 */
  180. .Skeleton {
  181. background: #f3f3f3;
  182. padding: 20upx 0;
  183. border-radius: 8upx;
  184. }
  185. .clamp {
  186. overflow: hidden;
  187. text-overflow: ellipsis;
  188. white-space: nowrap;
  189. display: block;
  190. }
  191. .common-hover {
  192. background: #f5f5f5;
  193. }
  194. /* input 样式 */
  195. .input-placeholder {
  196. color: #999999;
  197. }
  198. .placeholder {
  199. color: #999999;
  200. }
  201. </style>