Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
npm
/
glsx-common
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 80bb979a
authored
Sep 26, 2021
by
limin
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
调整http拦截逻辑
1 parent
746f7f08
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
17 additions
and
13 deletions
.gitignore
dist/glsx-common.js
package.json
src/http.js
src/util.js
.gitignore
View file @
80bb979
.DS_Store
.DS_Store
node_modules
node_modules
/dist
# local env files
# local env files
...
...
dist/glsx-common.js
0 → 100644
View file @
80bb979
This diff could not be displayed because it is too large.
package.json
View file @
80bb979
{
{
"name"
:
"glsx-common"
,
"name"
:
"glsx-common"
,
"version"
:
"1.3.
3
"
,
"version"
:
"1.3.
7
"
,
"description"
:
"glsx common"
,
"description"
:
"glsx common"
,
"main"
:
"./dist/glsx-common.js"
,
"main"
:
"./dist/glsx-common.js"
,
"private"
:
false
,
"private"
:
false
,
...
...
src/http.js
View file @
80bb979
...
@@ -38,9 +38,10 @@ Http.prototype.create = function () {
...
@@ -38,9 +38,10 @@ Http.prototype.create = function () {
let
_configSign
=
this
.
customer
.
sign
||
{}
let
_configSign
=
this
.
customer
.
sign
||
{}
data
=
createSign
(
Object
.
assign
({},
_configSign
,
data
),
this
.
customer
.
secret
,
noSignAttr
,
this
.
customer
.
signWay
)
data
=
createSign
(
Object
.
assign
({},
_configSign
,
data
),
this
.
customer
.
secret
,
noSignAttr
,
this
.
customer
.
signWay
)
}
}
if
(
config
.
method
.
toLocaleLowerCase
()
==
'get'
)
{
const
method
=
config
.
method
.
toLocaleLowerCase
()
if
(
method
==
'get'
)
{
config
.
params
=
data
config
.
params
=
data
}
else
if
(
config
.
method
.
toLocaleLowerCase
()
==
'post'
)
{
}
else
if
(
method
==
'post'
)
{
config
.
data
=
qs
.
stringify
(
data
)
config
.
data
=
qs
.
stringify
(
data
)
}
}
return
config
return
config
...
@@ -48,24 +49,27 @@ Http.prototype.create = function () {
...
@@ -48,24 +49,27 @@ Http.prototype.create = function () {
error
=>
Promise
.
reject
(
error
)
error
=>
Promise
.
reject
(
error
)
)
)
this
.
service
.
interceptors
.
response
.
use
(
this
.
service
.
interceptors
.
response
.
use
(
response
=>
{
({
data
:
res
,
config
:
{
returnAll
}
})
=>
{
const
{
response
:
result
}
=
this
.
customer
const
{
const
res
=
response
.
data
response
:
{
code_key
=
'returnCode'
,
errId
=
'errId'
,
code_success_value
=
'0'
,
data_key
=
'data'
},
let
code
=
res
[
result
.
code_key
||
'returnCode'
]
alert
let
errId
=
res
[
result
.
errId
||
'errId'
]
}
=
this
.
customer
let
code
=
res
[
code_key
]
// let errId = res[errId]
// 特殊的code处理,可以增加
// 特殊的code处理,可以增加
switch
(
code
+
''
)
{
switch
(
code
+
''
)
{
case
'200
'
:
case
code_success_value
+
'
'
:
// 请求成功,不弹提示框,成功code可以更改
// 请求成功,不弹提示框,成功code可以更改
break
break
default
:
default
:
this
.
customer
.
alert
&&
this
.
customer
.
alert
(
res
.
message
||
res
.
msg
||
'出错了,请联系管理员'
)
alert
&&
alert
(
res
.
message
||
res
.
msg
||
'出错了,请联系管理员'
)
break
break
}
}
return
re
sponse
.
config
.
returnAll
?
res
:
res
[
result
.
data_key
||
'data'
]
return
re
turnAll
?
res
:
res
[
data_key
]
},
},
error
=>
{
error
=>
{
this
.
customer
.
alert
&&
this
.
customer
.
alert
(
error
.
message
||
'出错了,请联系管理员'
)
const
{
alert
}
=
this
.
customer
alert
&&
alert
(
error
.
message
||
'出错了,请联系管理员'
)
// 返回接口返回的错误信息
// 返回接口返回的错误信息
return
Promise
.
reject
(
error
)
return
Promise
.
reject
(
error
)
}
}
...
...
src/util.js
View file @
80bb979
...
@@ -153,6 +153,7 @@ export const Util = {
...
@@ -153,6 +153,7 @@ export const Util = {
// 创建签名
// 创建签名
createSign
:
function
(
params
,
secret
,
noSignAttr
=
[],
way
=
'sha1'
)
{
createSign
:
function
(
params
,
secret
,
noSignAttr
=
[],
way
=
'sha1'
)
{
delete
params
.
sign
delete
params
.
sign
params
.
timestamp
=
new
Date
().
getTime
()
var
strQs
=
qs
.
stringify
(
params
,
{
arrayFormat
:
'indices'
,
encode
:
false
,
allowDots
:
true
})
var
strQs
=
qs
.
stringify
(
params
,
{
arrayFormat
:
'indices'
,
encode
:
false
,
allowDots
:
true
})
const
objQs
=
strQs
.
split
(
'&'
)
const
objQs
=
strQs
.
split
(
'&'
)
const
collect
=
objQs
.
reduce
((
collect
,
item
)
=>
{
const
collect
=
objQs
.
reduce
((
collect
,
item
)
=>
{
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment