Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
monorepo
/
venus
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 2c79ac1e
authored
Jul 11, 2024
by
likui628
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
refactor: small refactor in @vben-core/request
1 parent
d62a3da0
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
13 deletions
apps/web-antd/src/router/guard.ts
packages/@core/forward/request/src/request-client/request-client.ts
packages/@core/forward/request/src/request-client/types.ts
packages/@core/ui-kit/shadcn-ui/src/components/index.ts
apps/web-antd/src/router/guard.ts
View file @
2c79ac1
...
...
@@ -92,10 +92,9 @@ function setupAccessGuard(router: Router) {
// 生成路由表
// 当前登录用户拥有的角色标识列表
let
userRoles
:
string
[]
=
[];
const
userInfo
=
accessStore
.
userInfo
||
(
await
accessStore
.
fetchUserInfo
());
userRoles
=
userInfo
.
roles
??
[];
const
userRoles
=
userInfo
.
roles
??
[];
// 生成菜单和路由
const
{
accessibleMenus
,
accessibleRoutes
}
=
await
generateAccess
({
...
...
packages/@core/forward/request/src/request-client/request-client.ts
View file @
2c79ac1
...
...
@@ -6,7 +6,11 @@ import type {
InternalAxiosRequestConfig
,
}
from
'axios'
;
import
type
{
MakeAuthorizationFn
,
RequestClientOptions
}
from
'./types'
;
import
type
{
MakeAuthorizationFn
,
MakeErrorMessageFn
,
RequestClientOptions
,
}
from
'./types'
;
import
{
$t
}
from
'@vben-core/locales'
;
import
{
merge
}
from
'@vben-core/toolkit'
;
...
...
@@ -20,7 +24,8 @@ import { FileUploader } from './modules/uploader';
class
RequestClient
{
private
instance
:
AxiosInstance
;
private
makeAuthorization
:
MakeAuthorizationFn
|
undefined
;
private
options
:
RequestClientOptions
;
private
makeErrorMessage
:
MakeErrorMessageFn
|
undefined
;
public
addRequestInterceptor
:
InterceptorManager
[
'addRequestInterceptor'
];
public
addResponseInterceptor
:
InterceptorManager
[
'addResponseInterceptor'
];
public
download
:
FileDownloader
[
'download'
];
...
...
@@ -40,12 +45,12 @@ class RequestClient {
// 默认超时时间
timeout
:
10
_000
,
};
const
{
makeAuthorization
,
...
axiosConfig
}
=
options
;
this
.
options
=
options
;
const
{
makeAuthorization
,
makeErrorMessage
,
...
axiosConfig
}
=
options
;
const
requestConfig
=
merge
(
axiosConfig
,
defaultConfig
);
this
.
instance
=
axios
.
create
(
requestConfig
);
this
.
makeAuthorization
=
makeAuthorization
;
this
.
makeErrorMessage
=
makeErrorMessage
;
// 实例化拦截器管理器
const
interceptorManager
=
new
InterceptorManager
(
this
.
instance
);
...
...
@@ -111,9 +116,8 @@ class RequestClient {
}
else
if
(
error
?.
message
?.
includes
?.(
'timeout'
))
{
errMsg
=
$t
(
'fallback.http.requestTimeout'
);
}
const
{
makeAuthorization
,
makeErrorMessage
}
=
this
.
options
;
if
(
errMsg
)
{
makeErrorMessage
?.(
errMsg
);
this
.
makeErrorMessage
?.(
errMsg
);
return
Promise
.
reject
(
error
);
}
...
...
@@ -128,7 +132,7 @@ class RequestClient {
case
401
:
{
errorMessage
=
$t
(
'fallback.http.unauthorized'
);
makeAuthorization
?.().
unAuthorizedHandler
?.();
this
.
makeAuthorization
?.().
unAuthorizedHandler
?.();
break
;
}
case
403
:
{
...
...
@@ -150,7 +154,7 @@ class RequestClient {
}
}
makeErrorMessage
?.(
errorMessage
);
this
.
makeErrorMessage
?.(
errorMessage
);
return
Promise
.
reject
(
error
);
},
);
...
...
packages/@core/forward/request/src/request-client/types.ts
View file @
2c79ac1
...
...
@@ -16,7 +16,7 @@ type MakeAuthorizationFn = (
config
?:
InternalAxiosRequestConfig
,
)
=>
MakeAuthorization
;
type
ErrorMessageFn
=
(
message
:
string
)
=>
void
;
type
Make
ErrorMessageFn
=
(
message
:
string
)
=>
void
;
interface
RequestClientOptions
extends
CreateAxiosDefaults
{
/**
...
...
@@ -26,7 +26,7 @@ interface RequestClientOptions extends CreateAxiosDefaults {
/**
* 用于生成错误消息
*/
makeErrorMessage
?:
ErrorMessageFn
;
makeErrorMessage
?:
Make
ErrorMessageFn
;
}
interface
HttpResponse
<
T
=
any
>
{
...
...
@@ -42,6 +42,7 @@ interface HttpResponse<T = any> {
export
type
{
HttpResponse
,
MakeAuthorizationFn
,
MakeErrorMessageFn
,
RequestClientOptions
,
RequestContentType
,
};
packages/@core/ui-kit/shadcn-ui/src/components/index.ts
View file @
2c79ac1
// 修改过的button
export
*
from
'./alert-dialog'
;
export
*
from
'./avatar'
;
export
*
from
'./back-top'
;
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment