vben
2020-10-31 77028321816f00799cc3f70d3f0d6bde27c34522
src/layouts/default/index.tsx
@@ -1,4 +1,4 @@
import { defineComponent, unref, onMounted, computed } from 'vue';
import { defineComponent, unref, computed } from 'vue';
import { Layout, BackTop } from 'ant-design-vue';
import LayoutHeader from './LayoutHeader';
@@ -13,18 +13,24 @@
import { useFullContent } from '/@/hooks/web/useFullContent';
import LockPage from '/@/views/sys/lock/index.vue';
import { registerGlobComp } from '/@/components/registerGlobComp';
import './index.less';
// import { userStore } from '/@/store/modules/user';
export default defineComponent({
  name: 'DefaultLayout',
  setup() {
    // ! 在这里才注册全局组件
    // ! 可以减少首屏代码体积
    // default layout是在登录后才加载的。所以不会打包到首屏去
    registerGlobComp();
    // 获取项目配置
    const { getFullContent } = useFullContent();
    const getProjectConfigRef = computed(() => {
      return appStore.getProjectConfig;
    });
    const getLockMainScrollStateRef = computed(() => {
      return appStore.getLockMainScrollState;
    });
@@ -35,6 +41,7 @@
      } = unref(getProjectConfigRef);
      return show;
    });
    const isShowMixHeaderRef = computed(() => {
      const {
        menuSetting: { type },
@@ -49,12 +56,6 @@
      return show && mode !== MenuModeEnum.HORIZONTAL && !unref(getFullContent);
    });
    // const { currentRoute } = useRouter();
    onMounted(() => {
      // Each refresh will request the latest user information, if you don’t need it, you can delete it
      // userStore.getUserInfoAction({ userId: userStore.getUserInfoState.userId });
    });
    // Get project configuration
    // const { getFullContent } = useFullContent(currentRoute);
    function getTarget(): any {
@@ -63,6 +64,7 @@
      } = unref(getProjectConfigRef);
      return document.querySelector(`.default-layout__${fixed ? 'main' : 'content'}`);
    }
    return () => {
      const { getPageLoading, getLockInfo } = appStore;
      const {
@@ -72,20 +74,24 @@
        multiTabsSetting: { show: showTabs },
        headerSetting: { fixed },
      } = unref(getProjectConfigRef);
      // const fixedHeaderCls = fixed ? ('fixed' + getLockMainScrollState ? ' lock' : '') : '';
      const fixedHeaderCls = fixed
        ? 'fixed' + (unref(getLockMainScrollStateRef) ? ' lock' : '')
        : '';
      const { isLock } = getLockInfo;
      return (
        <Layout class="default-layout relative">
          {() => (
            <>
              {isLock && <LockPage />}
              {!unref(getFullContent) && unref(isShowMixHeaderRef) && unref(showHeaderRef) && (
                <LayoutHeader />
              )}
              {showSettingButton && <SettingBtn />}
              <Layout>
                {() => (
                  <>
@@ -102,7 +108,9 @@
                              {() => <MultipleTabs />}
                            </Layout.Header>
                          )}
                          {useOpenBackTop && <BackTop target={getTarget} />}
                          <div class={[`default-layout__main`, fixedHeaderCls]}>
                            {openPageLoading && (
                              <FullLoading