diff --git a/packages/fes-plugin-layout/src/template/runtime.tpl b/packages/fes-plugin-layout/src/template/runtime.tpl
index eae7324c..695e9125 100644
--- a/packages/fes-plugin-layout/src/template/runtime.tpl
+++ b/packages/fes-plugin-layout/src/template/runtime.tpl
@@ -1,19 +1,16 @@
-import { reactive, ref } from "vue";
+import { reactive } from "vue";
import { getRoutes, plugin, ApplyPluginsType } from "@@/core/coreExports";
import BaseLayout from "./views/BaseLayout.vue";
import { fillMenuData } from "./helpers";
const userConfig = reactive({{{REPLACE_USER_CONFIG}}});
-const langConfig = {
- localInited: ref(false),
- component: null
-};
export function rootContainer(childComponent, args) {
const runtimeConfig = plugin.applyPlugins({
key: "layout",
type: ApplyPluginsType.modify,
initialValue: {},
});
+ const localeShared = plugin.openShared("locale");
const routeConfig = getRoutes();
userConfig.menus = fillMenuData(userConfig.menus, routeConfig);
return () => {
@@ -21,15 +18,15 @@ export function rootContainer(childComponent, args) {
default: () => ,
userCenter: () => {
if(runtimeConfig.userCenter){
- return
+ return ()
}
- return
+ return null
},
- lang: () => {
- if(langConfig.localInited.value){
- return
+ locale: () => {
+ if(localeShared){
+ return ()
}
- return
+ return null
}
};
return (
@@ -37,11 +34,4 @@ export function rootContainer(childComponent, args) {
);
};
-}
-
-{{#HAS_LOCALE}}
-export function onLocaleReady({ i18n, SelectLang }){
- langConfig.localInited.value = true;
- langConfig.component = SelectLang;
-}
-{{/HAS_LOCALE}}
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/packages/fes-plugin-layout/src/views/BaseLayout.vue b/packages/fes-plugin-layout/src/views/BaseLayout.vue
index 82be0015..8e180c1f 100644
--- a/packages/fes-plugin-layout/src/views/BaseLayout.vue
+++ b/packages/fes-plugin-layout/src/views/BaseLayout.vue
@@ -20,7 +20,7 @@
-
+
diff --git a/packages/fes-plugin-locale/src/template/core.tpl b/packages/fes-plugin-locale/src/template/core.tpl
index fe1878a3..db3f542f 100644
--- a/packages/fes-plugin-locale/src/template/core.tpl
+++ b/packages/fes-plugin-locale/src/template/core.tpl
@@ -22,6 +22,9 @@ if (Array.isArray(locales)) {
const i18n = createI18n({ ...defaultOptions, messages });
+// 共享出去
+plugin.share("locale", { i18n, SelectLang })
+
const setLocale = (locale)=>{
i18n.global.locale = locale
};
@@ -32,11 +35,6 @@ const getAllLocales = ()=>{};
const install = (app)=>{
app.use(i18n);
- plugin.applyPlugins({
- key: 'onLocaleReady',
- type: ApplyPluginsType.event,
- args: { i18n, SelectLang }
- });
}
export { useI18n, setLocale, install }
\ No newline at end of file
diff --git a/packages/fes-preset-built-in/src/plugins/generateFiles/fes/fes.tpl b/packages/fes-preset-built-in/src/plugins/generateFiles/fes/fes.tpl
index 05f7c849..9e6c7211 100644
--- a/packages/fes-preset-built-in/src/plugins/generateFiles/fes/fes.tpl
+++ b/packages/fes-preset-built-in/src/plugins/generateFiles/fes/fes.tpl
@@ -73,13 +73,18 @@ const beforeRenderConfig = plugin.applyPlugins({
});
const beforeRender = async () => {
+ let initialState = {};
if (typeof beforeRenderConfig.action === "function") {
const app = createApp(beforeRenderConfig.loading);
app.mount("#app");
- const initialState = await beforeRenderConfig.action();
+ try {
+ initialState = await beforeRenderConfig.action();
+ } catch(e){
+ console.error(`[fes] beforeRender执行出现异常`)
+ }
app.unmount();
- return initialState;
}
+ return initialState;
};
const render = async () => {
diff --git a/packages/fes-runtime/src/plugin/index.js b/packages/fes-runtime/src/plugin/index.js
index 5d199f61..1fea1ad5 100644
--- a/packages/fes-runtime/src/plugin/index.js
+++ b/packages/fes-runtime/src/plugin/index.js
@@ -22,6 +22,17 @@ export default class Plugin {
constructor(opts) {
this.validKeys = opts?.validKeys || [];
this.hooks = {};
+ // 共享
+ this.shared = {};
+ }
+
+ share(key, obj) {
+ assert(!Object.keys(this.shared).includes(key), 'share failed, key repeat');
+ this.shared[key] = obj;
+ }
+
+ openShared(key) {
+ return this.shared[key];
}
register(plugin) {