Commit d9fe2826 authored by 邓晓峰's avatar 邓晓峰

fix: menu load bug

parent c0f6d3f5
Pipeline #23146 skipped with stages
This diff is collapsed.
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
"@babel/runtime": "^7.10.5", "@babel/runtime": "^7.10.5",
"promise.prototype.finally": "^3.1.2", "promise.prototype.finally": "^3.1.2",
"@wisdom-utils/components": "0.0.6", "@wisdom-utils/components": "0.0.6",
"@wisdom-utils/utils": "0.0.29", "@wisdom-utils/utils": "0.0.30",
"@wisdom-utils/vapp-browser-vm": "^0.0.11", "@wisdom-utils/vapp-browser-vm": "^0.0.11",
"@wisdom-utils/vapp-browser-vm-plugins": "^0.0.13", "@wisdom-utils/vapp-browser-vm-plugins": "^0.0.13",
"animate.css": "^4.1.1", "animate.css": "^4.1.1",
...@@ -106,7 +106,7 @@ ...@@ -106,7 +106,7 @@
"ip": "1.1.5", "ip": "1.1.5",
"js-base64": "^3.5.2", "js-base64": "^3.5.2",
"js-cookie": "^2.2.1", "js-cookie": "^2.2.1",
"kit_global_config": "^1.0.22", "kit_global_config": "^1.0.23",
"kit_logger": "^1.0.2", "kit_logger": "^1.0.2",
"kit_utils": "^1.3.8", "kit_utils": "^1.3.8",
"lodash": "4.17.11", "lodash": "4.17.11",
...@@ -155,7 +155,7 @@ ...@@ -155,7 +155,7 @@
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"multer": "^1.4.2", "multer": "^1.4.2",
"add-asset-html-webpack-plugin": "3.1.3", "add-asset-html-webpack-plugin": "3.1.3",
"antd": "^4.10.1", "antd": "^4.11.2",
"babel-core": "7.0.0-bridge.0", "babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.0.1", "babel-eslint": "10.0.1",
"babel-loader": "8.0.5", "babel-loader": "8.0.5",
......
...@@ -66,7 +66,8 @@ const initLocale = () => { ...@@ -66,7 +66,8 @@ const initLocale = () => {
const initGlobalConfig = () => { const initGlobalConfig = () => {
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
let config = {}; let config = createStoreage.get('globalConfig') || {};
store.dispatch(actionCreators.updateComplexConfig({}));
if (!Cookies.get('token') || config.token == null) { if (!Cookies.get('token') || config.token == null) {
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
createStoreage.remove(namespace); createStoreage.remove(namespace);
...@@ -87,7 +88,8 @@ const initGlobalConfig = () => { ...@@ -87,7 +88,8 @@ const initGlobalConfig = () => {
if (config.token !== null && Object.keys(config).length > 0) { if (config.token !== null && Object.keys(config).length > 0) {
store.dispatch(actionCreators.getConfig(config)); store.dispatch(actionCreators.getConfig(config));
render({ appContent: '', loading: true }); // render({ appContent: '', loading: true });
initMicroApps(loader, store);
} else { } else {
appService.getWateWayConfig().then(res => { appService.getWateWayConfig().then(res => {
const hasGateWay = const hasGateWay =
......
...@@ -82,6 +82,7 @@ class AvatarDropdown extends React.Component { ...@@ -82,6 +82,7 @@ class AvatarDropdown extends React.Component {
debugger debugger
this.props.updateCurrentIndex && this.props.updateCurrentIndex(0); this.props.updateCurrentIndex && this.props.updateCurrentIndex(0);
this.props.updateConfig && this.props.updateConfig({}); this.props.updateConfig && this.props.updateConfig({});
this.props.updateComplexConfig && this.props.updateComplexConfig({});
createStoreage.remove(`__PANDA_STORE__${location.hostname}`); createStoreage.remove(`__PANDA_STORE__${location.hostname}`);
this.props.history.push( this.props.history.push(
`/user/login/?client=${window.globalConfig.client}`, `/user/login/?client=${window.globalConfig.client}`,
......
...@@ -224,6 +224,9 @@ const mapDispatchToProps = dispatch => ({ ...@@ -224,6 +224,9 @@ const mapDispatchToProps = dispatch => ({
updateConfig(config) { updateConfig(config) {
dispatch(actionCreators.getConfig(config)) dispatch(actionCreators.getConfig(config))
}, },
updateComplexConfig(config) {
dispatch(actionCreators.updateComplexConfig(config))
},
}); });
export default connect( export default connect(
mapStateToProps, mapStateToProps,
......
...@@ -366,7 +366,7 @@ const BasicLayout = props => { ...@@ -366,7 +366,7 @@ const BasicLayout = props => {
props.updateComplexPathName(path); props.updateComplexPathName(path);
const findDeepLevelConfig = findPathByLeafId( const findDeepLevelConfig = findPathByLeafId(
parent.path, parent.path,
[currentRoutes], currentRoutes.routes,
'', '',
'path', 'path',
); );
...@@ -374,25 +374,40 @@ const BasicLayout = props => { ...@@ -374,25 +374,40 @@ const BasicLayout = props => {
setCollapse(true); setCollapse(true);
history.push(config.path); history.push(config.path);
} }
}, [props.location.pathname]); }, [props.location.pathname, currentRoutes]);
useEffect(() => { // useEffect(() => {
const menu = props.menu.filter(item => !item.hideInMenu); // const menu = props.menu.filter(item => !item.hideInMenu);
if(menu.length === 0) { // if(menu.length === 0) {
setLoading(true); // setLoading(true);
} // }
props.route && (props.route.routes.filter(item => !item.hideInMenu || item.path !== '/404' || item.path !== '/500')).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) { // if(menu.length > 0 && props.route && props.route.routes.length > 0) {
setCurrentRoutes(props.route.routes[props.currentMenuIndex]); // setCurrentRoutes(props.route.routes[props.currentMenuIndex]);
setLoading(false); // setLoading(false);
} // }
}, [props.route, props.menu]); // }, [props.currentMenuIndex, props.route, props.menu]);
useEffect(() => { useEffect(() => {
setLoading(true); setLoading(true);
clearTime = setTimeout(() => (setCurrentRoutes(props.route.routes[props.currentMenuIndex]), setLoading(false)), 400); clearTime = setTimeout(() => (setCurrentRoutes(props.route.routes[props.currentMenuIndex]), setLoading(false)), 400);
return () => clearTimeout && clearTimeout(clearTime); return () => clearTimeout && clearTimeout(clearTime);
}, [props.currentMenuIndex]) }, [props.currentMenuIndex]);
useEffect(() => {
const menu = props.menu.filter(item => !item.hideInMenu);
setLoading(true);
clearTime = setTimeout(() => {
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);
}
}, 400);
return () => clearTimeout && clearTimeout(clearTime);
}, [props.menu]);
useEffect(() => { useEffect(() => {
siteAction.setGlobalConfig(props.global); siteAction.setGlobalConfig(props.global);
...@@ -453,7 +468,7 @@ const BasicLayout = props => { ...@@ -453,7 +468,7 @@ const BasicLayout = props => {
); );
}, [location.pathname]); }, [location.pathname]);
const handleSelectedKey = item => { const handleSelectedKey = item => {
const config = findPathByLeafId(item.path, [currentRoutes], '', 'path'); const config = findPathByLeafId(item.path, currentRoutes.routes, '', 'path');
props.updateComplexConfig({}); props.updateComplexConfig({});
props.updateComplexPathName(null); props.updateComplexPathName(null);
if (config && config.routes && config.routes.length > 0) { if (config && config.routes && config.routes.length > 0) {
...@@ -744,10 +759,11 @@ const BasicLayout = props => { ...@@ -744,10 +759,11 @@ const BasicLayout = props => {
)} )}
openKeys={[...openKeys]} openKeys={[...openKeys]}
menuProps={{ menuProps={{
forceSubMenuRender: false,
onClick: ({ item, key, keyPath, domEvent }) => { onClick: ({ item, key, keyPath, domEvent }) => {
domEvent.persist(); domEvent.persist();
const keyField = key.indexOf('/') > -1 ? 'path' : 'key'; const keyField = key.indexOf('/') > -1 ? 'path' : 'key';
const config = findPathByLeafId(key, [currentRoutes], '', keyField); const config = findPathByLeafId(key, currentRoutes.routes, '', keyField);
props.updateComplexConfig({}); props.updateComplexConfig({});
props.updateComplexPathName(null); props.updateComplexPathName(null);
if (config && config.routes && config.routes.length > 0) { if (config && config.routes && config.routes.length > 0) {
......
...@@ -68,7 +68,6 @@ class Site { ...@@ -68,7 +68,6 @@ class Site {
ignoreSite: true, ignoreSite: true,
}) })
.then(res => { .then(res => {
debugger
if (res && res.say.errMsg === '' && res.say.statusCode === ERR_OK) { if (res && res.say.errMsg === '' && res.say.statusCode === ERR_OK) {
const result = res.getMe; const result = res.getMe;
let city = self.weatherCity; let city = self.weatherCity;
...@@ -347,6 +346,8 @@ class Site { ...@@ -347,6 +346,8 @@ class Site {
self.getCityStationsForUser().then(res => { self.getCityStationsForUser().then(res => {
window.share.event.emit('updateSite', res); window.share.event.emit('updateSite', res);
}); });
self.props && self.props.updateComplexConfig && self.props.updateComplexConfig({});
// window.location.reload(); // window.location.reload();
window.share.event.emit('triggerMicro', this.props.global); window.share.event.emit('triggerMicro', this.props.global);
}); });
......
...@@ -108,7 +108,7 @@ ...@@ -108,7 +108,7 @@
.@{ant-prefix}-menu-inline-collapsed .@{ant-prefix}-menu-inline-collapsed
.@{ant-prefix}-menu-item-only-child.@{ant-prefix}-menu-item-selected) { .@{ant-prefix}-menu-item-only-child.@{ant-prefix}-menu-item-selected) {
border-left: 2px solid @primary-color; border-left: 2px solid @primary-color;
background-color: @menu-dark-submenu-bg!important; background-color: @menu-dark-inline-submenu-bg!important;
transition: cubic-bezier(0.175, 0.885, 0.32, 1.275); transition: cubic-bezier(0.175, 0.885, 0.32, 1.275);
} }
:global(.@{ant-prefix}-menu-submenu-popup :global(.@{ant-prefix}-menu-submenu-popup
......
...@@ -53,12 +53,13 @@ export const initMicroApps = (loader, store) => { ...@@ -53,12 +53,13 @@ export const initMicroApps = (loader, store) => {
], ],
beforeMount: [ beforeMount: [
app => { app => {
debugger
store.dispatch(actionCreators.updateMicroMounted(false));
Logger.info(`[LifeCycle] before mount %c%s ${app.name}`); Logger.info(`[LifeCycle] before mount %c%s ${app.name}`);
}, },
], ],
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}`);
}, },
], ],
...@@ -145,8 +146,10 @@ export const defaultApp = () => { ...@@ -145,8 +146,10 @@ export const defaultApp = () => {
config.homepage !== '' && FILTER_FOLER_REG.test(config.homepage) config.homepage !== '' && FILTER_FOLER_REG.test(config.homepage)
? 'civweb4' ? 'civweb4'
: 'civweb4'; : 'civweb4';
setDefaultMountApp( const defaultURL =
`/${pkg.name.toLocaleLowerCase()}/${basePath}?client=${config.client}`, config.homepage === ''
); ? `/${pkg.name.toLocaleLowerCase()}/${basePath}?client=${config.client}`
: `${basePath}/${config.homepage}`;
setDefaultMountApp(defaultURL);
} }
}; };
...@@ -64,6 +64,7 @@ const BootPage = props => { ...@@ -64,6 +64,7 @@ const BootPage = props => {
props.history.push(`/?client=${props.global.client}`); props.history.push(`/?client=${props.global.client}`);
window.share.event.emit('triggerMicro', props.global); window.share.event.emit('triggerMicro', props.global);
props.updateCurrentIndex(0); props.updateCurrentIndex(0);
window.location.reload();
}); });
}, []); }, []);
useEffect(() => { useEffect(() => {
......
...@@ -661,6 +661,7 @@ class Login { ...@@ -661,6 +661,7 @@ class Login {
self.globalConfig.token = token; self.globalConfig.token = token;
if(response.access_token!== "") { if(response.access_token!== "") {
self.globalConfig.access_token = response.access_token; self.globalConfig.access_token = response.access_token;
localStorage.setItem('access_token', response.access_token);
} }
if (isRememberPWD) { if (isRememberPWD) {
Cookies.set(self.globalConfig.client, token, { Cookies.set(self.globalConfig.client, token, {
......
...@@ -52,6 +52,7 @@ export function getBaseName() { ...@@ -52,6 +52,7 @@ export function getBaseName() {
} }
const cache = {}; const cache = {};
export function findPathByLeafId(leafId, nodes, path, key) { export function findPathByLeafId(leafId, nodes, path, key) {
debugger
if (path === undefined) { if (path === undefined) {
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