| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <template>
- <a-layout :class="['admin-layout', 'beauty-scroll']">
- <drawer v-if="isMobile" v-model="drawerOpen">
- <side-menu
- :theme="theme.mode"
- :menuData="menuData"
- :collapsed="false"
- :collapsible="false"
- @menuSelect="onMenuSelect"
- />
- </drawer>
- <side-menu
- :class="[fixedSideBar ? 'fixed-side' : '']"
- :theme="theme.mode"
- v-else-if="layout === 'side' || layout === 'mix'"
- :menuData="sideMenuData"
- :collapsed="collapsed"
- :collapsible="true"
- />
- <div
- v-if="fixedSideBar && !isMobile"
- :style="`width: ${sideMenuWidth}; min-width: ${sideMenuWidth};max-width: ${sideMenuWidth};`"
- class="virtual-side"
- ></div>
- <drawer v-if="!hideSetting" v-model="showSetting" placement="right">
- <div class="setting" slot="handler">
- <a-icon :type="showSetting ? 'close' : 'setting'" />
- </div>
- <setting />
- </drawer>
- <a-layout class="admin-layout-main beauty-scroll">
- <admin-header
- :class="[
- {
- 'fixed-tabs': fixedTabs,
- 'fixed-header': fixedHeader,
- 'multi-page': multiPage,
- },
- ]"
- :style="headerStyle"
- :menuData="headMenuData"
- :collapsed="collapsed"
- @toggleCollapse="toggleCollapse"
- />
- <!-- <a-layout-header :class="['virtual-header', {'fixed-tabs' : fixedTabs, 'fixed-header': fixedHeader, 'multi-page': multiPage}]" v-show="fixedHeader"></a-layout-header> -->
- <a-layout-content
- class="admin-layout-content"
- :style="`min-height: ${minHeight}px;`"
- >
- <div style="position: relative" class="admin-layout-content-subject">
- <slot></slot>
- </div>
- </a-layout-content>
- <!-- <a-layout-footer style="padding: 0px">
- <page-footer :link-list="footerLinks" :copyright="copyright" />
- </a-layout-footer> -->
- </a-layout>
- </a-layout>
- </template>
- <script>
- import AdminHeader from "./header/AdminHeader";
- // import PageFooter from './footer/PageFooter'
- import Drawer from "../components/tool/Drawer";
- import SideMenu from "../components/menu/SideMenu";
- import Setting from "../components/setting/Setting";
- import { mapState, mapMutations, mapGetters } from "vuex";
- // const minHeight = window.innerHeight - 64 - 122
- export default {
- name: "AdminLayout",
- components: { Setting, SideMenu, Drawer, AdminHeader },
- data() {
- return {
- minHeight: window.innerHeight - 64 - 122,
- collapsed: false,
- showSetting: false,
- drawerOpen: false,
- };
- },
- provide() {
- return {
- adminLayout: this,
- };
- },
- watch: {
- $route(val) {
- this.setActivated(val);
- },
- layout() {
- this.setActivated(this.$route);
- },
- isMobile(val) {
- if (!val) {
- this.drawerOpen = false;
- }
- },
- },
- computed: {
- ...mapState("setting", [
- "isMobile",
- "theme",
- "layout",
- "footerLinks",
- "copyright",
- "fixedHeader",
- "fixedSideBar",
- "fixedTabs",
- "hideSetting",
- "multiPage",
- ]),
- ...mapGetters("setting", ["firstMenu", "subMenu", "menuData"]),
- sideMenuWidth() {
- return this.collapsed ? "80px" : "256px";
- },
- headerStyle() {
- let width =
- this.fixedHeader && this.layout !== "head" && !this.isMobile
- ? `calc(100% - ${this.sideMenuWidth})`
- : "100%";
- let position = this.fixedHeader ? "fixed" : "static";
- // console.log(width);
- // console.log(position);
- return `width: ${width}; position: ${position};`;
- },
- headMenuData() {
- const { layout, menuData, firstMenu } = this;
- return layout === "mix" ? firstMenu : menuData;
- },
- sideMenuData() {
- const { layout, menuData, subMenu } = this;
- console.log(menuData, 666, this);
- return layout === "mix" ? subMenu : menuData;
- },
- },
- methods: {
- ...mapMutations("setting", ["correctPageMinHeight", "setActivatedFirst"]),
- toggleCollapse() {
- this.collapsed = !this.collapsed;
- },
- onMenuSelect() {
- this.toggleCollapse();
- },
- setActivated(route) {
- if (this.layout === "mix") {
- let matched = route.matched;
- matched = matched.slice(0, matched.length - 1);
- const { firstMenu } = this;
- for (let menu of firstMenu) {
- if (matched.findIndex((item) => item.path === menu.fullPath) !== -1) {
- this.setActivatedFirst(menu.fullPath);
- break;
- }
- }
- }
- },
- },
- created() {
- this.correctPageMinHeight(this.minHeight - 24);
- this.setActivated(this.$route);
- },
- beforeDestroy() {
- this.correctPageMinHeight(-this.minHeight + 24);
- },
- };
- </script>
- <style lang="less" scoped>
- .admin-layout {
- height: 100%;
- .side-menu {
- &.fixed-side {
- position: fixed;
- height: 100vh;
- left: 0;
- top: 0;
- }
- }
- .virtual-side {
- transition: all 0.2s;
- }
- .virtual-header {
- transition: all 0.2s;
- opacity: 0;
- &.fixed-tabs.multi-page:not(.fixed-header) {
- height: 0;
- }
- }
- .admin-layout-main {
- // min-height: 100vh;
- height: 100%;
- .admin-header {
- top: 0;
- right: 0;
- overflow: hidden;
- transition: all 0.2s;
- &.fixed-tabs.multi-page:not(.fixed-header) {
- height: 0;
- }
- }
- }
- .admin-layout-content {
- padding: 24px 24px 0;
- box-sizing: border-box;
- // background: #fff;
- /*overflow-x: hidden;*/
- /*min-height: calc(100vh - 64px - 122px);*/
- .admin-layout-content-subject {
- height: 100%;
- padding-top: 24px;
- box-sizing: border-box;
- }
- }
- .setting {
- background-color: @primary-color;
- color: @base-bg-color;
- border-radius: 5px 0 0 5px;
- line-height: 40px;
- font-size: 22px;
- width: 40px;
- height: 40px;
- box-shadow: -2px 0 8px @shadow-color;
- }
- }
- </style>
|