2021-12-12 01:04:13 +08:00
|
|
|
import { defineComponent } from 'vue';
|
|
|
|
import { mapGetters } from 'vuex';
|
2021-12-12 15:46:02 +08:00
|
|
|
import TdesignHeader from './components/Header.vue';
|
2021-12-12 01:04:13 +08:00
|
|
|
import TdesignBreadcrumb from './components/Breadcrumb.vue';
|
|
|
|
import TdesignFooter from './components/Footer.vue';
|
|
|
|
import TdesignSideNav from './components/SideNav';
|
2021-12-12 15:46:02 +08:00
|
|
|
import TdesignContent from './components/Content.vue';
|
2021-12-12 01:04:13 +08:00
|
|
|
|
2021-12-22 12:07:29 +08:00
|
|
|
import { prefix } from '@/config/global';
|
2021-12-12 01:04:13 +08:00
|
|
|
import TdesignSetting from './setting.vue';
|
2021-12-20 12:32:33 +08:00
|
|
|
import { SettingType, ClassName } from '@/interface';
|
2021-12-12 01:04:13 +08:00
|
|
|
import '@/style/layout.less';
|
|
|
|
|
2021-12-22 12:07:29 +08:00
|
|
|
const name = `${prefix}-base-layout`;
|
2021-12-12 01:04:13 +08:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
name,
|
|
|
|
components: {
|
|
|
|
TdesignHeader,
|
|
|
|
TdesignFooter,
|
|
|
|
TdesignSideNav,
|
|
|
|
TdesignSetting,
|
|
|
|
TdesignBreadcrumb,
|
2021-12-12 15:46:02 +08:00
|
|
|
TdesignContent,
|
2021-12-12 01:04:13 +08:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
...mapGetters({
|
|
|
|
showSidebar: 'setting/showSidebar',
|
|
|
|
showHeader: 'setting/showHeader',
|
|
|
|
showHeaderLogo: 'setting/showHeaderLogo',
|
|
|
|
showSidebarLogo: 'setting/showSidebarLogo',
|
|
|
|
showFooter: 'setting/showFooter',
|
|
|
|
mode: 'setting/mode',
|
2021-12-12 15:46:02 +08:00
|
|
|
menuRouters: 'permission/routers',
|
2021-12-12 01:04:13 +08:00
|
|
|
}),
|
|
|
|
setting(): SettingType {
|
|
|
|
return this.$store.state.setting;
|
|
|
|
},
|
|
|
|
mainLayoutCls(): ClassName {
|
|
|
|
return [
|
|
|
|
{
|
|
|
|
't-layout-has-sider': this.showSidebar,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
},
|
2021-12-12 15:46:02 +08:00
|
|
|
headerMenu() {
|
|
|
|
const { layout, splitMenu } = this.$store.state.setting;
|
|
|
|
const { menuRouters } = this;
|
|
|
|
if (layout === 'mix') {
|
|
|
|
if (splitMenu) {
|
|
|
|
return menuRouters.map((menu) => ({
|
|
|
|
...menu,
|
|
|
|
children: [],
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
return menuRouters;
|
|
|
|
},
|
|
|
|
sideMenu() {
|
|
|
|
const { layout, splitMenu } = this.$store.state.setting;
|
2021-12-20 12:32:33 +08:00
|
|
|
let { menuRouters } = this;
|
2021-12-12 15:46:02 +08:00
|
|
|
if (layout === 'mix' && splitMenu) {
|
2021-12-20 12:32:33 +08:00
|
|
|
menuRouters.forEach((menu) => {
|
|
|
|
if (this.$route.path.indexOf(menu.path) === 0) {
|
|
|
|
menuRouters = menu.children.map((subMenu) => ({ ...subMenu, path: `${menu.path}/${subMenu.path}` }));
|
2021-12-12 15:46:02 +08:00
|
|
|
}
|
2021-12-20 12:32:33 +08:00
|
|
|
});
|
2021-12-12 15:46:02 +08:00
|
|
|
}
|
|
|
|
return menuRouters;
|
|
|
|
},
|
2021-12-12 01:04:13 +08:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
renderSidebar() {
|
|
|
|
return (
|
|
|
|
this.showSidebar && (
|
|
|
|
<tdesign-side-nav
|
|
|
|
showLogo={this.showSidebarLogo}
|
|
|
|
layout={this.setting.layout}
|
|
|
|
isFixed={this.setting.isSidebarFixed}
|
|
|
|
menu={this.sideMenu}
|
2021-12-20 12:32:33 +08:00
|
|
|
theme={this.mode}
|
2021-12-12 01:04:13 +08:00
|
|
|
isCompact={this.setting.isSidebarCompact}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
renderHeader() {
|
|
|
|
return (
|
|
|
|
this.showHeader && (
|
|
|
|
<tdesign-header
|
|
|
|
showLogo={this.showHeaderLogo}
|
2021-12-20 12:32:33 +08:00
|
|
|
theme={this.mode}
|
2021-12-12 01:04:13 +08:00
|
|
|
layout={this.setting.layout}
|
|
|
|
isFixed={this.setting.isHeaderFixed}
|
|
|
|
menu={this.headerMenu}
|
|
|
|
isCompact={this.setting.isSidebarCompact}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
|
|
|
renderContent() {
|
|
|
|
const { showBreadcrumb } = this.setting;
|
|
|
|
const { showFooter } = this;
|
|
|
|
return (
|
2021-12-22 12:07:29 +08:00
|
|
|
<t-layout class={[`${prefix}-layout`]}>
|
|
|
|
<t-content class={`${prefix}-content-layout`}>
|
2021-12-12 01:04:13 +08:00
|
|
|
{showBreadcrumb && <tdesign-breadcrumb />}
|
2021-12-12 15:46:02 +08:00
|
|
|
<TdesignContent />
|
2021-12-12 01:04:13 +08:00
|
|
|
</t-content>
|
|
|
|
{showFooter && this.renderFooter()}
|
|
|
|
</t-layout>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
renderFooter() {
|
|
|
|
return (
|
2021-12-22 12:07:29 +08:00
|
|
|
<t-footer class={`${prefix}-footer-layout`}>
|
2021-12-12 01:04:13 +08:00
|
|
|
<tdesign-footer />
|
|
|
|
</t-footer>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { layout } = this.setting;
|
|
|
|
const header = this.renderHeader();
|
|
|
|
const sidebar = this.renderSidebar();
|
|
|
|
const content = this.renderContent();
|
|
|
|
|
|
|
|
return (
|
2021-12-22 12:07:29 +08:00
|
|
|
<div class={`${prefix}-wrapper`}>
|
2021-12-12 01:04:13 +08:00
|
|
|
{layout === 'side' ? (
|
|
|
|
<t-layout class={this.mainLayoutCls} key="side">
|
2021-12-12 15:46:02 +08:00
|
|
|
<t-aside>{sidebar}</t-aside>
|
2021-12-12 01:04:13 +08:00
|
|
|
<t-layout>{[header, content]}</t-layout>
|
|
|
|
</t-layout>
|
|
|
|
) : (
|
|
|
|
<t-layout key="no-side">
|
|
|
|
{header}
|
|
|
|
<t-layout class={this.mainLayoutCls}>{[sidebar, content]}</t-layout>
|
|
|
|
</t-layout>
|
|
|
|
)}
|
|
|
|
<tdesign-setting />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
});
|