App.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. if(uni.getStorageSync('isActivityStatus')){
  82. const lockTime = uni.getStorageSync('lockTime')
  83. const eTime = this.diffTime(lockTime)
  84. this.$store.dispatch('setActivityFn',eTime)
  85. }else{
  86. this.$store.dispatch('setActivityFn',true)
  87. }
  88. },
  89. methods:{
  90. ...mapMutations(['login','logout','isWxAuthorize']),
  91. async getWxAuthorize(){
  92. const wechatCode = await authorize.getCode('weixin');// 根据微信的code获取用户登录状态:1已登录过 -1未登录过
  93. const getUserInfo = await authorize.getUserInfo('weixin');
  94. this.UserService.UserLoginAuthApplets({
  95. code:wechatCode,
  96. encryptedData:getUserInfo.encryptedData,
  97. iv:getUserInfo.iv
  98. })
  99. .then(response =>{
  100. this.$store.commit('updateStatus',response.data)
  101. this.login(response.data);
  102. uni.setStorageSync('token',response.data.token)
  103. uni.setStorageSync('unionId',response.data.unionId)
  104. })
  105. .catch(error =>{
  106. this.logout(error.data)
  107. uni.setStorageSync('unionId',error.data.unionId)
  108. this.$store.commit('updateStatus',error.data)
  109. })
  110. },
  111. refresh(){
  112. let TIME = (20*60)*1000;
  113. setInterval(()=>{
  114. this.getWxAuthorize()
  115. },TIME)
  116. },
  117. diffTime(t){
  118. let date = Date.now();
  119. return (date -t) < 2*60*1000 ? false : true
  120. }
  121. },
  122. onShow: function() {
  123. },
  124. onHide: function() {
  125. console.log('App Hide')
  126. },
  127. }
  128. </script>
  129. <style lang="scss">
  130. /*每个页面公共css */
  131. @import "@/common/css/common.scss";
  132. @import "@/common/css/iconfont.scss";
  133. @import "@/common/css/style/thorui.css";
  134. @import "@/common/css/style/icon.css";
  135. view,
  136. scroll-view,
  137. swiper,
  138. swiper-item,
  139. cover-view,
  140. cover-image,
  141. icon,
  142. text,
  143. rich-text,
  144. progress,
  145. button,
  146. checkbox,
  147. form,
  148. input,
  149. label,
  150. radio,
  151. slider,
  152. switch,
  153. textarea,
  154. navigator,
  155. audio,
  156. camera,
  157. image,
  158. video {
  159. // box-sizing: border-box;
  160. }
  161. // page {
  162. // width: 100%;
  163. // height: 100%;
  164. // background: #fff;
  165. // filter: grayscale(100%);
  166. // filter: gray;
  167. // filter: progid:DXImageTransform.Microsoft.BasicImage(grayscale=1);
  168. // --toast-default-width: 114px;
  169. // }
  170. page{
  171. height: 100%;
  172. background-color: #FFFFFF;
  173. }
  174. /* 骨架屏替代方案 */
  175. .Skeleton {
  176. background: #f3f3f3;
  177. padding: 20upx 0;
  178. border-radius: 8upx;
  179. }
  180. .clamp {
  181. overflow: hidden;
  182. text-overflow: ellipsis;
  183. white-space: nowrap;
  184. display: block;
  185. }
  186. .common-hover {
  187. background: #f5f5f5;
  188. }
  189. /* input 样式 */
  190. .input-placeholder {
  191. color: #999999;
  192. }
  193. .placeholder {
  194. color: #999999;
  195. }
  196. </style>