Commit 9b121196 authored by 邓晓峰's avatar 邓晓峰

fix: 修复退出登录子应用卸载

parent cffd4b71
Pipeline #48024 skipped with stages
...@@ -25,7 +25,7 @@ import { ...@@ -25,7 +25,7 @@ import {
AMAP_VIEW, AMAP_VIEW,
PD_VIEW, PD_VIEW,
} from './constants'; } from './constants';
import { store } from '@wisdom-utils/utils';
export function getConfig(data) { export function getConfig(data) {
return { return {
type: GET_CONFIG, type: GET_CONFIG,
...@@ -222,6 +222,17 @@ export function logout(data) { ...@@ -222,6 +222,17 @@ export function logout(data) {
// eslint-disable-next-line no-undef,no-restricted-globals // eslint-disable-next-line no-undef,no-restricted-globals
createStoreage.remove(`__PANDA_STORE__MICRO_${location.hostname}`); createStoreage.remove(`__PANDA_STORE__MICRO_${location.hostname}`);
localStorage.removeItem('JmReport-Access-Token'); localStorage.removeItem('JmReport-Access-Token');
const products = (window.globalConfig.products || []).map(item => {
if (item.PackageName === 'civweb4') {
return 'web4_console'
}
return `${item.PackageName}-main`;
});
Object.keys(products).forEach(item => {
window[products[item]] && window[products[item]] && window[products[item]].unmount && window[products[item]].unmount({ store: store });
});
return { return {
type: LOGINOUT, type: LOGINOUT,
data: { data: {
......
...@@ -106,8 +106,7 @@ export const initGlobalConfig = () => { ...@@ -106,8 +106,7 @@ export const initGlobalConfig = () => {
gateWayConfig, gateWayConfig,
), ),
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
updateConfig: data => updateConfig: data => store.dispatch(actionCreators.getConfig(data)),
store.dispatch(actionCreators.getConfig(data)),
isInit: false, isInit: false,
logout: () => store.dispatch(actionCreators.logout()), logout: () => store.dispatch(actionCreators.logout()),
}, },
...@@ -122,17 +121,10 @@ export const initGlobalConfig = () => { ...@@ -122,17 +121,10 @@ export const initGlobalConfig = () => {
true, true,
); );
} }
// eslint-disable-next-line no-shadow
} }
return res; return res;
}) })
// eslint-disable-next-line no-shadow
.then(res => { .then(res => {
// eslint-disable-next-line no-use-before-define
// initSensorType();
// eslint-disable-next-line no-use-before-define
// initIsMock();
render({ appContent: '', loading: true }); render({ appContent: '', loading: true });
}) })
.catch(error => { .catch(error => {
......
import React from 'react'; import React from 'react';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Redirect } from '@wisdom-utils/runtime'; import { Redirect, history } 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 { stringify } from 'querystring';
import { store, helpers } from '@wisdom-utils/utils'; import { store, helpers } from '@wisdom-utils/utils';
class SecurityLayout extends React.Component { class SecurityLayout extends React.Component {
state = { state = {
...@@ -18,8 +19,9 @@ class SecurityLayout extends React.Component { ...@@ -18,8 +19,9 @@ class SecurityLayout extends React.Component {
} }
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
debugger
const products = (this.props.global.products || []).map(item => { const products = (this.props.global.products || []).map(item => {
if(item.PackageName === 'civweb4') { if (item.PackageName === 'civweb4') {
return 'web4_console' return 'web4_console'
} }
return `${item.PackageName}-main`; return `${item.PackageName}-main`;
...@@ -30,14 +32,13 @@ class SecurityLayout extends React.Component { ...@@ -30,14 +32,13 @@ class SecurityLayout extends React.Component {
const nextPathname = nextProps.location.pathname; const nextPathname = nextProps.location.pathname;
const nextArgv = nextPathname.split('/'); const nextArgv = nextPathname.split('/');
console.log(argv[2], nextArgv[2]) if (argv[2] !== nextArgv[2]) {
if(argv[2] !== nextArgv[2]) {
Object.keys(products).forEach(item => { Object.keys(products).forEach(item => {
window[products[item]] && window[products[item]] && window[products[item]].unmount && window[products[item]].unmount({store: store}); window[products[item]] && window[products[item]] && window[products[item]].unmount && window[products[item]].unmount({ store: store });
}); });
} }
if(this.props.location.pathname !== nextProps.location.pathname) { if (this.props.location.pathname !== nextProps.location.pathname) {
store.set('event:globalConfig', {globalConfig: nextProps.global}); store.set('event:globalConfig', { globalConfig: nextProps.global });
} }
} }
...@@ -46,19 +47,21 @@ class SecurityLayout extends React.Component { ...@@ -46,19 +47,21 @@ class SecurityLayout extends React.Component {
const { isReady } = this.state; const { isReady } = this.state;
const { children, global, loading } = this.props; const { children, global, loading } = this.props;
const isLogin = Cookies.get('token') !== null && global.token !== null; const isLogin = Cookies.get('token') !== null && global.token !== null;
// const queryString = stringify({
// redirect: window.location.href, if (!isLogin && window.location.pathname !== '/civbase/user/login') {
// }); const { query = {}, search, pathname } = history.location;
if (!Cookies.get('token')) { const { redirect } = query;
const queryString = stringify({
redirect: pathname + search,
});
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 !== 'undefined' && !_.isNull(client) && !_.isUndefined(client) ? client : 'city'; client = client !== 'undefined' && !_.isNull(client) && !_.isUndefined(client) ? client : 'city';
// event.emit(?'event:initConfig');
let { generateType } = global; let { generateType } = global;
generateType = !_.isNull(generateType) && !_.isUndefined(generateType) && generateType !== 'undefined' ? `&generateType=${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}&${queryString}`}
/> />
); );
} }
......
import React from 'react'; import React, { useEffect } from 'react';
import BaseLogin from './template/baseLogin'; 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 { getParams } from '@wisdom-utils/utils/lib/helpers/params';
// import { useParams } from '@wisdom-utils/runtime';
import { initGlobalConfig } from '../../../initConfig'; import { initGlobalConfig } from '../../../initConfig';
const LoginTemplate = { const LoginTemplate = {
'新春 - 智联.html': NewYear, '新春 - 智联.html': NewYear,
...@@ -16,9 +18,10 @@ const LoginTemplate = { ...@@ -16,9 +18,10 @@ const LoginTemplate = {
}; };
/* eslint-disable */ /* eslint-disable */
export default (props) => { export default (props) => {
// React.useEffect(() => { const redirect = getParams('redirect');
// initGlobalConfig(); useEffect(() => {
// }, [props.location]); initGlobalConfig();
}, [redirect]);
const template = window.globalConfig && window.globalConfig.loginTemplate; const template = window.globalConfig && window.globalConfig.loginTemplate;
const RenderComponent = LoginTemplate[template] ? LoginTemplate[template]: LoginTemplate['default']; const RenderComponent = LoginTemplate[template] ? LoginTemplate[template]: LoginTemplate['default'];
return <RenderComponent {...props}/> return <RenderComponent {...props}/>
......
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