Commit 2e2cb5b9 authored by 邓晓峰's avatar 邓晓峰

fix: 修复应用通讯

parent 6d9a05be
Pipeline #47574 skipped with stages
export function genActiveRule(routerPrefix) {
return location => location.pathname.startsWith(routerPrefix);
return location => {
debugger
return location.pathname.startsWith(routerPrefix)
};
}
export default {
dev: [
......
......@@ -110,9 +110,9 @@
"@wisdom-map/Map": "^1.0.12-17",
"@wisdom-map/arcgismap": "^1.0.79-17",
"@wisdom-map/util": "^1.0.27-0",
"@wisdom-utils/components": "0.1.8",
"@wisdom-utils/components": "0.1.15",
"@wisdom-utils/runtime": "0.0.15",
"@wisdom-utils/utils": "0.1.48",
"@wisdom-utils/utils": "0.1.55",
"animate.css": "^4.1.1",
"antd": "^4.17.4",
"compression": "1.7.4",
......@@ -135,7 +135,7 @@
"pinyin-match": "^1.1.1",
"promise.prototype.finally": "^3.1.2",
"prop-types": "15.7.2",
"qiankun": "^2.7.8",
"qiankun": "^2.4.6",
"qrcode.react": "^1.0.0",
"rc-cascader": "^2.3.2",
"react": "16.12.0",
......
......@@ -10,7 +10,7 @@ import 'sanitize.css/sanitize.css';
import { event } from '@wisdom-utils/utils';
import { ConfigProvider } from 'antd';
import { Storeage } from '@wisdom-utils/utils/lib/helpers';
import { history } from '@wisdom-utils/runtime';
import { actionCreators } from './containers/App/store';
import { initGlobalConfig } from './initConfig';
import './utils/event';
......@@ -29,16 +29,17 @@ const initLocale = () => {
initGlobalConfig();
initLocale();
const unlisten = (function() {
let prePathname = '';
return history.listen(location => {
if (location.pathname.indexOf('/civbase/user/login') > -1 && location.pathname !== prePathname) {
initGlobalConfig();
}
prePathname = location.pathname;
});
})();
// const unlisten = (function() {
// let prePathname = '';
// return history.listen(location => {
// console.log(location)
// if (location.pathname.indexOf('/civbase/user/login') > -1 && location.pathname !== prePathname) {
// initGlobalConfig();
// }
// prePathname = location.pathname;
// });
// })();
event.on('event:logout', () => {
store.dispatch(actionCreators.logout());
});
// event.on('event:logout', () => {
// store.dispatch(actionCreators.logout());
// });
......@@ -233,6 +233,7 @@ class NoticeIconView extends Component {
className={styles.action}
count={this.state.count}
confirmRead={this.notifier.confirmRead}
config={this.props.global}
>
<NoticeIcon.Tab
list={this.state.noticeData}
......
import React, { useEffect, useRef, useState, useContext, Suspense } from 'react';
import { Anchor, Popover, Radio, Spin, Tabs, ConfigProvider } from 'antd';
import { Anchor, Popover, Radio, Spin, ConfigProvider } from 'antd';
import Icon, { LoadingOutlined } from '@ant-design/icons';
import { store, helpers } from '@wisdom-utils/utils';
import classNames from 'classnames';
......@@ -21,6 +21,7 @@ import layoutStyles from './BasicLayout.less';
const ArcgisMap = React.lazy(() => import('../pages/map/arcgis'));
const AMap = React.lazy(() => import('../pages/map/amap'));
const CesiumMap = React.lazy(() => import('../pages/map/cesiumMap'));
import actions from '../actions';
// eslint-disable-next-line import/extensions
const { params } = helpers;
const { getParamsV1 } = params;
......@@ -218,7 +219,11 @@ const Layout = props => {
const [collapse, setCollapse] = useState(false);
const [cityData, setCityData] = useState({});
const [siteLoading, setSiteLoading] = useState(false);
const [prevHistoryBase, setPrevHistoryBase] = useState(() => {
const pathname = props.location.pathname;
const argv = pathname.split('/');
return argv[1];
});
const [mapMode, setMapMode] = useState(WEB_GIS_TYPE.ARCGIS)
const [siteAction, setSiteAction] = useState(
() => new Site(props, setSiteLoading),
......@@ -231,6 +236,7 @@ const Layout = props => {
useEffect(() => {
siteAction.setGlobalConfig(props.global);
if (!Cookies.get('token')) {
let client = props.global && props.global.hasOwnProperty('client') ? props.global.get('client') : null;
client = client !== 'undefined' && !_.isNull(client) && !_.isUndefined(client) ? client : 'city';
......@@ -258,6 +264,7 @@ const Layout = props => {
*/
const handlerPageChange = () => {
const params = getParamsV1(props.location.pathname);
if (params.hasOwnProperty('mapType') && params.mapType === WEB_GIS_TYPE.AMAP) {
AMapLoader.reset();
......@@ -267,10 +274,27 @@ const Layout = props => {
AMapLoader.reset();
setMapMode(WEB_GIS_TYPE.ARCGIS)
}
}
}
// useEffect(() => {
// // actions.setGlobalState({
// // globalConfig: props.global
// // });
// // if(!/industry/.test(location.pathname)) {
// // store.set('props:globalConfig', {globalConfig: props.global});
// // } else {
// // store.off('props:globalConfig', state => {})
// // }
// console.log(props.location, location)
// const pathname = props.location.pathname;
// const argv = pathname.split('/');
// }, [location.pathname, props.global])
useEffect(() => {
window.share.event.on('updateSite', res => setCityData(res));
return () => {
......@@ -297,7 +321,7 @@ const Layout = props => {
const logo = props.global && _.isFunction(props.global.get) && props.global.get('bannerLogo') ? (props.global && _.isFunction(props.global.transformDevAssetsBaseURL) && props.global.transformDevAssetsBaseURL(props.global.get('bannerLogo'))) : defaultSetting.logo;
return (
<SecurityLayout loading>
<SecurityLayout loading {...props}>
<BasicLayout
route={props.route}
title={props.global.title}
......
......@@ -4,7 +4,7 @@ import { connect } from 'react-redux';
import { Redirect } from '@wisdom-utils/runtime';
import { PageLoading } from '@ant-design/pro-layout';
import _ from 'lodash';
import { store, helpers } from '@wisdom-utils/utils';
class SecurityLayout extends React.Component {
state = {
isReady: false,
......@@ -17,6 +17,31 @@ class SecurityLayout extends React.Component {
document.title = this.props.global.title;
}
componentWillReceiveProps(nextProps) {
const products = (this.props.global.products || []).map(item => {
if(item.PackageName === 'civweb4') {
return 'web4_console'
}
return `${item.PackageName}-main`;
});
const location = this.props.location;
const pathname = location.pathname;
const argv = pathname.split('/');
const nextPathname = nextProps.location.pathname;
const nextArgv = nextPathname.split('/');
if(argv[1] !== nextArgv[1]) {
Object.keys(products).forEach(item => {
window[products[item]] && window[products[item]] && window[products[item]].unmount && window[products[item]].unmount({store: store});
});
}
if(this.props.location.pathname !== nextProps.location.pathname) {
store.set('event:globalConfig', {globalConfig: nextProps.global});
}
}
render() {
const { isReady } = this.state;
const { children, global, loading } = this.props;
......@@ -27,22 +52,13 @@ class SecurityLayout extends React.Component {
if (!Cookies.get('token')) {
this.props.updateCurrentIndex && this.props.updateCurrentIndex(0);
let client = global.client || Cookies.get('city');
client =
client !== 'undefined' && !_.isNull(client) && !_.isUndefined(client)
? client
: 'city';
client = client !== 'undefined' && !_.isNull(client) && !_.isUndefined(client) ? client : 'city';
// event.emit(?'event:initConfig');
let { generateType } = global;
generateType =
!_.isNull(generateType) &&
!_.isUndefined(generateType) &&
generateType !== 'undefined'
? `&generateType=${generateType}`
: '';
generateType = !_.isNull(generateType) && !_.isUndefined(generateType) && generateType !== 'undefined' ? `&generateType=${generateType}` : '';
return (
<Redirect
to={`/user/login?client=${client}${generateType}`}
render={() => window.location.reload()}
/>
);
}
......@@ -50,21 +66,13 @@ class SecurityLayout extends React.Component {
if ((!isLogin && loading) || !isReady) {
return <PageLoading />;
}
// if (
// !isLogin &&
// window.location.pathname !== `/${getBaseName()}/user/login`
// ) {
// this.props.updateCurrentIndex && this.props.updateCurrentIndex(0);
// return (
// <Redirect to={`/user/login?client=${global.client}&${queryString}`} />
// );
// }
return children;
}
}
const mapStateToProps = state => ({
global: state.getIn(['global', 'globalConfig']),
location: state.getIn(['router', 'location']).toJS()
});
export default connect(
mapStateToProps,
......
......@@ -6,13 +6,12 @@ import { encode } from 'js-base64';
import Cookies from 'js-cookie';
import { cityJson } from '@wisdom-utils/utils';
import { CitySelector } from '@wisdom-utils/components';
import { appService } from '../api';
import Login from '../pages/user/login/login';
import styles from './UserLayout.less';
import { initMicroApps } from '@/micro';
import styles from './BasicLayout.less';
import { initMicroApps } from '../micro'
// import actions from '../actions';
const { Link } = Anchor;
const ERR_OK = '0000';
......@@ -338,54 +337,35 @@ class Site {
self.props.updateCurrentIndex && self.props.updateCurrentIndex(-1);
const login = new Login(this.props, () => {
self.setLoading(false);
// eslint-disable-next-line no-unused-expressions
self.props.updateCurrentIndex && self.props.updateCurrentIndex(0);
initMicroApps();
// debugger
// initMicroApps();
// 切换站点后,重置掉三级菜单
const homeType = self.globalConfig.homeType || 'civweb4';
const homePath = self.globalConfig.homepage
? self.globalConfig.homepage.startsWith(homeType)
? self.globalConfig.homepage
: `/${homeType}/${self.globalConfig.homepage}`
: `/${homeType}`;
window.share &&
window.share.event &&
window.share.event.emit('event:favitor', {
const homePath = self.globalConfig.homepage ? self.globalConfig.homepage.startsWith(homeType) ? self.globalConfig.homepage: `/${homeType}/${self.globalConfig.homepage}`: `/${homeType}`;
window.share && window.share.event && window.share.event.emit('event:favitor', {
name: '首页',
path: homePath,
icon: null,
});
});
// 重新加载订阅消息铃铛
window.share &&
window.share.event &&
window.share.event.emit('reloadNotice');
// window.history.replaceState(
// '',
// '',
// `/${self.globalConfig.homepage}`,
// );
window.share && window.share.event && window.share.event.emit('reloadNotice');
const config = self.globalConfig;
let url = !config.home ? ((config.homepage === '' || _.isNull(config.homepage)) ? `/civweb4`: `/civweb4/${config.homepage.replace(/^\//, '').replace(/^civweb4\//, '')}`) : `/${config.homepage.replace(/^\//, '')}`;
self.props.history && self.props.history.push(url)
self.getCityStationsForUser().then(res => {
window.share.event.emit('updateSite', res);
});
self.props &&
self.props.updateCollapsed &&
self.props.updateCollapsed(false);
self.props &&
self.props.updateComplexConfig &&
self.props.updateComplexConfig({});
// 切换站点,加载首页,否则默认加载web4
self.props.history &&
self.props.history.push(
self.globalConfig.homepage
? `/${self.globalConfig.homepage}`
: `/civweb4`,
);
// window.location.reload();
window.share.event.emit('triggerMicro', this.props.global);
});
login.init();
......
......@@ -76,47 +76,53 @@ export const initMicroApps = () => {
}) : config,
//createStoreage.get('globalConfig'),
XMLHttpRequest: window.XMLHttpRequest,
// offGlobalStateChange: actions.offGlobalStateChange
};
return item;
}), {
beforeLoad: [
app => {
store.dispatch(actionCreators.updateMicroMounted(true));
Logger.info('[LifeCycle] before load %c%s');
Logger.info('[LifeCycle] before load %c%s', app);
},
],
beforeMount: [
app => {
Logger.info(`[LifeCycle] before mount %c%s ${app.name}`);
microStore.off("event:globalConfig", () => {});
Logger.info(`[LifeCycle] before mount %c%s ${app.name}`, app);
},
],
afterMount: [
app => {
store.dispatch(actionCreators.updateMicroMounted(false));
Logger.info(`[LifeCycle] after mount %c%s ${app.name}`);
Logger.info(`[LifeCycle] after mount %c%s ${app.name}`, app);
},
],
beforeUnmount: [
app => {
window.share.event.removeAllListeners('changeRoute');
Logger.info(`[LifeCycle] after unmount %c%s ${app.name}`);
Logger.info(`[LifeCycle] beforeUnmount %c%s ${app.name}`, app);
// window.globalConfig = {}
// createStoreage.remove(`__PANDA_STORE__${location.hostname}`)
},
],
afterUnmount: [app => { }],
afterUnmount: [app => {
actions.offGlobalStateChange();
Logger.info(`[LifeCycle] after unmount %c%s ${app.name}`, app);
}],
},
);
const globalStore = store.getState().toJS();
const globalConfig = window.globalConfig;
// globalConfig.homepage = globalConfig.homepage && /civweb4/.test(globalConfig.homepage) ? config.homepage.replace(/civweb4\//, ''): globalConfig.homepage;
actions.setGlobalState({
// eslint-disable-next-line no-undef
globalConfig: globalConfig
//createStoreage.get('globalConfig'),
});
microStore.set("props:globalConfig", {
// actions.offGlobalStateChange();
// actions.setGlobalState({
// // eslint-disable-next-line no-undef
// globalConfig: globalConfig
// //createStoreage.get('globalConfig'),
// });
// actions.offGlobalStateChange();
microStore.set("event:globalConfig", {
globalConfig: globalConfig,
global: globalStore.global
});
......@@ -183,7 +189,7 @@ export const initMicroApps = () => {
};
export const defaultApp = () => {
// eslint-disable-next-line no-undef
const config = window.globalConfig;
......
......@@ -4,8 +4,13 @@ import BaseLogin from './template/baseLogin';
import NewYear from './template/newYear';
import InfoLogin from './template/infoLogin';
import Yulin from './template/yulin';
import { initGlobalConfig } from '../../../initConfig';
/* eslint-disable */
export default () => {
React.useEffect(() => {
initGlobalConfig();
}, []);
const loginTemplate = window.globalConfig && window.globalConfig.loginTemplate;
switch(loginTemplate) {
......@@ -22,3 +27,4 @@ export default () => {
return <BaseLogin/>;
}
};
......@@ -18,6 +18,9 @@ export const dyRoutes = (routes, layout) => {
{
path: '/user',
component: UserLayout,
beforeEnter(props) {
console.log(props);
},
routes: [
{
name: 'login',
......
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