Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-platform
Project
Project
Details
Activity
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
黄庭坚
jinfa-platform
Commits
7b316ff2
Commit
7b316ff2
authored
Jan 19, 2021
by
Bill
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修改bug
parent
65f62d55
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
207 additions
and
178 deletions
+207
-178
EmailVerifyPanel.tsx
...Setting/components/VerifyPanel/Panel/EmailVerifyPanel.tsx
+0
-2
PaycodeVerifyPanel.tsx
...tting/components/VerifyPanel/Panel/PaycodeVerifyPanel.tsx
+0
-2
PhoneVerifyPanel.tsx
...Setting/components/VerifyPanel/Panel/PhoneVerifyPanel.tsx
+1
-3
ResetPayCode.tsx
...ountSetting/components/VerifyPanel/Panel/ResetPayCode.tsx
+1
-1
index.tsx
src/pages/balance/accountsPayable/settlementList/index.tsx
+1
-1
index.tsx
...s/balance/accountsPayable/settlementList/schema/index.tsx
+1
-1
index.tsx
...alance/accountsReceivable/settlementList/schema/index.tsx
+1
-1
index.tsx
src/pages/balance/components/StatusActions/index.tsx
+24
-7
index.tsx
src/pages/balance/components/UploadPayVoucher/index.tsx
+13
-3
index.tsx
src/pages/balance/components/Voucher/index.tsx
+6
-2
index.tsx
...nce/platformSettlement/accountReceivable/schema/index.tsx
+1
-1
index.tsx
...ages/balance/platformSettlement/integral/schema/index.tsx
+1
-1
index.tsx
src/pages/handling/assign/processStock/index.tsx
+5
-0
request.ts
src/utils/request.ts
+152
-153
No files found.
src/pages/accountSetting/components/VerifyPanel/Panel/EmailVerifyPanel.tsx
View file @
7b316ff2
...
...
@@ -84,8 +84,6 @@ const EmailVerifyPanel = (props) => {
if
(
data
.
code
==
1000
)
{
message
.
success
(
"验证成功"
)
setVisible
(
true
);
}
else
{
message
.
error
(
data
.
message
)
}
})
}
...
...
src/pages/accountSetting/components/VerifyPanel/Panel/PaycodeVerifyPanel.tsx
View file @
7b316ff2
...
...
@@ -71,8 +71,6 @@ const PaycodeVerifyPanel: React.FC<IProps> = (props) => {
if
(
data
.
code
==
1000
)
{
message
.
success
(
"验证成功"
)
setVisible
(
true
);
}
else
{
message
.
error
(
data
.
message
)
}
})
}
...
...
src/pages/accountSetting/components/VerifyPanel/Panel/PhoneVerifyPanel.tsx
View file @
7b316ff2
...
...
@@ -82,11 +82,9 @@ const PhoneVerifyPanel: React.FC<IProps> = (props) => {
}
const
service
=
SERVICE_CHECK
[
props
.
pageType
];
service
({
smsCode
:
captcha
},
{
ctlType
:
'none'
}).
then
((
data
)
=>
{
if
(
data
.
code
==
1000
)
{
if
(
data
.
code
==
=
1000
)
{
message
.
success
(
"验证成功"
)
setVisible
(
true
);
}
else
{
message
.
error
(
data
.
message
)
}
})
...
...
src/pages/accountSetting/components/VerifyPanel/Panel/ResetPayCode.tsx
View file @
7b316ff2
...
...
@@ -50,7 +50,7 @@ const ResetPayCode: React.FC<IProps> = (props) => {
const
handleVerifySuccess
=
()
=>
{
const
captcha
=
form
.
getFieldValue
(
'captcha'
);
const
service
=
PublicApi
.
postMemberSecurityPaySmsCheck
service
({
smsCode
:
captcha
}).
then
((
data
)
=>
{
service
({
smsCode
:
captcha
}
,
{
ctlType
:
'none'
}
).
then
((
data
)
=>
{
console
.
log
(
data
);
if
(
data
.
code
==
1000
)
{
setVisible
(
true
);
...
...
src/pages/balance/accountsPayable/settlementList/index.tsx
View file @
7b316ff2
...
...
@@ -92,7 +92,7 @@ const SettlementList = () => {
title
:
'操作'
,
render
:
(
text
:
string
,
record
:
any
)
=>
{
if
(
record
.
status
===
1
)
{
return
<
Button
type=
"link"
onClick=
{
()
=>
handleManualsettlement
(
record
.
id
)
}
>
手动结算
</
Button
>
return
<
a
onClick=
{
()
=>
handleManualsettlement
(
record
.
id
)
}
>
手动结算
</
a
>
}
return
(
<
StatusActions
...
...
src/pages/balance/accountsPayable/settlementList/schema/index.tsx
View file @
7b316ff2
...
...
@@ -43,7 +43,7 @@ export const schema: ISchema = {
"x-component"
:
'RangePicker'
,
'x-component-props'
:
{
allowClear
:
true
,
placeholder
:
[
"结算
时间(开始时间)"
,
"结算时间(结束
时间)"
],
placeholder
:
[
"结算
日期(开始时间)"
,
"结算日期(开始
时间)"
],
style
:
{
minWidth
:
"320px"
}
...
...
src/pages/balance/accountsReceivable/settlementList/schema/index.tsx
View file @
7b316ff2
...
...
@@ -43,7 +43,7 @@ export const schema: ISchema = {
"x-component"
:
'RangePicker'
,
'x-component-props'
:
{
allowClear
:
true
,
placeholder
:
[
"结算
时间(开始时间)"
,
"结算时间
(结束时间)"
],
placeholder
:
[
"结算
日期(开始时间)"
,
"结算日期
(结束时间)"
],
style
:
{
minWidth
:
"320px"
}
...
...
src/pages/balance/components/StatusActions/index.tsx
View file @
7b316ff2
...
...
@@ -5,7 +5,7 @@
*/
import
React
,
{
useState
,
useEffect
}
from
'react'
;
import
ModalContainer
from
'../ModalContainer'
;
import
{
Modal
,
Space
,
Button
}
from
'antd'
;
import
{
Modal
,
Space
,
Button
,
Popconfirm
}
from
'antd'
;
import
ConfirmAccount
from
'../../components/ConfirmAccount'
;
import
Voucher
from
'../../components/Voucher'
;
import
{
StatusEnum
,
TO_BE_RECONCILED
,
TO_BE_PAY
,
TO_BE_COLLECTED
,
COMPLETED
}
from
'../../components/StatusTag'
;
...
...
@@ -167,9 +167,20 @@ interface FileType {
const
UploadVoucher
:
React
.
FC
<
UploadVocherProps
>
=
(
props
)
=>
{
const
{
settlementId
,
roleId
,
}
=
props
;
const
[
fileList
,
setFileList
]
=
useState
<
FileType
[]
>
([]);
const
[
isUploading
,
setIsUploading
]
=
useState
(
false
)
const
getFileList
=
(
list
:
FileType
[])
=>
{
setFileList
(
list
);
const
getFileList
=
(
list
:
FileType
[],
status
)
=>
{
if
(
status
===
'done'
)
{
setFileList
(
list
);
setIsUploading
(
false
)
}
else
{
setIsUploading
(
true
);
}
}
const
handleComfirm
=
(
params
)
=>
{
props
.
handleUpload
({
onCancel
:
params
.
cancel
,
id
:
params
.
id
,
fileList
:
params
.
fileList
})
}
return
(
...
...
@@ -186,10 +197,16 @@ const UploadVoucher: React.FC<UploadVocherProps> = (props) => {
footer=
{
(
<
Space
>
<
Button
onClick=
{
cancel
}
>
取消
</
Button
>
<
Button
type=
{
"primary"
}
onClick=
{
()
=>
props
.
handleUpload
({
onCancel
:
cancel
,
id
:
props
.
id
,
fileList
:
fileList
})
}
>
确认
</
Button
>
{
isUploading
?
<
Popconfirm
title=
"还有文件正在上传,是否确认提交?"
okText=
"是"
cancelText=
"否"
onConfirm=
{
()
=>
handleComfirm
({
onCancel
:
cancel
,
id
:
props
.
id
,
fileList
:
fileList
})
}
>
<
Button
type=
{
"primary"
}
>
确认
</
Button
>
</
Popconfirm
>
:
<
Button
type=
{
"primary"
}
onClick=
{
()
=>
handleComfirm
({
onCancel
:
cancel
,
id
:
props
.
id
,
fileList
:
fileList
})
}
>
确认
</
Button
>
}
</
Space
>
)
}
>
...
...
src/pages/balance/components/UploadPayVoucher/index.tsx
View file @
7b316ff2
...
...
@@ -17,7 +17,7 @@ import { PublicApi } from '@/services/api';
interface
Iprops
{
fileList
?:
VoucherFileProps
[],
id
:
number
,
// 结算方id
getFileList
:
(
params
:
any
[])
=>
void
,
getFileList
:
(
params
:
any
[]
,
status
:
string
)
=>
void
,
roleId
:
number
}
...
...
@@ -78,6 +78,7 @@ const UploadPayVoucher: React.FC<Iprops> = (props) => {
showUploadList
:
false
,
onChange
(
info
:
UploadChangeParam
)
{
if
(
info
.
file
.
status
===
'uploading'
)
{
props
.
getFileList
(
fileList
,
"uploading"
)
setLoading
(
true
)
return
;
}
...
...
@@ -94,7 +95,7 @@ const UploadPayVoucher: React.FC<Iprops> = (props) => {
proveUrl
:
data
})
setFileList
(
temp
);
props
.
getFileList
(
temp
)
props
.
getFileList
(
temp
,
"done"
)
}
setLoading
(
false
)
}
...
...
@@ -102,6 +103,15 @@ const UploadPayVoucher: React.FC<Iprops> = (props) => {
beforeUpload
};
const
handleRemove
=
(
value
)
=>
{
const
list
=
[...
fileList
];
const
res
=
list
.
filter
((
item
)
=>
item
.
proveUrl
!==
value
.
proveUrl
);
setFileList
(
res
)
if
(
props
.
getFileList
)
{
props
.
getFileList
(
res
,
"done"
)
}
}
return
(
<
div
className=
{
styles
.
container
}
>
<
div
className=
{
styles
.
formItem
}
>
...
...
@@ -117,7 +127,7 @@ const UploadPayVoucher: React.FC<Iprops> = (props) => {
<
span
className=
{
styles
.
value
}
>
{
accountInfo
?.
bankDeposit
}
</
span
>
</
div
>
<
p
className=
{
styles
.
voucherText
}
>
上传支付凭证
</
p
>
<
Voucher
files=
{
fileList
}
/>
<
Voucher
files=
{
fileList
}
onRemove=
{
handleRemove
}
/>
<
div
className=
{
styles
.
upload
}
>
<
Upload
{
...
uploadProps
}
>
<
Button
icon=
{
<
UploadOutlined
/>
}
loading=
{
loading
}
>
上传凭证
</
Button
>
...
...
src/pages/balance/components/Voucher/index.tsx
View file @
7b316ff2
...
...
@@ -10,12 +10,16 @@ import image_icon from '@/assets/imgs/image_icon.png';
import
{
VoucherFileProps
}
from
'../../common/type'
;
interface
Iprops
{
files
:
VoucherFileProps
[]
files
:
VoucherFileProps
[],
onRemove
:
(
item
)
=>
void
}
const
Voucher
:
React
.
FC
<
Iprops
>
=
(
props
)
=>
{
const
{
files
=
[]
}
=
props
;
console
.
log
(
files
);
const
handleRemove
=
(
item
)
=>
{
!!
props
.
onRemove
&&
props
.
onRemove
(
item
);
}
return
(
<>
{
...
...
@@ -30,7 +34,7 @@ const Voucher: React.FC<Iprops> = (props) => {
<
a
href=
{
item
.
proveUrl
}
target=
{
"_blank"
}
>
{
item
.
name
}
</
a
>
</
div
>
<
div
className=
{
styles
.
view
}
>
<
a
href=
{
item
.
proveUrl
}
target=
{
"_blank"
}
>
预览
</
a
>
<
a
onClick=
{
()
=>
handleRemove
(
item
)
}
>
删除
</
a
>
</
div
>
</
div
>
)
...
...
src/pages/balance/platformSettlement/accountReceivable/schema/index.tsx
View file @
7b316ff2
...
...
@@ -39,7 +39,7 @@ export const schema: ISchema = {
"x-component"
:
'RangePicker'
,
'x-component-props'
:
{
allowClear
:
true
,
placeholder
:
[
"结算
时间(开始时间)"
,
"结算时间
(结束时间)"
],
placeholder
:
[
"结算
日期(开始时间)"
,
"结算日期
(结束时间)"
],
style
:
{
minWidth
:
"320px"
}
...
...
src/pages/balance/platformSettlement/integral/schema/index.tsx
View file @
7b316ff2
...
...
@@ -44,7 +44,7 @@ export const schema: ISchema = {
"x-component"
:
'RangePicker'
,
'x-component-props'
:
{
allowClear
:
true
,
placeholder
:
[
"结算
时间(开始时间)"
,
"结算时间
(结束时间)"
],
placeholder
:
[
"结算
日期(开始时间)"
,
"结算日期
(结束时间)"
],
style
:
{
minWidth
:
"320px"
}
...
...
src/pages/handling/assign/processStock/index.tsx
View file @
7b316ff2
...
...
@@ -62,6 +62,10 @@ enum OuterAndInnerStatus {
*/
pending_confirm_logistics
=
'4_17'
,
/**
* 物流单不接受
*/
editing_logistics
=
"4_-17"
,
/**
* 待确认发货
*/
pending_confirm_deliver
=
'5_18'
,
...
...
@@ -185,6 +189,7 @@ const processStock: React.FC<{}> = () => {
),
[
OuterAndInnerStatus
.
pending_add_logistics
]:
<
Link
to
=
{
`
${
ADD_LOGISTICS_PATH
}
?createType=3&id=
${
record
.
id
}
`
}
>
新增物流单
<
/Link>
,
[
OuterAndInnerStatus
.
pending_confirm_logistics
]:
<
Link
to
=
{
`
${
DETAIL_LOGISTICS_PATH
}
?id=
${
record
.
logisticsOrderId
}
`
}
>
查看物流单
<
/Link>
,
[
OuterAndInnerStatus
.
editing_logistics
]:
<
Link
to
=
{
`memberCenter/logisticsAbility/logisticsSubmit/toOrderSumitList/edit?id=
${
record
.
logisticsOrderId
}
`
}
>
<
/
Link
>
,
[OuterAndInnerStatus.pending_confirm_deliver]:
<
Link
to=
{
`${PENDING_DELIVERD_PATH}/detail?id=${record.id}`
}
>
发货
</
Link
>
,
[OuterAndInnerStatus.pending_add_process_in_warehouse]: (
<
Link
...
...
src/utils/request.ts
View file @
7b316ff2
import
{
extend
,
ResponseError
,
OnionOptions
,
RequestOptionsInit
,
ResponseInterceptor
,
OnionMiddleware
,
Context
,
RequestMethod
}
from
'umi-request'
;
import
responseCode
from
'@/constants/responseCode'
import
{
IRequestError
,
IRequestSuccess
}
from
'..'
;
import
{
history
}
from
'umi'
import
{
message
}
from
'antd'
import
{
getAuth
,
removeAuth
}
from
'./auth'
;
import
{
GlobalConfig
}
from
'@/global/config'
;
import
qs
from
'qs'
export
type
CtlType
=
'none'
|
'message'
// 根前缀请求路径
const
basePrefix
=
'/api'
export
interface
IApiRequest
extends
RequestOptionsInit
{
ctlType
?:
CtlType
// 可以用于扩展请求配置
extendsOptions
?:
RequestOptionsInit
}
/**
*
* umi-request文档 https://github.com/umijs/umi-request/blob/master/README_zh-CN.md
*
*/
type
httpStatus
=
{
[
key
:
number
]:
string
}
const
errorMessage
:
httpStatus
=
{
400
:
"发出的请求有错误,服务器没有进行新建或修改数据的操作。"
,
401
:
"用户没有权限(令牌、用户名、密码错误)。"
,
403
:
"用户得到授权,但是访问是被禁止的。"
,
404
:
"发出的请求针对的是不存在的记录,服务器没有进行操作。"
,
406
:
"请求的格式不可得。"
,
410
:
"请求的资源被永久删除,且不会再得到的。"
,
422
:
"当创建一个对象时,发生一个验证错误。"
,
500
:
"服务器发生错误,请检查服务器。"
,
502
:
"网关错误。"
,
503
:
"服务不可用,服务器暂时过载或维护。"
,
504
:
"网关超时。"
,
};
const
errorHandler
=
(
error
:
ResponseError
):
IRequestError
=>
{
console
.
log
(
error
)
const
{
response
}
=
error
// http状态码非200的错误处理
const
messageText
=
response
?.
status
?
errorMessage
[
response
.
status
]
:
''
if
(
response
)
{
message
.
destroy
()
message
.
error
(
'http请求错误: '
+
response
.
status
+
'->'
+
messageText
,
3
)
}
else
{
// 请求超时, 会造成没有response
message
.
error
(
'请求超时'
)
}
// throw可令响应promise走catch, 如需走resolve需直接return
throw
{
message
:
messageText
,
...
error
}
}
const
defaultHeaders
=
{
'Content-Type'
:
'Application/json'
,
'source'
:
'1'
,
'environment'
:
'1'
,
'site'
:
GlobalConfig
.
global
.
siteInfo
.
id
.
toString
()
}
/**
* 配置request请求时的默认参数, 底层使用fetch进行请求
*/
const
baseRequest
=
extend
({
timeout
:
30
*
1000
,
headers
:
defaultHeaders
,
credentials
:
'include'
,
// 默认请求是否带上cookie
errorHandler
});
const
cache
=
{}
// 请求拦截器
baseRequest
.
interceptors
.
request
.
use
((
url
:
string
,
options
:
RequestOptionsInit
):
{
url
:
string
,
options
:
RequestOptionsInit
}
=>
{
// 判断是否有权限
const
{
userId
,
memberId
,
token
}
=
getAuth
()
||
{}
const
headers
:
any
=
{
...
options
.
headers
}
userId
&&
(
headers
.
userId
=
userId
)
token
&&
(
headers
.
token
=
token
)
memberId
&&
(
headers
.
memberId
=
memberId
)
options
.
paramsSerializer
=
params
=>
{
return
qs
.
stringify
(
params
,
{
arrayFormat
:
'indices'
})
}
return
{
// 前缀如果已经带上api, 跳过自动补前缀
url
:
url
.
startsWith
(
'/api'
)
?
url
:
basePrefix
+
url
,
options
:
{
...
options
,
headers
},
};
});
// 响应拦截器
baseRequest
.
interceptors
.
response
.
use
((
response
:
Response
,
options
:
RequestOptionsInit
)
=>
{
return
response
;
});
// 请求中间件
baseRequest
.
use
(
async
(
ctx
:
Context
,
next
:
()
=>
void
)
=>
{
await
next
()
})
/**
* 公共请求层
*/
class
ApiRequest
{
createRequest
<
T
>
(
url
:
string
,
options
:
IApiRequest
=
{
ctlType
:
'none'
}):
Promise
<
IRequestSuccess
<
T
>>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
baseRequest
<
IRequestSuccess
<
T
>>
(
url
,
options
).
then
(
res
=>
{
// 登录验证
if
(
res
.
code
===
1101
)
{
removeAuth
()
window
.
location
.
replace
(
`/user/login?redirect=
${
btoa
(
encodeURIComponent
(
String
(
window
.
location
)))}
`
)
message
.
destroy
()
message
.
error
(
res
.
message
)
reject
(
res
)
return
false
}
if
(
res
.
code
===
1000
)
{
if
(
options
.
ctlType
===
'message'
)
{
message
.
destroy
()
}
options
.
ctlType
===
'message'
&&
message
.
success
(
res
.
message
)
resolve
(
res
)
}
else
{
// 使用resolve将数据返回, 请求时需手动处理data为null的情况
resolve
(
res
)
// 这是展示接口错误信息,任何 ctlType 都可以,不然一些 get 请求出错了
// 错误信息无法展示给用户
res
.
message
&&
message
.
info
(
res
.
message
)
}
}).
catch
((
err
:
IRequestError
)
=>
{
// http错误处理, 直接透传
reject
(
err
)
})
})
}
}
export
default
new
ApiRequest
().
createRequest
;
\ No newline at end of file
import
{
extend
,
ResponseError
,
OnionOptions
,
RequestOptionsInit
,
ResponseInterceptor
,
OnionMiddleware
,
Context
,
RequestMethod
}
from
'umi-request'
;
import
responseCode
from
'@/constants/responseCode'
import
{
IRequestError
,
IRequestSuccess
}
from
'..'
;
import
{
history
}
from
'umi'
import
{
message
}
from
'antd'
import
{
getAuth
,
removeAuth
}
from
'./auth'
;
import
{
GlobalConfig
}
from
'@/global/config'
;
import
qs
from
'qs'
export
type
CtlType
=
'none'
|
'message'
// 根前缀请求路径
const
basePrefix
=
'/api'
export
interface
IApiRequest
extends
RequestOptionsInit
{
ctlType
?:
CtlType
// 可以用于扩展请求配置
extendsOptions
?:
RequestOptionsInit
}
/**
*
* umi-request文档 https://github.com/umijs/umi-request/blob/master/README_zh-CN.md
*
*/
type
httpStatus
=
{
[
key
:
number
]:
string
}
const
errorMessage
:
httpStatus
=
{
400
:
"发出的请求有错误,服务器没有进行新建或修改数据的操作。"
,
401
:
"用户没有权限(令牌、用户名、密码错误)。"
,
403
:
"用户得到授权,但是访问是被禁止的。"
,
404
:
"发出的请求针对的是不存在的记录,服务器没有进行操作。"
,
406
:
"请求的格式不可得。"
,
410
:
"请求的资源被永久删除,且不会再得到的。"
,
422
:
"当创建一个对象时,发生一个验证错误。"
,
500
:
"服务器发生错误,请检查服务器。"
,
502
:
"网关错误。"
,
503
:
"服务不可用,服务器暂时过载或维护。"
,
504
:
"网关超时。"
,
};
const
errorHandler
=
(
error
:
ResponseError
):
IRequestError
=>
{
console
.
log
(
error
)
const
{
response
}
=
error
// http状态码非200的错误处理
const
messageText
=
response
?.
status
?
errorMessage
[
response
.
status
]
:
''
if
(
response
)
{
message
.
destroy
()
message
.
error
(
'http请求错误: '
+
response
.
status
+
'->'
+
messageText
,
3
)
}
else
{
// 请求超时, 会造成没有response
message
.
error
(
'请求超时'
)
}
// throw可令响应promise走catch, 如需走resolve需直接return
throw
{
message
:
messageText
,
...
error
}
}
const
defaultHeaders
=
{
'Content-Type'
:
'Application/json'
,
'source'
:
'1'
,
'environment'
:
'1'
,
'site'
:
GlobalConfig
.
global
.
siteInfo
.
id
.
toString
()
}
/**
* 配置request请求时的默认参数, 底层使用fetch进行请求
*/
const
baseRequest
=
extend
({
timeout
:
30
*
1000
,
headers
:
defaultHeaders
,
credentials
:
'include'
,
// 默认请求是否带上cookie
errorHandler
});
const
cache
=
{}
// 请求拦截器
baseRequest
.
interceptors
.
request
.
use
((
url
:
string
,
options
:
RequestOptionsInit
):
{
url
:
string
,
options
:
RequestOptionsInit
}
=>
{
// 判断是否有权限
const
{
userId
,
memberId
,
token
}
=
getAuth
()
||
{}
const
headers
:
any
=
{
...
options
.
headers
}
userId
&&
(
headers
.
userId
=
userId
)
token
&&
(
headers
.
token
=
token
)
memberId
&&
(
headers
.
memberId
=
memberId
)
options
.
paramsSerializer
=
params
=>
{
return
qs
.
stringify
(
params
,
{
arrayFormat
:
'indices'
})
}
return
{
// 前缀如果已经带上api, 跳过自动补前缀
url
:
url
.
startsWith
(
'/api'
)
?
url
:
basePrefix
+
url
,
options
:
{
...
options
,
headers
},
};
});
// 响应拦截器
baseRequest
.
interceptors
.
response
.
use
((
response
:
Response
,
options
:
RequestOptionsInit
)
=>
{
return
response
;
});
// 请求中间件
baseRequest
.
use
(
async
(
ctx
:
Context
,
next
:
()
=>
void
)
=>
{
await
next
()
})
/**
* 公共请求层
*/
class
ApiRequest
{
createRequest
<
T
>
(
url
:
string
,
options
:
IApiRequest
=
{
ctlType
:
'none'
}):
Promise
<
IRequestSuccess
<
T
>>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
baseRequest
<
IRequestSuccess
<
T
>>
(
url
,
options
).
then
(
res
=>
{
// 登录验证
if
(
res
.
code
===
1101
)
{
removeAuth
()
window
.
location
.
replace
(
`/user/login?redirect=
${
btoa
(
encodeURIComponent
(
String
(
window
.
location
)))}
`
)
message
.
destroy
()
message
.
error
(
res
.
message
)
reject
(
res
)
return
false
}
if
(
res
.
code
===
1000
)
{
if
(
options
.
ctlType
===
'message'
)
{
message
.
destroy
()
}
options
.
ctlType
===
'message'
&&
message
.
success
(
res
.
message
)
resolve
(
res
)
}
else
{
// 使用resolve将数据返回, 请求时需手动处理data为null的情况
resolve
(
res
)
// 这是展示接口错误信息,任何 ctlType 都可以,不然一些 get 请求出错了
// 错误信息无法展示给用户
res
.
message
&&
message
.
info
(
res
.
message
)
}
}).
catch
((
err
:
IRequestError
)
=>
{
// http错误处理, 直接透传
reject
(
err
)
})
})
}
}
export
default
new
ApiRequest
().
createRequest
;
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