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

fix: 修复应用通讯

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