App.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <script>
  2. import {
  3. getUserInfo
  4. } from '@/request/api/login'
  5. export default {
  6. onLaunch() {
  7. console.log('App Launch')
  8. },
  9. onShow() {
  10. // #ifdef H5
  11. if (sessionStorage.getItem('store')) {
  12. this.$store.replaceState(Object.assign({}, this.$store.state, JSON.parse(sessionStorage.getItem(
  13. 'store'))));
  14. sessionStorage.setItem('store', ''); //重新置完清空session
  15. }
  16. window.addEventListener('beforeunload', () => {
  17. sessionStorage.setItem('store', JSON.stringify(this.$store.state));
  18. });
  19. // #endif
  20. // #ifdef MP-WEIXIN
  21. if (uni.getStorageSync('token') && !this.$store.getters.user.userId) {
  22. getUserInfo().then(user => {
  23. if (user.code === 200) {
  24. let userInfo = user.data;
  25. this.$store.dispatch('app/changeOrganization', userInfo.organization);
  26. this.$store.dispatch('app/changeUser', userInfo);
  27. }
  28. })
  29. }
  30. // #endif
  31. },
  32. onHide() {}
  33. }
  34. </script>
  35. <style lang="scss">
  36. /*每个页面公共css */
  37. @import '@/uni_modules/uni-scss/index.scss';
  38. // 设置整个项目的背景色
  39. page {
  40. color: $uni-main-color;
  41. font-size: 28rpx;
  42. background: $uni-background-color;
  43. img {
  44. width: 100%;
  45. height: 100%;
  46. }
  47. }
  48. </style>