Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Dr.Disrespect
vue-vben-admin
提交
50f94bfe
V
vue-vben-admin
项目概览
Dr.Disrespect
/
vue-vben-admin
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
V
vue-vben-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
50f94bfe
编写于
6月 06, 2021
作者:
V
Vben
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore(axios): remove useless code
上级
ee384b1f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
9 addition
and
14 deletion
+9
-14
src/utils/http/axios/Axios.ts
src/utils/http/axios/Axios.ts
+0
-1
src/utils/http/axios/axiosTransform.ts
src/utils/http/axios/axiosTransform.ts
+1
-1
src/utils/http/axios/const.ts
src/utils/http/axios/const.ts
+0
-2
src/utils/http/axios/helper.ts
src/utils/http/axios/helper.ts
+2
-2
src/utils/http/axios/index.ts
src/utils/http/axios/index.ts
+6
-8
未找到文件。
src/utils/http/axios/Axios.ts
浏览文件 @
50f94bfe
...
...
@@ -8,7 +8,6 @@ import { AxiosCanceler } from './axiosCancel';
import
{
isFunction
}
from
'
/@/utils/is
'
;
import
{
cloneDeep
}
from
'
lodash-es
'
;
//import { errorResult } from './const';
import
{
ContentTypeEnum
}
from
'
/@/enums/httpEnum
'
;
import
{
RequestEnum
}
from
'
../../../enums/httpEnum
'
;
...
...
src/utils/http/axios/axiosTransform.ts
浏览文件 @
50f94bfe
...
...
@@ -5,7 +5,7 @@ import type { AxiosRequestConfig, AxiosResponse } from 'axios';
import
type
{
RequestOptions
,
Result
}
from
'
./types
'
;
export
interface
CreateAxiosOptions
extends
AxiosRequestConfig
{
prefixUrl
?:
string
;
urlPrefix
?:
string
;
transform
?:
AxiosTransform
;
requestOptions
?:
RequestOptions
;
}
...
...
src/utils/http/axios/const.ts
已删除
100644 → 0
浏览文件 @
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
浏览文件 @
50f94bfe
...
...
@@ -2,12 +2,12 @@ import { isObject, isString } from '/@/utils/is';
const
DATE_TIME_FORMAT
=
'
YYYY-MM-DD HH:mm
'
;
export
function
createNow
<
T
extends
boolean
>
(
export
function
joinTimestamp
<
T
extends
boolean
>
(
join
:
boolean
,
restful
:
T
):
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
)
{
return
restful
?
''
:
{};
}
...
...
src/utils/http/axios/index.ts
浏览文件 @
50f94bfe
...
...
@@ -18,12 +18,11 @@ import { getToken } from '/@/utils/auth';
import
{
setObjToUrlParams
,
deepMerge
}
from
'
/@/utils
'
;
import
{
useErrorLogStoreWithOut
}
from
'
/@/store/modules/errorLog
'
;
//import { errorResult } from './const';
import
{
useI18n
}
from
'
/@/hooks/web/useI18n
'
;
import
{
createNow
,
formatRequestDate
}
from
'
./helper
'
;
import
{
joinTimestamp
,
formatRequestDate
}
from
'
./helper
'
;
const
globSetting
=
useGlobSetting
();
const
p
refix
=
globSetting
.
urlPrefix
;
const
urlP
refix
=
globSetting
.
urlPrefix
;
const
{
createMessage
,
createErrorModal
}
=
useMessage
();
/**
...
...
@@ -51,7 +50,6 @@ const transform: AxiosTransform = {
if
(
!
data
)
{
// return '[HTTP] Request has no return value';
throw
new
Error
(
t
(
'
sys.api.apiRequestFailed
'
));
//return errorResult;
}
// 这里 code,result,message为 后台统一的字段,需要在 types.ts内修改为项目自己的接口返回格式
const
{
code
,
result
,
message
}
=
data
;
...
...
@@ -91,7 +89,7 @@ const transform: AxiosTransform = {
const
{
apiUrl
,
joinPrefix
,
joinParamsToUrl
,
formatDate
,
joinTime
=
true
}
=
options
;
if
(
joinPrefix
)
{
config
.
url
=
`
${
p
refix
}${
config
.
url
}
`
;
config
.
url
=
`
${
urlP
refix
}${
config
.
url
}
`
;
}
if
(
apiUrl
&&
isString
(
apiUrl
))
{
...
...
@@ -101,10 +99,10 @@ const transform: AxiosTransform = {
if
(
config
.
method
?.
toUpperCase
()
===
RequestEnum
.
GET
)
{
if
(
!
isString
(
params
))
{
// 给 get 请求加上时间戳参数,避免从缓存中拿数据。
config
.
params
=
Object
.
assign
(
params
||
{},
createNow
(
joinTime
,
false
));
config
.
params
=
Object
.
assign
(
params
||
{},
joinTimestamp
(
joinTime
,
false
));
}
else
{
// 兼容restful风格
config
.
url
=
config
.
url
+
params
+
`
${
createNow
(
joinTime
,
true
)}
`
;
config
.
url
=
config
.
url
+
params
+
`
${
joinTimestamp
(
joinTime
,
true
)}
`
;
config
.
params
=
undefined
;
}
}
else
{
...
...
@@ -173,7 +171,7 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
// 基础接口地址
// baseURL: globSetting.apiUrl,
// 接口可能会有通用的地址部分,可以统一抽取出来
prefixUrl
:
p
refix
,
urlPrefix
:
urlP
refix
,
headers
:
{
'
Content-Type
'
:
ContentTypeEnum
.
JSON
},
// 如果是form-data格式
// headers: { 'Content-Type': ContentTypeEnum.FORM_URLENCODED },
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录