diff --git a/src/assets/api.js b/src/assets/api.js index bb7628ac..9977dd46 100644 --- a/src/assets/api.js +++ b/src/assets/api.js @@ -185,12 +185,12 @@ const getData = (method, url, params, responseType) => { }; const req = (method, url, params, responseType) => { + const token = `Bearer ${sessionStorage.getItem('authorization')}`; var obj = null; if (method == 'get') { obj = { headers: new Headers({ - authorization: sessionStorage.getItem('authorization') - // Version: Version, + authorization: token }) }; if (params) { @@ -206,23 +206,12 @@ const req = (method, url, params, responseType) => { } } } - if (method === 'unified') { - const token = sessionStorage.getItem('unified-token'); - obj = { - method: 'get', - headers: { - Authorization: `Bearer ${token}` - } - }; - } - if (method == 'login') { obj = { method: 'post', body: JSON.stringify(params), headers: new Headers({ 'Content-Type': 'application/json' - // Version: Version, }) }; } @@ -233,8 +222,7 @@ const req = (method, url, params, responseType) => { body: JSON.stringify(params), headers: new Headers({ 'Content-Type': 'application/json', - authorization: sessionStorage.getItem('authorization') - // Version: Version, + authorization: token }) }; } @@ -274,53 +262,12 @@ const req = (method, url, params, responseType) => { .catch((error) => console.error('Error:', error)); }; -const getCodesHttp = (url) => { - var obj = null; - const token = sessionStorage.getItem('unified-token'); - obj = { - method: 'get', - headers: { - Authorization: `Bearer ${token}` - } - }; - - let http = fetch(url, obj).then((res) => { - window.timeshow = res.headers.get('Date-Time'); - if (res.status == 200) { - return res.text(); - } else { - switch (res.status) { - case 401: - res - .json() - .then((response) => { - if (response.code == 401) { - Notify.clear(); - Notify.error(response.message); - setTimeout(() => { - window.location.href = '/'; - }, 2000); - } - }) - .catch(); - break; - default: - return; - } - } - }); - return http - .then((response) => response) - .catch((error) => console.error('Error:', error)); -}; - export const handelResponse = (res, cb, errCb) => { if (res && res.code == 200) { cb(res.data, res.message); } else { if (res && typeof errCb == 'function') { Notify.clear(); - // Notify.error(res.message); errCb(res.message); } } @@ -760,7 +707,7 @@ export const postLoginStandby = (data) => { //获取权限codes export const getCodes = () => { - return getCodesHttp(`${ApiUrl}/v1/menu/myCodes?systemId=2`); + return req('get', `${ApiUrl}/v1/menu/myCodes?systemId=2`); }; // logout退出登录 diff --git a/src/pages/login/login.js b/src/pages/login/login.js index ed3d1e34..bc1a2703 100644 --- a/src/pages/login/login.js +++ b/src/pages/login/login.js @@ -36,9 +36,9 @@ export default class App extends Component { /* 跳转统一登录平台 */ toUnifiedLogin() { setTimeout(() => { - window.location.href = `${ - window.unifiedUrl - }#/login?url=${encodeURIComponent(window.location.href)}`; + window.location.href = `${window.unifiedUrl}?url=${encodeURIComponent( + window.location.href + )}`; }, 1500); } @@ -59,10 +59,7 @@ export default class App extends Component { handelResponse( res, (response, msg) => { - sessionStorage.setItem('authorization', response.authorization); - - /* 统一登录得token */ - sessionStorage.setItem('unified-token', authorization); + sessionStorage.setItem('authorization', authorization); getAllEnum().then((res) => { handelResponse(res, (response, msg) => { sessionStorage.setItem('enmu', JSON.stringify(response)); @@ -70,8 +67,7 @@ export default class App extends Component { }); /* 获取codes */ - getCodes().then((data) => { - const { codes } = JSON.parse(data); + getCodes().then(({ codes }) => { let menuList = getMenus(codes); Notify.clear();