79 lines
2.5 KiB
Smarty
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { ref, defineComponent, computed } from 'vue';
import { plugin, ApplyPluginsType, getRoutes } from '@@/core/coreExports';
import BaseLayout from './views/BaseLayout.vue';
import getRuntimeConfig from './helpers/getRuntimeConfig';
import fillMenu from './helpers/fillMenu';
const Layout = defineComponent({
name: 'Layout',
setup() {
const userConfig = {{{REPLACE_USER_CONFIG}}};
const runtimeConfig = getRuntimeConfig();
const {
menus,
customHeader,
menuConfig,
// BaseLayout需要的
initialState,
sidebar,
header,
logo,
// logo冲突
logoUrl,
...otherConfig
} = runtimeConfig;
if (logoUrl) {
userConfig.logo = logoUrl;
}
if (menuConfig && typeof menuConfig === 'object') {
Object.assign(userConfig.menuConfig, menuConfig);
}
Object.keys(otherConfig).forEach((p) => {
if (otherConfig[p] !== undefined) {
userConfig[p] = otherConfig[p];
}
});
let menusRef = ref(userConfig.menus);
// menus
if (menus && typeof menus === 'function') {
menusRef = ref(menus(userConfig.menus));
}
// meta合并到menu配置中
const filledMenuRef = computed(() => {
return fillMenu(menusRef.value, getRoutes());
});
const localeShared = plugin.getShared('locale');
return () => {
const slots = {
customHeader: () => {
if (runtimeConfig.customHeader) {
return (
<runtimeConfig.customHeader></runtimeConfig.customHeader>
);
}
return null;
},
locale: () => {
if (localeShared) {
return (
<localeShared.SelectLang></localeShared.SelectLang>
);
}
return null;
}
};
return (
<BaseLayout
{...userConfig}
locale={localeShared ? true : false}
menus={filledMenuRef.value}
v-slots={slots}
></BaseLayout>
);
};
}
});
export default Layout;