Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
web
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
iuav
web
Commits
4560f80b
提交
4560f80b
authored
5月 24, 2023
作者:
翁进城
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
api请求出错全局提示
上级
d52a3900
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
43 行增加
和
4 行删除
+43
-4
request.ts
api/request.ts
+20
-2
_app.page.tsx
pages/_app.page.tsx
+14
-1
tsconfig.json
tsconfig.json
+2
-1
type.d.ts
typings/type.d.ts
+7
-0
没有找到文件。
api/request.ts
浏览文件 @
4560f80b
...
@@ -36,9 +36,9 @@ export default function request(url: string, method: String = 'get', data?: any,
...
@@ -36,9 +36,9 @@ export default function request(url: string, method: String = 'get', data?: any,
return
fetch
(
config
.
baseUrl
+
url
,
options
)
return
fetch
(
config
.
baseUrl
+
url
,
options
)
.
then
((
r
)
=>
{
.
then
((
r
)
=>
{
try
{
try
{
return
r
.
json
()
return
r
.
json
()
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
error
(
e
);
console
.
error
(
e
);
}
}
return
{
return
{
...
@@ -48,6 +48,24 @@ export default function request(url: string, method: String = 'get', data?: any,
...
@@ -48,6 +48,24 @@ export default function request(url: string, method: String = 'get', data?: any,
}
}
})
})
.
then
((
data
)
=>
{
.
then
((
data
)
=>
{
if
(
data
.
errors
)
{
//全局消息提示
window
.
messageApi
.
error
(
'请求出错'
)
if
(
Array
.
isArray
(
data
.
errors
))
{
data
.
errors
.
forEach
((
item
:
any
)
=>
{
if
(
item
.
defaultMessage
){
window
.
messageApi
.
error
(
item
.
defaultMessage
)
}
})
}
return
{
code
:
'-1'
,
message
:
'请求失败'
,
result
:
null
}
}
return
data
;
return
data
;
})
})
.
catch
(
error
=>
{
.
catch
(
error
=>
{
...
...
pages/_app.page.tsx
浏览文件 @
4560f80b
...
@@ -2,7 +2,20 @@ import '../public/antd.min.css';
...
@@ -2,7 +2,20 @@ import '../public/antd.min.css';
import
'../styles/index.scss'
;
import
'../styles/index.scss'
;
import
type
{
AppProps
}
from
'next/app'
;
import
type
{
AppProps
}
from
'next/app'
;
import
withTheme
from
'../theme'
;
import
withTheme
from
'../theme'
;
import
{
message
}
from
'antd'
;
import
{
useEffect
}
from
'react'
;
export
default
function
App
({
Component
,
pageProps
}:
AppProps
)
{
export
default
function
App
({
Component
,
pageProps
}:
AppProps
)
{
return
withTheme
(<
Component
{
...
pageProps
}
/>);
const
[
messageApi
,
contextHolder
]
=
message
.
useMessage
();
useEffect
(()
=>
{
//全局消息提示
window
.
messageApi
=
messageApi
;
},
[])
return
withTheme
(
<>
{
contextHolder
}
<
Component
{
...
pageProps
}
/>
</>
);
}
}
tsconfig.json
浏览文件 @
4560f80b
...
@@ -17,7 +17,8 @@
...
@@ -17,7 +17,8 @@
"incremental"
:
true
,
"incremental"
:
true
,
"paths"
:
{
"paths"
:
{
"~/*"
:
[
"./*"
]
"~/*"
:
[
"./*"
]
}
},
"typeRoots"
:
[
"./typings"
]
},
},
"include"
:
[
"next-env.d.ts"
,
"**/*.ts"
,
"**/*.tsx"
],
"include"
:
[
"next-env.d.ts"
,
"**/*.ts"
,
"**/*.tsx"
],
"exclude"
:
[
"node_modules"
]
"exclude"
:
[
"node_modules"
]
...
...
typings/type.d.ts
0 → 100644
浏览文件 @
4560f80b
import
{
MessageInstance
}
from
'antd/es/message/interface'
;
declare
global
{
interface
Window
{
messageApi
:
MessageInstance
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论