Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
cs_vsofpm
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wuhao
cs_vsofpm
Commits
9c2cdc66
Commit
9c2cdc66
authored
Aug 16, 2023
by
wuhao
🎯
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
asder
parent
89a3da6b
Pipeline
#4275
passed with stages
in 16 minutes and 39 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
125 deletions
+34
-125
config.ts
config/config.ts
+4
-1
routes.ts
config/routes.ts
+5
-0
app.jsx
src/app.jsx
+20
-10
index.jsx
src/layouts/dashboard/nav/index.jsx
+5
-5
requestErrorConfig.ts
src/requestErrorConfig.ts
+0
-109
No files found.
config/config.ts
View file @
9c2cdc66
...
...
@@ -108,5 +108,8 @@ export default defineConfig({
requestRecord
:
{},
define
:
env
[
REACT_APP_ENV
as
keyof
typeof
env
],
title
:
'精密测量虚拟仿真实训平台'
,
esbuildMinifyIIFE
:
true
esbuildMinifyIIFE
:
true
,
qiankun
:
{
master
:
{},
},
});
config/routes.ts
View file @
9c2cdc66
...
...
@@ -49,6 +49,11 @@ export default [
path
:
"/work"
,
redirect
:
"/work/homepage"
,
},
{
name
:
"首页"
,
path
:
"/work/app"
,
microApp
:
'app'
,
},
{
name
:
"个人主页"
,
path
:
"/work/homepage"
,
...
...
src/app.jsx
View file @
9c2cdc66
/*
* @Author: wuhao930406 1148547900@qq.com
* @Date: 2023-05-17 16:16:06
* @LastEditors: wuhao930406 1148547900@qq.com
* @LastEditTime: 2023-08-15 17:21:40
* @FilePath: /cs_vsofpm/src/app.jsx
* @Description:
*
* Copyright (c) 2023 by ${git_name_email}, All Rights Reserved.
*/
/* eslint-disable @typescript-eslint/no-unused-vars */
import
{
history
}
from
"@umijs/max"
;
import
{
errorConfig
}
from
"./requestErrorConfig"
;
import
{
doFetch
}
from
"./utils/doFetch"
;
const
loginPath
=
"/user/login"
;
...
...
@@ -13,7 +22,7 @@ export async function getInitialState() {
const
msg
=
await
doFetch
({
url
:
"/system/me"
,
});
localStorage
.
setItem
(
"ID"
,
msg
?.
data
?.
data
?.
id
)
localStorage
.
setItem
(
"ID"
,
msg
?.
data
?.
data
?.
id
);
return
msg
.
data
.
data
;
}
catch
(
error
)
{
history
.
push
(
loginPath
);
...
...
@@ -31,7 +40,7 @@ export async function getInitialState() {
activeUserIdList
:
[],
vs
:
false
,
nav
:
280
,
menuNum
:{},
menuNum
:
{},
message
:
{
open
:
false
,
snackbar
:
{
...
...
@@ -65,11 +74,12 @@ export async function getInitialState() {
nav
:
280
,
};
}
/**
* @name request 配置,可以配置错误处理
* 它基于 axios 和 ahooks 的 useRequest 提供了一套统一的网络请求和错误处理方案。
* @doc https://umijs.org/docs/max/request#配置
*/
export
const
request
=
{
...
errorConfig
,
export
const
qiankun
=
{
apps
:
[
{
name
:
"app"
,
entry
:
"//localhost:7001"
,
},
],
};
src/layouts/dashboard/nav/index.jsx
View file @
9c2cdc66
...
...
@@ -148,15 +148,17 @@ export default function Nav({ openNav, onCloseNav }) {
px
:
2
,
py
:
1.8
,
display
:
"flex"
,
justifyContent
:
"
center
"
,
justifyContent
:
"
flex-start
"
,
alignItems
:
"center"
,
flexDirection
:
"column"
,
gap
:
1
,
}
}
>
<
Logo
/>
<
Logo
sx=
{
{
width
:
60
,
height
:
60
}
}
/>
{
!
ifs
&&
(
<
Typography
component=
"b"
sx=
{
{
fontSize
:
16
,
paddingLeft
:
"10px"
,
fontWeight
:
"bold"
}
}
sx=
{
{
fontSize
:
21
,
fontWeight
:
"bold"
}
}
noWrap
>
精密测量虚拟仿真实训平台
...
...
@@ -243,8 +245,6 @@ export default function Nav({ openNav, onCloseNav }) {
</
Box
>
);
return
(
<
Box
component=
"nav"
...
...
src/requestErrorConfig.ts
deleted
100755 → 0
View file @
89a3da6b
import
type
{
RequestOptions
}
from
'@@/plugin-request/request'
;
import
type
{
RequestConfig
}
from
'@umijs/max'
;
import
{
message
,
notification
}
from
'antd'
;
// 错误处理方案: 错误类型
enum
ErrorShowType
{
SILENT
=
0
,
WARN_MESSAGE
=
1
,
ERROR_MESSAGE
=
2
,
NOTIFICATION
=
3
,
REDIRECT
=
9
,
}
// 与后端约定的响应数据格式
interface
ResponseStructure
{
success
:
boolean
;
data
:
any
;
errorCode
?:
number
;
errorMessage
?:
string
;
showType
?:
ErrorShowType
;
}
/**
* @name 错误处理
* pro 自带的错误处理, 可以在这里做自己的改动
* @doc https://umijs.org/docs/max/request#配置
*/
export
const
errorConfig
:
RequestConfig
=
{
// 错误处理: umi@3 的错误处理方案。
errorConfig
:
{
// 错误抛出
errorThrower
:
(
res
)
=>
{
const
{
success
,
data
,
errorCode
,
errorMessage
,
showType
}
=
res
as
unknown
as
ResponseStructure
;
if
(
!
success
)
{
const
error
:
any
=
new
Error
(
errorMessage
);
error
.
name
=
'BizError'
;
error
.
info
=
{
errorCode
,
errorMessage
,
showType
,
data
};
throw
error
;
// 抛出自制的错误
}
},
// 错误接收及处理
errorHandler
:
(
error
:
any
,
opts
:
any
)
=>
{
if
(
opts
?.
skipErrorHandler
)
throw
error
;
// 我们的 errorThrower 抛出的错误。
if
(
error
.
name
===
'BizError'
)
{
const
errorInfo
:
ResponseStructure
|
undefined
=
error
.
info
;
if
(
errorInfo
)
{
const
{
errorMessage
,
errorCode
}
=
errorInfo
;
switch
(
errorInfo
.
showType
)
{
case
ErrorShowType
.
SILENT
:
// do nothing
break
;
case
ErrorShowType
.
WARN_MESSAGE
:
message
.
warning
(
errorMessage
);
break
;
case
ErrorShowType
.
ERROR_MESSAGE
:
message
.
error
(
errorMessage
);
break
;
case
ErrorShowType
.
NOTIFICATION
:
notification
.
open
({
description
:
errorMessage
,
message
:
errorCode
,
});
break
;
case
ErrorShowType
.
REDIRECT
:
// TODO: redirect
break
;
default
:
message
.
error
(
errorMessage
);
}
}
}
else
if
(
error
.
response
)
{
// Axios 的错误
// 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围
message
.
error
(
`Response status:
${
error
.
response
.
status
}
`
);
}
else
if
(
error
.
request
)
{
// 请求已经成功发起,但没有收到响应
// \`error.request\` 在浏览器中是 XMLHttpRequest 的实例,
// 而在node.js中是 http.ClientRequest 的实例
message
.
error
(
'None response! Please retry.'
);
}
else
{
// 发送请求时出了点问题
message
.
error
(
'Request error, please retry.'
);
}
},
},
// 请求拦截器
requestInterceptors
:
[
(
config
:
RequestOptions
)
=>
{
// 拦截请求配置,进行个性化处理。
const
url
=
config
?.
url
?.
concat
(
'?token = 123'
);
return
{
...
config
,
url
};
},
],
// 响应拦截器
responseInterceptors
:
[
(
response
)
=>
{
// 拦截响应数据,进行个性化处理
const
{
data
}
=
response
as
unknown
as
ResponseStructure
;
if
(
data
?.
success
===
false
)
{
message
.
error
(
'请求失败!'
);
}
return
response
;
},
],
};
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
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 comment