Commit d33d1806 by Lin

feat: 默认页面功能开关配置

1 parent 7e46f7d9
......@@ -41,6 +41,63 @@ function initConfigReadyPromise() {
* @returns 路由数据
*/
export async function fetchMicroAppRouteConfig(): Promise<any> {
if(baseConfig.features.defaultRoute.enabled){
return {
"code": 200,
"message": "success",
"data": {
"microApps": [
{
"name": "home",
"entry": {
"development": "",
"production": "",
"test": "",
"default": ""
},
"container": "#subapp-viewport",
"activeRule": "/home",
"props": {
"routerBase": "/home"
},
"enabled": true,
"routes": {
"path": "/home",
"name": "Home",
"title": "首页",
"level": 1,
"isMicroApp": false,
"requiresAuth": true
},
"routerList": {
"id": "home",
"title": "首页",
"path": "/home",
"icon": "",
"sidebarMenus": [
{
"id": "home-dashboard",
"title": "工作台",
"path": "/home/dashboard",
"icon": "",
"level": 2,
"hidden": false,
"parentId": "home",
"meta": {
"title": "工作台",
"icon": "dashboard",
"noCache": false,
"link": null
},
"children": []
}
]
}
}
]
}
};
}
// 先检查本地缓存
const cachedData = localCache.get(ROUTER_CONFIG_CACHE_KEY);
if (cachedData) {
......@@ -55,7 +112,6 @@ export async function fetchMicroAppRouteConfig(): Promise<any> {
if (result) {
localCache.set(ROUTER_CONFIG_CACHE_KEY, result);
}
return result;
}
......
......@@ -11,7 +11,14 @@ let isConfigLoaded = false;
let configLoadPromise: Promise<void> | null = null;
// 默认配置(作为降级方案)
const defaultMicroApps: MicroAppConfig[] = [];
const defaultMicroApps: MicroAppConfig[] = [
{
name: 'Home',
entry: '', // 主应用页面,无需 entry
container: '#subapp-viewport', // 微应用容器
activeRule: '/home', // 对应路由路径
},
];
/**
* 加载并设置微应用配置
......@@ -32,15 +39,16 @@ export async function loadMicroAppConfig(): Promise<void> {
configLoadPromise = (async () => {
try {
const remoteConfig = await fetchMicroAppRouteConfig();
console.log('remoteConfigAAAAAA',JSON.stringify(remoteConfig));
// 获取子应用路由配置,并转换远程配置为 qiankun 配置(
// props注入:communicationManager消息管理,getGscRequest请求实例,mountParcel,name子应用名称,singleSpa
microApps = transformToQiankun(remoteConfig.data?.microApps);
// 如果远程配置为空,使用默认配置
if (microApps.length === 0) {
microApps = defaultMicroApps;
}
// if (config.features.defaultRoute.enabled) {
// microApps = defaultMicroApps;
// }
isConfigLoaded = true;
console.log('[微前端配置] 配置加载完成,共加载', microApps.length, '个微应用');
console.log('[微前端配置] 配置加载完成,共加载', microApps, '个微应用');
} catch (error) {
microApps = defaultMicroApps;
isConfigLoaded = true;
......
{
"code": 200,
"message": "success",
"data": {
"microApps": [
{
"name": "home",
"entry": {
"development": "",
"production": "",
"test": "",
"default": ""
},
"container": "#subapp-viewport",
"activeRule": "/home",
"props": {
"routerBase": "/home"
},
"enabled": true,
"routes": {
"path": "/home",
"name": "Home",
"title": "首页",
"level": 1,
"isMicroApp": false,
"requiresAuth": true
},
"routerList": {
"id": "home",
"title": "首页",
"path": "/home",
"icon": "",
"sidebarMenus": [
{
"id": "home-dashboard",
"title": "工作台",
"path": "/home/dashboard",
"icon": "",
"level": 2,
"hidden": false,
"parentId": "home",
"meta": {
"title": "工作台",
"icon": "dashboard",
"noCache": false,
"link": null
},
"children": []
}
]
}
}
]
}
}
......@@ -507,6 +507,9 @@ const handleDebounceClick = () => {
<GLButton type="danger">
危险按钮
</GLButton>
<GLButton>
普通按钮
</GLButton>
</div>
</div>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!