Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
高东东-金蝶建发
/
jf-yzj-employeeself-develop
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8bfc5b04
authored
Feb 08, 2025
by
zqm
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
update: 捕捉请求
parent
b2ed08b0
Pipeline
#24832
failed with stage
in 0 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
36 deletions
index.html
src/shared/polyfill/request.js
index.html
View file @
8bfc5b04
...
...
@@ -2,7 +2,7 @@
<html
lang=
"zh-CN"
>
<head>
<meta
charset=
"utf-8"
>
<title>
self-service
</title>
<title>
员工自助
</title>
<meta
name=
"format-detection"
content=
"telephone=no"
/>
<meta
name=
"viewport"
content=
"initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
>
<script
src=
"miniapp://common/js/qing/qing.js"
></script>
...
...
src/shared/polyfill/request.js
View file @
8bfc5b04
import
axios
from
'axios'
var
originAdapter
=
axios
.
defaults
.
adapter
axios
.
defaults
.
adapter
=
function
(
config
)
{
axios
.
defaults
.
adapter
=
function
(
config
)
{
if
(
!
/^https
?
/
.
test
(
config
.
url
))
{
return
originAdapter
(
config
)
}
...
...
@@ -23,7 +23,7 @@ function isFormData(fd) {
function
formData2obj
(
fd
)
{
var
data
=
{}
for
(
var
p
of
fd
.
entries
())
{
data
[
p
[
0
]]
=
p
[
1
]
data
[
p
[
0
]
]
=
p
[
1
]
}
return
data
}
...
...
@@ -33,15 +33,12 @@ function params2object(url) {
if
(
typeof
url
===
'object'
)
{
return
url
}
else
if
(
typeof
url
===
'string'
)
{
url
.
replace
(
/^.*
\?
|#.*$/g
,
''
)
.
split
(
'&'
)
.
forEach
((
n
)
=>
{
n
=
n
.
split
(
'='
)
if
(
n
.
length
===
2
)
{
params
[
n
[
0
]]
=
decodeURIComponent
(
n
[
1
])
}
})
url
.
replace
(
/^.*
\?
|#.*$/g
,
''
).
split
(
'&'
).
forEach
((
n
)
=>
{
n
=
n
.
split
(
'='
)
if
(
n
.
length
===
2
)
{
params
[
n
[
0
]
]
=
decodeURIComponent
(
n
[
1
])
}
})
}
return
params
}
...
...
@@ -65,33 +62,30 @@ function request(opt) {
opt
.
url
=
opt
.
url
.
replace
(
/^
\s
+|
\s
+$/g
,
''
)
// 将params拼接到url中
opt
.
url
=
opt
.
url
.
split
(
'?'
)[
0
]
+
opt
.
url
.
split
(
'?'
)[
0
]
+
'?'
+
Object
.
keys
(
urlParams
)
.
map
((
key
)
=>
{
var
val
=
urlParams
[
key
]
if
(
isObject
(
val
))
{
val
=
JSON
.
stringify
(
val
)
val
=
encodeURIComponent
(
val
)
}
else
if
(
/
[^\x
00-
\x
ff
]
/
.
test
(
val
))
{
val
=
encodeURIComponent
(
val
)
}
return
key
+
'='
+
val
})
.
join
(
'&'
)
Object
.
keys
(
urlParams
).
map
((
key
)
=>
{
var
val
=
urlParams
[
key
]
if
(
isObject
(
val
))
{
val
=
JSON
.
stringify
(
val
)
val
=
encodeURIComponent
(
val
)
}
else
if
(
/
[^\x
00-
\x
ff
]
/
.
test
(
val
))
{
val
=
encodeURIComponent
(
val
)
}
return
key
+
'='
+
val
}).
join
(
'&'
)
// post非json即是form。
if
(
opt
.
method
.
toLowerCase
()
===
'post'
)
{
var
data
=
opt
.
data
const
headers
=
opt
.
headers
const
contentType
=
headers
[
'content-type'
]
||
headers
[
'Content-Type'
]
||
headers
[
'CONTENT-TYPE'
]
||
''
const
contentType
=
headers
[
'content-type'
]
||
headers
[
'Content-Type'
]
||
headers
[
'CONTENT-TYPE'
]
||
''
if
(
contentType
.
indexOf
(
'application/json'
)
!==
-
1
)
{
serializer
=
'json'
}
if
((
serializer
===
'form'
)
&&
isFormData
(
data
))
{
opt
.
data
=
formData2obj
(
data
)
}
else
if
(
isString
(
data
))
{
}
else
if
(
isString
(
data
))
{
if
(
serializer
===
'json'
)
{
try
{
opt
.
data
=
JSON
.
parse
(
data
)
...
...
@@ -108,8 +102,8 @@ function request(opt) {
opt
.
headers
=
opt
.
headers
||
{}
const
headers
=
{}
// headers字段值必须是字符串型
Object
.
keys
(
opt
.
headers
).
forEach
(
function
(
key
)
{
var
val
=
opt
.
headers
[
key
]
Object
.
keys
(
opt
.
headers
).
forEach
(
function
(
key
)
{
var
val
=
opt
.
headers
[
key
]
if
(
val
)
{
var
type
=
typeof
val
if
(
type
!==
'string'
)
{
...
...
@@ -118,15 +112,14 @@ function request(opt) {
// 因content-type可能存在大小写不规范,这里先过滤掉,后面根据serializer统一添加
var
_key
=
key
.
toLowerCase
()
if
(
_key
!==
'content-type'
)
{
headers
[
_key
]
=
val
headers
[
_key
]
=
val
}
}
})
// 根据serializer统一添加content-type
headers
[
'content-type'
]
=
serializer
===
'json'
?
'application/json'
:
'application/x-www-form-urlencoded'
headers
[
'content-type'
]
=
serializer
===
'json'
?
'application/json'
:
'application/x-www-form-urlencoded'
opt
.
headers
=
headers
return
new
Promise
(
function
(
resolve
,
reject
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
qing
.
call
(
'request'
,
{
url
:
opt
.
url
,
method
:
opt
.
method
.
toUpperCase
(),
...
...
@@ -134,7 +127,9 @@ function request(opt) {
header
:
opt
.
headers
,
data
:
opt
.
data
||
{},
dataType
:
opt
.
dataType
,
success
:
function
(
resp
)
{
success
:
function
(
resp
)
{
console
.
log
(
'qing success opt>>'
,
opt
)
console
.
log
(
'qing success resp>>'
,
resp
)
var
response
=
{
data
:
resp
.
data
,
status
:
resp
.
statusCode
,
...
...
@@ -158,7 +153,9 @@ function request(opt) {
reject
(
error
)
}
},
error
:
function
(
e
)
{
error
:
function
(
e
)
{
console
.
log
(
'qing error opt>>'
,
opt
)
console
.
log
(
'qing error e>>'
,
e
)
var
error
=
new
Error
(
e
)
error
.
config
=
opt
reject
(
error
)
...
...
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