Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz-Vue-Mob-R7-Res
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7前端标准模板
iBiz-Vue-Mob-R7-Res
提交
bd9d6d19
提交
bd9d6d19
编写于
10月 13, 2020
作者:
KK
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复后台报错前端无任何提示bug & 代码格式化
上级
731ea5e4
变更
2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
40 行增加
和
34 行删除
+40
-34
http.ts
src/ibiz-core/utils/http/http.ts
+37
-25
interceptor.ts
src/utils/interceptor/interceptor.ts
+3
-9
未找到文件。
src/ibiz-core/utils/http/http.ts
浏览文件 @
bd9d6d19
import
axios
,
{
AxiosResponse
}
from
'axios'
;
import
qs
from
'qs'
;
import
{
HttpResponse
}
from
'./http-response'
;
import
{
Notice
}
from
'@/utils/notice/notice'
;
import
{
Loading
}
from
'../loading/loading'
;
/**
* Http net 对象
...
...
@@ -24,6 +25,15 @@ export class Http {
return
this
.
Http
;
}
/**
* 提示工具类
*
* @protected
* @type {Notice}
* @memberof UIActionBase
*/
private
notice
:
Notice
=
Notice
.
getInstance
();
/**
* 单例变量声明
*
...
...
@@ -106,36 +116,36 @@ export class Http {
* @returns {Promise<any>}
* @memberof Http
*/
public
get
(
url
:
string
,
params
:
any
=
{},
isloading
?:
boolean
,
serialnumber
?:
number
):
Promise
<
any
>
{
public
get
(
url
:
string
,
params
:
any
=
{},
isloading
?:
boolean
,
serialnumber
?:
number
):
Promise
<
any
>
{
params
=
this
.
handleRequestData
(
params
);
if
(
params
.
srfparentdata
)
{
Object
.
assign
(
params
,
params
.
srfparentdata
);
if
(
params
.
srfparentdata
)
{
Object
.
assign
(
params
,
params
.
srfparentdata
);
delete
params
.
srfparentdata
;
}
if
((
Object
.
keys
(
params
)).
length
>
0
)
{
let
tempParam
:
any
=
{};
let
sort
:
any
=
null
;
Object
.
keys
(
params
).
forEach
((
item
:
any
)
=>
{
if
(
params
[
item
]
||
Object
.
is
(
params
[
item
],
0
)
)
{
if
(
Object
.
is
(
item
,
'sort'
))
{
sort
=
params
[
item
];
}
else
{
tempParam
[
item
]
=
params
[
item
];
if
((
Object
.
keys
(
params
)).
length
>
0
)
{
let
tempParam
:
any
=
{};
let
sort
:
any
=
null
;
Object
.
keys
(
params
).
forEach
((
item
:
any
)
=>
{
if
(
params
[
item
]
||
Object
.
is
(
params
[
item
],
0
))
{
if
(
Object
.
is
(
item
,
'sort'
))
{
sort
=
params
[
item
];
}
else
{
tempParam
[
item
]
=
params
[
item
];
}
}
})
url
+=
`?
${
qs
.
stringify
(
tempParam
)}
`
;
if
(
sort
)
{
url
+=
'&sort='
+
sort
;
if
(
sort
)
{
url
+=
'&sort='
+
sort
;
}
}
}
if
(
isloading
)
{
this
.
beginLoading
();
}
return
new
Promise
((
resolve
:
any
,
reject
:
any
)
=>
{
axios
.
get
(
url
).
then
((
response
:
AxiosResponse
)
=>
{
resolve
(
this
.
doResponseRresult
(
response
,
resolve
,
isloading
,
serialnumber
));
}).
catch
((
response
:
AxiosResponse
)
=>
{
reject
(
this
.
doResponseRresult
(
response
,
reject
,
isloading
,
serialnumber
));
});
...
...
@@ -151,19 +161,19 @@ export class Http {
* @returns {Promise<any>}
* @memberof Http
*/
public
delete
(
url
:
string
,
isloading
?:
boolean
,
data
?:
any
,
serialnumber
?:
number
):
Promise
<
any
>
{
public
delete
(
url
:
string
,
isloading
?:
boolean
,
data
?:
any
,
serialnumber
?:
number
):
Promise
<
any
>
{
if
(
isloading
)
{
this
.
beginLoading
();
}
return
new
Promise
((
resolve
:
any
,
reject
:
any
)
=>
{
if
(
!
data
)
{
if
(
!
data
)
{
axios
.
delete
(
url
).
then
((
response
:
any
)
=>
{
resolve
(
this
.
doResponseRresult
(
response
,
resolve
,
isloading
,
serialnumber
));
}).
catch
((
response
:
any
)
=>
{
reject
(
this
.
doResponseRresult
(
response
,
reject
,
isloading
,
serialnumber
));
});
}
else
{
axios
.
delete
(
url
,
{
data
:
data
}).
then
((
response
:
any
)
=>
{
}
else
{
axios
.
delete
(
url
,
{
data
:
data
}).
then
((
response
:
any
)
=>
{
resolve
(
this
.
doResponseRresult
(
response
,
resolve
,
isloading
,
serialnumber
));
}).
catch
((
response
:
any
)
=>
{
reject
(
this
.
doResponseRresult
(
response
,
reject
,
isloading
,
serialnumber
));
...
...
@@ -217,8 +227,10 @@ export class Http {
if
(
response
.
status
===
200
)
{
return
new
HttpResponse
(
200
,
response
.
data
,
undefined
,
response
.
headers
);
}
this
.
notice
.
error
(
response
.
data
.
message
?
response
.
data
.
message
:
HttpResponse
.
getStatusMessage
(
response
.
status
));
return
new
HttpResponse
(
response
.
status
,
response
.
data
,
{
code
:
101
,
message
:
HttpResponse
.
getStatusMessage
(
response
.
status
)
},
response
.
headers
)
}
this
.
notice
.
error
(
HttpResponse
.
getStatusMessage
(
response
.
status
));
return
new
HttpResponse
(
500
,
null
,
{
code
:
100
,
message
:
'请求发生异常,无返回结果!'
},
response
.
headers
);
}
...
...
@@ -245,8 +257,8 @@ export class Http {
}
setTimeout
(()
=>
{
if
(
this
.
loadingCount
===
0
)
{
// todo 停止加载
Loading
.
hidden
();
// todo 停止加载
Loading
.
hidden
();
}
},
500
);
}
...
...
@@ -258,11 +270,11 @@ export class Http {
* @param data
* @memberof Http
*/
private
handleRequestData
(
data
:
any
)
{
if
(
data
.
srfsessionkey
)
{
private
handleRequestData
(
data
:
any
)
{
if
(
data
.
srfsessionkey
)
{
delete
data
.
srfsessionkey
;
}
if
(
data
.
srfsessionid
)
{
if
(
data
.
srfsessionid
)
{
delete
data
.
srfsessionid
;
}
return
data
;
...
...
src/utils/interceptor/interceptor.ts
浏览文件 @
bd9d6d19
...
...
@@ -3,7 +3,6 @@ import axios from 'axios';
import
Router
from
'vue-router'
;
import
i18n
from
'@/locale'
;
import
ignoreProxyMap
from
'./ignore-proxy'
;
import
{
Loading
}
from
'@/ibiz-core/utils'
;
/**
* 拦截器
*
...
...
@@ -30,7 +29,7 @@ export class Interceptors {
*/
private
store
:
Store
<
any
>
|
any
;
/**
* 单列对象
...
...
@@ -87,8 +86,8 @@ export class Interceptors {
const
token
=
window
.
localStorage
.
getItem
(
'token'
);
config
.
headers
.
Authorization
=
`Bearer
${
token
}
`
;
}
config
.
headers
[
'Accept-Language'
]
=
i18n
.
locale
;
config
.
headers
[
'Accept-Language'
]
=
i18n
.
locale
;
// 混合 app 代理处理
if
(
Object
.
is
(
process
.
env
.
VUE_APP_CURRENTMODE
,
'hybridapp'
)
&&
!
config
.
url
.
startsWith
(
'https://'
)
&&
!
config
.
url
.
startsWith
(
'http://'
))
{
if
(
!
ignoreProxyMap
.
has
(
config
.
url
))
{
...
...
@@ -104,22 +103,17 @@ export class Interceptors {
return
response
;
},
(
error
:
any
)
=>
{
error
=
error
?
error
:
{
response
:
{}
};
// tslint:disable-next-line:prefer-const
let
{
response
:
res
}
=
error
;
let
{
data
:
_data
}
=
res
;
if
(
res
.
status
===
401
)
{
// Loading.hidden();
this
.
doNoLogin
(
_data
.
data
);
}
if
(
res
.
status
===
404
)
{
// Loading.hidden();
this
.
router
.
push
({
path
:
'/404'
});
}
else
if
(
res
.
status
===
500
)
{
// Loading.hidden();
this
.
router
.
push
({
path
:
'/500'
});
}
return
Promise
.
reject
(
res
);
});
}
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录