后端

content-tabs.vue 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <div class="site-content site-content--tabs">
  3. <el-tabs
  4. v-model="tabActiveName"
  5. :closable="$store.state.contentTabs.tabList.length > 1"
  6. @tab-click="selectedTabHandle"
  7. @tab-remove="removeTabHandle">
  8. <el-tab-pane
  9. v-for="item in $store.state.contentTabs.tabList"
  10. :key="item.name"
  11. :label="item.title"
  12. :name="item.name">
  13. <el-card :body-style="contentViewHeight(item)">
  14. <iframe
  15. v-if="item.type === 'iframe'"
  16. :src="$store.state.menuNavIframeUrl + item.url"
  17. width="100%" height="100%" frameborder="0" scrolling="yes">
  18. </iframe>
  19. <keep-alive v-else>
  20. <router-view v-if="item.name === tabActiveName"></router-view>
  21. </keep-alive>
  22. </el-card>
  23. </el-tab-pane>
  24. </el-tabs>
  25. </div>
  26. </template>
  27. <script>
  28. import isEmpty from 'lodash/isEmpty'
  29. import { mapMutations } from 'vuex'
  30. export default {
  31. data () {
  32. return {
  33. }
  34. },
  35. computed: {
  36. tabActiveName: {
  37. get () {
  38. return this.$store.state.contentTabs.activeName
  39. },
  40. set (val) {
  41. this.UPDATE_CONTENT_TABS_ACTIVE_NAME({ name: val })
  42. }
  43. }
  44. },
  45. methods: {
  46. // tab内容容器显示高度
  47. contentViewHeight (tab) {
  48. var height = this.$store.state.documentClientHeight
  49. height -= 50 // site-topbar
  50. height -= 40 // el-tabs__header
  51. height -= 15 // el-tabs__header margin-bottom
  52. height -= 15 // el-tabs__content padding-bottom
  53. height -= 2 // el-card border-top border-bottom
  54. height += 'px'
  55. return tab.type === 'iframe' ? { height } : { minHeight: height }
  56. },
  57. // 选中tab
  58. selectedTabHandle (tab) {
  59. tab = this.$store.state.contentTabs.tabList.filter(item => item.name === tab.name)
  60. if (!isEmpty(tab)) {
  61. this.$router.push({ name: tab[0].name })
  62. }
  63. },
  64. // 删除tab
  65. removeTabHandle (tabName) {
  66. var newTabList = this.$store.state.contentTabs.tabList.filter(item => item.name !== tabName)
  67. if (!isEmpty(newTabList)) {
  68. // 当前选中tab被删除
  69. if (this.tabActiveName === tabName) {
  70. this.$router.push({ name: newTabList[newTabList.length - 1].name }, () => {
  71. this.tabActiveName = this.$route.name
  72. })
  73. }
  74. this.UPDATE_CONTENT_TABS({
  75. activeName: this.tabActiveName,
  76. tabList: newTabList
  77. })
  78. }
  79. },
  80. ...mapMutations(['UPDATE_CONTENT_TABS', 'UPDATE_CONTENT_TABS_ACTIVE_NAME'])
  81. }
  82. }
  83. </script>