App.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <script>
  2. import Vue from 'vue';
  3. export default {
  4. onLaunch: function() {
  5. // #ifdef MP-WEIXIN
  6. // 小程序更新
  7. const updateManager = uni.getUpdateManager();
  8. // 请求完新版本信息
  9. updateManager.onCheckForUpdate((res) => {
  10. // console.log(res.hasUpdate);
  11. });
  12. // 新的版本已经下载好
  13. updateManager.onUpdateReady((res) => {
  14. uni.showModal({
  15. title: '更新提示',
  16. content: '新版本已经准备好,是否重启应用?',
  17. success(res) {
  18. if (res.confirm) {
  19. // 调用 applyUpdate 应用新版本并重启
  20. updateManager.applyUpdate();
  21. }
  22. },
  23. });
  24. });
  25. // 新的版本下载失败
  26. updateManager.onUpdateFailed((res) => {});
  27. uni.$on('updateUserInfo', () => {
  28. this.updateUserInfo();
  29. });
  30. this.updateUserInfo();
  31. // #endif
  32. uni.getSystemInfo({
  33. success: function(e) {
  34. console.log(e);
  35. Vue.prototype.StatusBar = e.statusBarHeight;
  36. // #ifdef MP-WEIXIN
  37. let custom = wx.getMenuButtonBoundingClientRect();
  38. Vue.prototype.Custom = custom;
  39. Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight + 4;
  40. // #endif
  41. // #ifndef MP-WEIXIN
  42. Vue.prototype.CustomBar = 48
  43. // #endif
  44. //用来判断是否iphoneX类型的全面屏设备
  45. if (e.model.indexOf('iPhone X') == 0) {
  46. Vue.prototype.isIphoneX = 68;
  47. } else {
  48. Vue.prototype.isIphoneX = 0;
  49. }
  50. },
  51. });
  52. },
  53. onShow: function() {
  54. },
  55. onHide: function() {
  56. },
  57. methods: {
  58. // #ifdef MP-WEIXIN
  59. async updateUserInfo() {
  60. // if (this.$store.state.isLogin) {
  61. // const data = await this.$getUserInfo();
  62. // if (!data) {
  63. // this.$store.commit('changeLoginStatus', false);
  64. // this.$store.commit('changeToken', '');
  65. // uni.removeStorageSync('isLogin');
  66. // uni.removeStorageSync('token');
  67. // }
  68. // }
  69. // this.$isResolve();
  70. // uni.login({
  71. // provider: 'weixin',
  72. // success: (loginRes) => {
  73. // console.log(loginRes.code)
  74. // this.$axios({
  75. // url: '/v1app/user/auth',
  76. // params: {
  77. // code: loginRes.code,
  78. // },
  79. // }).then((res) => {
  80. // try {
  81. // console.log('====token====', res.data.token);
  82. // if (this.$store.state.isLogin) {
  83. // this.$store.commit('changeToken', res.data.token);
  84. // uni.setStorageSync('token', res.data.token);
  85. // this.$getUserInfo();
  86. // }
  87. // this.$isResolve();
  88. // } catch (e) {
  89. // console.error(e);
  90. // }
  91. // }).catch(res => {
  92. // this.$store.commit('changeLoginStatus', false);
  93. // this.$store.commit('changeToken', '');
  94. // uni.removeStorageSync('isLogin');
  95. // uni.removeStorageSync('token');
  96. // this.$isResolve();
  97. // })
  98. // },
  99. // });
  100. },
  101. // #endif
  102. },
  103. }
  104. </script>
  105. <style lang="scss">
  106. /*每个页面公共css */
  107. @import "uview-ui/index.scss";
  108. @import "styles/iconfont.css";
  109. </style>