Commit 034210fe authored by 邓晓峰's avatar 邓晓峰

fix: 修复左侧菜单栏初始化配置

parent 153bb209
This source diff could not be displayed because it is too large. You can view the blob instead.
File added
...@@ -132,7 +132,7 @@ const initGlobalConfig = () => { ...@@ -132,7 +132,7 @@ const initGlobalConfig = () => {
(async () => { (async () => {
(await (Cookies.get('token') && (await (Cookies.get('token') &&
window.globalConfig && window.globalConfig &&
window.globalConfig.token)) && initMicroApps(loader); window.globalConfig.token)) && initMicroApps(loader, store);
})(); })();
}, },
true, true,
...@@ -159,7 +159,7 @@ initLocale(); ...@@ -159,7 +159,7 @@ initLocale();
window.share && window.share &&
window.share.event && window.share.event &&
window.share.event.on('triggerMicro', () => { window.share.event.on('triggerMicro', () => {
initMicroApps(loader); initMicroApps(loader, store);
}); });
window.share && window.share &&
window.share.event && window.share.event &&
......
...@@ -7,7 +7,6 @@ import defaultSetting from '../../../config/defaultSetting'; ...@@ -7,7 +7,6 @@ import defaultSetting from '../../../config/defaultSetting';
import { dyRoutes } from '../../routes/config'; import { dyRoutes } from '../../routes/config';
function App(props) { function App(props) {
debugger
return ( return (
<> <>
<Helmet <Helmet
......
...@@ -18,6 +18,7 @@ import { ...@@ -18,6 +18,7 @@ import {
SELECT_MENU_KEY, SELECT_MENU_KEY,
SLIDER_MENU_MODE, SLIDER_MENU_MODE,
VALIDATE_AUTH, VALIDATE_AUTH,
GET_MICRO_MOUNTED_STATUS,
} from './constants'; } from './constants';
export function getConfig(data) { export function getConfig(data) {
...@@ -150,3 +151,10 @@ export function updateComplexPathName(data) { ...@@ -150,3 +151,10 @@ export function updateComplexPathName(data) {
data, data,
}; };
} }
export function updateMicroMounted(data) {
return {
type: GET_MICRO_MOUNTED_STATUS,
data,
};
}
...@@ -17,3 +17,4 @@ export const SELECT_MENU_KEY = 'App/SELECT_MENU_KEY'; ...@@ -17,3 +17,4 @@ export const SELECT_MENU_KEY = 'App/SELECT_MENU_KEY';
export const EXTEND_OPEN_KEY = 'App/EXTEND_OPEN_KEY'; export const EXTEND_OPEN_KEY = 'App/EXTEND_OPEN_KEY';
export const COMPLEX_CONFIG = 'App/COMPLEX_CONFIG'; export const COMPLEX_CONFIG = 'App/COMPLEX_CONFIG';
export const COMPLEX_PATHNAME = 'App/COMPLEX_PATHNAME'; export const COMPLEX_PATHNAME = 'App/COMPLEX_PATHNAME';
export const GET_MICRO_MOUNTED_STATUS = 'App/GET_MICRO_MOUNTED_STATUS';
...@@ -25,6 +25,7 @@ import { ...@@ -25,6 +25,7 @@ import {
SELECT_MENU_KEY, SELECT_MENU_KEY,
SLIDER_MENU_MODE, SLIDER_MENU_MODE,
VALIDATE_AUTH, VALIDATE_AUTH,
GET_MICRO_MOUNTED_STATUS,
} from './constants'; } from './constants';
const keywordStorage = new Storage( const keywordStorage = new Storage(
...@@ -61,6 +62,7 @@ export const initialState = fromJS({ ...@@ -61,6 +62,7 @@ export const initialState = fromJS({
openKeys: [], openKeys: [],
complexConfig: {}, complexConfig: {},
complexPathName: null, complexPathName: null,
microMounted: true,
}); });
/* eslint-disable default-case, no-param-reassign */ /* eslint-disable default-case, no-param-reassign */
...@@ -173,6 +175,10 @@ const appReducer = (state = initialState, action) => { ...@@ -173,6 +175,10 @@ const appReducer = (state = initialState, action) => {
return state.merge({ return state.merge({
complexPathName: action.data, complexPathName: action.data,
}); });
case GET_MICRO_MOUNTED_STATUS:
return state.merge({
microMounted: action.data,
});
default: default:
return state; return state;
} }
......
...@@ -11,11 +11,15 @@ import { Anchor, Button, Popover, Radio, Result, Spin } from 'antd'; ...@@ -11,11 +11,15 @@ import { Anchor, Button, Popover, Radio, Result, Spin } from 'antd';
import classNames from 'classnames'; import classNames from 'classnames';
import { dom } from 'kit_utils'; import { dom } from 'kit_utils';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { renderRoutes } from 'react-router-config'; // import { renderRoutes } from 'react-router-config';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import { useMountedState } from 'react-use'; import { useMountedState } from 'react-use';
import { LeftOutlined, MenuFoldOutlined, LoadingOutlined } from '@ant-design/icons'; import {
LeftOutlined,
MenuFoldOutlined,
LoadingOutlined,
} from '@ant-design/icons';
import ProLayout, { getPageTitle } from '@ant-design/pro-layout'; import ProLayout, { getPageTitle } from '@ant-design/pro-layout';
import { getMatchMenu } from '@umijs/route-utils'; import { getMatchMenu } from '@umijs/route-utils';
import pkg from '../../package.json'; import pkg from '../../package.json';
...@@ -326,9 +330,9 @@ const BasicLayout = props => { ...@@ -326,9 +330,9 @@ const BasicLayout = props => {
() => new Site(props, setSiteLoading), () => new Site(props, setSiteLoading),
); );
useEffect(() => { // useEffect(() => {
setCurrentRoutes(props.route.routes[props.currentMenuIndex]); // setCurrentRoutes(props.route.routes[props.currentMenuIndex]);
}, [props.route]); // }, [props.route, props.currentMenuIndex]);
useEffect(() => { useEffect(() => {
props.updatePathname(props.location.pathname); props.updatePathname(props.location.pathname);
...@@ -336,12 +340,12 @@ const BasicLayout = props => { ...@@ -336,12 +340,12 @@ const BasicLayout = props => {
const extraRender = menuExtraRender(currentRoutes); const extraRender = menuExtraRender(currentRoutes);
let clearTime = null; let clearTime = null;
//
useEffect(() => { // useEffect(() => {
setTimeout(() => { // setTimeout(() => {
if (isMounted) setPageLoading(!pageLoading); // if (isMounted) setPageLoading(!pageLoading);
}, 2000); // }, 2000);
}, []); // }, []);
useEffect(() => { useEffect(() => {
const config = findPathByLeafId( const config = findPathByLeafId(
...@@ -373,16 +377,22 @@ const BasicLayout = props => { ...@@ -373,16 +377,22 @@ const BasicLayout = props => {
}, [props.location.pathname]); }, [props.location.pathname]);
useEffect(() => { useEffect(() => {
props.menu.length === 0 ? setLoading(true): (setLoading(false)); const menu = props.menu.filter(item => !item.hideInMenu);
if(menu.length === 0) {
setLoading(true);
}
props.route && (props.route.routes.filter(item => !item.hideInMenu || item.path !== '/404' || item.path !== '/500')).length === 0 && setLoading(true);
if(menu.length > 0 && props.route && props.route.routes.length > 0) {
setCurrentRoutes(props.route.routes[props.currentMenuIndex]);
setLoading(false);
}
}, [props.route, props.menu]);
clearTime = setTimeout(() => { useEffect(() => {
if( props.menu.length > 0 && (props.route && props.route.routes.length > 0)) { setLoading(true);
setCurrentRoutes(props.route.routes[props.currentMenuIndex]); clearTime = setTimeout(() => (setCurrentRoutes(props.route.routes[props.currentMenuIndex]), setLoading(false)), 400);
setLoading(false); return () => clearTimeout && clearTimeout(clearTime);
} }, [props.currentMenuIndex])
}, 400);
// return () => clearTimeout && clearTimeout(clearTime);
}, [props.currentMenuIndex, props.route, props.menu]);
useEffect(() => { useEffect(() => {
siteAction.setGlobalConfig(props.global); siteAction.setGlobalConfig(props.global);
...@@ -396,11 +406,11 @@ const BasicLayout = props => { ...@@ -396,11 +406,11 @@ const BasicLayout = props => {
}); });
} }
}, [props.global]); }, [props.global]);
useEffect(() => { useEffect(() => {
window.share.event.on('updateSite', res => setCityData(res)); window.share.event.on('updateSite', res => setCityData(res));
return () => window.share.event.removeAllListeners('updateSite') return () => window.share.event.removeAllListeners('updateSite')
}, []) }, []);
useMemo(() => { useMemo(() => {
window.share.event.on('listenerRemoveTab', () => { window.share.event.on('listenerRemoveTab', () => {
...@@ -582,7 +592,7 @@ const BasicLayout = props => { ...@@ -582,7 +592,7 @@ const BasicLayout = props => {
navTheme="light" navTheme="light"
siderWidth={transformComplexSideWidth()} siderWidth={transformComplexSideWidth()}
style={{ style={{
height: '400px', height: '400px'
}} }}
> >
{complexConfig && Object.keys(complexConfig).length > 0 ? ( {complexConfig && Object.keys(complexConfig).length > 0 ? (
...@@ -658,6 +668,7 @@ const BasicLayout = props => { ...@@ -658,6 +668,7 @@ const BasicLayout = props => {
); );
}; };
const { openKeys } = props; const { openKeys } = props;
// const filterMenu = props.menu.filter(item => !item.hideInMenu)
return ( return (
<SecurityLayout loading updateCurrentIndex={props.updateCurrentIndex}> <SecurityLayout loading updateCurrentIndex={props.updateCurrentIndex}>
<ProLayout <ProLayout
...@@ -764,10 +775,8 @@ const BasicLayout = props => { ...@@ -764,10 +775,8 @@ const BasicLayout = props => {
settings={defaultSetting} settings={defaultSetting}
{...others} {...others}
> >
{/*{renderRoutes(props.route.routes)}*/}
<Spin <Spin
spinning={pageLoading} spinning={props.microMounted}
size="large" size="large"
wrapperClassName={styles.loadding} wrapperClassName={styles.loadding}
> >
...@@ -798,6 +807,7 @@ const BasicLayout = props => { ...@@ -798,6 +807,7 @@ const BasicLayout = props => {
publicPath={`/${basename}/theme`} publicPath={`/${basename}/theme`}
/> */} /> */}
</ProLayout> </ProLayout>
{/*<div id="micro-container" className="subapp-container" />*/}
</SecurityLayout> </SecurityLayout>
); );
}; };
...@@ -814,6 +824,7 @@ const mapStateToProps = state => ({ ...@@ -814,6 +824,7 @@ const mapStateToProps = state => ({
openKeys: state.getIn(['global', 'openKeys']), openKeys: state.getIn(['global', 'openKeys']),
complexConfig: state.getIn(['global', 'complexConfig']), complexConfig: state.getIn(['global', 'complexConfig']),
complexPathName: state.getIn(['global', 'complexPathName']), complexPathName: state.getIn(['global', 'complexPathName']),
microMounted: state.getIn(['global', 'microMounted']),
}); });
const mapDispatchToProps = dispatch => ({ const mapDispatchToProps = dispatch => ({
updageSetting(setting) { updageSetting(setting) {
......
...@@ -2,7 +2,7 @@ import React from 'react'; ...@@ -2,7 +2,7 @@ import React from 'react';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Redirect } from 'react-router-dom'; import { Redirect } from 'react-router-dom';
import PageLoading from '@ant-design/pro-layout'; import { PageLoading } from '@ant-design/pro-layout';
import { stringify } from 'querystring'; import { stringify } from 'querystring';
import { getBaseName } from '../utils/utils'; import { getBaseName } from '../utils/utils';
...@@ -26,12 +26,6 @@ class SecurityLayout extends React.Component { ...@@ -26,12 +26,6 @@ class SecurityLayout extends React.Component {
redirect: window.location.href, redirect: window.location.href,
}); });
// eslint-disable-next-line no-undef
// if(Cookie.get("token")==="") {
// return (
// <Redirect to={`/user/login?client=${global.client}`} />
// );
// }
if ((!isLogin && loading) || !isReady) { if ((!isLogin && loading) || !isReady) {
return <PageLoading />; return <PageLoading />;
} }
......
...@@ -10,6 +10,7 @@ import 'kit_logger'; ...@@ -10,6 +10,7 @@ import 'kit_logger';
import micorConfig from '../config/micor'; import micorConfig from '../config/micor';
import pkg from '../package.json'; import pkg from '../package.json';
import { FILTER_FOLER_REG } from './utils/constants'; import { FILTER_FOLER_REG } from './utils/constants';
import { actionCreators } from './containers/App/store';
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
const Logger = logger('micro'); const Logger = logger('micro');
const MICRO_STATUS = { const MICRO_STATUS = {
...@@ -26,37 +27,8 @@ const MICRO_STATUS = { ...@@ -26,37 +27,8 @@ const MICRO_STATUS = {
SKIP_BECAUSE_BROKEN: 'SKIP_BECAUSE_BROKEN', SKIP_BECAUSE_BROKEN: 'SKIP_BECAUSE_BROKEN',
LOAD_ERROR: 'LOAD_ERROR', LOAD_ERROR: 'LOAD_ERROR',
}; };
const excludeAssetFilter = [
'framework/amap/AMap.UI', export const initMicroApps = (loader, store) => {
'framework/amap/init.js',
'configuration/js',
'framework/three.js',
'threedimensional/frameworkthree',
'iframe/Civ3DLLab/js',
'framework/jquery/gridify-min.js',
'framework/jquery/gridify.qrcode.js',
'echarts',
'lbs.amap.com',
'restapi.amap.com',
'lbs.amap.com',
'restapi.amap.com',
'webapi.amap.com',
'webapi.amap.com/count',
'api.map.baidu.com',
'map.baidu.com',
'pv.sohu.com',
'mt0.google.cn',
'mt1.google.cn',
'mt2.google.cn',
'mt3.google.cn',
'hm.baidu.com',
'https://maponline0.bdimg.com',
'https://maponline1.bdimg.com',
'https://maponline2.bdimg.com',
'https://maponline3.bdimg.com',
'https://api.map.baidu.com/getscript',
];
export const initMicroApps = loader => {
const entrys = const entrys =
process.env.NODE_ENV !== 'production' ? micorConfig.dev : micorConfig.prod; process.env.NODE_ENV !== 'production' ? micorConfig.dev : micorConfig.prod;
...@@ -75,6 +47,7 @@ export const initMicroApps = loader => { ...@@ -75,6 +47,7 @@ export const initMicroApps = loader => {
{ {
beforeLoad: [ beforeLoad: [
app => { app => {
store.dispatch(actionCreators.updateMicroMounted(true));
Logger.info('[LifeCycle] before load %c%s'); Logger.info('[LifeCycle] before load %c%s');
}, },
], ],
...@@ -85,6 +58,7 @@ export const initMicroApps = loader => { ...@@ -85,6 +58,7 @@ export const initMicroApps = loader => {
], ],
afterMount: [ afterMount: [
app => { app => {
store.dispatch(actionCreators.updateMicroMounted(false));
Logger.info(`[LifeCycle] after mount %c%s ${app.name}`); Logger.info(`[LifeCycle] after mount %c%s ${app.name}`);
}, },
], ],
...@@ -115,7 +89,33 @@ export const initMicroApps = loader => { ...@@ -115,7 +89,33 @@ export const initMicroApps = loader => {
// prefetch: 'all', // prefetch: 'all',
// eslint-disable-next-line no-underscore-dangle // eslint-disable-next-line no-underscore-dangle
getPublicPath: window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__, getPublicPath: window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__,
excludeAssetFilter: url => excludeAssetFilter.includes(url), excludeAssetFilter: url =>
url.indexOf('framework/amap/AMap.UI') !== -1 ||
url.indexOf('framework/amap/init.js') !== -1 ||
url.indexOf('configuration/js') !== -1 ||
url.indexOf('framework/three.js') !== -1 ||
url.indexOf('threedimensional/frameworkthree') !== -1 ||
url.indexOf('iframe/Civ3DLLab/js') !== -1 ||
url.indexOf('framework/jquery/gridify-min.js') !== -1 ||
url.indexOf('framework/jquery/gridify.qrcode.js') !== -1 ||
url.indexOf('echarts') !== -1 ||
url.indexOf('lbs.amap.com') !== -1 ||
url.indexOf('restapi.amap.com') !== -1 ||
url.indexOf('webapi.amap.com') !== -1 ||
url.indexOf('webapi.amap.com/count') !== -1 ||
url.indexOf('api.map.baidu.com') !== -1 ||
url.indexOf('map.baidu.com') !== -1 ||
url.indexOf('pv.sohu.com') !== -1 ||
url.indexOf('mt0.google.cn') !== -1 ||
url.indexOf('mt1.google.cn') !== -1 ||
url.indexOf('mt2.google.cn') !== -1 ||
url.indexOf('mt3.google.cn') !== -1 ||
url.indexOf('hm.baidu.com') !== -1 ||
url.indexOf('https://maponline0.bdimg.com') !== -1 ||
url.indexOf('https://maponline1.bdimg.com') !== -1 ||
url.indexOf('https://maponline2.bdimg.com') !== -1 ||
url.indexOf('https://maponline3.bdimg.com') !== -1 ||
url.indexOf('https://api.map.baidu.com/getscript') !== -1,
}); });
runAfterFirstMounted(() => { runAfterFirstMounted(() => {
Logger.info('[MainApp] first app mounted'); Logger.info('[MainApp] first app mounted');
......
...@@ -17,8 +17,7 @@ import WxLogin from './components/WxLogin'; ...@@ -17,8 +17,7 @@ import WxLogin from './components/WxLogin';
import LoginAction from './login'; import LoginAction from './login';
import styles from './style.less'; import styles from './style.less';
import i18n from '../../../utils/share'; import i18n from '../../../utils/share';
import defaultSetting from '../../../../config/defaultSetting' import defaultSetting from '../../../../config/defaultSetting';
import { PageLoading } from '@ant-design/pro-layout';
const { UserName, Password, Mobile, Captcha, Submit } = LoginForm; const { UserName, Password, Mobile, Captcha, Submit } = LoginForm;
const Display = { const Display = {
Account: 'Account', Account: 'Account',
......
...@@ -25,7 +25,6 @@ export const dyRoutes = routes => { ...@@ -25,7 +25,6 @@ export const dyRoutes = routes => {
{ {
path: '/industry', path: '/industry',
component: BootPage, component: BootPage,
name: 'industry',
}, },
{ {
path: '/', path: '/',
......
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