Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
57fe7ccc
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
718
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,发现更多精彩内容 >>
提交
57fe7ccc
编写于
9月 06, 2019
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(app-plus-nvue): add interceptor
上级
16b244e2
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
106 addition
and
3 deletion
+106
-3
build/rollup.config.service.js
build/rollup.config.service.js
+2
-1
packages/uni-app-plus-nvue/dist/service.legacy.js
packages/uni-app-plus-nvue/dist/service.legacy.js
+103
-2
src/platforms/app-plus-nvue/services/api/legacy/api.js
src/platforms/app-plus-nvue/services/api/legacy/api.js
+1
-0
未找到文件。
build/rollup.config.service.js
浏览文件 @
57fe7ccc
...
...
@@ -11,7 +11,8 @@ module.exports = {
plugins
:
[
alias
({
'
uni-core
'
:
path
.
resolve
(
__dirname
,
'
../src/core
'
),
'
uni-shared
'
:
path
.
resolve
(
__dirname
,
'
../src/shared/util.js
'
)
'
uni-shared
'
:
path
.
resolve
(
__dirname
,
'
../src/shared/util.js
'
),
'
uni-helpers
'
:
path
.
resolve
(
__dirname
,
'
../src/core/helpers
'
)
}),
replace
({
__GLOBAL__
:
'
getGlobalUni()
'
,
...
...
packages/uni-app-plus-nvue/dist/service.legacy.js
浏览文件 @
57fe7ccc
const
_toString
=
Object
.
prototype
.
toString
;
const
hasOwnProperty
=
Object
.
prototype
.
hasOwnProperty
;
function
isFn
(
fn
)
{
return
typeof
fn
===
'
function
'
}
function
isPlainObject
(
obj
)
{
return
_toString
.
call
(
obj
)
===
'
[object Object]
'
}
function
hasOwn
(
obj
,
key
)
{
return
hasOwnProperty
.
call
(
obj
,
key
)
}
const
HOOKS
=
[
'
invoke
'
,
'
success
'
,
'
fail
'
,
'
complete
'
,
'
returnValue
'
];
const
globalInterceptors
=
{};
const
scopedInterceptors
=
{};
function
mergeHook
(
parentVal
,
childVal
)
{
const
res
=
childVal
?
parentVal
?
parentVal
.
concat
(
childVal
)
:
Array
.
isArray
(
childVal
)
?
childVal
:
[
childVal
]
:
parentVal
;
return
res
?
dedupeHooks
(
res
)
:
res
}
function
dedupeHooks
(
hooks
)
{
const
res
=
[];
for
(
let
i
=
0
;
i
<
hooks
.
length
;
i
++
)
{
if
(
res
.
indexOf
(
hooks
[
i
])
===
-
1
)
{
res
.
push
(
hooks
[
i
]);
}
}
return
res
}
function
removeHook
(
hooks
,
hook
)
{
const
index
=
hooks
.
indexOf
(
hook
);
if
(
index
!==
-
1
)
{
hooks
.
splice
(
index
,
1
);
}
}
function
mergeInterceptorHook
(
interceptor
,
option
)
{
Object
.
keys
(
option
).
forEach
(
hook
=>
{
if
(
HOOKS
.
indexOf
(
hook
)
!==
-
1
&&
isFn
(
option
[
hook
]))
{
interceptor
[
hook
]
=
mergeHook
(
interceptor
[
hook
],
option
[
hook
]);
}
});
}
function
removeInterceptorHook
(
interceptor
,
option
)
{
if
(
!
interceptor
||
!
option
)
{
return
}
Object
.
keys
(
option
).
forEach
(
hook
=>
{
if
(
HOOKS
.
indexOf
(
hook
)
!==
-
1
&&
isFn
(
option
[
hook
]))
{
removeHook
(
interceptor
[
hook
],
option
[
hook
]);
}
});
}
function
addInterceptor
(
method
,
option
)
{
if
(
typeof
method
===
'
string
'
&&
isPlainObject
(
option
))
{
mergeInterceptorHook
(
scopedInterceptors
[
method
]
||
(
scopedInterceptors
[
method
]
=
{}),
option
);
}
else
if
(
isPlainObject
(
method
))
{
mergeInterceptorHook
(
globalInterceptors
,
method
);
}
}
function
removeInterceptor
(
method
,
option
)
{
if
(
typeof
method
===
'
string
'
)
{
if
(
isPlainObject
(
option
))
{
removeInterceptorHook
(
scopedInterceptors
[
method
],
option
);
}
else
{
delete
scopedInterceptors
[
method
];
}
}
else
if
(
isPlainObject
(
method
))
{
removeInterceptorHook
(
globalInterceptors
,
method
);
}
}
function
wrapperHook
(
hook
)
{
return
function
(
data
)
{
return
hook
(
data
)
||
data
...
...
@@ -109,6 +190,19 @@ function invokeApi (method, api, options, ...params) {
return
api
(
options
,
...
params
)
}
const
promiseInterceptor
=
{
returnValue
(
res
)
{
if
(
!
isPromise
(
res
))
{
return
res
}
return
res
.
then
(
res
=>
{
return
res
[
1
]
}).
catch
(
res
=>
{
return
res
[
0
]
})
}
};
const
SYNC_API_RE
=
/^
\$
|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
;
...
...
@@ -655,6 +749,10 @@ function createLivePusherContext (id, vm) {
return
new
LivePusherContext
(
id
,
elm
)
}
const
interceptors
=
{
promiseInterceptor
};
var
apis
=
/*#__PURE__*/
Object
.
freeze
({
...
...
@@ -665,7 +763,10 @@ var apis = /*#__PURE__*/Object.freeze({
$emit
:
$emit
,
createMapContext
:
createMapContext
,
createVideoContext
:
createVideoContext
,
createLivePusherContext
:
createLivePusherContext
createLivePusherContext
:
createLivePusherContext
,
interceptors
:
interceptors
,
addInterceptor
:
addInterceptor
,
removeInterceptor
:
removeInterceptor
});
function
initUni
(
uni
,
nvue
,
plus
,
BroadcastChannel
)
{
...
...
src/platforms/app-plus-nvue/services/api/legacy/api.js
浏览文件 @
57fe7ccc
...
...
@@ -14,3 +14,4 @@ export {
export
*
from
'
../../../service/api/context/map
'
export
*
from
'
../../../service/api/context/video
'
export
*
from
'
../../../service/api/context/live-pusher
'
export
*
from
'
uni-core/service/api/base/interceptor
'
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录