mirror of
https://github.com/WeBankFinTech/fes.js.git
synced 2025-04-06 03:59:53 +08:00
refactor(plugin-layout): 优化index.jsx
n
This commit is contained in:
parent
96fe758a45
commit
d14891b70a
@ -50,13 +50,6 @@ export default (api) => {
|
|||||||
}`,
|
}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
api.writeTmpFile({
|
|
||||||
path: absFilePath,
|
|
||||||
content: Mustache.render(readFileSync(join(__dirname, 'runtime/views/index.tpl'), 'utf-8'), {
|
|
||||||
REPLACE_USER_CONFIG: JSON.stringify(userConfig),
|
|
||||||
}),
|
|
||||||
});
|
|
||||||
|
|
||||||
api.writeTmpFile({
|
api.writeTmpFile({
|
||||||
path: absConfigFilePath,
|
path: absConfigFilePath,
|
||||||
content: Mustache.render(readFileSync(join(__dirname, 'runtime/helpers/getConfig.tpl'), 'utf-8'), {
|
content: Mustache.render(readFileSync(join(__dirname, 'runtime/helpers/getConfig.tpl'), 'utf-8'), {
|
||||||
|
@ -29,27 +29,16 @@ const fillMenuByRoute = (menuConfig, routeConfig, dep = 0) => {
|
|||||||
menuConfig.forEach((menu) => {
|
menuConfig.forEach((menu) => {
|
||||||
const pageConfig = {};
|
const pageConfig = {};
|
||||||
if (menu.name) {
|
if (menu.name) {
|
||||||
Object.assign(
|
Object.assign(pageConfig, getMetaByName(routeConfig, menu.name));
|
||||||
pageConfig,
|
|
||||||
getMetaByName(routeConfig, menu.name)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
// menu的配置优先级高,当menu存在配置时,忽略页面的配置
|
// menu的配置优先级高,当menu存在配置时,忽略页面的配置
|
||||||
Object.keys(pageConfig).forEach((prop) => {
|
Object.keys(pageConfig).forEach((prop) => {
|
||||||
if (
|
if (menu[prop] === undefined || menu[prop] === null || menu[prop] === '') {
|
||||||
menu[prop] === undefined
|
|
||||||
|| menu[prop] === null
|
|
||||||
|| menu[prop] === ''
|
|
||||||
) {
|
|
||||||
menu[prop] = pageConfig[prop];
|
menu[prop] = pageConfig[prop];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (menu.children && menu.children.length > 0) {
|
if (menu.children && menu.children.length > 0) {
|
||||||
menu.children = fillMenuByRoute(
|
menu.children = fillMenuByRoute(menu.children, routeConfig, dep);
|
||||||
menu.children,
|
|
||||||
routeConfig,
|
|
||||||
dep
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
arr.push(menu);
|
arr.push(menu);
|
||||||
});
|
});
|
||||||
|
@ -189,14 +189,14 @@ export default {
|
|||||||
return [];
|
return [];
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
title: {
|
|
||||||
type: String,
|
|
||||||
default: '',
|
|
||||||
},
|
|
||||||
locale: {
|
locale: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
default: '',
|
||||||
|
},
|
||||||
logo: {
|
logo: {
|
||||||
type: String,
|
type: String,
|
||||||
default: defaultLogo,
|
default: defaultLogo,
|
||||||
|
54
packages/fes-plugin-layout/src/runtime/views/index.jsx
Normal file
54
packages/fes-plugin-layout/src/runtime/views/index.jsx
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
import { unref, defineComponent, computed } from 'vue';
|
||||||
|
import { plugin } from '@@/core/coreExports';
|
||||||
|
import { getRoutes } from '@@/core/routes/routes';
|
||||||
|
// eslint-disable-next-line import/extensions
|
||||||
|
import getConfig from '../helpers/getConfig';
|
||||||
|
import fillMenu from '../helpers/fillMenu';
|
||||||
|
import BaseLayout from './BaseLayout.vue';
|
||||||
|
|
||||||
|
const Layout = defineComponent({
|
||||||
|
name: 'Layout',
|
||||||
|
setup() {
|
||||||
|
const config = getConfig();
|
||||||
|
|
||||||
|
const menus = typeof config.menus === 'function' ? config.menus() : config.menus;
|
||||||
|
|
||||||
|
const routes = getRoutes();
|
||||||
|
|
||||||
|
// 把路由的 meta 合并到 menu 配置中
|
||||||
|
const filledMenuRef = computed(() => fillMenu(unref(menus) ?? [], routes));
|
||||||
|
|
||||||
|
const localeShared = plugin.getShared('locale');
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
const slots = {
|
||||||
|
renderCustom: config.renderCustom,
|
||||||
|
locale: () => {
|
||||||
|
if (localeShared) {
|
||||||
|
return <localeShared.SelectLang></localeShared.SelectLang>;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<BaseLayout
|
||||||
|
menus={filledMenuRef.value}
|
||||||
|
locale={localeShared ? true : false}
|
||||||
|
title={config.title}
|
||||||
|
logo={config.logo}
|
||||||
|
theme={config.theme}
|
||||||
|
navigation={config.navigation}
|
||||||
|
isFixedHeader={config.isFixedHeader}
|
||||||
|
isFixedSidebar={config.isFixedSidebar}
|
||||||
|
multiTabs={config.multiTabs}
|
||||||
|
sideWidth={config.sideWidth}
|
||||||
|
footer={config.footer}
|
||||||
|
menuProps={config.menuProps}
|
||||||
|
v-slots={slots}
|
||||||
|
></BaseLayout>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export default Layout;
|
@ -1,44 +0,0 @@
|
|||||||
import { ref, defineComponent, computed } from 'vue';
|
|
||||||
import { plugin } from '@@/core/coreExports';
|
|
||||||
import { getRoutes } from '@@/core/routes/routes';
|
|
||||||
import BaseLayout from './BaseLayout.vue';
|
|
||||||
// eslint-disable-next-line import/extensions
|
|
||||||
import getConfig from '../helpers/getConfig';
|
|
||||||
import fillMenu from '../helpers/fillMenu';
|
|
||||||
|
|
||||||
const Layout = defineComponent({
|
|
||||||
name: 'Layout',
|
|
||||||
setup() {
|
|
||||||
const initConfig = {{{REPLACE_USER_CONFIG}}}
|
|
||||||
const config = {...initConfig, ...getConfig()};
|
|
||||||
|
|
||||||
let menusRef = ref(config.menus);
|
|
||||||
// 如果运行时配置了,则需要处理
|
|
||||||
if (config.menus && typeof config.menus === 'function') {
|
|
||||||
menusRef = ref(config.menus());
|
|
||||||
}
|
|
||||||
// 把路由的meta合并到menu配置中
|
|
||||||
const filledMenuRef = computed(() => fillMenu(menusRef.value, getRoutes()));
|
|
||||||
|
|
||||||
const localeShared = plugin.getShared('locale');
|
|
||||||
|
|
||||||
const renderCustom = config.renderCustom;
|
|
||||||
|
|
||||||
delete config.renderCustom;
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
const slots = {
|
|
||||||
renderCustom,
|
|
||||||
locale: () => {
|
|
||||||
if (localeShared) {
|
|
||||||
return <localeShared.SelectLang></localeShared.SelectLang>;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
},
|
|
||||||
};
|
|
||||||
return <BaseLayout {...config} locale={localeShared ? true : false} menus={filledMenuRef.value} v-slots={slots}></BaseLayout>;
|
|
||||||
};
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export default Layout;
|
|
@ -1,12 +1,6 @@
|
|||||||
<template>
|
<template>
|
||||||
<monaco-editor
|
<monaco-editor ref="editorRef" v-model="json" :language="language" height="200px" check />
|
||||||
ref="editorRef"
|
{{ json }}
|
||||||
v-model="json"
|
|
||||||
:language="language"
|
|
||||||
height="200px"
|
|
||||||
check
|
|
||||||
/>
|
|
||||||
{{json}}
|
|
||||||
</template>
|
</template>
|
||||||
<config>
|
<config>
|
||||||
{
|
{
|
||||||
@ -21,7 +15,7 @@ import { MonacoEditor } from '@fesjs/fes';
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
MonacoEditor
|
MonacoEditor,
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
const editorRef = ref();
|
const editorRef = ref();
|
||||||
@ -35,8 +29,8 @@ export default {
|
|||||||
return {
|
return {
|
||||||
editorRef,
|
editorRef,
|
||||||
json,
|
json,
|
||||||
language
|
language,
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
import { defineBuildConfig } from '@fesjs/fes';
|
import { defineBuildConfig } from '@fesjs/fes';
|
||||||
|
|
||||||
export default defineBuildConfig({
|
export default defineBuildConfig({
|
||||||
swc: {
|
swc: false,
|
||||||
loader: {},
|
|
||||||
},
|
|
||||||
targets: {
|
targets: {
|
||||||
chrome: '78',
|
chrome: '78',
|
||||||
},
|
},
|
||||||
|
@ -21,7 +21,10 @@ export const beforeRender = {
|
|||||||
|
|
||||||
export const layout = (layoutConfig, { initialState }) => ({
|
export const layout = (layoutConfig, { initialState }) => ({
|
||||||
...layoutConfig,
|
...layoutConfig,
|
||||||
renderCustom: () => <UserCenter />,
|
renderCustom: (props) => {
|
||||||
|
console.log(props);
|
||||||
|
return <UserCenter />;
|
||||||
|
},
|
||||||
menus: () => {
|
menus: () => {
|
||||||
const menusRef = ref(layoutConfig.menus);
|
const menusRef = ref(layoutConfig.menus);
|
||||||
watch(
|
watch(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user