|
| 1 | +<template> |
| 2 | + <t-layout :class="[`${prefix}-layout`]"> |
| 3 | + <t-tabs |
| 4 | + v-if="isUseTabsRouter" |
| 5 | + theme="card" |
| 6 | + :class="`${prefix}-layout-tabs-nav`" |
| 7 | + :value="$route.path" |
| 8 | + @change="handleChangeCurrentTab" |
| 9 | + :style="{ position: 'sticky', top: 0, width: '100%' }" |
| 10 | + > |
| 11 | + <t-tab-panel |
| 12 | + v-for="(route, idx) in tabRouterList" |
| 13 | + :value="route.path" |
| 14 | + :key="`${route.path}_${idx}`" |
| 15 | + :removable="!route.isHome" |
| 16 | + @remove="() => this.handleRemove(route.path, idx)" |
| 17 | + > |
| 18 | + <template #label> |
| 19 | + <t-dropdown |
| 20 | + trigger="context-menu" |
| 21 | + :minColumnWidth="128" |
| 22 | + :popupProps="{ overlayClassName: 'route-tabs-dropdown' }" |
| 23 | + > |
| 24 | + <template v-if="!route.isHome"> |
| 25 | + {{ route.title }} |
| 26 | + </template> |
| 27 | + <home-icon v-else /> |
| 28 | + <template #dropdown> |
| 29 | + <t-dropdown-menu v-if="this.$route.path === route.path"> |
| 30 | + <t-dropdown-item @click="() => this.handleRefresh(route.path, idx)"> |
| 31 | + <refresh-icon /> |
| 32 | + 刷新 |
| 33 | + </t-dropdown-item> |
| 34 | + <t-dropdown-item v-if="idx > 0" @lick="() => this.handleCloseAhead(route.path, idx)"> |
| 35 | + <arrow-left-icon /> |
| 36 | + 关闭左侧 |
| 37 | + </t-dropdown-item> |
| 38 | + <t-dropdown-item |
| 39 | + v-if="idx < this.tabRouterList.length - 1" |
| 40 | + @click="() => this.handleCloseBehind(route.path, idx)" |
| 41 | + > |
| 42 | + <arrow-right-icon /> |
| 43 | + 关闭右侧 |
| 44 | + </t-dropdown-item> |
| 45 | + <t-dropdown-item @click="() => this.handleCloseOther(route.path, idx)"> |
| 46 | + <close-circle-icon /> |
| 47 | + 关闭其它 |
| 48 | + </t-dropdown-item> |
| 49 | + </t-dropdown-menu> |
| 50 | + </template> |
| 51 | + </t-dropdown> |
| 52 | + </template> |
| 53 | + </t-tab-panel> |
| 54 | + </t-tabs> |
| 55 | + <t-content :class="`${prefix}-content-layout`"> |
| 56 | + <l-breadcrumb v-if="setting.showBreadcrumb" /> |
| 57 | + <l-content /> |
| 58 | + </t-content> |
| 59 | + <t-footer v-if="showFooter" :class="`${prefix}-footer-layout`"> |
| 60 | + <l-footer /> |
| 61 | + </t-footer> |
| 62 | + </t-layout> |
| 63 | +</template> |
| 64 | + |
| 65 | +<script lang="ts"> |
| 66 | +import Vue from 'vue'; |
| 67 | +import { mapGetters } from 'vuex'; |
| 68 | +import { RefreshIcon, ArrowLeftIcon, ArrowRightIcon, HomeIcon, CloseCircleIcon } from 'tdesign-icons-vue'; |
| 69 | +
|
| 70 | +import LContent from './Content.vue'; |
| 71 | +import LBreadcrumb from './Breadcrumb.vue'; |
| 72 | +import LFooter from './Footer.vue'; |
| 73 | +
|
| 74 | +import { prefix } from '@/config/global'; |
| 75 | +import { SettingType } from '@/interface'; |
| 76 | +
|
| 77 | +export default Vue.extend({ |
| 78 | + name: 'LayoutContent', |
| 79 | + components: { |
| 80 | + LContent, |
| 81 | + LFooter, |
| 82 | + LBreadcrumb, |
| 83 | + RefreshIcon, |
| 84 | + ArrowLeftIcon, |
| 85 | + ArrowRightIcon, |
| 86 | + HomeIcon, |
| 87 | + CloseCircleIcon, |
| 88 | + }, |
| 89 | + data() { |
| 90 | + return { |
| 91 | + prefix, |
| 92 | + }; |
| 93 | + }, |
| 94 | + computed: { |
| 95 | + ...mapGetters({ |
| 96 | + showFooter: 'setting/showFooter', |
| 97 | + mode: 'setting/mode', |
| 98 | + isUseTabsRouter: 'setting/isUseTabsRouter', |
| 99 | + menuRouters: 'permission/routers', |
| 100 | + tabRouterList: 'tabRouter/tabRouterList', |
| 101 | + }), |
| 102 | + setting(): SettingType { |
| 103 | + return this.$store.state.setting; |
| 104 | + }, |
| 105 | + }, |
| 106 | + methods: { |
| 107 | + handleRemove(path: string, routeIdx: number) { |
| 108 | + const nextRouter = this.tabRouterList[routeIdx + 1] || this.tabRouterList[routeIdx - 1]; |
| 109 | +
|
| 110 | + this.$store.commit('tabRouter/subtractCurrentTabRouter', { path, routeIdx }); |
| 111 | + if (path === this.$router.history?.current?.path) { |
| 112 | + this.$router.push(nextRouter.path); |
| 113 | + } |
| 114 | + }, |
| 115 | + handleChangeCurrentTab(path: string) { |
| 116 | + this.$router.push(path); |
| 117 | + }, |
| 118 | + handleRefresh(currentPath: string, routeIdx: number) { |
| 119 | + this.$store.commit('tabRouter/toggleTabRouterAlive', routeIdx); |
| 120 | + this.$nextTick(() => { |
| 121 | + this.$store.commit('tabRouter/toggleTabRouterAlive', routeIdx); |
| 122 | + this.$router.replace({ path: currentPath }); |
| 123 | + }); |
| 124 | + }, |
| 125 | + handleCloseAhead(path: string, routeIdx: number) { |
| 126 | + this.$store.commit('tabRouter/subtractTabRouterAhead', { path, routeIdx }); |
| 127 | + }, |
| 128 | + handleCloseBehind(path: string, routeIdx: number) { |
| 129 | + this.$store.commit('tabRouter/subtractTabRouterBehind', { path, routeIdx }); |
| 130 | + }, |
| 131 | + handleCloseOther(path: string, routeIdx: number) { |
| 132 | + this.$store.commit('tabRouter/subtractTabRouterOther', { path, routeIdx }); |
| 133 | + }, |
| 134 | + }, |
| 135 | +}); |
| 136 | +</script> |
0 commit comments