赫艾前端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
4.3 KiB

4 years ago
  1. <template>
  2. <main class="site-content" :class="{ 'site-content--tabs': $route.meta.isTab }">
  3. <!-- 主入口标签页 s -->
  4. <el-tabs
  5. v-if="$route.meta.isTab"
  6. v-model="mainTabsActiveName"
  7. :closable="true"
  8. @tab-click="selectedTabHandle"
  9. @tab-remove="removeTabHandle">
  10. <el-dropdown class="site-tabs__tools" :show-timeout="0">
  11. <i class="el-icon-arrow-down el-icon--right"></i>
  12. <el-dropdown-menu slot="dropdown">
  13. <el-dropdown-item @click.native="tabsCloseCurrentHandle">关闭当前标签页</el-dropdown-item>
  14. <el-dropdown-item @click.native="tabsCloseOtherHandle">关闭其它标签页</el-dropdown-item>
  15. <el-dropdown-item @click.native="tabsCloseAllHandle">关闭全部标签页</el-dropdown-item>
  16. <el-dropdown-item @click.native="refresh()">刷新当前标签页</el-dropdown-item>
  17. </el-dropdown-menu>
  18. </el-dropdown>
  19. <el-tab-pane
  20. v-for="item in mainTabs"
  21. :key="item.name"
  22. :label="item.title"
  23. :name="item.name">
  24. <el-card :body-style="siteContentViewHeight">
  25. <iframe
  26. v-if="item.type === 'iframe'"
  27. :src="item.iframeUrl"
  28. width="100%" height="100%" frameborder="0" scrolling="yes">
  29. </iframe>
  30. <keep-alive v-else>
  31. <router-view v-if="item.name === mainTabsActiveName" />
  32. </keep-alive>
  33. </el-card>
  34. </el-tab-pane>
  35. </el-tabs>
  36. <!-- 主入口标签页 e -->
  37. <el-card v-else :body-style="siteContentViewHeight">
  38. <keep-alive>
  39. <router-view />
  40. </keep-alive>
  41. </el-card>
  42. </main>
  43. </template>
  44. <script>
  45. import { isURL } from '@/utils/validate'
  46. export default {
  47. inject: ['refresh'],
  48. data () {
  49. return {
  50. }
  51. },
  52. computed: {
  53. documentClientHeight: {
  54. get () { return this.$store.state.common.documentClientHeight }
  55. },
  56. menuActiveName: {
  57. get () { return this.$store.state.common.menuActiveName },
  58. set (val) { this.$store.commit('common/updateMenuActiveName', val) }
  59. },
  60. mainTabs: {
  61. get () { return this.$store.state.common.mainTabs },
  62. set (val) { this.$store.commit('common/updateMainTabs', val) }
  63. },
  64. mainTabsActiveName: {
  65. get () { return this.$store.state.common.mainTabsActiveName },
  66. set (val) { this.$store.commit('common/updateMainTabsActiveName', val) }
  67. },
  68. siteContentViewHeight () {
  69. var height = this.documentClientHeight - 50 - 30 - 2
  70. if (this.$route.meta.isTab) {
  71. height -= 40
  72. return isURL(this.$route.meta.iframeUrl) ? { height: height + 'px' } : { minHeight: height + 'px' }
  73. }
  74. return { minHeight: height + 'px' }
  75. }
  76. },
  77. methods: {
  78. // tabs, 选中tab
  79. selectedTabHandle (tab) {
  80. tab = this.mainTabs.filter(item => item.name === tab.name)
  81. if (tab.length >= 1) {
  82. this.$router.push({ name: tab[0].name, query: tab[0].query, params: tab[0].params })
  83. }
  84. },
  85. // tabs, 删除tab
  86. removeTabHandle (tabName) {
  87. this.mainTabs = this.mainTabs.filter(item => item.name !== tabName)
  88. if (this.mainTabs.length >= 1) {
  89. // 当前选中tab被删除
  90. if (tabName === this.mainTabsActiveName) {
  91. var tab = this.mainTabs[this.mainTabs.length - 1]
  92. this.$router.push({ name: tab.name, query: tab.query, params: tab.params }, () => {
  93. this.mainTabsActiveName = this.$route.name
  94. })
  95. }
  96. } else {
  97. this.menuActiveName = ''
  98. this.$router.push({ name: 'home' })
  99. }
  100. },
  101. // tabs, 关闭当前
  102. tabsCloseCurrentHandle () {
  103. this.removeTabHandle(this.mainTabsActiveName)
  104. },
  105. // tabs, 关闭其它
  106. tabsCloseOtherHandle () {
  107. this.mainTabs = this.mainTabs.filter(item => item.name === this.mainTabsActiveName)
  108. },
  109. // tabs, 关闭全部
  110. tabsCloseAllHandle () {
  111. this.mainTabs = []
  112. this.menuActiveName = ''
  113. this.$router.push({ name: 'home' })
  114. },
  115. // tabs, 刷新当前
  116. tabsRefreshCurrentHandle () {
  117. var tab = this.$route
  118. this.removeTabHandle(tab.name)
  119. this.$nextTick(() => {
  120. this.$router.push({ name: tab.name, query: tab.query, params: tab.params })
  121. })
  122. }
  123. }
  124. }
  125. </script>