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 { instanceRequest, service } from '@wisdom-utils/utils';
import { event } from 'microser-data';
import { actionCreators } from '../containers/App/store';
import AppService from './service/base';
import notificationService from './service/notification';
const { warning } = Modal;
......@@ -13,7 +14,7 @@ instanceRequest.transformRequestURL = function(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 url;
......@@ -49,10 +50,8 @@ instanceRequest.setErrorHandler(error => {
content: `${codeMessage[status]}`,
centered: true,
onOk(close) {
window.share &&
window.share.event &&
window.share.event.emit('triggerLoginout');
close();
event.emit('event:logout');
close();
},
});
}
......@@ -71,8 +70,6 @@ instanceRequest.setErrorHandler(error => {
}
return response;
});
console.log("instanceRequest", instanceRequest)
const appService = service(AppService);
const noticeService = service(notificationService);
export { appService, noticeService };
......@@ -21,10 +21,6 @@ import { params, Storeage } from 'kit_utils';
import { Provider } from 'react-redux';
import { history } from '@wisdom-utils/runtime';
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 { appService } from './api';
import { updateTheme } from './common/helpers/settingColor';
......@@ -38,8 +34,6 @@ import Login from './pages/user/login/login';
import { getToken, isString } from './utils/utils';
import './utils/event';
import Cookies from 'js-cookie';
const isHttps = document.location.protocol === 'https:';
const { pwa } = defaultSettings;
// eslint-disable-next-line no-restricted-globals
const namespace = `__PANDA_STORE__${location.hostname}`;
window.createStoreage = new Storeage(namespace);
......@@ -232,77 +226,9 @@ initLocale();
window.share && window.share.event && window.share.event.on('triggerMicro', () => {
initMicroApps(loader, store);
});
event.on('initConfig', () => {
event.on('event:initConfig', () => {
initGlobalConfig();
});
if (pwa) {
// 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);
});
});
}
}
event.on('event:logout', () => {
store.dispatch(actionCreators.logout())
});
......@@ -204,7 +204,7 @@ export function logout(data) {
localStorage.removeItem('access_token');
// eslint-disable-next-line no-undef,no-restricted-globals
createStoreage.remove(`__PANDA_STORE__${location.hostname}`);
event.emit('initConfig');
event.emit('event:initConfig');
return {
type: LOGINOUT,
data: {
......
......@@ -6,7 +6,7 @@ import InfoLogin from './template/infoLogin';
import Yulin from './template/yulin';
/* eslint-disable */
export default () => {
debugger
const loginTemplate = window.globalConfig && window.globalConfig.loginTemplate;
switch(loginTemplate) {
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