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

fix: 优化token过期退出登陆

parent 87a06f9e
Pipeline #39262 passed with stages
in 14 minutes 27 seconds
import { Modal, notification } from 'antd'; import { Modal, notification } from 'antd';
import { instanceRequest, service } from '@wisdom-utils/utils'; import { instanceRequest, service } from '@wisdom-utils/utils';
import { event } from 'microser-data';
import { actionCreators } from '../containers/App/store';
import AppService from './service/base'; import AppService from './service/base';
import notificationService from './service/notification'; import notificationService from './service/notification';
const { warning } = Modal; const { warning } = Modal;
...@@ -13,7 +14,7 @@ instanceRequest.transformRequestURL = function(url) { ...@@ -13,7 +14,7 @@ instanceRequest.transformRequestURL = function(url) {
return url; return url;
} }
if (window.globalConfig && window.globalConfig.hasGateWay && /^\/(cityinterface|CityInterface|CityServer|PandaInformatization)/.test(url)) { if (window.globalConfig && window.globalConfig.hasGateWay && /^\/(cityinterface|CityInterface|Cityinterface|CityServer|PandaInformatization)/.test(url)) {
return /\/CityInterface\/rest\/services.svc\/GetConfig/.test(url) ? url ? /^\/GateWay/.test(url) ? url : '/GateWay' + url: '/GateWay' + url: '/GateWay' + url; return /\/CityInterface\/rest\/services.svc\/GetConfig/.test(url) ? url ? /^\/GateWay/.test(url) ? url : '/GateWay' + url: '/GateWay' + url: '/GateWay' + url;
} }
return url; return url;
...@@ -49,10 +50,8 @@ instanceRequest.setErrorHandler(error => { ...@@ -49,10 +50,8 @@ instanceRequest.setErrorHandler(error => {
content: `${codeMessage[status]}`, content: `${codeMessage[status]}`,
centered: true, centered: true,
onOk(close) { onOk(close) {
window.share && event.emit('event:logout');
window.share.event && close();
window.share.event.emit('triggerLoginout');
close();
}, },
}); });
} }
...@@ -71,8 +70,6 @@ instanceRequest.setErrorHandler(error => { ...@@ -71,8 +70,6 @@ instanceRequest.setErrorHandler(error => {
} }
return response; return response;
}); });
console.log("instanceRequest", instanceRequest)
const appService = service(AppService); const appService = service(AppService);
const noticeService = service(notificationService); const noticeService = service(notificationService);
export { appService, noticeService }; export { appService, noticeService };
...@@ -21,10 +21,6 @@ import { params, Storeage } from 'kit_utils'; ...@@ -21,10 +21,6 @@ import { params, Storeage } from 'kit_utils';
import { Provider } from 'react-redux'; import { Provider } from 'react-redux';
import { history } from '@wisdom-utils/runtime'; import { history } from '@wisdom-utils/runtime';
import ErrorBoundary from './components/ErrorBoundary'; import ErrorBoundary from './components/ErrorBoundary';
import { useIntl } from '@/locales/localeExports';
// import { ErrorBoundary } from '@ant-design/pro-utils';
import defaultSettings from '../config/defaultSetting';
// import themePluginConfig from '../config/themePluginConfig'; // import themePluginConfig from '../config/themePluginConfig';
import { appService } from './api'; import { appService } from './api';
import { updateTheme } from './common/helpers/settingColor'; import { updateTheme } from './common/helpers/settingColor';
...@@ -38,8 +34,6 @@ import Login from './pages/user/login/login'; ...@@ -38,8 +34,6 @@ import Login from './pages/user/login/login';
import { getToken, isString } from './utils/utils'; import { getToken, isString } from './utils/utils';
import './utils/event'; import './utils/event';
import Cookies from 'js-cookie'; import Cookies from 'js-cookie';
const isHttps = document.location.protocol === 'https:';
const { pwa } = defaultSettings;
// 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);
...@@ -232,77 +226,9 @@ initLocale(); ...@@ -232,77 +226,9 @@ initLocale();
window.share && window.share.event && window.share.event.on('triggerMicro', () => { window.share && window.share.event && window.share.event.on('triggerMicro', () => {
initMicroApps(loader, store); initMicroApps(loader, store);
}); });
event.on('initConfig', () => { event.on('event:initConfig', () => {
initGlobalConfig(); initGlobalConfig();
}); });
event.on('event:logout', () => {
if (pwa) { store.dispatch(actionCreators.logout())
// const appPWA = window.i18n.getI18n('app'); });
window.addEventListener('sw.offline', () => {
message.warning(useIntl().formatMessage({ id: 'app.pwa.offline' }));
});
window.addEventListener('sw.updated', event => {
const e = event;
const reloadSW = async () => {
const worker = e.detail && e.detail.waiting;
if (!worker) {
return true;
}
await new Promise((resolve, reject) => {
const channel = new MessageChannel();
channel.port1.onmessage = msgEvent => {
if (msgEvent.data.error) {
reject(msgEvent.data.error);
} else {
resolve(msgEvent.data);
}
};
worker.postMessage({ type: 'skip-waiting' }, [channel.port2]);
});
window.location.reload(true);
return true;
};
const key = `open${Date.now()}`;
const btn = (
<Button
type="primary"
onClick={() => {
notification.close(key);
reloadSW();
}}
>
{useIntl().formatMessage({ id: 'app.pwa.serviceworker.updated.ok' })}
</Button>
);
notification.open({
message: useIntl().formatMessage({ id: 'pwa.serviceworker.updated' }),
description: useIntl().formatMessage({
id: 'pwa.serviceworker.updated.hint',
}),
btn,
key,
onClose: async () => null,
});
});
} else if ('serviceWorker' in navigator && isHttps) {
const { serviceWorker } = navigator;
if (serviceWorker.getRegistrations) {
serviceWorker.getRegistrations().then(sws => {
sws.forEach(sw => {
sw.unregister();
});
});
}
serviceWorker.getRegistration().then(sw => {
if (sw) sw.unregister();
});
if (window.caches && window.caches.keys) {
caches.keys().then(keys => {
keys.forEach(key => {
caches.delete(key);
});
});
}
}
...@@ -204,7 +204,7 @@ export function logout(data) { ...@@ -204,7 +204,7 @@ export function logout(data) {
localStorage.removeItem('access_token'); localStorage.removeItem('access_token');
// eslint-disable-next-line no-undef,no-restricted-globals // eslint-disable-next-line no-undef,no-restricted-globals
createStoreage.remove(`__PANDA_STORE__${location.hostname}`); createStoreage.remove(`__PANDA_STORE__${location.hostname}`);
event.emit('initConfig'); event.emit('event:initConfig');
return { return {
type: LOGINOUT, type: LOGINOUT,
data: { data: {
......
...@@ -6,7 +6,7 @@ import InfoLogin from './template/infoLogin'; ...@@ -6,7 +6,7 @@ import InfoLogin from './template/infoLogin';
import Yulin from './template/yulin'; import Yulin from './template/yulin';
/* eslint-disable */ /* eslint-disable */
export default () => { export default () => {
debugger
const loginTemplate = window.globalConfig && window.globalConfig.loginTemplate; const loginTemplate = window.globalConfig && window.globalConfig.loginTemplate;
switch(loginTemplate) { switch(loginTemplate) {
case '新春 - 智联.html': case '新春 - 智联.html':
......
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