fix: zhst/slave 修改logOut方法
This commit is contained in:
parent
3f92df816c
commit
5f2873c152
@ -12,8 +12,4 @@
|
|||||||
&-btns-divider {
|
&-btns-divider {
|
||||||
margin: 8px 0;
|
margin: 8px 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
&-create-modal {
|
|
||||||
// width: 600px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,16 @@
|
|||||||
# @zhst/utils
|
# @zhst/utils
|
||||||
|
|
||||||
|
## 0.14.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- feat: 重新发版
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @zhst/request@0.14.0
|
||||||
|
|
||||||
## 0.13.0
|
## 0.13.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@zhst/func",
|
"name": "@zhst/func",
|
||||||
"version": "0.13.0",
|
"version": "0.14.0",
|
||||||
"description": "函数合集",
|
"description": "函数合集",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"hooks"
|
"hooks"
|
||||||
|
@ -1,5 +1,16 @@
|
|||||||
# @zhst/hooks
|
# @zhst/hooks
|
||||||
|
|
||||||
|
## 0.12.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- feat: 重新发版
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @zhst/func@0.14.0
|
||||||
|
|
||||||
## 0.11.0
|
## 0.11.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@zhst/hooks",
|
"name": "@zhst/hooks",
|
||||||
"version": "0.11.0",
|
"version": "0.12.0",
|
||||||
"description": "hooks合集",
|
"description": "hooks合集",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"hooks"
|
"hooks"
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
# @zhst/icon
|
# @zhst/icon
|
||||||
|
|
||||||
|
## 0.4.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- feat: 重新发版
|
||||||
|
|
||||||
## 0.3.0
|
## 0.3.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@zhst/icon",
|
"name": "@zhst/icon",
|
||||||
"version": "0.3.0",
|
"version": "0.4.0",
|
||||||
"description": "图标库",
|
"description": "图标库",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"icon",
|
"icon",
|
||||||
|
@ -5,7 +5,10 @@
|
|||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|
||||||
- Updated dependencies
|
- Updated dependencies
|
||||||
- @zhst/biz@0.19.1
|
- @zhst/hooks@0.12.0
|
||||||
|
- @zhst/func@0.14.0
|
||||||
|
- @zhst/meta@0.18.0
|
||||||
|
- @zhst/biz@0.20.0
|
||||||
|
|
||||||
## 0.14.0
|
## 0.14.0
|
||||||
|
|
||||||
|
@ -1,5 +1,19 @@
|
|||||||
# @zhst/utils
|
# @zhst/utils
|
||||||
|
|
||||||
|
## 0.18.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- feat: 重新发版
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @zhst/hooks@0.12.0
|
||||||
|
- @zhst/func@0.14.0
|
||||||
|
- @zhst/icon@0.4.0
|
||||||
|
- @zhst/meta@0.18.0
|
||||||
|
|
||||||
## 0.17.0
|
## 0.17.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@zhst/meta",
|
"name": "@zhst/meta",
|
||||||
"version": "0.17.0",
|
"version": "0.18.0",
|
||||||
"description": "原子组件",
|
"description": "原子组件",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"meta",
|
"meta",
|
||||||
|
@ -1,5 +1,16 @@
|
|||||||
# @zhst/request
|
# @zhst/request
|
||||||
|
|
||||||
|
## 0.14.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- feat: 重新发版
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @zhst/func@0.14.0
|
||||||
|
|
||||||
## 0.13.0
|
## 0.13.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
@ -10,7 +10,10 @@ export var reqConfig = function reqConfig(config) {
|
|||||||
authorization = _ref.authorization,
|
authorization = _ref.authorization,
|
||||||
_ref$showMsg = _ref.showMsg,
|
_ref$showMsg = _ref.showMsg,
|
||||||
showMsg = _ref$showMsg === void 0 ? true : _ref$showMsg,
|
showMsg = _ref$showMsg === void 0 ? true : _ref$showMsg,
|
||||||
onError = _ref.onError;
|
onError = _ref.onError,
|
||||||
|
onExpired = _ref.onExpired,
|
||||||
|
_ref$expiredCodes = _ref.expiredCodes,
|
||||||
|
expiredCodes = _ref$expiredCodes === void 0 ? [403, 401, 203] : _ref$expiredCodes;
|
||||||
return _objectSpread({
|
return _objectSpread({
|
||||||
timeout: 1000,
|
timeout: 1000,
|
||||||
baseURL: location.origin,
|
baseURL: location.origin,
|
||||||
@ -46,14 +49,11 @@ export var reqConfig = function reqConfig(config) {
|
|||||||
responseInterceptors: [
|
responseInterceptors: [
|
||||||
// 一个二元组,第一个元素是 request 拦截器,第二个元素是错误处理
|
// 一个二元组,第一个元素是 request 拦截器,第二个元素是错误处理
|
||||||
[function (response) {
|
[function (response) {
|
||||||
// if (response.status !== 200) {
|
|
||||||
// throw Error(JSON.stringify(response.data));
|
|
||||||
// }
|
|
||||||
var _ref2 = (response === null || response === void 0 ? void 0 : response.data) || {},
|
var _ref2 = (response === null || response === void 0 ? void 0 : response.data) || {},
|
||||||
code = _ref2.code;
|
code = _ref2.code;
|
||||||
if ([403, 401, 203].includes(code)) {
|
if (expiredCodes.includes(code)) {
|
||||||
message.error('登录过期,请重新登录');
|
message.error('登录过期,请重新登录');
|
||||||
onError === null || onError === void 0 || onError(response === null || response === void 0 ? void 0 : response.data);
|
onExpired === null || onExpired === void 0 || onExpired(response === null || response === void 0 ? void 0 : response.data);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
if (showMsg && code !== 200) {
|
if (showMsg && code !== 200) {
|
||||||
|
@ -27,7 +27,9 @@ var reqConfig = (config) => {
|
|||||||
const {
|
const {
|
||||||
authorization,
|
authorization,
|
||||||
showMsg = true,
|
showMsg = true,
|
||||||
onError
|
onError,
|
||||||
|
onExpired,
|
||||||
|
expiredCodes = [403, 401, 203]
|
||||||
} = config || {};
|
} = config || {};
|
||||||
return {
|
return {
|
||||||
timeout: 1e3,
|
timeout: 1e3,
|
||||||
@ -71,9 +73,9 @@ var reqConfig = (config) => {
|
|||||||
(response) => {
|
(response) => {
|
||||||
var _a;
|
var _a;
|
||||||
const { code } = (response == null ? void 0 : response.data) || {};
|
const { code } = (response == null ? void 0 : response.data) || {};
|
||||||
if ([403, 401, 203].includes(code)) {
|
if (expiredCodes.includes(code)) {
|
||||||
import_antd.message.error("登录过期,请重新登录");
|
import_antd.message.error("登录过期,请重新登录");
|
||||||
onError == null ? void 0 : onError(response == null ? void 0 : response.data);
|
onExpired == null ? void 0 : onExpired(response == null ? void 0 : response.data);
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
if (showMsg && code !== 200) {
|
if (showMsg && code !== 200) {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@zhst/request",
|
"name": "@zhst/request",
|
||||||
"version": "0.13.0",
|
"version": "0.14.0",
|
||||||
"description": "请求库",
|
"description": "请求库",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"request",
|
"request",
|
||||||
|
@ -15,6 +15,8 @@ export interface ReqConfigProps {
|
|||||||
*/
|
*/
|
||||||
authorization?: string
|
authorization?: string
|
||||||
showMsg?: boolean
|
showMsg?: boolean
|
||||||
|
onExpired?: (error?: any) => void;
|
||||||
|
expiredCodes?: number[];
|
||||||
/**
|
/**
|
||||||
* 报错捕捉
|
* 报错捕捉
|
||||||
* @param error 报错信息
|
* @param error 报错信息
|
||||||
@ -28,6 +30,8 @@ export const reqConfig = (config: ReqConfigProps) => {
|
|||||||
authorization,
|
authorization,
|
||||||
showMsg = true,
|
showMsg = true,
|
||||||
onError,
|
onError,
|
||||||
|
onExpired,
|
||||||
|
expiredCodes = [403, 401, 203]
|
||||||
} = config || {}
|
} = config || {}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -72,14 +76,11 @@ export const reqConfig = (config: ReqConfigProps) => {
|
|||||||
// 一个二元组,第一个元素是 request 拦截器,第二个元素是错误处理
|
// 一个二元组,第一个元素是 request 拦截器,第二个元素是错误处理
|
||||||
[
|
[
|
||||||
(response: { status: number; data: any; }) => {
|
(response: { status: number; data: any; }) => {
|
||||||
// if (response.status !== 200) {
|
|
||||||
// throw Error(JSON.stringify(response.data));
|
|
||||||
// }
|
|
||||||
const { code } = response?.data || {}
|
const { code } = response?.data || {}
|
||||||
|
|
||||||
if ([403,401, 203].includes(code)) {
|
if (expiredCodes.includes(code)) {
|
||||||
message.error('登录过期,请重新登录')
|
message.error('登录过期,请重新登录')
|
||||||
onError?.(response?.data)
|
onExpired?.(response?.data)
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,22 @@
|
|||||||
# @zhst/slave
|
# @zhst/slave
|
||||||
|
|
||||||
|
## 0.10.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- feat: 修改 logOut 事件
|
||||||
|
|
||||||
|
## 0.9.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- feat: 重新发版
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @zhst/func@0.14.0
|
||||||
|
|
||||||
## 0.8.0
|
## 0.8.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
@ -27,6 +27,7 @@ var Slave = /*#__PURE__*/function () {
|
|||||||
while (1) switch (_context.prev = _context.next) {
|
while (1) switch (_context.prev = _context.next) {
|
||||||
case 0:
|
case 0:
|
||||||
_opt$jumpToLogin = opt.jumpToLogin, jumpToLogin = _opt$jumpToLogin === void 0 ? true : _opt$jumpToLogin, jumpUrl = opt.jumpUrl, tokenKey = opt.tokenKey, _opt$showMsg = opt.showMsg, showMsg = _opt$showMsg === void 0 ? true : _opt$showMsg, msgText = opt.msgText, from = opt.from, to = opt.to;
|
_opt$jumpToLogin = opt.jumpToLogin, jumpToLogin = _opt$jumpToLogin === void 0 ? true : _opt$jumpToLogin, jumpUrl = opt.jumpUrl, tokenKey = opt.tokenKey, _opt$showMsg = opt.showMsg, showMsg = _opt$showMsg === void 0 ? true : _opt$showMsg, msgText = opt.msgText, from = opt.from, to = opt.to;
|
||||||
|
this.config = opt;
|
||||||
this.checkUrl(jumpUrl, 'jumpUrl');
|
this.checkUrl(jumpUrl, 'jumpUrl');
|
||||||
// 当前链接
|
// 当前链接
|
||||||
currentUrl = new URL(location.href); // 当前待跳转链接
|
currentUrl = new URL(location.href); // 当前待跳转链接
|
||||||
@ -58,7 +59,7 @@ var Slave = /*#__PURE__*/function () {
|
|||||||
location.href = currentJumpUrl.href;
|
location.href = currentJumpUrl.href;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 10:
|
case 11:
|
||||||
case "end":
|
case "end":
|
||||||
return _context.stop();
|
return _context.stop();
|
||||||
}
|
}
|
||||||
@ -113,14 +114,29 @@ var Slave = /*#__PURE__*/function () {
|
|||||||
// 退出登录
|
// 退出登录
|
||||||
}, {
|
}, {
|
||||||
key: "logOut",
|
key: "logOut",
|
||||||
value: function logOut() {
|
value: function logOut(jumpUrl, config) {
|
||||||
this.removeToken();
|
this.removeToken();
|
||||||
location.replace(location.origin + location.pathname);
|
var _ref = config || this.config || {},
|
||||||
|
from = _ref.from,
|
||||||
|
to = _ref.to;
|
||||||
|
var targetUrl = new URL(jumpUrl);
|
||||||
|
this._setUrlKey({
|
||||||
|
targetKey: 'from',
|
||||||
|
targetUrl: from,
|
||||||
|
jumpUrl: targetUrl
|
||||||
|
});
|
||||||
|
this._setUrlKey({
|
||||||
|
targetKey: 'to',
|
||||||
|
targetUrl: to,
|
||||||
|
jumpUrl: targetUrl
|
||||||
|
});
|
||||||
|
location.href = targetUrl.href;
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: "setToken",
|
key: "setToken",
|
||||||
value: function setToken(val) {
|
value: function setToken(val) {
|
||||||
var tokenKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.authTokenDefine;
|
var tokenKey = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this.authTokenDefine;
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
||||||
val && localStorage.setItem(tokenKey, val);
|
val && localStorage.setItem(tokenKey, val);
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
|
@ -40,6 +40,7 @@ var Slave = class {
|
|||||||
to
|
to
|
||||||
// force
|
// force
|
||||||
} = opt;
|
} = opt;
|
||||||
|
this.config = opt;
|
||||||
this.checkUrl(jumpUrl, "jumpUrl");
|
this.checkUrl(jumpUrl, "jumpUrl");
|
||||||
let currentUrl = new URL(location.href);
|
let currentUrl = new URL(location.href);
|
||||||
let currentJumpUrl = new URL(jumpUrl);
|
let currentJumpUrl = new URL(jumpUrl);
|
||||||
@ -100,9 +101,21 @@ var Slave = class {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 退出登录
|
// 退出登录
|
||||||
logOut() {
|
logOut(jumpUrl, config) {
|
||||||
this.removeToken();
|
this.removeToken();
|
||||||
location.replace(location.origin + location.pathname);
|
const { from, to } = config || this.config || {};
|
||||||
|
const targetUrl = new URL(jumpUrl);
|
||||||
|
this._setUrlKey({
|
||||||
|
targetKey: "from",
|
||||||
|
targetUrl: from,
|
||||||
|
jumpUrl: targetUrl
|
||||||
|
});
|
||||||
|
this._setUrlKey({
|
||||||
|
targetKey: "to",
|
||||||
|
targetUrl: to,
|
||||||
|
jumpUrl: targetUrl
|
||||||
|
});
|
||||||
|
location.href = targetUrl.href;
|
||||||
}
|
}
|
||||||
setToken(val, tokenKey = this.authTokenDefine) {
|
setToken(val, tokenKey = this.authTokenDefine) {
|
||||||
val && localStorage.setItem(tokenKey, val);
|
val && localStorage.setItem(tokenKey, val);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@zhst/slave",
|
"name": "@zhst/slave",
|
||||||
"version": "0.8.0",
|
"version": "0.10.0",
|
||||||
"description": "微前端子应用方法库",
|
"description": "微前端子应用方法库",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"slave",
|
"slave",
|
||||||
|
@ -42,6 +42,7 @@ class Slave {
|
|||||||
to,
|
to,
|
||||||
// force
|
// force
|
||||||
} = opt
|
} = opt
|
||||||
|
this.config = opt
|
||||||
this.checkUrl(jumpUrl, 'jumpUrl')
|
this.checkUrl(jumpUrl, 'jumpUrl')
|
||||||
// 当前链接
|
// 当前链接
|
||||||
let currentUrl = new URL(location.href)
|
let currentUrl = new URL(location.href)
|
||||||
@ -117,12 +118,26 @@ class Slave {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 退出登录
|
// 退出登录
|
||||||
public logOut() {
|
public logOut(jumpUrl: string, config?: ISlaveConfig) {
|
||||||
this.removeToken()
|
this.removeToken()
|
||||||
location.replace(location.origin + location.pathname)
|
const { from, to } = config || this.config || {}
|
||||||
|
const targetUrl = new URL(jumpUrl)
|
||||||
|
|
||||||
|
this._setUrlKey({
|
||||||
|
targetKey: 'from',
|
||||||
|
targetUrl: from,
|
||||||
|
jumpUrl: targetUrl
|
||||||
|
})
|
||||||
|
this._setUrlKey({
|
||||||
|
targetKey: 'to',
|
||||||
|
targetUrl: to,
|
||||||
|
jumpUrl: targetUrl
|
||||||
|
})
|
||||||
|
location.href = targetUrl.href
|
||||||
}
|
}
|
||||||
|
|
||||||
public setToken(val: string | null, tokenKey: string = this.authTokenDefine) {
|
public setToken(val: string | null, tokenKey: string = this.authTokenDefine) {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
|
||||||
val && localStorage.setItem(tokenKey, val)
|
val && localStorage.setItem(tokenKey, val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user