App.vue 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <script>
  2. import Vue from 'vue'
  3. import { getAuthToken } from '@/common/js/util.js'
  4. let __timerId = 0;
  5. export default {
  6. onLaunch() {
  7. uni.getSystemInfo({
  8. success: e=> {
  9. this.initSize(e);
  10. }
  11. })
  12. this.initLogin();
  13. },
  14. methods: {
  15. // 初始化登陆状态
  16. async initLogin(){
  17. const token = getAuthToken()
  18. if (!token) {
  19. return;
  20. }
  21. // 通过设置 Token 的方式,触发加载用户信息
  22. this.$store.commit('setToken', {
  23. token
  24. });
  25. },
  26. /**
  27. * 存储设备信息 参考colorUI
  28. * @param {Object}
  29. */
  30. initSize(e){
  31. const systemInfo = e;
  32. let navigationBarHeight;
  33. let custom = {};
  34. // #ifndef MP
  35. custom = {height: 36,width: 88};
  36. navigationBarHeight = 44;
  37. // #endif
  38. // #ifdef MP
  39. custom = wx.getMenuButtonBoundingClientRect();
  40. navigationBarHeight = custom.bottom + custom.top - e.statusBarHeight * 2;
  41. // #endif
  42. systemInfo.custom = custom;
  43. systemInfo.navigationBarHeight = navigationBarHeight;
  44. Vue.prototype.systemInfo = systemInfo;
  45. },
  46. //打开全局定时器
  47. openTimer(){
  48. this.closeTimer();
  49. __timerId = setInterval(()=>{
  50. this.$store.commit('setStateAttr', {
  51. key: 'timerIdent',
  52. val: !this.$store.state.timerIdent
  53. })
  54. }, 1000)
  55. },
  56. //关闭定时器
  57. closeTimer(){
  58. if(__timerId != 0){
  59. clearInterval(__timerId);
  60. __timerId = 0;
  61. }
  62. },
  63. },
  64. onShow() {
  65. console.log('app show');
  66. this.openTimer();
  67. },
  68. onHide() {
  69. this.closeTimer();
  70. }
  71. }
  72. </script>
  73. <style lang="scss">
  74. /*每个页面公共css */
  75. @import "@/uni_modules/uview-ui/index.scss";
  76. @import url("./common/css/common.css");
  77. @import url("./common/css/icon.css");
  78. </style>