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

fix: 云平台下切换站点bug

parent 8a13e303
File added
......@@ -14046,7 +14046,7 @@
"micromatch": {
"version": "4.0.2",
"resolved": "https://g.civnet.cn:4873/micromatch/-/micromatch-4.0.2.tgz",
"integrity": "sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q==",
"integrity": "sha1-T8sJmb+fvC/L3SEvbWKbmlbDklk=",
"dev": true,
"requires": {
"braces": "^3.0.1",
......@@ -16099,7 +16099,7 @@
"micromatch": {
"version": "4.0.2",
"resolved": "https://g.civnet.cn:4873/micromatch/-/micromatch-4.0.2.tgz",
"integrity": "sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q==",
"integrity": "sha1-T8sJmb+fvC/L3SEvbWKbmlbDklk=",
"dev": true,
"requires": {
"braces": "^3.0.1",
......@@ -18793,9 +18793,9 @@
"dev": true
},
"kit_global_config": {
"version": "1.0.21",
"resolved": "https://g.civnet.cn:4873/kit_global_config/-/kit_global_config-1.0.21.tgz",
"integrity": "sha512-iMSXpoYdFAKPHf1we0f0KZo5DJFYa+Bwz3shEcPdiD1hwttalVnvLTP6tW7RHFLgktZMcnx24HclDukeFAPbug==",
"version": "1.0.22",
"resolved": "https://g.civnet.cn:4873/kit_global_config/-/kit_global_config-1.0.22.tgz",
"integrity": "sha512-L/JsC2eL5pRGociJ1ZT3gZK5mJbR28uh9h5drgNcBJK313GcRQSFMzk5AAif14LGwbIBM1zi7k8uUQXseDAsyg==",
"requires": {
"@babel/runtime": "^7.10.5",
"js-base64": "^3.5.2",
......@@ -20380,7 +20380,7 @@
"micromatch": {
"version": "3.1.10",
"resolved": "https://g.civnet.cn:4873/micromatch/-/micromatch-3.1.10.tgz",
"integrity": "sha512-MWikgl9n9M3w+bpsY3He8L+w9eF9338xRl8IAO5viDizwSzziFEyUzo2xrrloB64ADbTf8uA8vRqqttDTOmccg==",
"integrity": "sha1-cIWbyVyYQJUvNZoGij/En57PrCM=",
"dev": true,
"requires": {
"arr-diff": "^4.0.0",
......@@ -28512,7 +28512,7 @@
"micromatch": {
"version": "3.1.10",
"resolved": "https://g.civnet.cn:4873/micromatch/-/micromatch-3.1.10.tgz",
"integrity": "sha512-MWikgl9n9M3w+bpsY3He8L+w9eF9338xRl8IAO5viDizwSzziFEyUzo2xrrloB64ADbTf8uA8vRqqttDTOmccg==",
"integrity": "sha1-cIWbyVyYQJUvNZoGij/En57PrCM=",
"dev": true,
"requires": {
"arr-diff": "^4.0.0",
......@@ -28737,7 +28737,7 @@
"micromatch": {
"version": "4.0.2",
"resolved": "https://g.civnet.cn:4873/micromatch/-/micromatch-4.0.2.tgz",
"integrity": "sha512-y7FpHSbMUMoyPbYUSzO6PaZ6FyRnQOpHuKwbo1G+Knck95XVU4QAiKdGEnj5wwoS7PlOgthX/09u5iFJ+aYf5Q==",
"integrity": "sha1-T8sJmb+fvC/L3SEvbWKbmlbDklk=",
"dev": true,
"requires": {
"braces": "^3.0.1",
......@@ -56,12 +56,12 @@ const services = {
},
getWebSiteConfig: {
url: () =>
window.globalConfig &&
window.globalConfig &&
window.globalConfig.hasGateWay
? API.GET_WEB_SITE_CONFIG_GEWAY
: API.GET_WEB_SITE_CONFIG,
url: () => API.GET_WEB_SITE_CONFIG_GEWAY,
// window.globalConfig &&
// window.globalConfig &&
// window.globalConfig.hasGateWay
// ? API.GET_WEB_SITE_CONFIG_GEWAY
// : API.GET_WEB_SITE_CONFIG,
method: constants.REQUEST_METHOD_GET,
type: constants.REQUEST_HTTP,
},
......
......@@ -65,12 +65,12 @@ const initLocale = () => {
};
const initGlobalConfig = () => {
debugger
// eslint-disable-next-line no-undef
const config = createStoreage.get('globalConfig') || {};
let config = {};
if (!Cookies.get('token') || config.token == null) {
// eslint-disable-next-line no-undef
createStoreage.remove(namespace);
config = {};
}
if (!params.getParams('client', window.location.search) && config) {
// eslint-disable-next-line no-undef
......@@ -81,45 +81,11 @@ const initGlobalConfig = () => {
if (!createStoreage.get('globalConfig')) {
window.createStoreage = new Storeage(namespace);
}
if(!Cookies.get('token')) {
if (!Cookies.get('token')) {
localStorage.removeItem('loginSite');
}
if (params.getParams('client')) {
appService
.queryConfig({ client: params.getParams('client') || 'city' })
.then(res => {
if (res) {
const data = res;
if (!data.client) {
delete data.client;
}
store.dispatch(
actionCreators.getConfig(
Object.assign({}, window.globalConfig, data),
),
);
// eslint-disable-next-line no-shadow
}
return res;
})
// eslint-disable-next-line no-shadow
.then(res => {
render({ appContent: '', loading: true });
})
.catch(error => {
store.dispatch(actionCreators.getConfigError(error));
});
}
if (config.token !== null && Object.keys(config).length > 0) {
// eslint-disable-next-line no-new
new Login(
{
global: config,
updateConfig: data => store.dispatch(actionCreators.getConfig(data)),
},
() => {},
true,
);
store.dispatch(actionCreators.getConfig(config));
render({ appContent: '', loading: true });
} else {
......@@ -143,7 +109,7 @@ const initGlobalConfig = () => {
if (res) {
const data = res;
if (!data.client) {
delete data.client;
data.client = 'city';
}
store.dispatch(
actionCreators.getConfig(
......@@ -151,16 +117,28 @@ const initGlobalConfig = () => {
),
);
// eslint-disable-next-line no-new
new Login(
{
global: Object.assign({}, window.globalConfig, data),
// eslint-disable-next-line no-shadow
updateConfig: data =>
store.dispatch(actionCreators.getConfig(data)),
},
() => {},
true,
);
if (Cookies.get('token')) {
// eslint-disable-next-line no-new
new Login(
{
global: Object.assign({}, data, {
token: Cookies.get('token'),
}),
// eslint-disable-next-line no-shadow
updateConfig: data =>
store.dispatch(actionCreators.getConfig(data)),
},
() => {
(async () => {
(await (Cookies.get('token') &&
window.globalConfig &&
window.globalConfig.token)) && initMicroApps(loader);
})();
},
true,
);
}
// eslint-disable-next-line no-shadow
}
return res;
......@@ -173,9 +151,6 @@ const initGlobalConfig = () => {
store.dispatch(actionCreators.getConfigError(error));
});
}
if (config.token) {
initMicroApps(loader);
}
};
initGlobalConfig();
......
......@@ -3,7 +3,7 @@ import React, { useEffect, useRef, useState } from 'react';
import classNames from 'classnames';
import propTypes from 'prop-types';
import KeyCode from 'rc-util/lib/KeyCode';
import { Spin } from 'antd';
import Icon, { MenuOutlined } from '@ant-design/icons';
import Categories from './Categories';
......@@ -29,14 +29,13 @@ const Panel = props => {
props.visible ? styles.visible : styles.hidden,
);
const domRef = useRef();
const [currentMenu, setCurrentMenu] = useState(
() =>
(props.data &&
Array.isArray(props.data) &&
props.data.length > 0 &&
props.data[0]) ||
{},
);
// eslint-disable-next-line no-debugger;
const [currentMenu, setCurrentMenu] = useState(null);
useEffect(() => {
setCurrentMenu(props.data[props.currentMenuIndex]);
}, [props.data, props.currentMenuIndex]);
// eslint-disable-next-line no-underscore-dangle
let _clickEvents = null;
const handleKeyDown = event => {
......@@ -136,7 +135,9 @@ const Panel = props => {
/>
</div>
<div className={styles['main-menus']}>
<Menu data={currentMenu || []} handleClick={selectItem} />
<Spin spinning={!currentMenu}>
<Menu data={currentMenu || []} handleClick={selectItem} />
</Spin>
</div>
</div>
</div>
......
......@@ -50,7 +50,10 @@ const noMatch = (
const renderIcon = (icon, size, alias) => {
const transformIcon = () => icon.replace(/\s*/g, '');
const url = `${baseURI}/${alias}/${transformIcon()}`;
const isURL = /^(http|https)/;
const url = isURL.test(transformIcon())
? transformIcon()
: `${baseURI}/${alias}/${transformIcon()}`;
return (
<img
src={url}
......@@ -66,20 +69,22 @@ const menuExtraRender = currentRoutes => {
return {
render: ({ collapsed }) => {
if (currentRoutes) {
const iconURL =
currentRoutes && currentRoutes.extData && currentRoutes.extData.icon
? `${baseURI}/civweb4/${currentRoutes.extData.icon}`
: '';
return (
<>
<Spin
spinning={currentRoutes.extData && !currentRoutes.extData.icon}
>
{currentRoutes.extData && currentRoutes.extData.icon && (
{iconURL && (
<a
style={{ display: 'flex', alignItems: 'center' }}
onClick={() => setToggleSystem(!toggleSystem)}
>
<img
src={`${baseURI}/civweb4/${currentRoutes &&
currentRoutes.extData &&
currentRoutes.extData.icon}`}
src={iconURL}
style={{ width: '20px', height: '20px' }}
alt=""
/>
......@@ -211,7 +216,7 @@ const Stations = props => {
);
};
const renderTitle = (
const renderTitle = ({
title,
action,
data,
......@@ -219,8 +224,9 @@ const renderTitle = (
setLoading,
collapsed,
fixedHeader,
config
) => {
config,
}) => {
// eslint-disable-next-line react-hooks/rules-of-hooks,no-debugger
// eslint-disable-next-line react-hooks/rules-of-hooks
const [visible, setVisible] = useState(false);
const header = document.querySelector('.ant-pro-fixed-header');
......@@ -244,8 +250,7 @@ const renderTitle = (
if(config && config.userInfo && config.userInfo.site === "") {
loaded = false;
}
return {
render: (
return (
<>
<span className={styles['header-title']} style={{ marginLeft }}>
{title}
......@@ -296,8 +301,7 @@ const renderTitle = (
</Spin>
</>
),
};
);
};
const BasicLayout = props => {
/* eslint-disable no-unused-vars */
......@@ -336,7 +340,7 @@ const BasicLayout = props => {
useEffect(() => {
setTimeout(() => {
if (isMounted) setPageLoading(!pageLoading);
}, 1000);
}, 2000);
}, []);
useEffect(() => {
......@@ -371,23 +375,31 @@ const BasicLayout = props => {
useEffect(() => {
setLoading(true);
clearTime = setTimeout(() => {
setCurrentRoutes(props.route.routes[props.currentMenuIndex]);
setLoading(false);
}, 20);
if(props.route && props.route.routes.length > 0) {
setCurrentRoutes(props.route.routes[props.currentMenuIndex]);
setLoading(false);
}
}, 400);
return () => clearTimeout && clearTimeout(clearTime);
}, [props.currentMenuIndex]);
}, [props.currentMenuIndex, props.route]);
useEffect(() => {
siteAction.setGlobalConfig(props.global);
if (!Cookies.get('token')) {
history.replace(`/user/login?client=${props.global.get('client')}`);
return;
}
if(props.global && props.global.userInfo && props.global.userInfo.token !== null && Object.keys(cityData).length === 0) {
if(props.global && props.global.userInfo && props.global.userInfo.token !== null && props.global.userInfo.loginName && Object.keys(cityData).length === 0) {
siteAction.getCityStationsForUser().then(res => {
setCityData(res);
});
}
}, [props.global]);
useEffect(() => {
window.share.event.on('updateSite', res => setCityData(res));
return () => window.share.event.removeAllListeners('updateSite')
}, [])
useMemo(() => {
window.share.event.on('listenerRemoveTab', () => {
......@@ -469,16 +481,17 @@ const BasicLayout = props => {
fixSiderbar: true,
collapsed: collapse,
};
const headerContentRender = renderTitle(
props.global.get('title'),
siteAction,
cityData,
siteLoading,
setSiteLoading,
collapse,
others.fixedHeader,
props.global,
);
const headerContentRender = renderTitle({
title: props.global.get('title'),
action: siteAction,
data: cityData,
loading: siteLoading,
setLoading: setSiteLoading,
collapsed: collapse,
fixedHeader: others.fixedHeader,
config: props.global,
});
const menuComplexDataRender = menuList =>
menuList.map(item => {
......@@ -657,7 +670,7 @@ const BasicLayout = props => {
onMenuHeaderClick={event => handleLogo(event)}
menuExtraRender={props.menu.length > 0 ? extraRender.render : null}
rightContentRender={() => <RightContent {...props} />}
headerContentRender={() => headerContentRender.render}
headerContentRender={() => headerContentRender}
menu={{
loading,
}}
......
import React from 'react';
import Cookies from 'js-cookie';
import { connect } from 'react-redux';
import { Redirect } from 'react-router-dom';
import PageLoading from '@ant-design/pro-layout';
......@@ -20,7 +20,7 @@ class SecurityLayout extends React.Component {
const { isReady } = this.state;
const { children, global, loading } = this.props;
const isLogin =
global.token !== null ||
Cookies.get('token') !== null ||
((global.qrcodeData &&
global.qrcodeData.state !== '' &&
global.qrcodeData.code !== '') ||
......@@ -32,8 +32,8 @@ class SecurityLayout extends React.Component {
// <Redirect to={`/user/login?client=${global.client}`} />
// );
// }
if((!isLogin && loading) || !isReady) {
return <PageLoading/>
if ((!isLogin && loading) || !isReady) {
return <PageLoading />;
}
if (
!isLogin &&
......
......@@ -28,6 +28,10 @@ class Site {
// this.initWeatherCity();
}
setGlobalConfig(config) {
this.globalConfig = config;
}
initWeatherCity() {
try {
if (
......@@ -64,6 +68,7 @@ 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;
......@@ -161,7 +166,7 @@ class Site {
self.globalConfig.userInfo.groupType = allStation[0].groupType;
}
}
debugger
if (allStation.length > 1) {
self.currentStationName = arr[arr.length - 1];
self.citySelector = self.AvailableofRegionName(projectStation);
......@@ -334,8 +339,16 @@ class Site {
self.setLoading(false);
// eslint-disable-next-line no-unused-expressions
self.props.updateCurrentIndex && self.props.updateCurrentIndex(0);
window.history.replaceState('', '', `/civbase/`);
window.location.reload();
window.history.replaceState(
'',
'',
`/civbase/civweb4/${self.globalConfig.homepage}`,
);
self.getCityStationsForUser().then(res => {
window.share.event.emit('updateSite', res);
});
// window.location.reload();
window.share.event.emit('triggerMicro', this.props.global);
});
login.init();
}
......
......@@ -378,6 +378,14 @@
:global(.@{ant-prefix}-pro-basicLayout .@{ant-prefix}-pro-sider-logo h1) {
display: none;
}
:global(.@{ant-prefix}-pro-basicLayout .@{ant-prefix}-layout-sider-children .@{ant-prefix}-spin-lg .@{ant-prefix}-spin-dot) {
font-size: 20px;
}
:global(.@{ant-prefix}-pro-basicLayout .@{ant-prefix}-layout-sider-children .@{ant-prefix}-spin-lg .@{ant-prefix}-spin-dot i) {
width: 9px;
height: 9px;
}
//:global(.@{ant-prefix}-layout-sider-collapsed
//// .@{ant-prefix}-menu-dark.@{ant-prefix}-menu-vertical
......
......@@ -25,5 +25,4 @@ export default {
'component.header.icon.home': '首页',
'component.header.icon.order': '工单',
'component.header.icon.alarm': '报警',
};
......@@ -26,6 +26,36 @@ const MICRO_STATUS = {
SKIP_BECAUSE_BROKEN: 'SKIP_BECAUSE_BROKEN',
LOAD_ERROR: 'LOAD_ERROR',
};
const excludeAssetFilter = [
'framework/amap/AMap.UI',
'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 =
process.env.NODE_ENV !== 'production' ? micorConfig.dev : micorConfig.prod;
......@@ -85,33 +115,7 @@ export const initMicroApps = loader => {
// prefetch: 'all',
// eslint-disable-next-line no-underscore-dangle
getPublicPath: window.__INJECTED_PUBLIC_PATH_BY_QIANKUN__,
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,
excludeAssetFilter: url => excludeAssetFilter.includes(url),
});
runAfterFirstMounted(() => {
Logger.info('[MainApp] first app mounted');
......
......@@ -540,7 +540,8 @@ class Login {
}
getUserInfoAndConfig(failCallback, flag, industry) {
const { token } = this.globalConfig;
// const { token } = this.globalConfig;
const token = Cookies.get('token');
const site = Cookies.get('site');
const self = this;
/* eslint-disable */
......
......@@ -57,6 +57,7 @@ const generRotes = (widgets, parent, level = 0) => {
component: 'BasicLayout',
parent,
alias: alias,
hideInMenu: item.hideInMenu || false,
routes: generRotes(
item.widgets,
Object.assign({}, item, { path, key: subKey }),
......@@ -64,7 +65,7 @@ const generRotes = (widgets, parent, level = 0) => {
),
extData: {
...item,
icon: (item && item.icon && item.icon !== null && item.icon.replace(/\s*/g, '')) || '_',
icon: (item && item.icon && item.icon !== null && item.icon.replace(/\s*/g, '')) || '',
},
});
} else {
......@@ -91,11 +92,11 @@ const generRotes = (widgets, parent, level = 0) => {
href: url,
target: isURL(url) ? '_blank' : '',
key: guid('panda'),
hideInMenu: l > 3,
hideInMenu: l > 3 ? true: item.hideInMenu || false,
alias: item.product || DEFAULT_APPLICATION,
extData: {
...item,
icon: (item && item.icon.replace(/\s*/g, '')) || '_',
icon: (item && item.icon.replace(/\s*/g, '')) || '',
},
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