index.vue 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div ref="layouts" :class="{ 'app-container': !$route.meta.hideTabBar }">
  3. <div class="layout-content">
  4. <keep-alive :include="include">
  5. <router-view v-if="$route.meta.keepAlive"></router-view>
  6. </keep-alive>
  7. <router-view v-if="!$route.meta.keepAlive"></router-view>
  8. </div>
  9. <div v-if="!$route.meta.hideTabBar" class="layout-footer">
  10. <TabBar />
  11. </div>
  12. </div>
  13. </template>
  14. <script>
  15. import TabBar from '@/components/TabBar'
  16. import { userInfo } from '@/api/public'
  17. export default {
  18. name:"home",
  19. data() {
  20. return {
  21. container: null,
  22. include: [],
  23. }
  24. },
  25. components: {
  26. TabBar
  27. },
  28. created() {
  29. this.getUserInfo();
  30. },
  31. watch: {
  32. $route(to, from) {
  33. //console.log("home route",to,from);
  34. if(to.query && to.query.event=='SwitchUser')
  35. {
  36. this.getUserInfo();
  37. }
  38. //如果 要 to(进入) 的页面是需要 keepAlive 缓存的,把 name push 进 include数组
  39. if (to.meta.keepAlive) {
  40. !this.include.includes(to.name) && this.include.push(to.name)
  41. console.log(this.include, '缓存列表')
  42. }
  43. /**
  44. * 如果要form(离开)的页面是keepAlive缓存的,
  45. * 再根据deep来判断是前进还是后退
  46. */
  47. //后退
  48. console.log(from.meta.keepAlive, to.meta.deep, from.meta.deep, 'ppppppppp')
  49. if (from.meta.keepAlive && to.meta.deep < from.meta.deep) {
  50. let index = this.include.indexOf(from.name)
  51. index !== -1 && this.include.splice(index, 1)
  52. console.log(this.include, '缓存列表2')
  53. }
  54. console.log(this.include, '缓存列表3')
  55. }
  56. },
  57. methods: {
  58. getUserInfo() {
  59. userInfo().then(info => {
  60. this.$store.commit('SET_USER_NAME', info.user.name)
  61. this.$store.commit('SET_USER_ROLELIST', info.roleList)
  62. this.$store.commit('SET_USER_ID', info.user.id)
  63. this.$store.commit('SET_USER_ORGID', info.user.orgId)
  64. this.$store.commit('SET_USER_ORGNAME', info.user.orgName)
  65. this.$store.commit('SET_USER_ORGTYPE', info.user.orgType)
  66. // this.$store.commit('SET_USER_SUBUSERLIST', info.subUserList??null)
  67. this.$store.commit('SET_MASTER_USER_ID', info.masterUserId)
  68. this.$store.commit('SET_MASTER_USER_NAME', info.masterUserName)
  69. this.$store.commit('SET_MASTER_SIGNATURE_SEAL', info.user.signatureSeal)
  70. //登陆之后手动触发一次水印数据刷新
  71. this.$parent.$refs.watercom.getWater(1)
  72. })
  73. this.$store.dispatch('getOrgTree');
  74. this.$store.dispatch('getOrgTreeHangshe');
  75. this.$store.dispatch('redDot')
  76. },
  77. }
  78. }
  79. </script>