@ali-dayu/yunqiao-umi-request
Version:
封装前端登录鉴权相关逻辑,所有使用方法同umi-request。
33 lines (30 loc) • 1.21 kB
JavaScript
import { __awaiter, __generator } from "tslib";
import umiRequest from 'umi-request';
umiRequest.interceptors.response.use(function (response, options) {
return __awaiter(void 0, void 0, void 0, function () {
var data, code, extInfo, redirectUrl, callbackKey, loginPath;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
return [4
/*yield*/
, response.clone().json()];
case 1:
data = _a.sent();
code = data.code, extInfo = data.extInfo;
if (code === 'ConsoleNeedLogin') {
redirectUrl = extInfo.redirectUrl;
callbackKey = redirectUrl.match(/callbackKey=([^&]+)/)[1];
loginPath = redirectUrl.match(/loginPath=([^&]+)/)[1];
redirectUrl = redirectUrl.split('&callbackKey')[0];
window.location.href = "".concat(redirectUrl).concat(encodeURIComponent(window.location.origin + "".concat(loginPath, "?").concat(callbackKey, "=").concat(encodeURIComponent(window.location.href))));
}
return [2
/*return*/
, response];
}
});
});
});
export { umiRequest as default };
export * from 'umi-request';