App.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. console.log(uni.getStorageSync('token') && !this.$store.getters.user.userId);
  22. if (uni.getStorageSync('token') && !this.$store.getters.user.userId) {
  23. getUserInfo().then(user => {
  24. if (user.code === 200) {
  25. let userInfo = user.data;
  26. this.$store.dispatch('app/changeOrganization', userInfo.organization);
  27. this.$store.dispatch('app/changeUser', userInfo);
  28. }
  29. })
  30. }
  31. // #endif
  32. },
  33. onHide() {}
  34. }
  35. </script>
  36. <style lang="scss">
  37. /*每个页面公共css */
  38. @import '@/uni_modules/uni-scss/index.scss';
  39. // 设置整个项目的背景色
  40. page {
  41. color: $uni-main-color;
  42. font-size: 28rpx;
  43. background: $uni-background-color;
  44. img {
  45. width: 100%;
  46. height: 100%;
  47. }
  48. }
  49. </style>