Commit 383a9651 authored by 邓晓峰's avatar 邓晓峰

feat: 添加首页

parent 4230c42a
Pipeline #38192 passed with stages
in 5 minutes 21 seconds
......@@ -3,12 +3,12 @@ export function genActiveRule(routerPrefix) {
}
export default {
dev: [
{
name: 'civ_energy',
entry: `//${window.location.hostname}:8081/civ_energy`,
container: '#micro-container',
activeRule: '/civbase/civ_energy',
},
// {
// name: 'civ_energy',
// entry: `//${window.location.hostname}:8081/civ_energy`,
// container: '#micro-container',
// activeRule: '/civbase/civ_energy',
// },
// {
// name: 'civ_water',
// entry: `//${window.location.hostname}:8081/civ_water`,
......@@ -35,7 +35,7 @@ export default {
},
{
name: 'middleground',
entry: `//${window.location.hostname}:8081/middleground`,
entry: `//${window.location.hostname}:8082/middleground`,
container: '#micro-container',
activeRule: '/civbase/middleground',
},
......
......@@ -100,23 +100,49 @@ const appReducer = (state = initialState, action) => {
const config = window.globalConfig;
// config.access_token = "";
// eslint-disable-next-line no-case-declarations
const generMenu = generRoutes(config.widgets || []);
// eslint-disable-next-line no-case-declarations
const { homepage } = window.globalConfig;
if (homepage !== '') {
// const index = generMenu.findIndex(item => item.level === -1);
// if (index > -1) {
// generMenu = generMenu.reverse();
// }
const modulePkg = {};
window.globalConfig.products.map(item => {
modulePkg[item.PackageName] = item;
})
const generMenu = generRoutes(config.widgets || [], null, 0, modulePkg);
const flatMenu = generFlatRoutes(generMenu || [], null, null, modulePkg);
const home = flatMenu.find(item => {
let path = item.path.split("|");
let currentPath = path[0];
if(/^\//.test(currentPath)) {
currentPath = currentPath.replace(/^\//, '');
}
return currentPath === homepage
});
let currentMenuIndex = 0;
if(home) {
console.log("home", home);
const parent = home.level >= 2 ? home.parent.parent: home.level >= 3 ? home.parent.parent.parent: home.parent;
if(parent) {
currentMenuIndex = generMenu.findIndex(item => item.name === parent.label);
currentProduct.set('currentMenuIndex', currentMenuIndex);
store.set('updateMenuIndex', currentMenuIndex)
}
}
// eslint-disable-next-line no-case-declarations
const flatMenu = generFlatRoutes(generMenu || []);
// eslint-disable-next-line no-case-declarations
window.globalConfig.home = home;
Cookies.set('city', Cookies.get('city') || window.globalConfig.client);
return state.merge({
globalConfig: config,
menu: generMenu,
flatMenu,
currentMenu: generMenu[state.currentMenuIndex],
currentMenu: generMenu[currentMenuIndex || state.currentMenuIndex],
currentMenuIndex: currentMenuIndex || 0
});
case GET_ERROR_CONFIG:
return state.merge({
......
......@@ -180,19 +180,25 @@ export const defaultApp = () => {
const config = createStoreage.get('globalConfig');
if (config && config.token) {
// console.log(config)
// const startWith = config.homepage ? config.homepage.split('/') : [];
// console.log(findPathByLeafId(config.homepage, '', 'url'))
// // const startWith = config.homepage ? config.homepage.split('/') : [];
// // console.log(findPathByLeafId(config.homepage, '', 'url'))
const basePath =
config.homepage !== '' && FILTER_FOLER_REG.test(config.homepage) ?
'civweb4' :
'civweb4';
const defaultURL =
config.homepage === '' ?
`/${pkg.name.toLocaleLowerCase()}/${basePath}?client=${config.client}` :
`/${pkg.name.toLocaleLowerCase()}/${basePath}/${config.homepage}`;
setDefaultMountApp(defaultURL);
// const defaultURL =
// config.homepage === '' ?
// `/${pkg.name.toLocaleLowerCase()}/${basePath}?client=${config.client}` :
// `/${pkg.name.toLocaleLowerCase()}/${basePath}/${config.homepage}`;
// console.log("config.home.path", config.home.path)
if(config && config.home) {
setDefaultMountApp(`/civbase/${config.home.path.replace(/^\//, '')}`);
} else {
setDefaultMountApp(`/${pkg.name.toLocaleLowerCase()}/${basePath}/${config.homepage}`)
}
}
};
......
......@@ -64,6 +64,7 @@ const generRotes = (widgets, parent, level = 0) => {
item.widgets,
Object.assign({}, item, { path, key: subKey }),
_level_,
item.label
),
extData: {
...item,
......@@ -123,16 +124,18 @@ export function simpleNormalizeChildren(children) {
return children;
}
export const generFlatRoutes = (widgets, parent, subSystem) => {
export const generFlatRoutes = (widgets, parent, subSystem, modulePkg) => {
const treeKeys = [];
const flatMenu = [];
(widgets || []).forEach(item => {
if (item.hasOwnProperty('routes')) {
const route = generFlatRoutes(item.routes, item, item.name);
const route = generFlatRoutes(item.routes, item, item.name, modulePkg);
flatMenu.push(simpleNormalizeChildren(route));
} else {
flatMenu.push({
...item,
origin: item,
moduleName: modulePkg[item.alias],
treeKeys,
subSystem,
parent,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment