Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
7ba48ed7
U
uni-app
项目概览
DCloud
/
uni-app
大约 1 个月 前同步成功
通知
702
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7ba48ed7
编写于
4月 10, 2020
作者:
d-u-a
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
quickapp: add api request
上级
388ee882
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
143 addition
and
1 deletion
+143
-1
src/platforms/quickapp-vue/service/api/network/request.js
src/platforms/quickapp-vue/service/api/network/request.js
+134
-0
src/platforms/quickapp-vue/service/base-api.js
src/platforms/quickapp-vue/service/base-api.js
+2
-1
src/platforms/quickapp-vue/service/bridge.js
src/platforms/quickapp-vue/service/bridge.js
+4
-0
src/platforms/quickapp-vue/service/platform-api.js
src/platforms/quickapp-vue/service/platform-api.js
+3
-0
未找到文件。
src/platforms/quickapp-vue/service/api/network/request.js
0 → 100644
浏览文件 @
7ba48ed7
import
{
publish
}
from
'
../../bridge
'
import
stream
from
'
@system.fetch
'
let
requestTaskId
=
0
const
requestTasks
=
{}
const
publishStateChange
=
res
=>
{
publish
(
'
onRequestTaskStateChange
'
,
res
)
delete
requestTasks
[
requestTaskId
]
}
export
function
createRequestTaskById
(
requestTaskId
,
{
url
,
data
,
header
,
method
=
'
GET
'
,
responseType
,
sslVerify
=
true
}
=
{})
{
let
abortTimeout
let
aborted
const
timeout
=
60000
if
(
timeout
)
{
abortTimeout
=
setTimeout
(()
=>
{
aborted
=
true
publishStateChange
({
requestTaskId
,
state
:
'
fail
'
,
statusCode
:
0
,
errMsg
:
'
timeout
'
})
},
(
timeout
+
100
))
}
const
options
=
{
method
,
url
:
url
.
trim
(),
header
,
type
:
responseType
,
timeout
:
timeout
||
6
e5
}
if
(
method
!==
'
GET
'
)
{
options
.
body
=
data
}
try
{
stream
.
fetch
({
...
options
,
success
:
({
code
,
data
,
headers
})
=>
{
console
.
log
(
data
)
if
(
aborted
)
{
return
}
if
(
abortTimeout
)
{
clearTimeout
(
abortTimeout
)
}
const
statusCode
=
code
if
(
statusCode
>
0
)
{
publishStateChange
({
requestTaskId
,
state
:
'
success
'
,
data
:
data
,
statusCode
,
header
:
headers
})
}
else
{
publishStateChange
({
requestTaskId
,
state
:
'
fail
'
,
statusCode
,
errMsg
:
'
abort statusCode:
'
+
statusCode
})
}
},
fail
:
(
data
,
code
)
=>
{
publishStateChange
({
requestTaskId
,
state
:
'
fail
'
,
statusCode
:
code
,
errMsg
:
'
abort statusCode:
'
+
code
})
}
})
requestTasks
[
requestTaskId
]
=
{
abort
()
{
aborted
=
true
if
(
abortTimeout
)
{
clearTimeout
(
abortTimeout
)
}
publishStateChange
({
requestTaskId
,
state
:
'
fail
'
,
statusCode
:
0
,
errMsg
:
'
abort
'
})
}
}
}
catch
(
e
)
{
return
{
requestTaskId
,
errMsg
:
'
createRequestTask:fail
'
}
}
return
{
requestTaskId
,
errMsg
:
'
createRequestTask:ok
'
}
}
export
function
createRequestTask
(
args
)
{
return
createRequestTaskById
(
++
requestTaskId
,
args
)
}
export
function
operateRequestTask
({
requestTaskId
,
operationType
}
=
{})
{
const
requestTask
=
requestTasks
[
requestTaskId
]
if
(
requestTask
&&
operationType
===
'
abort
'
)
{
requestTask
.
abort
()
return
{
errMsg
:
'
operateRequestTask:ok
'
}
}
return
{
errMsg
:
'
operateRequestTask:fail
'
}
}
src/platforms/quickapp-vue/service/base-api.js
浏览文件 @
7ba48ed7
...
...
@@ -5,5 +5,6 @@ export * from 'uni-core/service/api/base/interceptor'
export
*
from
'
uni-core/service/api/base/upx2px
'
export
*
from
'
uni-core/service/api/context/audio
'
export
*
from
'
uni-core/service/api/context/background-audio
'
export
*
from
'
uni-core/service/api/context/background-audio
'
export
*
from
'
uni-core/service/api/network/request
'
// TODO
src/platforms/quickapp-vue/service/bridge.js
浏览文件 @
7ba48ed7
export
function
invoke
(...
args
)
{
return
global
.
UniServiceJSBridge
.
invokeCallbackHandler
(...
args
)
}
export
function
publish
(
name
,
...
args
)
{
return
global
.
UniServiceJSBridge
.
emit
(
'
api.
'
+
name
,
...
args
)
}
src/platforms/quickapp-vue/service/platform-api.js
浏览文件 @
7ba48ed7
...
...
@@ -4,3 +4,6 @@ export * from './api/route/redirect-to'
// device
export
*
from
'
./api/device/clipboard
'
// network
export
*
from
'
./api/network/request
'
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录