Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
najiu-admin-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
najiu-frontend
najiu-admin-template
Commits
50f94bfe
Commit
50f94bfe
authored
Jun 06, 2021
by
Vben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore(axios): remove useless code
parent
ee384b1f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
9 additions
and
14 deletions
+9
-14
Axios.ts
src/utils/http/axios/Axios.ts
+0
-1
axiosTransform.ts
src/utils/http/axios/axiosTransform.ts
+1
-1
const.ts
src/utils/http/axios/const.ts
+0
-2
helper.ts
src/utils/http/axios/helper.ts
+2
-2
index.ts
src/utils/http/axios/index.ts
+6
-8
No files found.
src/utils/http/axios/Axios.ts
View file @
50f94bfe
...
@@ -8,7 +8,6 @@ import { AxiosCanceler } from './axiosCancel';
...
@@ -8,7 +8,6 @@ import { AxiosCanceler } from './axiosCancel';
import
{
isFunction
}
from
'
/@/utils/is
'
;
import
{
isFunction
}
from
'
/@/utils/is
'
;
import
{
cloneDeep
}
from
'
lodash-es
'
;
import
{
cloneDeep
}
from
'
lodash-es
'
;
//import { errorResult } from './const';
import
{
ContentTypeEnum
}
from
'
/@/enums/httpEnum
'
;
import
{
ContentTypeEnum
}
from
'
/@/enums/httpEnum
'
;
import
{
RequestEnum
}
from
'
../../../enums/httpEnum
'
;
import
{
RequestEnum
}
from
'
../../../enums/httpEnum
'
;
...
...
src/utils/http/axios/axiosTransform.ts
View file @
50f94bfe
...
@@ -5,7 +5,7 @@ import type { AxiosRequestConfig, AxiosResponse } from 'axios';
...
@@ -5,7 +5,7 @@ import type { AxiosRequestConfig, AxiosResponse } from 'axios';
import
type
{
RequestOptions
,
Result
}
from
'
./types
'
;
import
type
{
RequestOptions
,
Result
}
from
'
./types
'
;
export
interface
CreateAxiosOptions
extends
AxiosRequestConfig
{
export
interface
CreateAxiosOptions
extends
AxiosRequestConfig
{
prefixUrl
?:
string
;
urlPrefix
?:
string
;
transform
?:
AxiosTransform
;
transform
?:
AxiosTransform
;
requestOptions
?:
RequestOptions
;
requestOptions
?:
RequestOptions
;
}
}
...
...
src/utils/http/axios/const.ts
deleted
100644 → 0
View file @
ee384b1f
// The interface return value data cannot be this, otherwise the request will be judged as a failure
export
const
errorResult
=
'
__ERROR_RESULT__
'
;
src/utils/http/axios/helper.ts
View file @
50f94bfe
...
@@ -2,12 +2,12 @@ import { isObject, isString } from '/@/utils/is';
...
@@ -2,12 +2,12 @@ import { isObject, isString } from '/@/utils/is';
const
DATE_TIME_FORMAT
=
'
YYYY-MM-DD HH:mm
'
;
const
DATE_TIME_FORMAT
=
'
YYYY-MM-DD HH:mm
'
;
export
function
createNow
<
T
extends
boolean
>
(
export
function
joinTimestamp
<
T
extends
boolean
>
(
join
:
boolean
,
join
:
boolean
,
restful
:
T
restful
:
T
):
T
extends
true
?
string
:
object
;
):
T
extends
true
?
string
:
object
;
export
function
createNow
(
join
:
boolean
,
restful
=
false
):
string
|
object
{
export
function
joinTimestamp
(
join
:
boolean
,
restful
=
false
):
string
|
object
{
if
(
!
join
)
{
if
(
!
join
)
{
return
restful
?
''
:
{};
return
restful
?
''
:
{};
}
}
...
...
src/utils/http/axios/index.ts
View file @
50f94bfe
...
@@ -18,12 +18,11 @@ import { getToken } from '/@/utils/auth';
...
@@ -18,12 +18,11 @@ import { getToken } from '/@/utils/auth';
import
{
setObjToUrlParams
,
deepMerge
}
from
'
/@/utils
'
;
import
{
setObjToUrlParams
,
deepMerge
}
from
'
/@/utils
'
;
import
{
useErrorLogStoreWithOut
}
from
'
/@/store/modules/errorLog
'
;
import
{
useErrorLogStoreWithOut
}
from
'
/@/store/modules/errorLog
'
;
//import { errorResult } from './const';
import
{
useI18n
}
from
'
/@/hooks/web/useI18n
'
;
import
{
useI18n
}
from
'
/@/hooks/web/useI18n
'
;
import
{
createNow
,
formatRequestDate
}
from
'
./helper
'
;
import
{
joinTimestamp
,
formatRequestDate
}
from
'
./helper
'
;
const
globSetting
=
useGlobSetting
();
const
globSetting
=
useGlobSetting
();
const
p
refix
=
globSetting
.
urlPrefix
;
const
urlP
refix
=
globSetting
.
urlPrefix
;
const
{
createMessage
,
createErrorModal
}
=
useMessage
();
const
{
createMessage
,
createErrorModal
}
=
useMessage
();
/**
/**
...
@@ -51,7 +50,6 @@ const transform: AxiosTransform = {
...
@@ -51,7 +50,6 @@ const transform: AxiosTransform = {
if
(
!
data
)
{
if
(
!
data
)
{
// return '[HTTP] Request has no return value';
// return '[HTTP] Request has no return value';
throw
new
Error
(
t
(
'
sys.api.apiRequestFailed
'
));
throw
new
Error
(
t
(
'
sys.api.apiRequestFailed
'
));
//return errorResult;
}
}
// 这里 code,result,message为 后台统一的字段,需要在 types.ts内修改为项目自己的接口返回格式
// 这里 code,result,message为 后台统一的字段,需要在 types.ts内修改为项目自己的接口返回格式
const
{
code
,
result
,
message
}
=
data
;
const
{
code
,
result
,
message
}
=
data
;
...
@@ -91,7 +89,7 @@ const transform: AxiosTransform = {
...
@@ -91,7 +89,7 @@ const transform: AxiosTransform = {
const
{
apiUrl
,
joinPrefix
,
joinParamsToUrl
,
formatDate
,
joinTime
=
true
}
=
options
;
const
{
apiUrl
,
joinPrefix
,
joinParamsToUrl
,
formatDate
,
joinTime
=
true
}
=
options
;
if
(
joinPrefix
)
{
if
(
joinPrefix
)
{
config
.
url
=
`
${
p
refix
}${
config
.
url
}
`
;
config
.
url
=
`
${
urlP
refix
}${
config
.
url
}
`
;
}
}
if
(
apiUrl
&&
isString
(
apiUrl
))
{
if
(
apiUrl
&&
isString
(
apiUrl
))
{
...
@@ -101,10 +99,10 @@ const transform: AxiosTransform = {
...
@@ -101,10 +99,10 @@ const transform: AxiosTransform = {
if
(
config
.
method
?.
toUpperCase
()
===
RequestEnum
.
GET
)
{
if
(
config
.
method
?.
toUpperCase
()
===
RequestEnum
.
GET
)
{
if
(
!
isString
(
params
))
{
if
(
!
isString
(
params
))
{
// 给 get 请求加上时间戳参数,避免从缓存中拿数据。
// 给 get 请求加上时间戳参数,避免从缓存中拿数据。
config
.
params
=
Object
.
assign
(
params
||
{},
createNow
(
joinTime
,
false
));
config
.
params
=
Object
.
assign
(
params
||
{},
joinTimestamp
(
joinTime
,
false
));
}
else
{
}
else
{
// 兼容restful风格
// 兼容restful风格
config
.
url
=
config
.
url
+
params
+
`
${
createNow
(
joinTime
,
true
)}
`
;
config
.
url
=
config
.
url
+
params
+
`
${
joinTimestamp
(
joinTime
,
true
)}
`
;
config
.
params
=
undefined
;
config
.
params
=
undefined
;
}
}
}
else
{
}
else
{
...
@@ -173,7 +171,7 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
...
@@ -173,7 +171,7 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
// 基础接口地址
// 基础接口地址
// baseURL: globSetting.apiUrl,
// baseURL: globSetting.apiUrl,
// 接口可能会有通用的地址部分,可以统一抽取出来
// 接口可能会有通用的地址部分,可以统一抽取出来
prefixUrl
:
p
refix
,
urlPrefix
:
urlP
refix
,
headers
:
{
'
Content-Type
'
:
ContentTypeEnum
.
JSON
},
headers
:
{
'
Content-Type
'
:
ContentTypeEnum
.
JSON
},
// 如果是form-data格式
// 如果是form-data格式
// headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED },
// headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED },
...
...
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