Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
c9188a20
U
uni-app
项目概览
DCloud
/
uni-app
6 个月 前同步成功
通知
806
Star
38709
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
8
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
8
Issue
8
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
c9188a20
编写于
1月 09, 2023
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(interceptor): pass params to callback
上级
665d51a1
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
107 addition
and
84 deletion
+107
-84
packages/uni-api/src/helpers/interceptor.ts
packages/uni-api/src/helpers/interceptor.ts
+15
-7
packages/uni-app-plus/dist/uni.runtime.esm.js
packages/uni-app-plus/dist/uni.runtime.esm.js
+8
-7
packages/uni-h5/dist/uni-h5.cjs.js
packages/uni-h5/dist/uni-h5.cjs.js
+10
-7
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+10
-7
packages/uni-mp-alipay/dist/uni.api.esm.js
packages/uni-mp-alipay/dist/uni.api.esm.js
+8
-7
packages/uni-mp-baidu/dist/uni.api.esm.js
packages/uni-mp-baidu/dist/uni.api.esm.js
+8
-7
packages/uni-mp-kuaishou/dist/uni.api.esm.js
packages/uni-mp-kuaishou/dist/uni.api.esm.js
+8
-7
packages/uni-mp-lark/dist/uni.api.esm.js
packages/uni-mp-lark/dist/uni.api.esm.js
+8
-7
packages/uni-mp-qq/dist/uni.api.esm.js
packages/uni-mp-qq/dist/uni.api.esm.js
+8
-7
packages/uni-mp-toutiao/dist/uni.api.esm.js
packages/uni-mp-toutiao/dist/uni.api.esm.js
+8
-7
packages/uni-mp-weixin/dist/uni.api.esm.js
packages/uni-mp-weixin/dist/uni.api.esm.js
+8
-7
packages/uni-quickapp-webview/dist/uni.api.esm.js
packages/uni-quickapp-webview/dist/uni.api.esm.js
+8
-7
未找到文件。
packages/uni-api/src/helpers/interceptor.ts
浏览文件 @
c9188a20
...
...
@@ -20,20 +20,24 @@ export type Interceptors = { [P in HOOKS]?: Function[] }
export
const
globalInterceptors
:
Interceptors
=
{}
export
const
scopedInterceptors
:
{
[
key
:
string
]:
Interceptors
}
=
{}
function
wrapperHook
(
hook
:
Function
)
{
function
wrapperHook
(
hook
:
Function
,
params
?:
Record
<
string
,
any
>
)
{
return
function
(
data
:
unknown
)
{
return
hook
(
data
)
||
data
return
hook
(
data
,
params
)
||
data
}
}
function
queue
(
hooks
:
Function
[],
data
:
unknown
):
Promise
<
any
>
{
function
queue
(
hooks
:
Function
[],
data
:
unknown
,
params
?:
Record
<
string
,
any
>
):
Promise
<
any
>
{
let
promise
:
any
=
false
for
(
let
i
=
0
;
i
<
hooks
.
length
;
i
++
)
{
const
hook
=
hooks
[
i
]
if
(
promise
)
{
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
))
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
,
params
))
}
else
{
const
res
=
hook
(
data
)
const
res
=
hook
(
data
,
params
)
if
(
isPromise
(
res
))
{
promise
=
Promise
.
resolve
(
res
)
}
...
...
@@ -66,7 +70,7 @@ function wrapperOptions(
}
const
oldCallback
=
options
[
name
]
options
[
name
]
=
function
callbackInterceptor
(
res
:
unknown
)
{
queue
(
hooks
,
res
).
then
((
res
:
unknown
)
=>
{
queue
(
hooks
,
res
,
options
).
then
((
res
:
unknown
)
=>
{
return
(
isFunction
(
oldCallback
)
&&
oldCallback
(
res
))
||
res
})
}
...
...
@@ -122,7 +126,11 @@ export function invokeApi(
if
(
isArray
(
interceptor
.
invoke
))
{
const
res
=
queue
(
interceptor
.
invoke
,
options
)
return
res
.
then
((
options
)
=>
{
return
api
(
wrapperOptions
(
interceptor
,
options
),
...
params
)
// 重新访问 getApiInterceptorHooks, 允许 invoke 中再次调用 addInterceptor,removeInterceptor
return
api
(
wrapperOptions
(
getApiInterceptorHooks
(
method
),
options
),
...
params
)
})
}
else
{
return
api
(
wrapperOptions
(
interceptor
,
options
),
...
params
)
...
...
packages/uni-app-plus/dist/uni.runtime.esm.js
浏览文件 @
c9188a20
...
...
@@ -358,20 +358,20 @@ const HOOK_FAIL = 'fail';
const HOOK_COMPLETE = 'complete';
const globalInterceptors = {};
const scopedInterceptors = {};
function wrapperHook(hook) {
function wrapperHook(hook
, params
) {
return function (data) {
return hook(data) || data;
return hook(data
, params
) || data;
};
}
function queue(hooks, data) {
function queue(hooks, data
, params
) {
let promise = false;
for (let i = 0; i < hooks.length; i++) {
const hook = hooks[i];
if (promise) {
promise = Promise.resolve(wrapperHook(hook));
promise = Promise.resolve(wrapperHook(hook
, params
));
}
else {
const res = hook(data);
const res = hook(data
, params
);
if (isPromise(res)) {
promise = Promise.resolve(res);
}
...
...
@@ -398,7 +398,7 @@ function wrapperOptions(interceptors, options = {}) {
}
const oldCallback = options[name];
options[name] = function callbackInterceptor(res) {
queue(hooks, res).then((res) => {
queue(hooks, res
, options
).then((res) => {
return (isFunction(oldCallback) && oldCallback(res)) || res;
});
};
...
...
@@ -442,7 +442,8 @@ function invokeApi(method, api, options, params) {
if (isArray(interceptor.invoke)) {
const res = queue(interceptor.invoke, options);
return res.then((options) => {
return api(wrapperOptions(interceptor, options), ...params);
// 重新访问 getApiInterceptorHooks, 允许 invoke 中再次调用 addInterceptor,removeInterceptor
return api(wrapperOptions(getApiInterceptorHooks(method), options), ...params);
});
}
else {
...
...
packages/uni-h5/dist/uni-h5.cjs.js
浏览文件 @
c9188a20
...
...
@@ -1273,19 +1273,19 @@ const HOOK_FAIL = "fail";
const
HOOK_COMPLETE
=
"
complete
"
;
const
globalInterceptors
=
{};
const
scopedInterceptors
=
{};
function
wrapperHook
(
hook
)
{
function
wrapperHook
(
hook
,
params
)
{
return
function
(
data
)
{
return
hook
(
data
)
||
data
;
return
hook
(
data
,
params
)
||
data
;
};
}
function
queue
(
hooks
,
data
)
{
function
queue
(
hooks
,
data
,
params
)
{
let
promise
=
false
;
for
(
let
i
=
0
;
i
<
hooks
.
length
;
i
++
)
{
const
hook
=
hooks
[
i
];
if
(
promise
)
{
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
));
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
,
params
));
}
else
{
const
res
=
hook
(
data
);
const
res
=
hook
(
data
,
params
);
if
(
shared
.
isPromise
(
res
))
{
promise
=
Promise
.
resolve
(
res
);
}
...
...
@@ -1315,7 +1315,7 @@ function wrapperOptions(interceptors, options = {}) {
}
const
oldCallback
=
options
[
name
];
options
[
name
]
=
function
callbackInterceptor
(
res
)
{
queue
(
hooks
,
res
).
then
((
res2
)
=>
{
queue
(
hooks
,
res
,
options
).
then
((
res2
)
=>
{
return
shared
.
isFunction
(
oldCallback
)
&&
oldCallback
(
res2
)
||
res2
;
});
};
...
...
@@ -1361,7 +1361,10 @@ function invokeApi(method, api2, options, params) {
if
(
shared
.
isArray
(
interceptor
.
invoke
))
{
const
res
=
queue
(
interceptor
.
invoke
,
options
);
return
res
.
then
((
options2
)
=>
{
return
api2
(
wrapperOptions
(
interceptor
,
options2
),
...
params
);
return
api2
(
wrapperOptions
(
getApiInterceptorHooks
(
method
),
options2
),
...
params
);
});
}
else
{
return
api2
(
wrapperOptions
(
interceptor
,
options
),
...
params
);
...
...
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
c9188a20
...
...
@@ -2866,19 +2866,19 @@ const HOOK_FAIL = "fail";
const HOOK_COMPLETE = "complete";
const globalInterceptors = {};
const scopedInterceptors = {};
function wrapperHook(hook) {
function wrapperHook(hook
, params
) {
return function(data) {
return hook(data) || data;
return hook(data
, params
) || data;
};
}
function queue(hooks, data) {
function queue(hooks, data
, params
) {
let promise = false;
for (let i = 0; i < hooks.length; i++) {
const hook = hooks[i];
if (promise) {
promise = Promise.resolve(wrapperHook(hook));
promise = Promise.resolve(wrapperHook(hook
, params
));
} else {
const res = hook(data);
const res = hook(data
, params
);
if (isPromise(res)) {
promise = Promise.resolve(res);
}
...
...
@@ -2908,7 +2908,7 @@ function wrapperOptions(interceptors2, options = {}) {
}
const oldCallback = options[name];
options[name] = function callbackInterceptor(res) {
queue(hooks, res).then((res2) => {
queue(hooks, res
, options
).then((res2) => {
return isFunction(oldCallback) && oldCallback(res2) || res2;
});
};
...
...
@@ -2954,7 +2954,10 @@ function invokeApi(method, api2, options, params) {
if (isArray(interceptor.invoke)) {
const res = queue(interceptor.invoke, options);
return res.then((options2) => {
return api2(wrapperOptions(interceptor, options2), ...params);
return api2(
wrapperOptions(getApiInterceptorHooks(method), options2),
...params
);
});
} else {
return api2(wrapperOptions(interceptor, options), ...params);
...
...
packages/uni-mp-alipay/dist/uni.api.esm.js
浏览文件 @
c9188a20
...
...
@@ -227,20 +227,20 @@ const HOOK_FAIL = 'fail';
const
HOOK_COMPLETE
=
'
complete
'
;
const
globalInterceptors
=
{};
const
scopedInterceptors
=
{};
function
wrapperHook
(
hook
)
{
function
wrapperHook
(
hook
,
params
)
{
return
function
(
data
)
{
return
hook
(
data
)
||
data
;
return
hook
(
data
,
params
)
||
data
;
};
}
function
queue
(
hooks
,
data
)
{
function
queue
(
hooks
,
data
,
params
)
{
let
promise
=
false
;
for
(
let
i
=
0
;
i
<
hooks
.
length
;
i
++
)
{
const
hook
=
hooks
[
i
];
if
(
promise
)
{
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
));
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
,
params
));
}
else
{
const
res
=
hook
(
data
);
const
res
=
hook
(
data
,
params
);
if
(
isPromise
(
res
))
{
promise
=
Promise
.
resolve
(
res
);
}
...
...
@@ -267,7 +267,7 @@ function wrapperOptions(interceptors, options = {}) {
}
const
oldCallback
=
options
[
name
];
options
[
name
]
=
function
callbackInterceptor
(
res
)
{
queue
(
hooks
,
res
).
then
((
res
)
=>
{
queue
(
hooks
,
res
,
options
).
then
((
res
)
=>
{
return
(
isFunction
(
oldCallback
)
&&
oldCallback
(
res
))
||
res
;
});
};
...
...
@@ -311,7 +311,8 @@ function invokeApi(method, api, options, params) {
if
(
isArray
(
interceptor
.
invoke
))
{
const
res
=
queue
(
interceptor
.
invoke
,
options
);
return
res
.
then
((
options
)
=>
{
return
api
(
wrapperOptions
(
interceptor
,
options
),
...
params
);
// 重新访问 getApiInterceptorHooks, 允许 invoke 中再次调用 addInterceptor,removeInterceptor
return
api
(
wrapperOptions
(
getApiInterceptorHooks
(
method
),
options
),
...
params
);
});
}
else
{
...
...
packages/uni-mp-baidu/dist/uni.api.esm.js
浏览文件 @
c9188a20
...
...
@@ -227,20 +227,20 @@ const HOOK_FAIL = 'fail';
const
HOOK_COMPLETE
=
'
complete
'
;
const
globalInterceptors
=
{};
const
scopedInterceptors
=
{};
function
wrapperHook
(
hook
)
{
function
wrapperHook
(
hook
,
params
)
{
return
function
(
data
)
{
return
hook
(
data
)
||
data
;
return
hook
(
data
,
params
)
||
data
;
};
}
function
queue
(
hooks
,
data
)
{
function
queue
(
hooks
,
data
,
params
)
{
let
promise
=
false
;
for
(
let
i
=
0
;
i
<
hooks
.
length
;
i
++
)
{
const
hook
=
hooks
[
i
];
if
(
promise
)
{
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
));
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
,
params
));
}
else
{
const
res
=
hook
(
data
);
const
res
=
hook
(
data
,
params
);
if
(
isPromise
(
res
))
{
promise
=
Promise
.
resolve
(
res
);
}
...
...
@@ -267,7 +267,7 @@ function wrapperOptions(interceptors, options = {}) {
}
const
oldCallback
=
options
[
name
];
options
[
name
]
=
function
callbackInterceptor
(
res
)
{
queue
(
hooks
,
res
).
then
((
res
)
=>
{
queue
(
hooks
,
res
,
options
).
then
((
res
)
=>
{
return
(
isFunction
(
oldCallback
)
&&
oldCallback
(
res
))
||
res
;
});
};
...
...
@@ -311,7 +311,8 @@ function invokeApi(method, api, options, params) {
if
(
isArray
(
interceptor
.
invoke
))
{
const
res
=
queue
(
interceptor
.
invoke
,
options
);
return
res
.
then
((
options
)
=>
{
return
api
(
wrapperOptions
(
interceptor
,
options
),
...
params
);
// 重新访问 getApiInterceptorHooks, 允许 invoke 中再次调用 addInterceptor,removeInterceptor
return
api
(
wrapperOptions
(
getApiInterceptorHooks
(
method
),
options
),
...
params
);
});
}
else
{
...
...
packages/uni-mp-kuaishou/dist/uni.api.esm.js
浏览文件 @
c9188a20
...
...
@@ -227,20 +227,20 @@ const HOOK_FAIL = 'fail';
const
HOOK_COMPLETE
=
'
complete
'
;
const
globalInterceptors
=
{};
const
scopedInterceptors
=
{};
function
wrapperHook
(
hook
)
{
function
wrapperHook
(
hook
,
params
)
{
return
function
(
data
)
{
return
hook
(
data
)
||
data
;
return
hook
(
data
,
params
)
||
data
;
};
}
function
queue
(
hooks
,
data
)
{
function
queue
(
hooks
,
data
,
params
)
{
let
promise
=
false
;
for
(
let
i
=
0
;
i
<
hooks
.
length
;
i
++
)
{
const
hook
=
hooks
[
i
];
if
(
promise
)
{
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
));
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
,
params
));
}
else
{
const
res
=
hook
(
data
);
const
res
=
hook
(
data
,
params
);
if
(
isPromise
(
res
))
{
promise
=
Promise
.
resolve
(
res
);
}
...
...
@@ -267,7 +267,7 @@ function wrapperOptions(interceptors, options = {}) {
}
const
oldCallback
=
options
[
name
];
options
[
name
]
=
function
callbackInterceptor
(
res
)
{
queue
(
hooks
,
res
).
then
((
res
)
=>
{
queue
(
hooks
,
res
,
options
).
then
((
res
)
=>
{
return
(
isFunction
(
oldCallback
)
&&
oldCallback
(
res
))
||
res
;
});
};
...
...
@@ -311,7 +311,8 @@ function invokeApi(method, api, options, params) {
if
(
isArray
(
interceptor
.
invoke
))
{
const
res
=
queue
(
interceptor
.
invoke
,
options
);
return
res
.
then
((
options
)
=>
{
return
api
(
wrapperOptions
(
interceptor
,
options
),
...
params
);
// 重新访问 getApiInterceptorHooks, 允许 invoke 中再次调用 addInterceptor,removeInterceptor
return
api
(
wrapperOptions
(
getApiInterceptorHooks
(
method
),
options
),
...
params
);
});
}
else
{
...
...
packages/uni-mp-lark/dist/uni.api.esm.js
浏览文件 @
c9188a20
...
...
@@ -227,20 +227,20 @@ const HOOK_FAIL = 'fail';
const
HOOK_COMPLETE
=
'
complete
'
;
const
globalInterceptors
=
{};
const
scopedInterceptors
=
{};
function
wrapperHook
(
hook
)
{
function
wrapperHook
(
hook
,
params
)
{
return
function
(
data
)
{
return
hook
(
data
)
||
data
;
return
hook
(
data
,
params
)
||
data
;
};
}
function
queue
(
hooks
,
data
)
{
function
queue
(
hooks
,
data
,
params
)
{
let
promise
=
false
;
for
(
let
i
=
0
;
i
<
hooks
.
length
;
i
++
)
{
const
hook
=
hooks
[
i
];
if
(
promise
)
{
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
));
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
,
params
));
}
else
{
const
res
=
hook
(
data
);
const
res
=
hook
(
data
,
params
);
if
(
isPromise
(
res
))
{
promise
=
Promise
.
resolve
(
res
);
}
...
...
@@ -267,7 +267,7 @@ function wrapperOptions(interceptors, options = {}) {
}
const
oldCallback
=
options
[
name
];
options
[
name
]
=
function
callbackInterceptor
(
res
)
{
queue
(
hooks
,
res
).
then
((
res
)
=>
{
queue
(
hooks
,
res
,
options
).
then
((
res
)
=>
{
return
(
isFunction
(
oldCallback
)
&&
oldCallback
(
res
))
||
res
;
});
};
...
...
@@ -311,7 +311,8 @@ function invokeApi(method, api, options, params) {
if
(
isArray
(
interceptor
.
invoke
))
{
const
res
=
queue
(
interceptor
.
invoke
,
options
);
return
res
.
then
((
options
)
=>
{
return
api
(
wrapperOptions
(
interceptor
,
options
),
...
params
);
// 重新访问 getApiInterceptorHooks, 允许 invoke 中再次调用 addInterceptor,removeInterceptor
return
api
(
wrapperOptions
(
getApiInterceptorHooks
(
method
),
options
),
...
params
);
});
}
else
{
...
...
packages/uni-mp-qq/dist/uni.api.esm.js
浏览文件 @
c9188a20
...
...
@@ -227,20 +227,20 @@ const HOOK_FAIL = 'fail';
const
HOOK_COMPLETE
=
'
complete
'
;
const
globalInterceptors
=
{};
const
scopedInterceptors
=
{};
function
wrapperHook
(
hook
)
{
function
wrapperHook
(
hook
,
params
)
{
return
function
(
data
)
{
return
hook
(
data
)
||
data
;
return
hook
(
data
,
params
)
||
data
;
};
}
function
queue
(
hooks
,
data
)
{
function
queue
(
hooks
,
data
,
params
)
{
let
promise
=
false
;
for
(
let
i
=
0
;
i
<
hooks
.
length
;
i
++
)
{
const
hook
=
hooks
[
i
];
if
(
promise
)
{
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
));
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
,
params
));
}
else
{
const
res
=
hook
(
data
);
const
res
=
hook
(
data
,
params
);
if
(
isPromise
(
res
))
{
promise
=
Promise
.
resolve
(
res
);
}
...
...
@@ -267,7 +267,7 @@ function wrapperOptions(interceptors, options = {}) {
}
const
oldCallback
=
options
[
name
];
options
[
name
]
=
function
callbackInterceptor
(
res
)
{
queue
(
hooks
,
res
).
then
((
res
)
=>
{
queue
(
hooks
,
res
,
options
).
then
((
res
)
=>
{
return
(
isFunction
(
oldCallback
)
&&
oldCallback
(
res
))
||
res
;
});
};
...
...
@@ -311,7 +311,8 @@ function invokeApi(method, api, options, params) {
if
(
isArray
(
interceptor
.
invoke
))
{
const
res
=
queue
(
interceptor
.
invoke
,
options
);
return
res
.
then
((
options
)
=>
{
return
api
(
wrapperOptions
(
interceptor
,
options
),
...
params
);
// 重新访问 getApiInterceptorHooks, 允许 invoke 中再次调用 addInterceptor,removeInterceptor
return
api
(
wrapperOptions
(
getApiInterceptorHooks
(
method
),
options
),
...
params
);
});
}
else
{
...
...
packages/uni-mp-toutiao/dist/uni.api.esm.js
浏览文件 @
c9188a20
...
...
@@ -227,20 +227,20 @@ const HOOK_FAIL = 'fail';
const
HOOK_COMPLETE
=
'
complete
'
;
const
globalInterceptors
=
{};
const
scopedInterceptors
=
{};
function
wrapperHook
(
hook
)
{
function
wrapperHook
(
hook
,
params
)
{
return
function
(
data
)
{
return
hook
(
data
)
||
data
;
return
hook
(
data
,
params
)
||
data
;
};
}
function
queue
(
hooks
,
data
)
{
function
queue
(
hooks
,
data
,
params
)
{
let
promise
=
false
;
for
(
let
i
=
0
;
i
<
hooks
.
length
;
i
++
)
{
const
hook
=
hooks
[
i
];
if
(
promise
)
{
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
));
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
,
params
));
}
else
{
const
res
=
hook
(
data
);
const
res
=
hook
(
data
,
params
);
if
(
isPromise
(
res
))
{
promise
=
Promise
.
resolve
(
res
);
}
...
...
@@ -267,7 +267,7 @@ function wrapperOptions(interceptors, options = {}) {
}
const
oldCallback
=
options
[
name
];
options
[
name
]
=
function
callbackInterceptor
(
res
)
{
queue
(
hooks
,
res
).
then
((
res
)
=>
{
queue
(
hooks
,
res
,
options
).
then
((
res
)
=>
{
return
(
isFunction
(
oldCallback
)
&&
oldCallback
(
res
))
||
res
;
});
};
...
...
@@ -311,7 +311,8 @@ function invokeApi(method, api, options, params) {
if
(
isArray
(
interceptor
.
invoke
))
{
const
res
=
queue
(
interceptor
.
invoke
,
options
);
return
res
.
then
((
options
)
=>
{
return
api
(
wrapperOptions
(
interceptor
,
options
),
...
params
);
// 重新访问 getApiInterceptorHooks, 允许 invoke 中再次调用 addInterceptor,removeInterceptor
return
api
(
wrapperOptions
(
getApiInterceptorHooks
(
method
),
options
),
...
params
);
});
}
else
{
...
...
packages/uni-mp-weixin/dist/uni.api.esm.js
浏览文件 @
c9188a20
...
...
@@ -227,20 +227,20 @@ const HOOK_FAIL = 'fail';
const
HOOK_COMPLETE
=
'
complete
'
;
const
globalInterceptors
=
{};
const
scopedInterceptors
=
{};
function
wrapperHook
(
hook
)
{
function
wrapperHook
(
hook
,
params
)
{
return
function
(
data
)
{
return
hook
(
data
)
||
data
;
return
hook
(
data
,
params
)
||
data
;
};
}
function
queue
(
hooks
,
data
)
{
function
queue
(
hooks
,
data
,
params
)
{
let
promise
=
false
;
for
(
let
i
=
0
;
i
<
hooks
.
length
;
i
++
)
{
const
hook
=
hooks
[
i
];
if
(
promise
)
{
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
));
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
,
params
));
}
else
{
const
res
=
hook
(
data
);
const
res
=
hook
(
data
,
params
);
if
(
isPromise
(
res
))
{
promise
=
Promise
.
resolve
(
res
);
}
...
...
@@ -267,7 +267,7 @@ function wrapperOptions(interceptors, options = {}) {
}
const
oldCallback
=
options
[
name
];
options
[
name
]
=
function
callbackInterceptor
(
res
)
{
queue
(
hooks
,
res
).
then
((
res
)
=>
{
queue
(
hooks
,
res
,
options
).
then
((
res
)
=>
{
return
(
isFunction
(
oldCallback
)
&&
oldCallback
(
res
))
||
res
;
});
};
...
...
@@ -311,7 +311,8 @@ function invokeApi(method, api, options, params) {
if
(
isArray
(
interceptor
.
invoke
))
{
const
res
=
queue
(
interceptor
.
invoke
,
options
);
return
res
.
then
((
options
)
=>
{
return
api
(
wrapperOptions
(
interceptor
,
options
),
...
params
);
// 重新访问 getApiInterceptorHooks, 允许 invoke 中再次调用 addInterceptor,removeInterceptor
return
api
(
wrapperOptions
(
getApiInterceptorHooks
(
method
),
options
),
...
params
);
});
}
else
{
...
...
packages/uni-quickapp-webview/dist/uni.api.esm.js
浏览文件 @
c9188a20
...
...
@@ -227,20 +227,20 @@ const HOOK_FAIL = 'fail';
const
HOOK_COMPLETE
=
'
complete
'
;
const
globalInterceptors
=
{};
const
scopedInterceptors
=
{};
function
wrapperHook
(
hook
)
{
function
wrapperHook
(
hook
,
params
)
{
return
function
(
data
)
{
return
hook
(
data
)
||
data
;
return
hook
(
data
,
params
)
||
data
;
};
}
function
queue
(
hooks
,
data
)
{
function
queue
(
hooks
,
data
,
params
)
{
let
promise
=
false
;
for
(
let
i
=
0
;
i
<
hooks
.
length
;
i
++
)
{
const
hook
=
hooks
[
i
];
if
(
promise
)
{
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
));
promise
=
Promise
.
resolve
(
wrapperHook
(
hook
,
params
));
}
else
{
const
res
=
hook
(
data
);
const
res
=
hook
(
data
,
params
);
if
(
isPromise
(
res
))
{
promise
=
Promise
.
resolve
(
res
);
}
...
...
@@ -267,7 +267,7 @@ function wrapperOptions(interceptors, options = {}) {
}
const
oldCallback
=
options
[
name
];
options
[
name
]
=
function
callbackInterceptor
(
res
)
{
queue
(
hooks
,
res
).
then
((
res
)
=>
{
queue
(
hooks
,
res
,
options
).
then
((
res
)
=>
{
return
(
isFunction
(
oldCallback
)
&&
oldCallback
(
res
))
||
res
;
});
};
...
...
@@ -311,7 +311,8 @@ function invokeApi(method, api, options, params) {
if
(
isArray
(
interceptor
.
invoke
))
{
const
res
=
queue
(
interceptor
.
invoke
,
options
);
return
res
.
then
((
options
)
=>
{
return
api
(
wrapperOptions
(
interceptor
,
options
),
...
params
);
// 重新访问 getApiInterceptorHooks, 允许 invoke 中再次调用 addInterceptor,removeInterceptor
return
api
(
wrapperOptions
(
getApiInterceptorHooks
(
method
),
options
),
...
params
);
});
}
else
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录