App.vue 2.7 KB

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