2020-12-31 11:47:52 +08:00
|
|
|
|
<template>
|
2021-03-15 12:44:58 +08:00
|
|
|
|
<el-main class="layout-main">
|
|
|
|
|
<el-scrollbar
|
|
|
|
|
ref="layoutScrollbarRef"
|
2022-04-29 22:57:31 +08:00
|
|
|
|
:class="{
|
|
|
|
|
'layout-scrollbar':
|
|
|
|
|
(!isClassicOrTransverse && !currentRouteMeta.isLink && !currentRouteMeta.isIframe) ||
|
|
|
|
|
(!isClassicOrTransverse && currentRouteMeta.isLink && !currentRouteMeta.isIframe),
|
|
|
|
|
}"
|
2021-03-15 12:44:58 +08:00
|
|
|
|
>
|
2022-04-29 22:57:31 +08:00
|
|
|
|
<LayoutParentView
|
|
|
|
|
:style="{
|
|
|
|
|
padding: !isClassicOrTransverse || (currentRouteMeta.isLink && currentRouteMeta.isIframe) ? '0' : '15px',
|
|
|
|
|
transition: 'padding 0.3s ease-in-out',
|
|
|
|
|
}"
|
|
|
|
|
/>
|
2022-04-18 19:14:38 +08:00
|
|
|
|
<Footer v-if="themeConfig.isFooter" />
|
2021-03-15 12:44:58 +08:00
|
|
|
|
</el-scrollbar>
|
|
|
|
|
</el-main>
|
2020-12-31 11:47:52 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
2022-04-29 22:57:31 +08:00
|
|
|
|
import { defineComponent, toRefs, reactive, getCurrentInstance, watch, onMounted, computed } from 'vue';
|
2021-07-07 20:16:31 +08:00
|
|
|
|
import { useRoute } from 'vue-router';
|
2022-04-18 19:14:38 +08:00
|
|
|
|
import { storeToRefs } from 'pinia';
|
|
|
|
|
import { useThemeConfig } from '/@/stores/themeConfig';
|
2021-06-19 17:49:42 +08:00
|
|
|
|
import LayoutParentView from '/@/layout/routerView/parent.vue';
|
|
|
|
|
import Footer from '/@/layout/footer/index.vue';
|
2022-02-21 23:52:59 +08:00
|
|
|
|
|
|
|
|
|
// 定义接口来定义对象的类型
|
|
|
|
|
interface MainState {
|
|
|
|
|
headerHeight: string | number;
|
|
|
|
|
currentRouteMeta: any;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-31 11:47:52 +08:00
|
|
|
|
export default defineComponent({
|
2021-03-15 12:44:58 +08:00
|
|
|
|
name: 'layoutMain',
|
2021-07-07 20:16:31 +08:00
|
|
|
|
components: { LayoutParentView, Footer },
|
2021-03-15 12:44:58 +08:00
|
|
|
|
setup() {
|
2022-02-21 23:52:59 +08:00
|
|
|
|
const { proxy } = <any>getCurrentInstance();
|
2022-04-18 19:14:38 +08:00
|
|
|
|
const storesThemeConfig = useThemeConfig();
|
|
|
|
|
const { themeConfig } = storeToRefs(storesThemeConfig);
|
2021-03-15 12:44:58 +08:00
|
|
|
|
const route = useRoute();
|
2022-02-21 23:52:59 +08:00
|
|
|
|
const state = reactive<MainState>({
|
2021-03-15 12:44:58 +08:00
|
|
|
|
headerHeight: '',
|
|
|
|
|
currentRouteMeta: {},
|
|
|
|
|
});
|
2022-04-29 22:57:31 +08:00
|
|
|
|
// 判断布局
|
|
|
|
|
const isClassicOrTransverse = computed(() => {
|
|
|
|
|
const { layout } = themeConfig.value;
|
|
|
|
|
return layout === 'classic' || layout === 'transverse';
|
|
|
|
|
});
|
2021-03-15 12:44:58 +08:00
|
|
|
|
// 设置 main 的高度
|
|
|
|
|
const initHeaderHeight = () => {
|
2022-02-21 23:52:59 +08:00
|
|
|
|
const bool = state.currentRouteMeta.isLink && state.currentRouteMeta.isIframe;
|
2022-04-18 19:14:38 +08:00
|
|
|
|
let { isTagsview } = themeConfig.value;
|
2022-04-29 22:57:31 +08:00
|
|
|
|
if (isTagsview) return (state.headerHeight = bool ? `86px` : `115px`);
|
|
|
|
|
else return (state.headerHeight = `80px`);
|
2021-03-15 12:44:58 +08:00
|
|
|
|
};
|
2021-07-07 20:16:31 +08:00
|
|
|
|
// 初始化获取当前路由 meta,用于设置 iframes padding
|
|
|
|
|
const initGetMeta = () => {
|
|
|
|
|
state.currentRouteMeta = route.meta;
|
|
|
|
|
};
|
2021-03-15 12:44:58 +08:00
|
|
|
|
// 页面加载前
|
2022-02-21 23:52:59 +08:00
|
|
|
|
onMounted(async () => {
|
|
|
|
|
await initGetMeta();
|
2021-03-15 12:44:58 +08:00
|
|
|
|
initHeaderHeight();
|
|
|
|
|
});
|
2021-07-07 20:16:31 +08:00
|
|
|
|
// 监听路由变化
|
2021-03-15 12:44:58 +08:00
|
|
|
|
watch(
|
|
|
|
|
() => route.path,
|
|
|
|
|
() => {
|
2021-07-07 20:16:31 +08:00
|
|
|
|
state.currentRouteMeta = route.meta;
|
2022-02-21 23:52:59 +08:00
|
|
|
|
const bool = state.currentRouteMeta.isLink && state.currentRouteMeta.isIframe;
|
2022-04-29 22:57:31 +08:00
|
|
|
|
state.headerHeight = bool ? `86px` : `115px`;
|
2022-02-21 23:52:59 +08:00
|
|
|
|
proxy.$refs.layoutScrollbarRef.update();
|
2021-03-15 12:44:58 +08:00
|
|
|
|
}
|
|
|
|
|
);
|
2022-02-21 23:52:59 +08:00
|
|
|
|
// 监听 themeConfig 配置文件的变化,更新菜单 el-scrollbar 的高度
|
2022-04-29 22:57:31 +08:00
|
|
|
|
watch(
|
|
|
|
|
themeConfig,
|
|
|
|
|
(val) => {
|
|
|
|
|
state.currentRouteMeta = route.meta;
|
|
|
|
|
const bool = state.currentRouteMeta.isLink && state.currentRouteMeta.isIframe;
|
|
|
|
|
state.headerHeight = val.isTagsview ? (bool ? `86px` : `115px`) : '51px';
|
|
|
|
|
proxy.$refs?.layoutScrollbarRef?.update();
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
deep: true,
|
2022-02-21 23:52:59 +08:00
|
|
|
|
}
|
2022-04-29 22:57:31 +08:00
|
|
|
|
);
|
2021-03-15 12:44:58 +08:00
|
|
|
|
return {
|
2022-04-18 19:14:38 +08:00
|
|
|
|
themeConfig,
|
2022-04-29 22:57:31 +08:00
|
|
|
|
isClassicOrTransverse,
|
2021-03-15 12:44:58 +08:00
|
|
|
|
...toRefs(state),
|
|
|
|
|
};
|
|
|
|
|
},
|
2020-12-31 11:47:52 +08:00
|
|
|
|
});
|
|
|
|
|
</script>
|