vue-vben-admin/src/layouts/default/index.tsx

140 lines
4.3 KiB
TypeScript
Raw Normal View History

2020-10-31 19:51:24 +08:00
import { defineComponent, unref, computed } from 'vue';
2020-09-28 20:19:10 +08:00
import { Layout, BackTop } from 'ant-design-vue';
2020-11-10 23:50:47 +08:00
import LayoutHeader from './header/LayoutHeader';
2020-09-28 20:19:10 +08:00
import { appStore } from '/@/store/modules/app';
import LayoutContent from './LayoutContent';
import LayoutSideBar from './LayoutSideBar';
import SettingBtn from './setting/index.vue';
import MultipleTabs from './multitabs/index';
import { MenuModeEnum, MenuTypeEnum } from '/@/enums/menuEnum';
import { useFullContent } from '/@/hooks/web/useFullContent';
import LockPage from '/@/views/sys/lock/index.vue';
import { registerGlobComp } from '/@/components/registerGlobComp';
2020-09-28 20:19:10 +08:00
import './index.less';
export default defineComponent({
name: 'DefaultLayout',
setup() {
2020-11-10 22:45:39 +08:00
// ! Only register global components here
// ! Can reduce the size of the first screen code
// default layout It is loaded after login. So it wont be packaged to the first screen
registerGlobComp();
2020-09-28 20:19:10 +08:00
const { getFullContent } = useFullContent();
const getProjectConfigRef = computed(() => appStore.getProjectConfig);
2020-10-31 19:51:24 +08:00
const getLockMainScrollStateRef = computed(() => appStore.getLockMainScrollState);
2020-09-28 20:19:10 +08:00
const showHeaderRef = computed(() => {
const {
headerSetting: { show },
} = unref(getProjectConfigRef);
return show;
});
2020-10-31 19:51:24 +08:00
2020-09-28 20:19:10 +08:00
const isShowMixHeaderRef = computed(() => {
const {
menuSetting: { type },
} = unref(getProjectConfigRef);
return type !== MenuTypeEnum.SIDEBAR && unref(showHeaderRef);
});
const getIsLockRef = computed(() => {
const { getLockInfo } = appStore;
const { isLock } = getLockInfo;
return isLock;
});
2020-09-28 20:19:10 +08:00
const showSideBarRef = computed(() => {
const {
2020-11-02 23:04:25 +08:00
menuSetting: { show, mode, split },
2020-09-28 20:19:10 +08:00
} = unref(getProjectConfigRef);
2020-11-02 23:04:25 +08:00
return split || (show && mode !== MenuModeEnum.HORIZONTAL && !unref(getFullContent));
2020-09-28 20:19:10 +08:00
});
const showFullHeaderRef = computed(() => {
return !unref(getFullContent) && unref(isShowMixHeaderRef) && unref(showHeaderRef);
});
2020-10-31 19:51:24 +08:00
const showInsetHeaderRef = computed(() => {
return !unref(getFullContent) && !unref(isShowMixHeaderRef) && unref(showHeaderRef);
});
const fixedHeaderClsRef = computed(() => {
2020-09-28 20:19:10 +08:00
const {
headerSetting: { fixed },
} = unref(getProjectConfigRef);
const fixedHeaderCls = fixed
? 'fixed' + (unref(getLockMainScrollStateRef) ? ' lock' : '')
: '';
return fixedHeaderCls;
});
2020-10-31 19:51:24 +08:00
const showTabsRef = computed(() => {
const {
multiTabsSetting: { show },
} = unref(getProjectConfigRef);
return show && !unref(getFullContent);
});
const showClassSideBarRef = computed(() => {
const {
menuSetting: { split, hidden },
} = unref(getProjectConfigRef);
return split ? hidden : true;
});
2020-11-02 23:04:25 +08:00
function getTarget(): any {
const {
headerSetting: { fixed },
} = unref(getProjectConfigRef);
return document.querySelector(`.default-layout__${fixed ? 'main' : 'content'}`);
}
return () => {
const { useOpenBackTop, showSettingButton } = unref(getProjectConfigRef);
2020-09-28 20:19:10 +08:00
return (
<Layout class="default-layout relative">
{() => (
<>
2020-11-10 23:50:47 +08:00
{/* lock page */}
{unref(getIsLockRef) && <LockPage />}
2020-11-10 23:50:47 +08:00
{/* back top */}
{useOpenBackTop && <BackTop target={getTarget} />}
{/* open setting drawer */}
{showSettingButton && <SettingBtn />}
2020-10-14 21:08:07 +08:00
{unref(showFullHeaderRef) && <LayoutHeader />}
2020-10-14 21:08:07 +08:00
2020-09-28 20:19:10 +08:00
<Layout>
{() => (
<>
{unref(showSideBarRef) && (
<LayoutSideBar class={unref(showClassSideBarRef) ? '' : 'hidden'} />
)}
<Layout class={[`default-layout__content`, unref(fixedHeaderClsRef)]}>
2020-09-28 20:19:10 +08:00
{() => (
<>
{unref(showInsetHeaderRef) && <LayoutHeader />}
2020-09-28 20:19:10 +08:00
{unref(showTabsRef) && <MultipleTabs />}
2020-11-10 23:50:47 +08:00
<LayoutContent class={unref(fixedHeaderClsRef)} />
2020-09-28 20:19:10 +08:00
</>
)}
</Layout>
</>
)}
</Layout>
</>
)}
</Layout>
);
};
},
});