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) { ...@@ -3,12 +3,12 @@ export function genActiveRule(routerPrefix) {
} }
export default { export default {
dev: [ dev: [
{ // {
name: 'civ_energy', // name: 'civ_energy',
entry: `//${window.location.hostname}:8081/civ_energy`, // entry: `//${window.location.hostname}:8081/civ_energy`,
container: '#micro-container', // container: '#micro-container',
activeRule: '/civbase/civ_energy', // activeRule: '/civbase/civ_energy',
}, // },
// { // {
// name: 'civ_water', // name: 'civ_water',
// entry: `//${window.location.hostname}:8081/civ_water`, // entry: `//${window.location.hostname}:8081/civ_water`,
...@@ -35,7 +35,7 @@ export default { ...@@ -35,7 +35,7 @@ export default {
}, },
{ {
name: 'middleground', name: 'middleground',
entry: `//${window.location.hostname}:8081/middleground`, entry: `//${window.location.hostname}:8082/middleground`,
container: '#micro-container', container: '#micro-container',
activeRule: '/civbase/middleground', activeRule: '/civbase/middleground',
}, },
......
...@@ -100,23 +100,49 @@ const appReducer = (state = initialState, action) => { ...@@ -100,23 +100,49 @@ const appReducer = (state = initialState, action) => {
const config = window.globalConfig; const config = window.globalConfig;
// config.access_token = ""; // config.access_token = "";
// eslint-disable-next-line no-case-declarations // eslint-disable-next-line no-case-declarations
const generMenu = generRoutes(config.widgets || []);
// eslint-disable-next-line no-case-declarations
const { homepage } = window.globalConfig; const { homepage } = window.globalConfig;
if (homepage !== '') { const modulePkg = {};
// const index = generMenu.findIndex(item => item.level === -1); window.globalConfig.products.map(item => {
// if (index > -1) { modulePkg[item.PackageName] = item;
// generMenu = generMenu.reverse(); })
// } 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 // 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); Cookies.set('city', Cookies.get('city') || window.globalConfig.client);
return state.merge({ return state.merge({
globalConfig: config, globalConfig: config,
menu: generMenu, menu: generMenu,
flatMenu, flatMenu,
currentMenu: generMenu[state.currentMenuIndex], currentMenu: generMenu[currentMenuIndex || state.currentMenuIndex],
currentMenuIndex: currentMenuIndex || 0
}); });
case GET_ERROR_CONFIG: case GET_ERROR_CONFIG:
return state.merge({ return state.merge({
......
...@@ -180,19 +180,25 @@ export const defaultApp = () => { ...@@ -180,19 +180,25 @@ export const defaultApp = () => {
const config = createStoreage.get('globalConfig'); const config = createStoreage.get('globalConfig');
if (config && config.token) { if (config && config.token) {
// console.log(config)
// // const startWith = config.homepage ? config.homepage.split('/') : [];
// const startWith = config.homepage ? config.homepage.split('/') : []; // // console.log(findPathByLeafId(config.homepage, '', 'url'))
// console.log(findPathByLeafId(config.homepage, '', 'url'))
const basePath = const basePath =
config.homepage !== '' && FILTER_FOLER_REG.test(config.homepage) ? config.homepage !== '' && FILTER_FOLER_REG.test(config.homepage) ?
'civweb4' : 'civweb4' :
'civweb4'; 'civweb4';
const defaultURL = // const defaultURL =
config.homepage === '' ? // config.homepage === '' ?
`/${pkg.name.toLocaleLowerCase()}/${basePath}?client=${config.client}` : // `/${pkg.name.toLocaleLowerCase()}/${basePath}?client=${config.client}` :
`/${pkg.name.toLocaleLowerCase()}/${basePath}/${config.homepage}`; // `/${pkg.name.toLocaleLowerCase()}/${basePath}/${config.homepage}`;
setDefaultMountApp(defaultURL); // 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) => { ...@@ -64,6 +64,7 @@ const generRotes = (widgets, parent, level = 0) => {
item.widgets, item.widgets,
Object.assign({}, item, { path, key: subKey }), Object.assign({}, item, { path, key: subKey }),
_level_, _level_,
item.label
), ),
extData: { extData: {
...item, ...item,
...@@ -123,16 +124,18 @@ export function simpleNormalizeChildren(children) { ...@@ -123,16 +124,18 @@ export function simpleNormalizeChildren(children) {
return children; return children;
} }
export const generFlatRoutes = (widgets, parent, subSystem) => { export const generFlatRoutes = (widgets, parent, subSystem, modulePkg) => {
const treeKeys = []; const treeKeys = [];
const flatMenu = []; const flatMenu = [];
(widgets || []).forEach(item => { (widgets || []).forEach(item => {
if (item.hasOwnProperty('routes')) { 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)); flatMenu.push(simpleNormalizeChildren(route));
} else { } else {
flatMenu.push({ flatMenu.push({
...item, ...item,
origin: item,
moduleName: modulePkg[item.alias],
treeKeys, treeKeys,
subSystem, subSystem,
parent, 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