fix(reqeust,func): zhst/request 修改重新登录问题,zhst/func 添加指定路由跳转方法
This commit is contained in:
parent
3b9d13d9b9
commit
b2dbace653
@ -1,5 +1,14 @@
|
|||||||
# @zhst/biz
|
# @zhst/biz
|
||||||
|
|
||||||
|
## 0.22.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @zhst/func@0.16.0
|
||||||
|
- @zhst/hooks@0.13.1
|
||||||
|
- @zhst/meta@0.21.2
|
||||||
|
|
||||||
## 0.22.1
|
## 0.22.1
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@zhst/biz",
|
"name": "@zhst/biz",
|
||||||
"version": "0.22.1",
|
"version": "0.22.2",
|
||||||
"description": "业务库",
|
"description": "业务库",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"business",
|
"business",
|
||||||
|
@ -1,5 +1,16 @@
|
|||||||
# @zhst/utils
|
# @zhst/utils
|
||||||
|
|
||||||
|
## 0.16.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- zhst/request 修改重新登录问题,zhst/func 添加指定路由跳转方法
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @zhst/request@0.16.0
|
||||||
|
|
||||||
## 0.15.0
|
## 0.15.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@zhst/func",
|
"name": "@zhst/func",
|
||||||
"version": "0.15.0",
|
"version": "0.16.0",
|
||||||
"description": "函数合集",
|
"description": "函数合集",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"hooks"
|
"hooks"
|
||||||
|
@ -90,3 +90,19 @@ export const pxToRem = (value: string, rootFontSize?: number) => {
|
|||||||
|
|
||||||
return valueArr.filter(o => o).map(val => ((parseFloat(val) / fontSize) + 'rem')).join(' ')
|
return valueArr.filter(o => o).map(val => ((parseFloat(val) / fontSize) + 'rem')).join(' ')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 跳转到指定URL
|
||||||
|
* @param to 跳转的url
|
||||||
|
* @returns URL
|
||||||
|
*/
|
||||||
|
export const jumpTo = (to: string) => {
|
||||||
|
const from = (location.origin + location.pathname)
|
||||||
|
// 检查是否为url,并且跑出错误
|
||||||
|
if (!isUrl(to)) {
|
||||||
|
throw Error(`请输入正确的链接,以http(s)://开头!'`)
|
||||||
|
}
|
||||||
|
let _targetUrl = new URL(to)
|
||||||
|
_targetUrl.searchParams.set('from', from)
|
||||||
|
return _targetUrl
|
||||||
|
}
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
# @zhst/hooks
|
# @zhst/hooks
|
||||||
|
|
||||||
|
## 0.13.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @zhst/func@0.16.0
|
||||||
|
|
||||||
## 0.13.0
|
## 0.13.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@zhst/hooks",
|
"name": "@zhst/hooks",
|
||||||
"version": "0.13.0",
|
"version": "0.13.1",
|
||||||
"description": "hooks合集",
|
"description": "hooks合集",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"hooks"
|
"hooks"
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
# @zhst/material
|
# @zhst/material
|
||||||
|
|
||||||
|
## 0.18.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @zhst/func@0.16.0
|
||||||
|
- @zhst/biz@0.22.2
|
||||||
|
- @zhst/hooks@0.13.1
|
||||||
|
- @zhst/meta@0.21.2
|
||||||
|
|
||||||
## 0.18.1
|
## 0.18.1
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@zhst/material",
|
"name": "@zhst/material",
|
||||||
"version": "0.18.1",
|
"version": "0.18.2",
|
||||||
"description": "物料库",
|
"description": "物料库",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"business",
|
"business",
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
# @zhst/utils
|
# @zhst/utils
|
||||||
|
|
||||||
|
## 0.21.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @zhst/func@0.16.0
|
||||||
|
- @zhst/hooks@0.13.1
|
||||||
|
- @zhst/meta@0.21.2
|
||||||
|
|
||||||
## 0.21.1
|
## 0.21.1
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@zhst/meta",
|
"name": "@zhst/meta",
|
||||||
"version": "0.21.1",
|
"version": "0.21.2",
|
||||||
"description": "原子组件",
|
"description": "原子组件",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"meta",
|
"meta",
|
||||||
|
@ -1,5 +1,16 @@
|
|||||||
# @zhst/request
|
# @zhst/request
|
||||||
|
|
||||||
|
## 0.16.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- zhst/request 修改重新登录问题,zhst/func 添加指定路由跳转方法
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @zhst/func@0.16.0
|
||||||
|
|
||||||
## 0.15.0
|
## 0.15.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@zhst/request",
|
"name": "@zhst/request",
|
||||||
"version": "0.15.0",
|
"version": "0.16.0",
|
||||||
"description": "请求库",
|
"description": "请求库",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"request",
|
"request",
|
||||||
|
0
packages/request/src/demo/index.tsx
Normal file
0
packages/request/src/demo/index.tsx
Normal file
@ -15,6 +15,11 @@ export interface ReqConfigProps {
|
|||||||
*/
|
*/
|
||||||
authorization?: string
|
authorization?: string
|
||||||
showMsg?: boolean
|
showMsg?: boolean
|
||||||
|
/**
|
||||||
|
* 过期信息捕捉
|
||||||
|
* @param error
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
onExpired?: (error?: any) => void;
|
onExpired?: (error?: any) => void;
|
||||||
expiredCodes?: number[];
|
expiredCodes?: number[];
|
||||||
/**
|
/**
|
||||||
@ -38,17 +43,42 @@ export const reqConfig = (config: ReqConfigProps) => {
|
|||||||
timeout: 1000,
|
timeout: 1000,
|
||||||
baseURL: location.origin,
|
baseURL: location.origin,
|
||||||
errorConfig: {
|
errorConfig: {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
errorHandler(error) {
|
errorHandler(response) {
|
||||||
// const { status } = error?.request || {}
|
const { code, message: resMessage } = response?.data || {}
|
||||||
onError?.(error)
|
let msg = resMessage || '请求失败!'
|
||||||
message.error('网络异常')
|
|
||||||
},
|
if (response.status !== 200) {
|
||||||
// @ts-ignore
|
// 服务器错误
|
||||||
errorThrower(res) {
|
msg = '网络异常'
|
||||||
console.log('报错啦:', res);
|
onError?.(response)
|
||||||
},
|
} else if (expiredCodes.includes(code)) {
|
||||||
|
// 登录失效
|
||||||
|
msg = '登录过期,请重新登录'
|
||||||
|
onExpired?.(response)
|
||||||
|
}
|
||||||
|
showMsg && message.error(msg)
|
||||||
},
|
},
|
||||||
|
// @ts-ignore
|
||||||
|
errorThrower(res) {
|
||||||
|
console.log('报错啦:', res);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
// @ts-ignore
|
||||||
|
responseInterceptors: [
|
||||||
|
// 一个二元组,第一个元素是 request 拦截器,第二个元素是错误处理
|
||||||
|
[
|
||||||
|
(response: { status: number; data: any; }) => {
|
||||||
|
const { code, data = {} } = response?.data || {}
|
||||||
|
|
||||||
|
if (code !== 200) {
|
||||||
|
// 报错捕捉
|
||||||
|
return Promise.reject(response)
|
||||||
|
}
|
||||||
|
return response?.data || {};
|
||||||
|
}
|
||||||
|
],
|
||||||
|
],
|
||||||
// 请求
|
// 请求
|
||||||
requestInterceptors: [
|
requestInterceptors: [
|
||||||
// 一个二元组,第一个元素是 request 拦截器,第二个元素是错误处理
|
// 一个二元组,第一个元素是 request 拦截器,第二个元素是错误处理
|
||||||
@ -71,35 +101,6 @@ export const reqConfig = (config: ReqConfigProps) => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
// 返回
|
|
||||||
responseInterceptors: [
|
|
||||||
// 一个二元组,第一个元素是 request 拦截器,第二个元素是错误处理
|
|
||||||
[
|
|
||||||
(response: { status: number; data: any; }) => {
|
|
||||||
const { code } = response?.data || {}
|
|
||||||
|
|
||||||
if (expiredCodes.includes(code)) {
|
|
||||||
message.error('登录过期,请重新登录')
|
|
||||||
onExpired?.(response?.data)
|
|
||||||
return {}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (showMsg && code !== 200) {
|
|
||||||
message.error(response.data?.message || '请求失败!')
|
|
||||||
return {}
|
|
||||||
}
|
|
||||||
return response.data || {};
|
|
||||||
},
|
|
||||||
(error: any) => {
|
|
||||||
const { code } = error.response?.data || {}
|
|
||||||
|
|
||||||
if (showMsg && code !== 200) {
|
|
||||||
message.error(error.response.data.message || '请求失败!')
|
|
||||||
}
|
|
||||||
return Promise.reject(error.response);
|
|
||||||
},
|
|
||||||
],
|
|
||||||
],
|
|
||||||
...config
|
...config
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
# @zhst/slave
|
# @zhst/slave
|
||||||
|
|
||||||
|
## 0.11.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- Updated dependencies
|
||||||
|
- @zhst/func@0.16.0
|
||||||
|
|
||||||
## 0.11.0
|
## 0.11.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@zhst/slave",
|
"name": "@zhst/slave",
|
||||||
"version": "0.11.0",
|
"version": "0.11.1",
|
||||||
"description": "微前端子应用方法库",
|
"description": "微前端子应用方法库",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"slave",
|
"slave",
|
||||||
|
Loading…
Reference in New Issue
Block a user