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 868264dc
authored
Sep 30, 2022
by
杨明
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
formData
1 parent
ce518e43
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
3 deletions
src/http.js
src/util.js
src/http.js
View file @
868264d
...
...
@@ -4,7 +4,7 @@
* @Last Modified by: huyue
* @Last Modified time: 2021-07-16 18:02:05
*/
import
{
createSign
}
from
'./util'
import
util
from
'./util'
import
axios
from
'axios'
import
qs
from
'qs'
function
Http
(
options
=
{})
{
...
...
@@ -32,13 +32,18 @@ Http.prototype.create = function () {
data
.
sessionId
=
this
.
customer
.
sessionId
||
data
.
sessionId
if
(
sign
)
{
let
_configSign
=
this
.
customer
.
sign
||
{}
data
=
createSign
(
Object
.
assign
({},
_configSign
,
data
),
this
.
customer
.
secret
,
noSignAttr
,
this
.
customer
.
signWay
)
data
=
util
.
createSign
(
Object
.
assign
({},
_configSign
,
data
),
this
.
customer
.
secret
,
noSignAttr
,
this
.
customer
.
signWay
)
}
const
method
=
config
.
method
.
toLowerCase
()
if
(
method
==
'get'
)
{
config
.
params
=
data
}
else
if
(
method
==
'post'
)
{
config
.
data
=
qs
.
stringify
(
data
)
if
(
config
.
format
==
'formData'
)
{
config
.
headers
[
'Content-Type'
]
=
'multipart/form-data'
config
.
data
=
util
.
appendFormData
(
data
)
}
else
{
config
.
data
=
qs
.
stringify
(
data
)
}
}
return
config
},
...
...
src/util.js
View file @
868264d
...
...
@@ -173,6 +173,16 @@ export const Util = {
},
[])
collect
.
sign
=
{
sha1
,
md5
}[
way
](
secret
+
str
.
join
(
''
)
+
secret
).
toUpperCase
()
return
collect
},
// 转为formData数据
appendFormData
:
function
(
obj
)
{
const
formData
=
new
FormData
()
for
(
let
k
in
obj
)
{
if
(
obj
.
hasOwnProperty
(
k
))
{
formData
.
append
(
k
,
obj
[
k
])
}
}
return
formData
}
}
export
const
createSign
=
Util
.
createSign
...
...
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