AppMain.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <section class="app-main">
  3. <div v-if="!$route.meta.nocrumb" style="height: 42.5px;">
  4. <breadcrumb :keep-alive-component-instance="keepAliveComponentInstance" :t_name="t_name" class="breadcrumb-container" />
  5. </div>
  6. <div ref="keepAliveContainer" class="keepAliveContainer" :style="{
  7. height: !$route.meta.nocrumb ? `calc(100% - 42.5px)` : '100%'
  8. }">
  9. <keep-alive>
  10. <router-view v-if="$route.meta.keepAlive && isRouterAlive" :key="$route.fullPath"/>
  11. </keep-alive>
  12. <router-view v-if="!$route.meta.keepAlive && isRouterAlive" :key="$route.fullPath"></router-view>
  13. </div>
  14. </section>
  15. </template>
  16. <script>
  17. import { setToken } from '@/utils/auth';
  18. import Breadcrumb from './Breadcrumb.vue';
  19. export default {
  20. name: 'AppMain',
  21. name: 'Layout',
  22. components: {
  23. Breadcrumb
  24. },
  25. provide () {
  26. // 父组件中通过provide来提供变量,在子组件中通过inject来注入。
  27. return {
  28. reloads: this.reloads,
  29. t_title: this.t_title
  30. };
  31. },
  32. data() {
  33. return {
  34. keepAliveComponentInstance: null,
  35. isRouterAlive: true,
  36. t_name:''
  37. };
  38. },
  39. methods:{
  40. reloads () {
  41. this.isRouterAlive = false;
  42. this.$nextTick(function () {
  43. this.isRouterAlive = true;
  44. });
  45. },
  46. t_title(e){
  47. this.t_name = e;
  48. this.$nextTick(function () {
  49. this.t_name = '';
  50. });
  51. console.log(this.t_name)
  52. }
  53. },
  54. mounted() {
  55. setTimeout(() => {
  56. window.addEventListener('message',function(e){
  57. if (e.data == 12312312) {
  58. setToken('');
  59. this.$router.push(`/login`);
  60. }
  61. },false)
  62. }, 2000)
  63. this.keepAliveComponentInstance = this.$refs.keepAliveContainer.childNodes[0].__vue__;
  64. },
  65. watch: {
  66. $route(to, from) {
  67. const { tagsView } = this.$store.state
  68. const whiteList = ['/hospital-search', '/hospital-caseViews', '/hospital-details', '/hospital-chargeDetails']
  69. if (tagsView && tagsView.visitedViews.length) {
  70. let bSwitch = 1
  71. tagsView.visitedViews.map(item => {
  72. if (whiteList.includes(item.path)) {
  73. bSwitch = 0
  74. }
  75. })
  76. if (bSwitch) {
  77. sessionStorage.removeItem("jingmiao_token")
  78. this.$router.push(`/login`);
  79. }
  80. }
  81. }
  82. }
  83. };
  84. </script>
  85. <style scoped>
  86. .app-main {
  87. /*50 = navbar */
  88. /* min-height: calc(100vh - 60px); */
  89. flex: 1;
  90. display: flex;
  91. flex-direction: column;
  92. width: 100%;
  93. /* width: 100%; */
  94. position: relative;
  95. /* overflow: hidden; */
  96. background: #f4f4f4;
  97. height: 100%;
  98. }
  99. .fixed-header + .app-main {
  100. margin-top: 50px;
  101. height: calc(100% - 50px);
  102. }
  103. .keepAliveContainer {
  104. flex: 1;
  105. display: flex;
  106. width: 100%;
  107. height: 100%;
  108. }
  109. .keepAliveContainer > div {
  110. /* display: flex; */
  111. /* flex: 1; */
  112. /* flex-direction: column; */
  113. /* overflow: auto; */
  114. width: calc(100% - 32px);
  115. height: calc(100% - 32px);
  116. padding: 0px !important;
  117. overflow: auto;
  118. margin: 16px !important
  119. }
  120. </style>
  121. <style lang="scss">
  122. // fix css style bug in open el-dialog
  123. .el-popup-parent--hidden {
  124. .fixed-header {
  125. padding-right: 15px;
  126. }
  127. }
  128. </style>