Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
fetch-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
劳工
fetch-api
Commits
60cae9e1
Commit
60cae9e1
authored
Mar 10, 2022
by
rockyl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
init
parent
66d1a76e
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
7 deletions
+25
-7
index.js
out/index.js
+14
-4
index.js.map
out/index.js.map
+1
-1
package.json
package.json
+2
-1
index.ts
src/index.ts
+8
-1
No files found.
out/index.js
View file @
60cae9e1
"use strict"
;
"use strict"
;
var
__createBinding
=
(
this
&&
this
.
__createBinding
)
||
(
Object
.
create
?
(
function
(
o
,
m
,
k
,
k2
)
{
var
__createBinding
=
(
this
&&
this
.
__createBinding
)
||
(
Object
.
create
?
(
function
(
o
,
m
,
k
,
k2
)
{
if
(
k2
===
undefined
)
k2
=
k
;
if
(
k2
===
undefined
)
k2
=
k
;
Object
.
defineProperty
(
o
,
k2
,
{
enumerable
:
true
,
get
:
function
()
{
return
m
[
k
];
}
});
var
desc
=
Object
.
getOwnPropertyDescriptor
(
m
,
k
);
if
(
!
desc
||
(
"get"
in
desc
?
!
m
.
__esModule
:
desc
.
writable
||
desc
.
configurable
))
{
desc
=
{
enumerable
:
true
,
get
:
function
()
{
return
m
[
k
];
}
};
}
Object
.
defineProperty
(
o
,
k2
,
desc
);
})
:
(
function
(
o
,
m
,
k
,
k2
)
{
})
:
(
function
(
o
,
m
,
k
,
k2
)
{
if
(
k2
===
undefined
)
k2
=
k
;
if
(
k2
===
undefined
)
k2
=
k
;
o
[
k2
]
=
m
[
k
];
o
[
k2
]
=
m
[
k
];
...
@@ -66,7 +70,7 @@ async function fetchApi(uri, { host = '', params, headers = {}, method = 'get',
...
@@ -66,7 +70,7 @@ async function fetchApi(uri, { host = '', params, headers = {}, method = 'get',
break
;
break
;
case
'form'
:
case
'form'
:
options
.
headers
[
'Content-Type'
]
=
'application/x-www-form-urlencoded'
;
options
.
headers
[
'Content-Type'
]
=
'application/x-www-form-urlencoded'
;
options
.
body
=
querystringify_1
.
stringify
(
params
);
options
.
body
=
(
0
,
querystringify_1
.
stringify
)
(
params
);
break
;
break
;
case
'json'
:
case
'json'
:
options
.
headers
[
'Content-Type'
]
=
'application/json'
;
options
.
headers
[
'Content-Type'
]
=
'application/json'
;
...
@@ -76,7 +80,7 @@ async function fetchApi(uri, { host = '', params, headers = {}, method = 'get',
...
@@ -76,7 +80,7 @@ async function fetchApi(uri, { host = '', params, headers = {}, method = 'get',
}
}
else
{
else
{
url
+=
url
.
indexOf
(
'?'
)
<
0
?
'?'
:
''
;
url
+=
url
.
indexOf
(
'?'
)
<
0
?
'?'
:
''
;
url
+=
(
url
.
endsWith
(
'?'
)
?
''
:
'&'
)
+
querystringify_1
.
stringify
(
params
);
url
+=
(
url
.
endsWith
(
'?'
)
?
''
:
'&'
)
+
(
0
,
querystringify_1
.
stringify
)
(
params
);
}
}
}
}
try
{
try
{
...
@@ -84,12 +88,18 @@ async function fetchApi(uri, { host = '', params, headers = {}, method = 'get',
...
@@ -84,12 +88,18 @@ async function fetchApi(uri, { host = '', params, headers = {}, method = 'get',
const
response
=
await
fetchMethod
(
url
,
options
);
const
response
=
await
fetchMethod
(
url
,
options
);
const
respText
=
await
response
.
text
();
const
respText
=
await
response
.
text
();
if
(
response
.
status
===
310
)
{
if
(
response
.
status
===
310
)
{
console
.
log
(
'重定向到:'
+
respText
);
try
{
location
.
href
=
respText
;
location
.
href
=
respText
;
}
}
catch
(
e
)
{
}
}
let
jsonObj
=
JSON
.
parse
(
respText
);
let
jsonObj
=
JSON
.
parse
(
respText
);
if
(
_options
.
successfullyJudge
(
jsonObj
))
{
if
(
_options
.
successfullyJudge
(
jsonObj
))
{
return
jsonObj
.
data
;
return
jsonObj
.
data
;
}
}
console
.
log
(
jsonObj
);
return
Promise
.
reject
(
new
ApiError
(
'call api failed'
,
jsonObj
.
code
,
errMessage
||
jsonObj
[
_options
.
messageField
]));
return
Promise
.
reject
(
new
ApiError
(
'call api failed'
,
jsonObj
.
code
,
errMessage
||
jsonObj
[
_options
.
messageField
]));
}
}
catch
(
e
)
{
catch
(
e
)
{
...
...
out/index.js.map
View file @
60cae9e1
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAMA,oCAAiC;AACjC,mDAAyC;AACzC,+EAA0D;AAE1D,gEAA8C;AAK9C,MAAM,QAAS,SAAQ,KAAK;IAI3B,YAAY,IAAY,EAAE,IAAa,EAAE,OAAgB;QACxD,KAAK,EAAE,CAAC;QAJT,SAAI,GAAW,CAAC,CAAC;QACjB,YAAO,GAAW,EAAE,CAAC;QAKpB,IAAI,IAAI,EAAE;YACT,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;SACjB;QACD,IAAI,IAAI,EAAE;YACT,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;SACjB;QACD,IAAI,OAAO,EAAE;YACZ,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;SACvB;IACF,CAAC;CACD;AAqDD,IAAI,QAAQ,GAAiB;IAC5B,OAAO,EAAE,EAAE;IACX,iBAAiB,EAAE,0CAAY;IAC/B,YAAY,EAAE,KAAK;CACnB,CAAC;AAMF,SAAgB,KAAK,CAAC,OAAqB;IAC1C,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;AAClC,CAAC;AAFD,sBAEC;AAOM,KAAK,UAAU,QAAQ,CAC7B,GAAW,EACX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,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QAEvC,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE;YAE5B,OAAO,CAAC,GAAG,CAAC,OAAO,GAAG,QAAQ,CAAC,CAAA;YAC/B,IAAI;gBACH,QAAQ,CAAC,IAAI,GAAG,QAAQ,CAAC;aACzB;YAAC,OAAO,CAAC,EAAE;aAEX;SACD;QAED,IAAI,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QACnC,IAAI,QAAQ,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE;YACxC,OAAO,OAAO,CAAC,IAAI,CAAC;SACpB;QAED,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;QAEpB,OAAO,OAAO,CAAC,MAAM,CACpB,IAAI,QAAQ,CAAC,iBAAiB,EAAE,OAAO,CAAC,IAAI,EAAE,UAAU,IAAI,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC,CAC3F,CAAC;KACF;IAAC,OAAO,CAAC,EAAE;QACX,OAAO,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;KACzB;AACF,CAAC;AA/ED,4BA+EC"}
\ No newline at end of file
\ No newline at end of file
package.json
View file @
60cae9e1
...
@@ -10,6 +10,7 @@
...
@@ -10,6 +10,7 @@
},
},
"scripts"
:
{
"scripts"
:
{
"dev"
:
"tsc -w"
,
"dev"
:
"tsc -w"
,
"build"
:
"tsc"
"build"
:
"tsc"
,
"release"
:
"npm version patch && npm publish"
}
}
}
}
src/index.ts
View file @
60cae9e1
...
@@ -160,7 +160,12 @@ export async function fetchApi(
...
@@ -160,7 +160,12 @@ export async function fetchApi(
if
(
response
.
status
===
310
)
{
if
(
response
.
status
===
310
)
{
//客户端重定向,用于跨域重定向
//客户端重定向,用于跨域重定向
console
.
log
(
'重定向到:'
+
respText
)
try
{
location
.
href
=
respText
;
location
.
href
=
respText
;
}
catch
(
e
)
{
}
}
}
let
jsonObj
=
JSON
.
parse
(
respText
);
let
jsonObj
=
JSON
.
parse
(
respText
);
...
@@ -168,6 +173,8 @@ export async function fetchApi(
...
@@ -168,6 +173,8 @@ export async function fetchApi(
return
jsonObj
.
data
;
return
jsonObj
.
data
;
}
}
console
.
log
(
jsonObj
)
return
Promise
.
reject
(
return
Promise
.
reject
(
new
ApiError
(
'call api failed'
,
jsonObj
.
code
,
errMessage
||
jsonObj
[
_options
.
messageField
]),
new
ApiError
(
'call api failed'
,
jsonObj
.
code
,
errMessage
||
jsonObj
[
_options
.
messageField
]),
);
);
...
...
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