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

fix: 修复多用户切换,用户信息错乱

parent fa23b26e
...@@ -79,6 +79,26 @@ module.exports = { ...@@ -79,6 +79,26 @@ module.exports = {
'/PandaCore': '/PandaCore', '/PandaCore': '/PandaCore',
}, },
}, },
'/PandaInformatization': {
target: proxyURL,
changeOrigin: true,
headers: {
'Access-Control-Allow-Origin': '*',
},
pathRewrite: {
'/PandaInformatization': '/PandaInformatization',
},
},
'/PandaWorkFlow': {
target: proxyURL,
changeOrigin: true,
headers: {
'Access-Control-Allow-Origin': '*',
},
pathRewrite: {
'/PandaWorkFlow': '/PandaWorkFlow',
},
},
'/CityTemp': { '/CityTemp': {
// target: 'http://192.168.10.150:8777', // target: 'http://192.168.10.150:8777',
target: proxyURL, target: proxyURL,
......
...@@ -8,114 +8,33 @@ import 'antd/dist/antd.less'; ...@@ -8,114 +8,33 @@ import 'antd/dist/antd.less';
import 'file-loader?name=.htaccess!./.htaccess'; // eslint-disable-line import/extensions import 'file-loader?name=.htaccess!./.htaccess'; // eslint-disable-line import/extensions
import 'kit_utils/lib/format'; import 'kit_utils/lib/format';
import 'sanitize.css/sanitize.css'; import 'sanitize.css/sanitize.css';
// import './locales/zh-CN';
// import './loader';
// import './vm';
import React from 'react';
import ReactDOM from 'react-dom';
import { event } from 'microser-data'; import { event } from 'microser-data';
import _ from 'lodash'; import _ from 'lodash';
import { Button, ConfigProvider, message, notification } from 'antd'; import { ConfigProvider} from 'antd';
import { ConnectedRouter } from 'connected-react-router/immutable'; import { Storeage } from 'kit_utils';
import Immutable from 'immutable';
import { params, Storeage } from 'kit_utils';
import { Provider } from 'react-redux';
import { history } from '@wisdom-utils/runtime'; import { history } from '@wisdom-utils/runtime';
import ErrorBoundary from './components/ErrorBoundary';
// import themePluginConfig from '../config/themePluginConfig';
import { appService } from './api';
// import { updateTheme } from './common/helpers/settingColor';
import Container from './components/Container';
import configureStore from './configureStore';
import App from './containers/App';
import { actionCreators } from './containers/App/store'; import { actionCreators } from './containers/App/store';
import { LocaleContainer } from './locales/locale'; // import { initMicroApps } from './micro';
import { initMicroApps } from './micro';
import { initGlobalConfig } from './initConfig' import { initGlobalConfig } from './initConfig'
import './utils/event'; import './utils/event';
import store from './stores'
// import Cookies from 'js-cookie'; // import Cookies from 'js-cookie';
// eslint-disable-next-line no-restricted-globals // eslint-disable-next-line no-restricted-globals
const namespace = `__PANDA_STORE__${location.hostname}`; const namespace = `__PANDA_STORE__${location.hostname}`;
window.createStoreage = new Storeage(namespace); window.createStoreage = new Storeage(namespace);
// eslint-disable-next-line no-underscore-dangle
const initialState = Immutable.Map();
const store = configureStore(initialState, history);
const MOUNT_NODE = document.getElementById('root');
ConfigProvider.config({ ConfigProvider.config({
prefixCls: 'panda-console-base' prefixCls: 'panda-console-base'
}); });
const render = () => {
// eslint-disable-next-line react-hooks/rules-of-hooks
ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history}>
<LocaleContainer>
<ConfigProvider prefixCls="panda-console-base">
<ErrorBoundary>
<Container>
<App />
</Container>
</ErrorBoundary>
</ConfigProvider>
</LocaleContainer>
</ConnectedRouter>
</Provider>,
MOUNT_NODE,
);
};
// updateTheme('#ff9600');
const loader = (appContent, loading) => render({ appContent, loading });
const initLocale = () => { const initLocale = () => {
localStorage.setItem('umi_locale', 'zh-CN'); localStorage.setItem('umi_locale', 'zh-CN');
}; };
const PRODUCT_NAME = ['civ_water', 'civ_monitor']; // const PRODUCT_NAME = ['civ_water', 'civ_monitor'];
const initSensorType = () => {
let filterProduct =
(window.globalConfig && window.globalConfig.products) || [];
filterProduct = filterProduct.filter(item =>
PRODUCT_NAME.includes(item.PackageName),
);
if (filterProduct.length > 0) {
appService.getSensorType().then(res => {
store.dispatch(
actionCreators.getConfig(
Object.assign({}, window.globalConfig, {
sensorType: res.data,
}),
),
);
});
}
};
const initIsMock = () => { initGlobalConfig();
appService
.sysConfiguration({
moduleName: '是否mock数据',
})
.then(res => {
store.dispatch(
actionCreators.getConfig(
Object.assign({}, window.globalConfig, {
isMock: res.data === '是',
}),
),
);
});
};
initGlobalConfig(loader, store, render);
initLocale(); initLocale();
window.share && window.share.event && window.share.event.on('triggerMicro', () => {
initMicroApps(loader, store);
});
const unlisten = history.listen(location => { const unlisten = history.listen(location => {
if(location.pathname.indexOf('/civbase/user/login') > -1) { if(location.pathname.indexOf('/civbase/user/login') > -1) {
initGlobalConfig(loader, store, render); initGlobalConfig();
} }
}) })
......
...@@ -76,6 +76,7 @@ export const initialState = fromJS({ ...@@ -76,6 +76,7 @@ export const initialState = fromJS({
const appReducer = (state = initialState, action) => { const appReducer = (state = initialState, action) => {
switch (action.type) { switch (action.type) {
case GET_CONFIG: case GET_CONFIG:
debugger
// eslint-disable-next-line no-debugger // eslint-disable-next-line no-debugger
// eslint-disable-next-line no-underscore-dangle // eslint-disable-next-line no-underscore-dangle
window.__INITIAL_STATE__ = Object.assign( window.__INITIAL_STATE__ = Object.assign(
......
...@@ -3,16 +3,19 @@ import { initMicroApps } from './micro'; ...@@ -3,16 +3,19 @@ import { initMicroApps } from './micro';
import { params, Storeage } from 'kit_utils'; import { params, Storeage } from 'kit_utils';
import { actionCreators } from './containers/App/store'; import { actionCreators } from './containers/App/store';
import { getToken, isString } from './utils/utils'; import { getToken, isString } from './utils/utils';
import loader, { render } from './render';
import store from './stores';
import Login from './pages/user/login/login'; import Login from './pages/user/login/login';
const namespace = `__PANDA_STORE__${location.hostname}`; const namespace = `__PANDA_STORE__${location.hostname}`;
window.createStoreage = new Storeage(namespace); window.createStoreage = new Storeage(namespace);
export const initGlobalConfig = () => {
export const initGlobalConfig = (loader, store, render) => {
// eslint-disable-next-line no-debugger // eslint-disable-next-line no-debugger
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
createStoreage.remove(`__PANDA_STORE__${location.hostname}`); createStoreage.remove(`__PANDA_STORE__${location.hostname}`);
window.globalConfig = {}; window.globalConfig = {};
let config = createStoreage.get('globalConfig') || {}; window.__INITIAL_STATE__ = {};
let config = window.globalConfig || {};
//createStoreage.get('globalConfig') || {};
store.dispatch(actionCreators.updateComplexConfig({})); store.dispatch(actionCreators.updateComplexConfig({}));
if (!getToken() || config.token == null) { if (!getToken() || config.token == null) {
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
...@@ -32,8 +35,8 @@ export const initGlobalConfig = (loader, store, render) => { ...@@ -32,8 +35,8 @@ export const initGlobalConfig = (loader, store, render) => {
localStorage.removeItem('loginSite'); localStorage.removeItem('loginSite');
} }
if (config.token !== null && Object.keys(config).length > 0) { if (window.globalConfig.token !== null && Object.keys(window.globalConfig).length > 0) {
store.dispatch(actionCreators.getConfig(config)); store.dispatch(actionCreators.getConfig(window.globalConfig));
// render({ appContent: '', loading: true }); // render({ appContent: '', loading: true });
initMicroApps(loader, store); initMicroApps(loader, store);
if (config.isNewYear) { if (config.isNewYear) {
......
...@@ -9,12 +9,14 @@ import { ...@@ -9,12 +9,14 @@ import {
setDefaultMountApp, setDefaultMountApp,
start, start,
} from 'qiankun'; } from 'qiankun';
import { store as microStore } from 'microser-data';
import micorConfig, { genActiveRule } from '../config/micor'; import micorConfig, { genActiveRule } from '../config/micor';
import pkg from '../package.json'; import pkg from '../package.json';
import { actionCreators } from './containers/App/store'; import { actionCreators } from './containers/App/store';
import { FILTER_FOLER_REG } from './utils/constants'; import { FILTER_FOLER_REG } from './utils/constants';
import loader from './render';
import store from './stores';
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
const Logger = logger('micro'); const Logger = logger('micro');
const MICRO_STATUS = { const MICRO_STATUS = {
...@@ -32,12 +34,15 @@ const MICRO_STATUS = { ...@@ -32,12 +34,15 @@ const MICRO_STATUS = {
LOAD_ERROR: 'LOAD_ERROR', LOAD_ERROR: 'LOAD_ERROR',
}; };
export const initMicroApps = (loader, store) => { export const initMicroApps = () => {
debugger
/* eslint-disable */ /* eslint-disable */
const config = createStoreage.get('globalConfig'); const config = window.globalConfig || {};
//createStoreage.get('globalConfig');
const application = config && config.products || []; const application = config && config.products || [];
let products = []; let products = [];
application && Array.isArray(application) && application.length > 0 && application.map(item => { application && Array.isArray(application) && application.length > 0 && application.map(item => {
if(item.PackageName === 'report') { if(item.PackageName === 'report') {
products.push({ products.push({
...@@ -77,7 +82,8 @@ export const initMicroApps = (loader, store) => { ...@@ -77,7 +82,8 @@ export const initMicroApps = (loader, store) => {
baseRoot: item.name, baseRoot: item.name,
// eslint- // eslint-
// disable-next-line no-undef // disable-next-line no-undef
globalConfig: createStoreage.get('globalConfig'), globalConfig: config,
//createStoreage.get('globalConfig'),
XMLHttpRequest: window.XMLHttpRequest, XMLHttpRequest: window.XMLHttpRequest,
}; };
return item; return item;
...@@ -103,6 +109,8 @@ export const initMicroApps = (loader, store) => { ...@@ -103,6 +109,8 @@ export const initMicroApps = (loader, store) => {
app => { app => {
window.share.event.removeAllListeners('changeRoute'); window.share.event.removeAllListeners('changeRoute');
Logger.info(`[LifeCycle] after unmount %c%s ${app.name}`); Logger.info(`[LifeCycle] after unmount %c%s ${app.name}`);
window.globalConfig = {}
createStoreage.remove(`__PANDA_STORE__${location.hostname}`)
}, },
], ],
afterUnmount: [app => {}], afterUnmount: [app => {}],
...@@ -111,12 +119,19 @@ export const initMicroApps = (loader, store) => { ...@@ -111,12 +119,19 @@ export const initMicroApps = (loader, store) => {
const globalStore = store.getState().toJS(); const globalStore = store.getState().toJS();
const { setGlobalState } = initGlobalState({ const { setGlobalState } = initGlobalState({
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
globalConfig: createStoreage.get('globalConfig'), globalConfig: window.globalConfig,
//createStoreage.get('globalConfig'),
global: globalStore.global global: globalStore.global
}); });
setGlobalState({ setGlobalState({
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
globalConfig: createStoreage.get('globalConfig'), globalConfig: window.globalConfig,
//createStoreage.get('globalConfig'),
});
microStore.set("props:globalConfig", {
globalConfig: window.globalConfig,
global: globalStore.global
}); });
start({ start({
sandbox: { sandbox: {
......
...@@ -601,7 +601,7 @@ class Login { ...@@ -601,7 +601,7 @@ class Login {
generateType: params.getParams('generateType') || '' generateType: params.getParams('generateType') || ''
}) })
.then(response => { .then(response => {
debugger
self.globalConfig.layout = 'blank'; self.globalConfig.layout = 'blank';
if (response && response.token) { if (response && response.token) {
...@@ -645,7 +645,7 @@ class Login { ...@@ -645,7 +645,7 @@ class Login {
expires: date, expires: date,
path: '/', path: '/',
}) })
debugger
// self.globalConfig.Industry = industry; // self.globalConfig.Industry = industry;
self.updateConfig && self.updateConfig(self.globalConfig); self.updateConfig && self.updateConfig(self.globalConfig);
const loginSite = {}; const loginSite = {};
......
...@@ -17,6 +17,7 @@ import styles from '../style.less'; ...@@ -17,6 +17,7 @@ import styles from '../style.less';
import useRenderQcode from '../js/useRenderQcode'; import useRenderQcode from '../js/useRenderQcode';
import Account from '../js/useAccount'; import Account from '../js/useAccount';
import IotComponent from '../js/useIOTComponent'; import IotComponent from '../js/useIOTComponent';
import { initMicroApps } from '../../../../micro';
const Login = forwardRef((props, _ref) => { const Login = forwardRef((props, _ref) => {
const videoRef = useRef(); const videoRef = useRef();
const loginRef = useRef(); const loginRef = useRef();
...@@ -62,7 +63,9 @@ const Login = forwardRef((props, _ref) => { ...@@ -62,7 +63,9 @@ const Login = forwardRef((props, _ref) => {
setSubmitting(false); setSubmitting(false);
props.updateCurrentIndex && props.updateCurrentIndex(0); props.updateCurrentIndex && props.updateCurrentIndex(0);
props.history.push(`/?client=${props.global.client}`); props.history.push(`/?client=${props.global.client}`);
window.share.event.emit('triggerMicro', props.global); // debugger
// window.share.event.emit('triggerMicro', props.global);
initMicroApps();
}); });
action && action.events.on('loginError', event => { action && action.events.on('loginError', event => {
setVisible(false); setVisible(false);
...@@ -78,7 +81,8 @@ const Login = forwardRef((props, _ref) => { ...@@ -78,7 +81,8 @@ const Login = forwardRef((props, _ref) => {
action && action &&
action.events.on('loginSuccess', event => { action.events.on('loginSuccess', event => {
props.history.push(`/?client=${props.global.client}`); props.history.push(`/?client=${props.global.client}`);
window.share.event.emit('triggerMicro', props.global); // window.share.event.emit('triggerMicro', props.global);
initMicroApps();
}); });
action && action &&
action.events.on('loginError', event => { action.events.on('loginError', event => {
......
...@@ -24,6 +24,7 @@ import UnSelected from '@/assets/oa/login/unselected.jpg' ...@@ -24,6 +24,7 @@ import UnSelected from '@/assets/oa/login/unselected.jpg'
import LoginAction from '../login'; import LoginAction from '../login';
import { actionCreators } from '@/containers/App/store'; import { actionCreators } from '@/containers/App/store';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import { initMicroApps } from '../../../../micro';
const Logger = logger('login'); const Logger = logger('login');
// 、登录页 // 、登录页
class InfoLogin extends React.Component{ class InfoLogin extends React.Component{
...@@ -108,7 +109,8 @@ changeQrCode=(item)=>{ ...@@ -108,7 +109,8 @@ changeQrCode=(item)=>{
action && action.events.on('loginSuccess', event => { action && action.events.on('loginSuccess', event => {
this.props.updateCurrentIndex && this.props.updateCurrentIndex(0); this.props.updateCurrentIndex && this.props.updateCurrentIndex(0);
this.props.history.push(`/?client=${this.props.global.client}`); this.props.history.push(`/?client=${this.props.global.client}`);
window.share.event.emit('triggerMicro', this.props.global); // window.share.event.emit('triggerMicro', this.props.global);
initMicroApps();
}); });
action && action.events.on('loginError', event => { action && action.events.on('loginError', event => {
......
...@@ -20,6 +20,7 @@ import LoginAction from '../login'; ...@@ -20,6 +20,7 @@ import LoginAction from '../login';
import { actionCreators } from '@/containers/App/store'; import { actionCreators } from '@/containers/App/store';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
import QRCode from 'qrcode.react'; import QRCode from 'qrcode.react';
import { initMicroApps } from '../../../../micro';
const Logger = logger('login'); const Logger = logger('login');
// 、登录页 // 、登录页
class InfoLogin extends React.Component { class InfoLogin extends React.Component {
...@@ -139,7 +140,8 @@ class InfoLogin extends React.Component { ...@@ -139,7 +140,8 @@ class InfoLogin extends React.Component {
action && action.events.on('loginSuccess', event => { action && action.events.on('loginSuccess', event => {
this.props.updateCurrentIndex && this.props.updateCurrentIndex(0); this.props.updateCurrentIndex && this.props.updateCurrentIndex(0);
this.props.history.push(`/?client=${this.props.global.client}`); this.props.history.push(`/?client=${this.props.global.client}`);
window.share.event.emit('triggerMicro', this.props.global); // window.share.event.emit('triggerMicro', this.props.global);
initMicroApps();
}); });
action && action.events.on('loginError', event => { action && action.events.on('loginError', event => {
......
import React from 'react';
import ReactDOM from 'react-dom';
import store from './stores'
import { history } from '@wisdom-utils/runtime';
import { Provider } from 'react-redux';
import { ConfigProvider } from 'antd';
import { ConnectedRouter } from 'connected-react-router/immutable';
import ErrorBoundary from './components/ErrorBoundary';
import Container from './components/Container';
import { LocaleContainer } from './locales/locale';
import App from './containers/App';
const MOUNT_NODE = document.getElementById('root');
export const render = () => {
// eslint-disable-next-line react-hooks/rules-of-hooks
ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history}>
<LocaleContainer>
<ConfigProvider prefixCls="panda-console-base">
<ErrorBoundary>
<Container>
<App />
</Container>
</ErrorBoundary>
</ConfigProvider>
</LocaleContainer>
</ConnectedRouter>
</Provider>,
MOUNT_NODE,
);
};
// updateTheme('#ff9600');
const loader = (appContent, loading) => render({ appContent, loading });
export default loader;
\ No newline at end of file
import { history } from '@wisdom-utils/runtime';
import Immutable from 'immutable';
const initialState = Immutable.Map();
import configureStore from './configureStore';
const store = configureStore(initialState, history);
export default store;
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