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