Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
陈庄旺
uni-app
提交
5b21378e
U
uni-app
项目概览
陈庄旺
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5b21378e
编写于
6月 22, 2022
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(push): getPushClientId support promise
上级
6d569fc0
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
952 addition
and
200 deletion
+952
-200
packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/TestModule.kt.map
...iplugin/android/src/io/dcloud/uniplugin/TestModule.kt.map
+1
-1
packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/log.kt.map
...test-uniplugin/android/src/io/dcloud/uniplugin/log.kt.map
+1
-1
packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/test.kt.map
...kage/nativeplugins/test-uniplugin/android/src/test.kt.map
+1
-1
packages/uni-api/src/service/keyboard/getSelectedTextRange.ts
...ages/uni-api/src/service/keyboard/getSelectedTextRange.ts
+1
-1
packages/uni-api/src/service/plugin/push.ts
packages/uni-api/src/service/plugin/push.ts
+15
-27
packages/uni-app-plus/dist/uni.runtime.esm.js
packages/uni-app-plus/dist/uni.runtime.esm.js
+6
-16
packages/uni-h5/dist/uni-h5.es.js
packages/uni-h5/dist/uni-h5.es.js
+6
-16
packages/uni-mp-alipay/dist/uni.api.esm.js
packages/uni-mp-alipay/dist/uni.api.esm.js
+115
-17
packages/uni-mp-baidu/dist/uni.api.esm.js
packages/uni-mp-baidu/dist/uni.api.esm.js
+115
-17
packages/uni-mp-kuaishou/dist/uni.api.esm.js
packages/uni-mp-kuaishou/dist/uni.api.esm.js
+115
-17
packages/uni-mp-lark/dist/uni.api.esm.js
packages/uni-mp-lark/dist/uni.api.esm.js
+115
-17
packages/uni-mp-qq/dist/uni.api.esm.js
packages/uni-mp-qq/dist/uni.api.esm.js
+115
-17
packages/uni-mp-toutiao/dist/uni.api.esm.js
packages/uni-mp-toutiao/dist/uni.api.esm.js
+115
-17
packages/uni-mp-weixin/dist/uni.api.esm.js
packages/uni-mp-weixin/dist/uni.api.esm.js
+115
-17
packages/uni-quickapp-webview/dist/uni.api.esm.js
packages/uni-quickapp-webview/dist/uni.api.esm.js
+115
-17
pnpm-lock.yaml
pnpm-lock.yaml
+1
-1
未找到文件。
packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/TestModule.kt.map
浏览文件 @
5b21378e
{"version":3,"sources":["/Users/fxy/Projects/GitHub/uni-app/uni-app-next/packages/playground/uts/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/TestModule.uts"],"names":["TestModule","UniModule","TAG","UniJSMethod","uiThread","testAsyncFunc","options","callback","log","data","JSONObject","invoke","testSyncFunc","onActivityResult","requestCode","resultCode","REQUEST_CODE","hasExtra","getStringExtra"],"mappings":"AAAA;AAAA,OAAmB,sBAAwB,CAAC;AAC5C,OAAuB,+BAAiC,CAAC;AACzD,OAAsB,yCAA2C,CAAC;AAClE,OAAwB,+CAAiD,CAAC;AAC1E,OAA0B,6CAA+C,CAAC;AAC1E,OAAgB,2BAAO,CAAC;AACT,WAAMA,UAAU,GAASC,SAAS,EAAE;IACjDC,SAAAA,GAAG,GAAG,YAAY,CAAC;IAGnB,CAACC,WAAW,CAAC,CAAEC,QAAQ,GAAE,IAAI,CAAE,CAAC;IAAA,SAChCC,aAAa,CAACC,OAAmB,EAAV,UAAU,EAAEC,QAAwB,EAAb,aAAa,CAAA,EAAE;QAC3DC,GAAG,CAAC,IAAI,CAACN,GAAG,EAAE,yBAAyB,CAAC,CAAC;QACzC,IAAIK,QAAQ,IAAI,IAAI,EAAE;YACpB,IAAME,IAAI,GAAG,AAAIC,UAAU,EAAE,AAAC;YAC9BD,IAAI,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC;YAC9BF,QAAQ,CAACI,MAAM,CAACF,IAAI,CAAC,CAAC;;;IAI1B,CAACN,WAAW,CAAC,CAAEC,QAAQ,GAAE,KAAK,CAAE,CAAC;IAAA,SACjCQ,YAAY,CAACN,OAAmB,EAAV,UAAU,GAAG,UAAU,CAAC;QAC5C,IAAMG,IAAI,GAAG,AAAIC,UAAU,EAAE,AAAC;QAC9BD,IAAI,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC;QAC5B,OAAOA,IAAI,CAAC;;IAEd,aAASI,gBAAgB,CAACC,WAAgB,EAAH,GAAG,EAAEC,UAAe,EAAH,GAAG,EAAEN,IAAY,EAAN,MAAM,EAAE;QACzE,IAAIK,WAAW,IAAId,UAAU,CAACgB,YAAY,IAAIP,IAAI,CAACQ,QAAQ,CAAC,SAAS,CAAC,EAAE;YACtET,GAAG,CAAC,IAAI,CAACN,GAAG,EAAE,wBAAY,GAAGO,IAAI,CAACS,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC;;QAC9D,MAAM;YACL,KAAK,CAACL,gBAAgB,CAACC,WAAW,EAAEC,UAAU,EAAEN,IAAI,CAAC,CAAC;;;;QAtB1D,IAAOO,YAAY,GAAG,IAAI,CAAC;;CAyB5B"}
\ No newline at end of file
{"version":3,"sources":["/Users/fxy/Documents/projects/GitHub/uni-app/uni-app-next/packages/playground/uts/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/TestModule.uts"],"names":["TestModule","UniModule","TAG","UniJSMethod","uiThread","testAsyncFunc","options","callback","log","data","JSONObject","invoke","testSyncFunc","onActivityResult","requestCode","resultCode","REQUEST_CODE","hasExtra","getStringExtra"],"mappings":"AAAA;AAAA,OAAmB,sBAAwB,CAAC;AAC5C,OAAuB,+BAAiC,CAAC;AACzD,OAAsB,yCAA2C,CAAC;AAClE,OAAwB,+CAAiD,CAAC;AAC1E,OAA0B,6CAA+C,CAAC;AAC1E,OAAgB,2BAAO,CAAC;AACT,WAAMA,UAAU,GAASC,SAAS,EAAE;IACjDC,SAAAA,GAAG,GAAG,YAAY,CAAC;IAGnB,CAACC,WAAW,CAAC,CAAEC,QAAQ,GAAE,IAAI,CAAE,CAAC;IAAA,SAChCC,aAAa,CAACC,OAAmB,EAAV,UAAU,EAAEC,QAAwB,EAAb,aAAa,CAAA,EAAE;QAC3DC,GAAG,CAAC,IAAI,CAACN,GAAG,EAAE,yBAAyB,CAAC,CAAC;QACzC,IAAIK,QAAQ,IAAI,IAAI,EAAE;YACpB,IAAME,IAAI,GAAG,AAAIC,UAAU,EAAE,AAAC;YAC9BD,IAAI,CAAC,MAAM,CAAC,GAAG,cAAc,CAAC;YAC9BF,QAAQ,CAACI,MAAM,CAACF,IAAI,CAAC,CAAC;;;IAI1B,CAACN,WAAW,CAAC,CAAEC,QAAQ,GAAE,KAAK,CAAE,CAAC;IAAA,SACjCQ,YAAY,CAACN,OAAmB,EAAV,UAAU,GAAG,UAAU,CAAC;QAC5C,IAAMG,IAAI,GAAG,AAAIC,UAAU,EAAE,AAAC;QAC9BD,IAAI,CAAC,MAAM,CAAC,GAAG,YAAY,CAAC;QAC5B,OAAOA,IAAI,CAAC;;IAEd,aAASI,gBAAgB,CAACC,WAAgB,EAAH,GAAG,EAAEC,UAAe,EAAH,GAAG,EAAEN,IAAY,EAAN,MAAM,EAAE;QACzE,IAAIK,WAAW,IAAId,UAAU,CAACgB,YAAY,IAAIP,IAAI,CAACQ,QAAQ,CAAC,SAAS,CAAC,EAAE;YACtET,GAAG,CAAC,IAAI,CAACN,GAAG,EAAE,wBAAY,GAAGO,IAAI,CAACS,cAAc,CAAC,SAAS,CAAC,CAAC,CAAC;;QAC9D,MAAM;YACL,KAAK,CAACL,gBAAgB,CAACC,WAAW,EAAEC,UAAU,EAAEN,IAAI,CAAC,CAAC;;;;QAtB1D,IAAOO,YAAY,GAAG,IAAI,CAAC;;CAyB5B"}
\ No newline at end of file
packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/log.kt.map
浏览文件 @
5b21378e
{"version":3,"sources":["/Users/fxy/Projects/GitHub/uni-app/uni-app-next/packages/playground/uts/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/log.uts"],"names":["log","tag","msg","Log","e"],"mappings":"AAAA;AAAA,OAAgB,gBAAkB,CAAC;AACpB,IAASA,GAAG,CAACC,GAAW,EAAN,MAAM,EAAEC,GAAW,EAAN,MAAM,EAAE;IACpDC,GAAG,GAAEC,CAAC,CAACH,GAAG,EAAEC,GAAG,CAAC,CAAC"}
\ No newline at end of file
{"version":3,"sources":["/Users/fxy/Documents/projects/GitHub/uni-app/uni-app-next/packages/playground/uts/nativeplugins/test-uniplugin/android/src/io/dcloud/uniplugin/log.uts"],"names":["log","tag","msg","Log","e"],"mappings":"AAAA;AAAA,OAAgB,gBAAkB,CAAC;AACpB,IAASA,GAAG,CAACC,GAAW,EAAN,MAAM,EAAEC,GAAW,EAAN,MAAM,EAAE;IACpDC,GAAG,GAAEC,CAAC,CAACH,GAAG,EAAEC,GAAG,CAAC,CAAC"}
\ No newline at end of file
packages/playground/uts/unpackage/nativeplugins/test-uniplugin/android/src/test.kt.map
浏览文件 @
5b21378e
{"version":3,"sources":["/Users/fxy/Projects/GitHub/uni-app/uni-app-next/packages/playground/uts/nativeplugins/test-uniplugin/android/src/test.uts"],"names":["log","tag","msg","Log","e"],"mappings":"AAAA;AAAA,OAAgB,gBAAkB,CAAC;AACpB,IAASA,GAAG,CAACC,GAAW,EAAN,MAAM,EAAEC,GAAW,EAAN,MAAM,EAAE;IACpDC,GAAG,CAACC,CAAC,CAACH,GAAG,EAAEC,GAAG,CAAC,CAAC"}
\ No newline at end of file
{"version":3,"sources":["/Users/fxy/Documents/projects/GitHub/uni-app/uni-app-next/packages/playground/uts/nativeplugins/test-uniplugin/android/src/test.uts"],"names":["log","tag","msg","Log","e"],"mappings":"AAAA;AAAA,OAAgB,gBAAkB,CAAC;AACpB,IAASA,GAAG,CAACC,GAAW,EAAN,MAAM,EAAEC,GAAW,EAAN,MAAM,EAAE;IACpDC,GAAG,CAACC,CAAC,CAACH,GAAG,EAAEC,GAAG,CAAC,CAAC"}
\ No newline at end of file
packages/uni-api/src/service/keyboard/getSelectedTextRange.ts
浏览文件 @
5b21378e
...
...
@@ -12,7 +12,7 @@ export const getSelectedTextRange =
UniServiceJSBridge
.
invokeViewMethod
<
{},
UniApp
.
GetSelectedTextRangeSuccessCallbackResult
>
(
'
getSelectedTextRange
'
,
{},
getCurrentPageId
(),
(
res
)
=>
{
>
(
API_GET_SELECTED_TEXT_RANGE
,
{},
getCurrentPageId
(),
(
res
)
=>
{
if
(
typeof
res
.
end
===
'
undefined
'
&&
typeof
res
.
start
===
'
undefined
'
...
...
packages/uni-api/src/service/plugin/push.ts
浏览文件 @
5b21378e
import
{
isFunction
,
isPlainObject
}
from
'
@vue/shared
'
import
{
getApiCallbacks
}
from
'
../../helpers/api/callback
'
import
{
defineAsyncApi
}
from
'
../../helpers/api
'
interface
OnPushCidCallback
{
type
:
'
clientId
'
...
...
@@ -62,10 +61,6 @@ export function invokePushCallback(
}
}
interface
GetPushCidOptions
{
success
?:
OnPushMessageSuccess
}
const
getPushCidCallbacks
:
((
cid
?:
string
,
errMsg
?:
string
)
=>
void
)[]
=
[]
function
invokeGetPushCidCallbacks
(
cid
?:
string
,
errMsg
?:
string
)
{
...
...
@@ -75,29 +70,22 @@ function invokeGetPushCidCallbacks(cid?: string, errMsg?: string) {
getPushCidCallbacks
.
length
=
0
}
export
function
getPushClientId
(
args
:
GetPushCidOptions
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{}
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
)
const
hasSuccess
=
isFunction
(
success
)
const
hasFail
=
isFunction
(
fail
)
const
hasComplete
=
isFunction
(
complete
)
getPushCidCallbacks
.
push
((
cid
?:
string
,
errMsg
?:
string
)
=>
{
let
res
:
Record
<
string
,
unknown
>
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushClientId:ok
'
,
cid
}
hasSuccess
&&
success
(
res
)
}
else
{
res
=
{
errMsg
:
'
getPushClientId:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
}
hasFail
&&
fail
(
res
)
const
API_GET_PUSH_CLIENT_ID
=
'
getPushClientId
'
export
const
getPushClientId
=
defineAsyncApi
(
API_GET_PUSH_CLIENT_ID
,
(
_
,
{
resolve
,
reject
})
=>
{
getPushCidCallbacks
.
push
((
cid
?:
string
,
errMsg
?:
string
)
=>
{
if
(
cid
)
{
resolve
({
cid
})
}
else
{
reject
(
errMsg
)
}
})
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
))
}
hasComplete
&&
complete
(
res
)
})
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
))
}
}
)
interface
OnPushMessageSuccess
{
type
:
'
click
'
|
'
receive
'
...
...
packages/uni-app-plus/dist/uni.runtime.esm.js
浏览文件 @
5b21378e
...
...
@@ -10994,7 +10994,7 @@ const setPageMeta = defineAsyncApi(API_SET_PAGE_META, (options, { resolve }) =>
const API_GET_SELECTED_TEXT_RANGE = 'getSelectedTextRange';
const getSelectedTextRange = defineAsyncApi(API_GET_SELECTED_TEXT_RANGE, (_, { resolve, reject }) => {
UniServiceJSBridge.invokeViewMethod(
'getSelectedTextRange'
, {}, getCurrentPageId(), (res) => {
UniServiceJSBridge.invokeViewMethod(
API_GET_SELECTED_TEXT_RANGE
, {}, getCurrentPageId(), (res) => {
if (typeof res.end === 'undefined' &&
typeof res.start === 'undefined') {
reject('no focused');
...
...
@@ -11115,30 +11115,20 @@ function invokeGetPushCidCallbacks(cid, errMsg) {
});
getPushCidCallbacks.length = 0;
}
function getPushClientId(args) {
if (!isPlainObject(args)) {
args = {};
}
const { success, fail, complete } = getApiCallbacks(args);
const hasSuccess = isFunction(success);
const hasFail = isFunction(fail);
const hasComplete = isFunction(complete);
const API_GET_PUSH_CLIENT_ID = 'getPushClientId';
const getPushClientId = defineAsyncApi(API_GET_PUSH_CLIENT_ID, (_, { resolve, reject }) => {
getPushCidCallbacks.push((cid, errMsg) => {
let res;
if (cid) {
res = { errMsg: 'getPushClientId:ok', cid };
hasSuccess && success(res);
resolve({ cid });
}
else {
res = { errMsg: 'getPushClientId:fail' + (errMsg ? ' ' + errMsg : '') };
hasFail && fail(res);
reject(errMsg);
}
hasComplete && complete(res);
});
if (typeof cid !== 'undefined') {
Promise.resolve().then(() => invokeGetPushCidCallbacks(cid, cidErrMsg));
}
}
}
);
const onPushMessageCallbacks = [];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const onPushMessage = (fn) => {
...
...
packages/uni-h5/dist/uni-h5.es.js
浏览文件 @
5b21378e
...
...
@@ -4508,7 +4508,7 @@ const setPageMeta = /* @__PURE__ */ defineAsyncApi(API_SET_PAGE_META, (options,
});
const API_GET_SELECTED_TEXT_RANGE = "getSelectedTextRange";
const getSelectedTextRange$1 = /* @__PURE__ */ defineAsyncApi(API_GET_SELECTED_TEXT_RANGE, (_, { resolve, reject }) => {
UniServiceJSBridge.invokeViewMethod(
"getSelectedTextRange"
, {}, getCurrentPageId(), (res) => {
UniServiceJSBridge.invokeViewMethod(
API_GET_SELECTED_TEXT_RANGE
, {}, getCurrentPageId(), (res) => {
if (typeof res.end === "undefined" && typeof res.start === "undefined") {
reject("no focused");
} else {
...
...
@@ -4619,29 +4619,19 @@ function invokeGetPushCidCallbacks(cid2, errMsg) {
});
getPushCidCallbacks.length = 0;
}
function getPushClientId(args) {
if (!isPlainObject(args)) {
args = {};
}
const { success, fail, complete } = getApiCallbacks(args);
const hasSuccess = isFunction(success);
const hasFail = isFunction(fail);
const hasComplete = isFunction(complete);
const API_GET_PUSH_CLIENT_ID = "getPushClientId";
const getPushClientId = /* @__PURE__ */ defineAsyncApi(API_GET_PUSH_CLIENT_ID, (_, { resolve, reject }) => {
getPushCidCallbacks.push((cid2, errMsg) => {
let res;
if (cid2) {
res = { errMsg: "getPushClientId:ok", cid: cid2 };
hasSuccess && success(res);
resolve({ cid: cid2 });
} else {
res = { errMsg: "getPushClientId:fail" + (errMsg ? " " + errMsg : "") };
hasFail && fail(res);
reject(errMsg);
}
hasComplete && complete(res);
});
if (typeof cid !== "undefined") {
Promise.resolve().then(() => invokeGetPushCidCallbacks(cid, cidErrMsg));
}
}
}
);
const onPushMessageCallbacks = [];
const onPushMessage = (fn) => {
if (onPushMessageCallbacks.indexOf(fn) === -1) {
...
...
packages/uni-mp-alipay/dist/uni.api.esm.js
浏览文件 @
5b21378e
import
{
isArray
,
hasOwn
,
isString
,
isPlainObject
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isFunction
,
isPromise
,
remove
,
extend
}
from
'
@vue/shared
'
;
import
{
isArray
,
hasOwn
,
isString
,
isPlainObject
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isFunction
,
isPromise
,
extend
,
remove
}
from
'
@vue/shared
'
;
import
{
normalizeLocale
,
LOCALE_EN
}
from
'
@dcloudio/uni-i18n
'
;
import
{
Emitter
,
onCreateVueApp
,
invokeCreateVueAppHook
}
from
'
@dcloudio/uni-shared
'
;
import
{
LINEFEED
,
Emitter
,
onCreateVueApp
,
invokeCreateVueAppHook
}
from
'
@dcloudio/uni-shared
'
;
const
eventChannels
=
{};
const
eventChannelStack
=
[];
...
...
@@ -190,6 +190,32 @@ function tryCatch(fn) {
};
}
let
invokeCallbackId
=
1
;
const
invokeCallbacks
=
{};
function
addInvokeCallback
(
id
,
name
,
callback
,
keepAlive
=
false
)
{
invokeCallbacks
[
id
]
=
{
name
,
keepAlive
,
callback
,
};
return
id
;
}
// onNativeEventReceive((event,data)=>{}) 需要两个参数,目前写死最多两个参数
function
invokeCallback
(
id
,
res
,
extras
)
{
if
(
typeof
id
===
'
number
'
)
{
const
opts
=
invokeCallbacks
[
id
];
if
(
opts
)
{
if
(
!
opts
.
keepAlive
)
{
delete
invokeCallbacks
[
id
];
}
return
opts
.
callback
(
res
,
extras
);
}
}
return
res
;
}
const
API_SUCCESS
=
'
success
'
;
const
API_FAIL
=
'
fail
'
;
const
API_COMPLETE
=
'
complete
'
;
function
getApiCallbacks
(
args
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
args
)
{
...
...
@@ -200,6 +226,36 @@ function getApiCallbacks(args) {
}
}
return
apiCallbacks
;
}
function
normalizeErrMsg$1
(
errMsg
,
name
)
{
if
(
!
errMsg
||
errMsg
.
indexOf
(
'
:fail
'
)
===
-
1
)
{
return
name
+
'
:ok
'
;
}
return
name
+
errMsg
.
substring
(
errMsg
.
indexOf
(
'
:fail
'
));
}
function
createAsyncApiCallback
(
name
,
args
=
{},
{
beforeAll
,
beforeSuccess
}
=
{})
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFunction
(
success
);
const
hasFail
=
isFunction
(
fail
);
const
hasComplete
=
isFunction
(
complete
);
const
callbackId
=
invokeCallbackId
++
;
addInvokeCallback
(
callbackId
,
name
,
(
res
)
=>
{
res
=
res
||
{};
res
.
errMsg
=
normalizeErrMsg$1
(
res
.
errMsg
,
name
);
isFunction
(
beforeAll
)
&&
beforeAll
(
res
);
if
(
res
.
errMsg
===
name
+
'
:ok
'
)
{
isFunction
(
beforeSuccess
)
&&
beforeSuccess
(
res
,
args
);
hasSuccess
&&
success
(
res
);
}
else
{
hasFail
&&
fail
(
res
);
}
hasComplete
&&
complete
(
res
);
});
return
callbackId
;
}
const
HOOK_SUCCESS
=
'
success
'
;
...
...
@@ -301,6 +357,13 @@ function invokeApi(method, api, options, params) {
return
api
(
options
,
...
params
);
}
function
hasCallback
(
args
)
{
if
(
isPlainObject
(
args
)
&&
[
API_SUCCESS
,
API_FAIL
,
API_COMPLETE
].
find
((
cb
)
=>
isFunction
(
args
[
cb
])))
{
return
true
;
}
return
false
;
}
function
handlePromise
(
promise
)
{
// if (__UNI_FEATURE_PROMISE__) {
// return promise
...
...
@@ -310,6 +373,16 @@ function handlePromise(promise) {
// .catch((err) => [err])
// }
return
promise
;
}
function
promisify$1
(
name
,
fn
)
{
return
(
args
=
{},
...
rest
)
=>
{
if
(
hasCallback
(
args
))
{
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
fn
,
args
,
rest
));
}
return
wrapperReturnValue
(
name
,
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
invokeApi
(
name
,
fn
,
extend
(
args
,
{
success
:
resolve
,
fail
:
reject
}),
rest
);
})));
};
}
function
formatApiArgs
(
args
,
options
)
{
...
...
@@ -337,6 +410,12 @@ function formatApiArgs(args, options) {
}
}
}
function
invokeSuccess
(
id
,
name
,
res
)
{
return
invokeCallback
(
id
,
extend
(
res
||
{},
{
errMsg
:
name
+
'
:ok
'
}));
}
function
invokeFail
(
id
,
name
,
errMsg
,
errRes
)
{
return
invokeCallback
(
id
,
extend
({
errMsg
:
name
+
'
:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
},
errRes
));
}
function
beforeInvokeApi
(
name
,
args
,
protocol
,
options
)
{
if
((
process
.
env
.
NODE_ENV
!==
'
production
'
))
{
validateProtocols
(
name
,
args
,
protocol
);
...
...
@@ -352,6 +431,29 @@ function beforeInvokeApi(name, args, protocol, options) {
return
errMsg
;
}
}
function
normalizeErrMsg
(
errMsg
)
{
if
(
!
errMsg
||
isString
(
errMsg
))
{
return
errMsg
;
}
if
(
errMsg
.
stack
)
{
console
.
error
(
errMsg
.
message
+
LINEFEED
+
errMsg
.
stack
);
return
errMsg
.
message
;
}
return
errMsg
;
}
function
wrapperTaskApi
(
name
,
fn
,
protocol
,
options
)
{
return
(
args
)
=>
{
const
id
=
createAsyncApiCallback
(
name
,
args
,
options
);
const
errMsg
=
beforeInvokeApi
(
name
,
[
args
],
protocol
,
options
);
if
(
errMsg
)
{
return
invokeFail
(
id
,
name
,
errMsg
);
}
return
fn
(
args
,
{
resolve
:
(
res
)
=>
invokeSuccess
(
id
,
name
,
res
),
reject
:
(
errMsg
,
errRes
)
=>
invokeFail
(
id
,
name
,
normalizeErrMsg
(
errMsg
),
errRes
),
});
};
}
function
wrapperSyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
(...
args
)
=>
{
const
errMsg
=
beforeInvokeApi
(
name
,
args
,
protocol
,
options
);
...
...
@@ -361,8 +463,14 @@ function wrapperSyncApi(name, fn, protocol, options) {
return
fn
.
apply
(
null
,
args
);
};
}
function
wrapperAsyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
wrapperTaskApi
(
name
,
fn
,
protocol
,
options
);
}
function
defineSyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
wrapperSyncApi
(
name
,
fn
,
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
?
protocol
:
undefined
,
options
);
}
function
defineAsyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
promisify$1
(
name
,
wrapperAsyncApi
(
name
,
fn
,
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
?
protocol
:
undefined
,
options
));
}
const
API_UPX2PX
=
'
upx2px
'
;
...
...
@@ -582,30 +690,20 @@ function invokeGetPushCidCallbacks(cid, errMsg) {
});
getPushCidCallbacks
.
length
=
0
;
}
function
getPushClientId
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFunction
(
success
);
const
hasFail
=
isFunction
(
fail
);
const
hasComplete
=
isFunction
(
complete
);
const
API_GET_PUSH_CLIENT_ID
=
'
getPushClientId
'
;
const
getPushClientId
=
defineAsyncApi
(
API_GET_PUSH_CLIENT_ID
,
(
_
,
{
resolve
,
reject
})
=>
{
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
;
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushClientId:ok
'
,
cid
};
hasSuccess
&&
success
(
res
);
resolve
({
cid
});
}
else
{
res
=
{
errMsg
:
'
getPushClientId:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
};
hasFail
&&
fail
(
res
);
reject
(
errMsg
);
}
hasComplete
&&
complete
(
res
);
});
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
));
}
}
}
);
const
onPushMessageCallbacks
=
[];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const
onPushMessage
=
(
fn
)
=>
{
...
...
packages/uni-mp-baidu/dist/uni.api.esm.js
浏览文件 @
5b21378e
import
{
isArray
,
hasOwn
,
isString
,
isPlainObject
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isFunction
,
isPromise
,
remove
,
extend
}
from
'
@vue/shared
'
;
import
{
isArray
,
hasOwn
,
isString
,
isPlainObject
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isFunction
,
isPromise
,
extend
,
remove
}
from
'
@vue/shared
'
;
import
{
normalizeLocale
,
LOCALE_EN
}
from
'
@dcloudio/uni-i18n
'
;
import
{
Emitter
,
onCreateVueApp
,
invokeCreateVueAppHook
}
from
'
@dcloudio/uni-shared
'
;
import
{
LINEFEED
,
Emitter
,
onCreateVueApp
,
invokeCreateVueAppHook
}
from
'
@dcloudio/uni-shared
'
;
const
eventChannels
=
{};
const
eventChannelStack
=
[];
...
...
@@ -190,6 +190,32 @@ function tryCatch(fn) {
};
}
let
invokeCallbackId
=
1
;
const
invokeCallbacks
=
{};
function
addInvokeCallback
(
id
,
name
,
callback
,
keepAlive
=
false
)
{
invokeCallbacks
[
id
]
=
{
name
,
keepAlive
,
callback
,
};
return
id
;
}
// onNativeEventReceive((event,data)=>{}) 需要两个参数,目前写死最多两个参数
function
invokeCallback
(
id
,
res
,
extras
)
{
if
(
typeof
id
===
'
number
'
)
{
const
opts
=
invokeCallbacks
[
id
];
if
(
opts
)
{
if
(
!
opts
.
keepAlive
)
{
delete
invokeCallbacks
[
id
];
}
return
opts
.
callback
(
res
,
extras
);
}
}
return
res
;
}
const
API_SUCCESS
=
'
success
'
;
const
API_FAIL
=
'
fail
'
;
const
API_COMPLETE
=
'
complete
'
;
function
getApiCallbacks
(
args
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
args
)
{
...
...
@@ -200,6 +226,36 @@ function getApiCallbacks(args) {
}
}
return
apiCallbacks
;
}
function
normalizeErrMsg$1
(
errMsg
,
name
)
{
if
(
!
errMsg
||
errMsg
.
indexOf
(
'
:fail
'
)
===
-
1
)
{
return
name
+
'
:ok
'
;
}
return
name
+
errMsg
.
substring
(
errMsg
.
indexOf
(
'
:fail
'
));
}
function
createAsyncApiCallback
(
name
,
args
=
{},
{
beforeAll
,
beforeSuccess
}
=
{})
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFunction
(
success
);
const
hasFail
=
isFunction
(
fail
);
const
hasComplete
=
isFunction
(
complete
);
const
callbackId
=
invokeCallbackId
++
;
addInvokeCallback
(
callbackId
,
name
,
(
res
)
=>
{
res
=
res
||
{};
res
.
errMsg
=
normalizeErrMsg$1
(
res
.
errMsg
,
name
);
isFunction
(
beforeAll
)
&&
beforeAll
(
res
);
if
(
res
.
errMsg
===
name
+
'
:ok
'
)
{
isFunction
(
beforeSuccess
)
&&
beforeSuccess
(
res
,
args
);
hasSuccess
&&
success
(
res
);
}
else
{
hasFail
&&
fail
(
res
);
}
hasComplete
&&
complete
(
res
);
});
return
callbackId
;
}
const
HOOK_SUCCESS
=
'
success
'
;
...
...
@@ -301,6 +357,13 @@ function invokeApi(method, api, options, params) {
return
api
(
options
,
...
params
);
}
function
hasCallback
(
args
)
{
if
(
isPlainObject
(
args
)
&&
[
API_SUCCESS
,
API_FAIL
,
API_COMPLETE
].
find
((
cb
)
=>
isFunction
(
args
[
cb
])))
{
return
true
;
}
return
false
;
}
function
handlePromise
(
promise
)
{
// if (__UNI_FEATURE_PROMISE__) {
// return promise
...
...
@@ -310,6 +373,16 @@ function handlePromise(promise) {
// .catch((err) => [err])
// }
return
promise
;
}
function
promisify$1
(
name
,
fn
)
{
return
(
args
=
{},
...
rest
)
=>
{
if
(
hasCallback
(
args
))
{
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
fn
,
args
,
rest
));
}
return
wrapperReturnValue
(
name
,
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
invokeApi
(
name
,
fn
,
extend
(
args
,
{
success
:
resolve
,
fail
:
reject
}),
rest
);
})));
};
}
function
formatApiArgs
(
args
,
options
)
{
...
...
@@ -337,6 +410,12 @@ function formatApiArgs(args, options) {
}
}
}
function
invokeSuccess
(
id
,
name
,
res
)
{
return
invokeCallback
(
id
,
extend
(
res
||
{},
{
errMsg
:
name
+
'
:ok
'
}));
}
function
invokeFail
(
id
,
name
,
errMsg
,
errRes
)
{
return
invokeCallback
(
id
,
extend
({
errMsg
:
name
+
'
:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
},
errRes
));
}
function
beforeInvokeApi
(
name
,
args
,
protocol
,
options
)
{
if
((
process
.
env
.
NODE_ENV
!==
'
production
'
))
{
validateProtocols
(
name
,
args
,
protocol
);
...
...
@@ -352,6 +431,29 @@ function beforeInvokeApi(name, args, protocol, options) {
return
errMsg
;
}
}
function
normalizeErrMsg
(
errMsg
)
{
if
(
!
errMsg
||
isString
(
errMsg
))
{
return
errMsg
;
}
if
(
errMsg
.
stack
)
{
console
.
error
(
errMsg
.
message
+
LINEFEED
+
errMsg
.
stack
);
return
errMsg
.
message
;
}
return
errMsg
;
}
function
wrapperTaskApi
(
name
,
fn
,
protocol
,
options
)
{
return
(
args
)
=>
{
const
id
=
createAsyncApiCallback
(
name
,
args
,
options
);
const
errMsg
=
beforeInvokeApi
(
name
,
[
args
],
protocol
,
options
);
if
(
errMsg
)
{
return
invokeFail
(
id
,
name
,
errMsg
);
}
return
fn
(
args
,
{
resolve
:
(
res
)
=>
invokeSuccess
(
id
,
name
,
res
),
reject
:
(
errMsg
,
errRes
)
=>
invokeFail
(
id
,
name
,
normalizeErrMsg
(
errMsg
),
errRes
),
});
};
}
function
wrapperSyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
(...
args
)
=>
{
const
errMsg
=
beforeInvokeApi
(
name
,
args
,
protocol
,
options
);
...
...
@@ -361,8 +463,14 @@ function wrapperSyncApi(name, fn, protocol, options) {
return
fn
.
apply
(
null
,
args
);
};
}
function
wrapperAsyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
wrapperTaskApi
(
name
,
fn
,
protocol
,
options
);
}
function
defineSyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
wrapperSyncApi
(
name
,
fn
,
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
?
protocol
:
undefined
,
options
);
}
function
defineAsyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
promisify$1
(
name
,
wrapperAsyncApi
(
name
,
fn
,
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
?
protocol
:
undefined
,
options
));
}
const
API_UPX2PX
=
'
upx2px
'
;
...
...
@@ -582,30 +690,20 @@ function invokeGetPushCidCallbacks(cid, errMsg) {
});
getPushCidCallbacks
.
length
=
0
;
}
function
getPushClientId
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFunction
(
success
);
const
hasFail
=
isFunction
(
fail
);
const
hasComplete
=
isFunction
(
complete
);
const
API_GET_PUSH_CLIENT_ID
=
'
getPushClientId
'
;
const
getPushClientId
=
defineAsyncApi
(
API_GET_PUSH_CLIENT_ID
,
(
_
,
{
resolve
,
reject
})
=>
{
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
;
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushClientId:ok
'
,
cid
};
hasSuccess
&&
success
(
res
);
resolve
({
cid
});
}
else
{
res
=
{
errMsg
:
'
getPushClientId:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
};
hasFail
&&
fail
(
res
);
reject
(
errMsg
);
}
hasComplete
&&
complete
(
res
);
});
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
));
}
}
}
);
const
onPushMessageCallbacks
=
[];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const
onPushMessage
=
(
fn
)
=>
{
...
...
packages/uni-mp-kuaishou/dist/uni.api.esm.js
浏览文件 @
5b21378e
import
{
isArray
,
hasOwn
,
isString
,
isPlainObject
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isFunction
,
isPromise
,
remove
,
extend
}
from
'
@vue/shared
'
;
import
{
isArray
,
hasOwn
,
isString
,
isPlainObject
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isFunction
,
isPromise
,
extend
,
remove
}
from
'
@vue/shared
'
;
import
{
normalizeLocale
,
LOCALE_EN
}
from
'
@dcloudio/uni-i18n
'
;
import
{
Emitter
,
onCreateVueApp
,
invokeCreateVueAppHook
}
from
'
@dcloudio/uni-shared
'
;
import
{
LINEFEED
,
Emitter
,
onCreateVueApp
,
invokeCreateVueAppHook
}
from
'
@dcloudio/uni-shared
'
;
const
eventChannels
=
{};
const
eventChannelStack
=
[];
...
...
@@ -190,6 +190,32 @@ function tryCatch(fn) {
};
}
let
invokeCallbackId
=
1
;
const
invokeCallbacks
=
{};
function
addInvokeCallback
(
id
,
name
,
callback
,
keepAlive
=
false
)
{
invokeCallbacks
[
id
]
=
{
name
,
keepAlive
,
callback
,
};
return
id
;
}
// onNativeEventReceive((event,data)=>{}) 需要两个参数,目前写死最多两个参数
function
invokeCallback
(
id
,
res
,
extras
)
{
if
(
typeof
id
===
'
number
'
)
{
const
opts
=
invokeCallbacks
[
id
];
if
(
opts
)
{
if
(
!
opts
.
keepAlive
)
{
delete
invokeCallbacks
[
id
];
}
return
opts
.
callback
(
res
,
extras
);
}
}
return
res
;
}
const
API_SUCCESS
=
'
success
'
;
const
API_FAIL
=
'
fail
'
;
const
API_COMPLETE
=
'
complete
'
;
function
getApiCallbacks
(
args
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
args
)
{
...
...
@@ -200,6 +226,36 @@ function getApiCallbacks(args) {
}
}
return
apiCallbacks
;
}
function
normalizeErrMsg$1
(
errMsg
,
name
)
{
if
(
!
errMsg
||
errMsg
.
indexOf
(
'
:fail
'
)
===
-
1
)
{
return
name
+
'
:ok
'
;
}
return
name
+
errMsg
.
substring
(
errMsg
.
indexOf
(
'
:fail
'
));
}
function
createAsyncApiCallback
(
name
,
args
=
{},
{
beforeAll
,
beforeSuccess
}
=
{})
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFunction
(
success
);
const
hasFail
=
isFunction
(
fail
);
const
hasComplete
=
isFunction
(
complete
);
const
callbackId
=
invokeCallbackId
++
;
addInvokeCallback
(
callbackId
,
name
,
(
res
)
=>
{
res
=
res
||
{};
res
.
errMsg
=
normalizeErrMsg$1
(
res
.
errMsg
,
name
);
isFunction
(
beforeAll
)
&&
beforeAll
(
res
);
if
(
res
.
errMsg
===
name
+
'
:ok
'
)
{
isFunction
(
beforeSuccess
)
&&
beforeSuccess
(
res
,
args
);
hasSuccess
&&
success
(
res
);
}
else
{
hasFail
&&
fail
(
res
);
}
hasComplete
&&
complete
(
res
);
});
return
callbackId
;
}
const
HOOK_SUCCESS
=
'
success
'
;
...
...
@@ -301,6 +357,13 @@ function invokeApi(method, api, options, params) {
return
api
(
options
,
...
params
);
}
function
hasCallback
(
args
)
{
if
(
isPlainObject
(
args
)
&&
[
API_SUCCESS
,
API_FAIL
,
API_COMPLETE
].
find
((
cb
)
=>
isFunction
(
args
[
cb
])))
{
return
true
;
}
return
false
;
}
function
handlePromise
(
promise
)
{
// if (__UNI_FEATURE_PROMISE__) {
// return promise
...
...
@@ -310,6 +373,16 @@ function handlePromise(promise) {
// .catch((err) => [err])
// }
return
promise
;
}
function
promisify$1
(
name
,
fn
)
{
return
(
args
=
{},
...
rest
)
=>
{
if
(
hasCallback
(
args
))
{
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
fn
,
args
,
rest
));
}
return
wrapperReturnValue
(
name
,
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
invokeApi
(
name
,
fn
,
extend
(
args
,
{
success
:
resolve
,
fail
:
reject
}),
rest
);
})));
};
}
function
formatApiArgs
(
args
,
options
)
{
...
...
@@ -337,6 +410,12 @@ function formatApiArgs(args, options) {
}
}
}
function
invokeSuccess
(
id
,
name
,
res
)
{
return
invokeCallback
(
id
,
extend
(
res
||
{},
{
errMsg
:
name
+
'
:ok
'
}));
}
function
invokeFail
(
id
,
name
,
errMsg
,
errRes
)
{
return
invokeCallback
(
id
,
extend
({
errMsg
:
name
+
'
:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
},
errRes
));
}
function
beforeInvokeApi
(
name
,
args
,
protocol
,
options
)
{
if
((
process
.
env
.
NODE_ENV
!==
'
production
'
))
{
validateProtocols
(
name
,
args
,
protocol
);
...
...
@@ -352,6 +431,29 @@ function beforeInvokeApi(name, args, protocol, options) {
return
errMsg
;
}
}
function
normalizeErrMsg
(
errMsg
)
{
if
(
!
errMsg
||
isString
(
errMsg
))
{
return
errMsg
;
}
if
(
errMsg
.
stack
)
{
console
.
error
(
errMsg
.
message
+
LINEFEED
+
errMsg
.
stack
);
return
errMsg
.
message
;
}
return
errMsg
;
}
function
wrapperTaskApi
(
name
,
fn
,
protocol
,
options
)
{
return
(
args
)
=>
{
const
id
=
createAsyncApiCallback
(
name
,
args
,
options
);
const
errMsg
=
beforeInvokeApi
(
name
,
[
args
],
protocol
,
options
);
if
(
errMsg
)
{
return
invokeFail
(
id
,
name
,
errMsg
);
}
return
fn
(
args
,
{
resolve
:
(
res
)
=>
invokeSuccess
(
id
,
name
,
res
),
reject
:
(
errMsg
,
errRes
)
=>
invokeFail
(
id
,
name
,
normalizeErrMsg
(
errMsg
),
errRes
),
});
};
}
function
wrapperSyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
(...
args
)
=>
{
const
errMsg
=
beforeInvokeApi
(
name
,
args
,
protocol
,
options
);
...
...
@@ -361,8 +463,14 @@ function wrapperSyncApi(name, fn, protocol, options) {
return
fn
.
apply
(
null
,
args
);
};
}
function
wrapperAsyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
wrapperTaskApi
(
name
,
fn
,
protocol
,
options
);
}
function
defineSyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
wrapperSyncApi
(
name
,
fn
,
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
?
protocol
:
undefined
,
options
);
}
function
defineAsyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
promisify$1
(
name
,
wrapperAsyncApi
(
name
,
fn
,
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
?
protocol
:
undefined
,
options
));
}
const
API_UPX2PX
=
'
upx2px
'
;
...
...
@@ -582,30 +690,20 @@ function invokeGetPushCidCallbacks(cid, errMsg) {
});
getPushCidCallbacks
.
length
=
0
;
}
function
getPushClientId
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFunction
(
success
);
const
hasFail
=
isFunction
(
fail
);
const
hasComplete
=
isFunction
(
complete
);
const
API_GET_PUSH_CLIENT_ID
=
'
getPushClientId
'
;
const
getPushClientId
=
defineAsyncApi
(
API_GET_PUSH_CLIENT_ID
,
(
_
,
{
resolve
,
reject
})
=>
{
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
;
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushClientId:ok
'
,
cid
};
hasSuccess
&&
success
(
res
);
resolve
({
cid
});
}
else
{
res
=
{
errMsg
:
'
getPushClientId:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
};
hasFail
&&
fail
(
res
);
reject
(
errMsg
);
}
hasComplete
&&
complete
(
res
);
});
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
));
}
}
}
);
const
onPushMessageCallbacks
=
[];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const
onPushMessage
=
(
fn
)
=>
{
...
...
packages/uni-mp-lark/dist/uni.api.esm.js
浏览文件 @
5b21378e
import
{
isArray
,
hasOwn
,
isString
,
isPlainObject
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isFunction
,
isPromise
,
remove
,
extend
}
from
'
@vue/shared
'
;
import
{
isArray
,
hasOwn
,
isString
,
isPlainObject
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isFunction
,
isPromise
,
extend
,
remove
}
from
'
@vue/shared
'
;
import
{
normalizeLocale
,
LOCALE_EN
}
from
'
@dcloudio/uni-i18n
'
;
import
{
Emitter
,
onCreateVueApp
,
invokeCreateVueAppHook
}
from
'
@dcloudio/uni-shared
'
;
import
{
LINEFEED
,
Emitter
,
onCreateVueApp
,
invokeCreateVueAppHook
}
from
'
@dcloudio/uni-shared
'
;
const
eventChannels
=
{};
const
eventChannelStack
=
[];
...
...
@@ -190,6 +190,32 @@ function tryCatch(fn) {
};
}
let
invokeCallbackId
=
1
;
const
invokeCallbacks
=
{};
function
addInvokeCallback
(
id
,
name
,
callback
,
keepAlive
=
false
)
{
invokeCallbacks
[
id
]
=
{
name
,
keepAlive
,
callback
,
};
return
id
;
}
// onNativeEventReceive((event,data)=>{}) 需要两个参数,目前写死最多两个参数
function
invokeCallback
(
id
,
res
,
extras
)
{
if
(
typeof
id
===
'
number
'
)
{
const
opts
=
invokeCallbacks
[
id
];
if
(
opts
)
{
if
(
!
opts
.
keepAlive
)
{
delete
invokeCallbacks
[
id
];
}
return
opts
.
callback
(
res
,
extras
);
}
}
return
res
;
}
const
API_SUCCESS
=
'
success
'
;
const
API_FAIL
=
'
fail
'
;
const
API_COMPLETE
=
'
complete
'
;
function
getApiCallbacks
(
args
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
args
)
{
...
...
@@ -200,6 +226,36 @@ function getApiCallbacks(args) {
}
}
return
apiCallbacks
;
}
function
normalizeErrMsg$1
(
errMsg
,
name
)
{
if
(
!
errMsg
||
errMsg
.
indexOf
(
'
:fail
'
)
===
-
1
)
{
return
name
+
'
:ok
'
;
}
return
name
+
errMsg
.
substring
(
errMsg
.
indexOf
(
'
:fail
'
));
}
function
createAsyncApiCallback
(
name
,
args
=
{},
{
beforeAll
,
beforeSuccess
}
=
{})
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFunction
(
success
);
const
hasFail
=
isFunction
(
fail
);
const
hasComplete
=
isFunction
(
complete
);
const
callbackId
=
invokeCallbackId
++
;
addInvokeCallback
(
callbackId
,
name
,
(
res
)
=>
{
res
=
res
||
{};
res
.
errMsg
=
normalizeErrMsg$1
(
res
.
errMsg
,
name
);
isFunction
(
beforeAll
)
&&
beforeAll
(
res
);
if
(
res
.
errMsg
===
name
+
'
:ok
'
)
{
isFunction
(
beforeSuccess
)
&&
beforeSuccess
(
res
,
args
);
hasSuccess
&&
success
(
res
);
}
else
{
hasFail
&&
fail
(
res
);
}
hasComplete
&&
complete
(
res
);
});
return
callbackId
;
}
const
HOOK_SUCCESS
=
'
success
'
;
...
...
@@ -301,6 +357,13 @@ function invokeApi(method, api, options, params) {
return
api
(
options
,
...
params
);
}
function
hasCallback
(
args
)
{
if
(
isPlainObject
(
args
)
&&
[
API_SUCCESS
,
API_FAIL
,
API_COMPLETE
].
find
((
cb
)
=>
isFunction
(
args
[
cb
])))
{
return
true
;
}
return
false
;
}
function
handlePromise
(
promise
)
{
// if (__UNI_FEATURE_PROMISE__) {
// return promise
...
...
@@ -310,6 +373,16 @@ function handlePromise(promise) {
// .catch((err) => [err])
// }
return
promise
;
}
function
promisify$1
(
name
,
fn
)
{
return
(
args
=
{},
...
rest
)
=>
{
if
(
hasCallback
(
args
))
{
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
fn
,
args
,
rest
));
}
return
wrapperReturnValue
(
name
,
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
invokeApi
(
name
,
fn
,
extend
(
args
,
{
success
:
resolve
,
fail
:
reject
}),
rest
);
})));
};
}
function
formatApiArgs
(
args
,
options
)
{
...
...
@@ -337,6 +410,12 @@ function formatApiArgs(args, options) {
}
}
}
function
invokeSuccess
(
id
,
name
,
res
)
{
return
invokeCallback
(
id
,
extend
(
res
||
{},
{
errMsg
:
name
+
'
:ok
'
}));
}
function
invokeFail
(
id
,
name
,
errMsg
,
errRes
)
{
return
invokeCallback
(
id
,
extend
({
errMsg
:
name
+
'
:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
},
errRes
));
}
function
beforeInvokeApi
(
name
,
args
,
protocol
,
options
)
{
if
((
process
.
env
.
NODE_ENV
!==
'
production
'
))
{
validateProtocols
(
name
,
args
,
protocol
);
...
...
@@ -352,6 +431,29 @@ function beforeInvokeApi(name, args, protocol, options) {
return
errMsg
;
}
}
function
normalizeErrMsg
(
errMsg
)
{
if
(
!
errMsg
||
isString
(
errMsg
))
{
return
errMsg
;
}
if
(
errMsg
.
stack
)
{
console
.
error
(
errMsg
.
message
+
LINEFEED
+
errMsg
.
stack
);
return
errMsg
.
message
;
}
return
errMsg
;
}
function
wrapperTaskApi
(
name
,
fn
,
protocol
,
options
)
{
return
(
args
)
=>
{
const
id
=
createAsyncApiCallback
(
name
,
args
,
options
);
const
errMsg
=
beforeInvokeApi
(
name
,
[
args
],
protocol
,
options
);
if
(
errMsg
)
{
return
invokeFail
(
id
,
name
,
errMsg
);
}
return
fn
(
args
,
{
resolve
:
(
res
)
=>
invokeSuccess
(
id
,
name
,
res
),
reject
:
(
errMsg
,
errRes
)
=>
invokeFail
(
id
,
name
,
normalizeErrMsg
(
errMsg
),
errRes
),
});
};
}
function
wrapperSyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
(...
args
)
=>
{
const
errMsg
=
beforeInvokeApi
(
name
,
args
,
protocol
,
options
);
...
...
@@ -361,8 +463,14 @@ function wrapperSyncApi(name, fn, protocol, options) {
return
fn
.
apply
(
null
,
args
);
};
}
function
wrapperAsyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
wrapperTaskApi
(
name
,
fn
,
protocol
,
options
);
}
function
defineSyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
wrapperSyncApi
(
name
,
fn
,
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
?
protocol
:
undefined
,
options
);
}
function
defineAsyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
promisify$1
(
name
,
wrapperAsyncApi
(
name
,
fn
,
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
?
protocol
:
undefined
,
options
));
}
const
API_UPX2PX
=
'
upx2px
'
;
...
...
@@ -582,30 +690,20 @@ function invokeGetPushCidCallbacks(cid, errMsg) {
});
getPushCidCallbacks
.
length
=
0
;
}
function
getPushClientId
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFunction
(
success
);
const
hasFail
=
isFunction
(
fail
);
const
hasComplete
=
isFunction
(
complete
);
const
API_GET_PUSH_CLIENT_ID
=
'
getPushClientId
'
;
const
getPushClientId
=
defineAsyncApi
(
API_GET_PUSH_CLIENT_ID
,
(
_
,
{
resolve
,
reject
})
=>
{
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
;
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushClientId:ok
'
,
cid
};
hasSuccess
&&
success
(
res
);
resolve
({
cid
});
}
else
{
res
=
{
errMsg
:
'
getPushClientId:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
};
hasFail
&&
fail
(
res
);
reject
(
errMsg
);
}
hasComplete
&&
complete
(
res
);
});
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
));
}
}
}
);
const
onPushMessageCallbacks
=
[];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const
onPushMessage
=
(
fn
)
=>
{
...
...
packages/uni-mp-qq/dist/uni.api.esm.js
浏览文件 @
5b21378e
import
{
isArray
,
hasOwn
,
isString
,
isPlainObject
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isFunction
,
isPromise
,
remove
,
extend
}
from
'
@vue/shared
'
;
import
{
isArray
,
hasOwn
,
isString
,
isPlainObject
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isFunction
,
isPromise
,
extend
,
remove
}
from
'
@vue/shared
'
;
import
{
normalizeLocale
,
LOCALE_EN
}
from
'
@dcloudio/uni-i18n
'
;
import
{
Emitter
,
onCreateVueApp
,
invokeCreateVueAppHook
}
from
'
@dcloudio/uni-shared
'
;
import
{
LINEFEED
,
Emitter
,
onCreateVueApp
,
invokeCreateVueAppHook
}
from
'
@dcloudio/uni-shared
'
;
const
eventChannels
=
{};
const
eventChannelStack
=
[];
...
...
@@ -190,6 +190,32 @@ function tryCatch(fn) {
};
}
let
invokeCallbackId
=
1
;
const
invokeCallbacks
=
{};
function
addInvokeCallback
(
id
,
name
,
callback
,
keepAlive
=
false
)
{
invokeCallbacks
[
id
]
=
{
name
,
keepAlive
,
callback
,
};
return
id
;
}
// onNativeEventReceive((event,data)=>{}) 需要两个参数,目前写死最多两个参数
function
invokeCallback
(
id
,
res
,
extras
)
{
if
(
typeof
id
===
'
number
'
)
{
const
opts
=
invokeCallbacks
[
id
];
if
(
opts
)
{
if
(
!
opts
.
keepAlive
)
{
delete
invokeCallbacks
[
id
];
}
return
opts
.
callback
(
res
,
extras
);
}
}
return
res
;
}
const
API_SUCCESS
=
'
success
'
;
const
API_FAIL
=
'
fail
'
;
const
API_COMPLETE
=
'
complete
'
;
function
getApiCallbacks
(
args
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
args
)
{
...
...
@@ -200,6 +226,36 @@ function getApiCallbacks(args) {
}
}
return
apiCallbacks
;
}
function
normalizeErrMsg$1
(
errMsg
,
name
)
{
if
(
!
errMsg
||
errMsg
.
indexOf
(
'
:fail
'
)
===
-
1
)
{
return
name
+
'
:ok
'
;
}
return
name
+
errMsg
.
substring
(
errMsg
.
indexOf
(
'
:fail
'
));
}
function
createAsyncApiCallback
(
name
,
args
=
{},
{
beforeAll
,
beforeSuccess
}
=
{})
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFunction
(
success
);
const
hasFail
=
isFunction
(
fail
);
const
hasComplete
=
isFunction
(
complete
);
const
callbackId
=
invokeCallbackId
++
;
addInvokeCallback
(
callbackId
,
name
,
(
res
)
=>
{
res
=
res
||
{};
res
.
errMsg
=
normalizeErrMsg$1
(
res
.
errMsg
,
name
);
isFunction
(
beforeAll
)
&&
beforeAll
(
res
);
if
(
res
.
errMsg
===
name
+
'
:ok
'
)
{
isFunction
(
beforeSuccess
)
&&
beforeSuccess
(
res
,
args
);
hasSuccess
&&
success
(
res
);
}
else
{
hasFail
&&
fail
(
res
);
}
hasComplete
&&
complete
(
res
);
});
return
callbackId
;
}
const
HOOK_SUCCESS
=
'
success
'
;
...
...
@@ -301,6 +357,13 @@ function invokeApi(method, api, options, params) {
return
api
(
options
,
...
params
);
}
function
hasCallback
(
args
)
{
if
(
isPlainObject
(
args
)
&&
[
API_SUCCESS
,
API_FAIL
,
API_COMPLETE
].
find
((
cb
)
=>
isFunction
(
args
[
cb
])))
{
return
true
;
}
return
false
;
}
function
handlePromise
(
promise
)
{
// if (__UNI_FEATURE_PROMISE__) {
// return promise
...
...
@@ -310,6 +373,16 @@ function handlePromise(promise) {
// .catch((err) => [err])
// }
return
promise
;
}
function
promisify$1
(
name
,
fn
)
{
return
(
args
=
{},
...
rest
)
=>
{
if
(
hasCallback
(
args
))
{
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
fn
,
args
,
rest
));
}
return
wrapperReturnValue
(
name
,
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
invokeApi
(
name
,
fn
,
extend
(
args
,
{
success
:
resolve
,
fail
:
reject
}),
rest
);
})));
};
}
function
formatApiArgs
(
args
,
options
)
{
...
...
@@ -337,6 +410,12 @@ function formatApiArgs(args, options) {
}
}
}
function
invokeSuccess
(
id
,
name
,
res
)
{
return
invokeCallback
(
id
,
extend
(
res
||
{},
{
errMsg
:
name
+
'
:ok
'
}));
}
function
invokeFail
(
id
,
name
,
errMsg
,
errRes
)
{
return
invokeCallback
(
id
,
extend
({
errMsg
:
name
+
'
:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
},
errRes
));
}
function
beforeInvokeApi
(
name
,
args
,
protocol
,
options
)
{
if
((
process
.
env
.
NODE_ENV
!==
'
production
'
))
{
validateProtocols
(
name
,
args
,
protocol
);
...
...
@@ -352,6 +431,29 @@ function beforeInvokeApi(name, args, protocol, options) {
return
errMsg
;
}
}
function
normalizeErrMsg
(
errMsg
)
{
if
(
!
errMsg
||
isString
(
errMsg
))
{
return
errMsg
;
}
if
(
errMsg
.
stack
)
{
console
.
error
(
errMsg
.
message
+
LINEFEED
+
errMsg
.
stack
);
return
errMsg
.
message
;
}
return
errMsg
;
}
function
wrapperTaskApi
(
name
,
fn
,
protocol
,
options
)
{
return
(
args
)
=>
{
const
id
=
createAsyncApiCallback
(
name
,
args
,
options
);
const
errMsg
=
beforeInvokeApi
(
name
,
[
args
],
protocol
,
options
);
if
(
errMsg
)
{
return
invokeFail
(
id
,
name
,
errMsg
);
}
return
fn
(
args
,
{
resolve
:
(
res
)
=>
invokeSuccess
(
id
,
name
,
res
),
reject
:
(
errMsg
,
errRes
)
=>
invokeFail
(
id
,
name
,
normalizeErrMsg
(
errMsg
),
errRes
),
});
};
}
function
wrapperSyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
(...
args
)
=>
{
const
errMsg
=
beforeInvokeApi
(
name
,
args
,
protocol
,
options
);
...
...
@@ -361,8 +463,14 @@ function wrapperSyncApi(name, fn, protocol, options) {
return
fn
.
apply
(
null
,
args
);
};
}
function
wrapperAsyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
wrapperTaskApi
(
name
,
fn
,
protocol
,
options
);
}
function
defineSyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
wrapperSyncApi
(
name
,
fn
,
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
?
protocol
:
undefined
,
options
);
}
function
defineAsyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
promisify$1
(
name
,
wrapperAsyncApi
(
name
,
fn
,
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
?
protocol
:
undefined
,
options
));
}
const
API_UPX2PX
=
'
upx2px
'
;
...
...
@@ -582,30 +690,20 @@ function invokeGetPushCidCallbacks(cid, errMsg) {
});
getPushCidCallbacks
.
length
=
0
;
}
function
getPushClientId
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFunction
(
success
);
const
hasFail
=
isFunction
(
fail
);
const
hasComplete
=
isFunction
(
complete
);
const
API_GET_PUSH_CLIENT_ID
=
'
getPushClientId
'
;
const
getPushClientId
=
defineAsyncApi
(
API_GET_PUSH_CLIENT_ID
,
(
_
,
{
resolve
,
reject
})
=>
{
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
;
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushClientId:ok
'
,
cid
};
hasSuccess
&&
success
(
res
);
resolve
({
cid
});
}
else
{
res
=
{
errMsg
:
'
getPushClientId:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
};
hasFail
&&
fail
(
res
);
reject
(
errMsg
);
}
hasComplete
&&
complete
(
res
);
});
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
));
}
}
}
);
const
onPushMessageCallbacks
=
[];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const
onPushMessage
=
(
fn
)
=>
{
...
...
packages/uni-mp-toutiao/dist/uni.api.esm.js
浏览文件 @
5b21378e
import
{
isArray
,
hasOwn
,
isString
,
isPlainObject
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isFunction
,
isPromise
,
remove
,
extend
}
from
'
@vue/shared
'
;
import
{
isArray
,
hasOwn
,
isString
,
isPlainObject
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isFunction
,
isPromise
,
extend
,
remove
}
from
'
@vue/shared
'
;
import
{
normalizeLocale
,
LOCALE_EN
}
from
'
@dcloudio/uni-i18n
'
;
import
{
Emitter
,
onCreateVueApp
,
invokeCreateVueAppHook
}
from
'
@dcloudio/uni-shared
'
;
import
{
LINEFEED
,
Emitter
,
onCreateVueApp
,
invokeCreateVueAppHook
}
from
'
@dcloudio/uni-shared
'
;
const
eventChannels
=
{};
const
eventChannelStack
=
[];
...
...
@@ -190,6 +190,32 @@ function tryCatch(fn) {
};
}
let
invokeCallbackId
=
1
;
const
invokeCallbacks
=
{};
function
addInvokeCallback
(
id
,
name
,
callback
,
keepAlive
=
false
)
{
invokeCallbacks
[
id
]
=
{
name
,
keepAlive
,
callback
,
};
return
id
;
}
// onNativeEventReceive((event,data)=>{}) 需要两个参数,目前写死最多两个参数
function
invokeCallback
(
id
,
res
,
extras
)
{
if
(
typeof
id
===
'
number
'
)
{
const
opts
=
invokeCallbacks
[
id
];
if
(
opts
)
{
if
(
!
opts
.
keepAlive
)
{
delete
invokeCallbacks
[
id
];
}
return
opts
.
callback
(
res
,
extras
);
}
}
return
res
;
}
const
API_SUCCESS
=
'
success
'
;
const
API_FAIL
=
'
fail
'
;
const
API_COMPLETE
=
'
complete
'
;
function
getApiCallbacks
(
args
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
args
)
{
...
...
@@ -200,6 +226,36 @@ function getApiCallbacks(args) {
}
}
return
apiCallbacks
;
}
function
normalizeErrMsg$1
(
errMsg
,
name
)
{
if
(
!
errMsg
||
errMsg
.
indexOf
(
'
:fail
'
)
===
-
1
)
{
return
name
+
'
:ok
'
;
}
return
name
+
errMsg
.
substring
(
errMsg
.
indexOf
(
'
:fail
'
));
}
function
createAsyncApiCallback
(
name
,
args
=
{},
{
beforeAll
,
beforeSuccess
}
=
{})
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFunction
(
success
);
const
hasFail
=
isFunction
(
fail
);
const
hasComplete
=
isFunction
(
complete
);
const
callbackId
=
invokeCallbackId
++
;
addInvokeCallback
(
callbackId
,
name
,
(
res
)
=>
{
res
=
res
||
{};
res
.
errMsg
=
normalizeErrMsg$1
(
res
.
errMsg
,
name
);
isFunction
(
beforeAll
)
&&
beforeAll
(
res
);
if
(
res
.
errMsg
===
name
+
'
:ok
'
)
{
isFunction
(
beforeSuccess
)
&&
beforeSuccess
(
res
,
args
);
hasSuccess
&&
success
(
res
);
}
else
{
hasFail
&&
fail
(
res
);
}
hasComplete
&&
complete
(
res
);
});
return
callbackId
;
}
const
HOOK_SUCCESS
=
'
success
'
;
...
...
@@ -301,6 +357,13 @@ function invokeApi(method, api, options, params) {
return
api
(
options
,
...
params
);
}
function
hasCallback
(
args
)
{
if
(
isPlainObject
(
args
)
&&
[
API_SUCCESS
,
API_FAIL
,
API_COMPLETE
].
find
((
cb
)
=>
isFunction
(
args
[
cb
])))
{
return
true
;
}
return
false
;
}
function
handlePromise
(
promise
)
{
// if (__UNI_FEATURE_PROMISE__) {
// return promise
...
...
@@ -310,6 +373,16 @@ function handlePromise(promise) {
// .catch((err) => [err])
// }
return
promise
;
}
function
promisify$1
(
name
,
fn
)
{
return
(
args
=
{},
...
rest
)
=>
{
if
(
hasCallback
(
args
))
{
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
fn
,
args
,
rest
));
}
return
wrapperReturnValue
(
name
,
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
invokeApi
(
name
,
fn
,
extend
(
args
,
{
success
:
resolve
,
fail
:
reject
}),
rest
);
})));
};
}
function
formatApiArgs
(
args
,
options
)
{
...
...
@@ -337,6 +410,12 @@ function formatApiArgs(args, options) {
}
}
}
function
invokeSuccess
(
id
,
name
,
res
)
{
return
invokeCallback
(
id
,
extend
(
res
||
{},
{
errMsg
:
name
+
'
:ok
'
}));
}
function
invokeFail
(
id
,
name
,
errMsg
,
errRes
)
{
return
invokeCallback
(
id
,
extend
({
errMsg
:
name
+
'
:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
},
errRes
));
}
function
beforeInvokeApi
(
name
,
args
,
protocol
,
options
)
{
if
((
process
.
env
.
NODE_ENV
!==
'
production
'
))
{
validateProtocols
(
name
,
args
,
protocol
);
...
...
@@ -352,6 +431,29 @@ function beforeInvokeApi(name, args, protocol, options) {
return
errMsg
;
}
}
function
normalizeErrMsg
(
errMsg
)
{
if
(
!
errMsg
||
isString
(
errMsg
))
{
return
errMsg
;
}
if
(
errMsg
.
stack
)
{
console
.
error
(
errMsg
.
message
+
LINEFEED
+
errMsg
.
stack
);
return
errMsg
.
message
;
}
return
errMsg
;
}
function
wrapperTaskApi
(
name
,
fn
,
protocol
,
options
)
{
return
(
args
)
=>
{
const
id
=
createAsyncApiCallback
(
name
,
args
,
options
);
const
errMsg
=
beforeInvokeApi
(
name
,
[
args
],
protocol
,
options
);
if
(
errMsg
)
{
return
invokeFail
(
id
,
name
,
errMsg
);
}
return
fn
(
args
,
{
resolve
:
(
res
)
=>
invokeSuccess
(
id
,
name
,
res
),
reject
:
(
errMsg
,
errRes
)
=>
invokeFail
(
id
,
name
,
normalizeErrMsg
(
errMsg
),
errRes
),
});
};
}
function
wrapperSyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
(...
args
)
=>
{
const
errMsg
=
beforeInvokeApi
(
name
,
args
,
protocol
,
options
);
...
...
@@ -361,8 +463,14 @@ function wrapperSyncApi(name, fn, protocol, options) {
return
fn
.
apply
(
null
,
args
);
};
}
function
wrapperAsyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
wrapperTaskApi
(
name
,
fn
,
protocol
,
options
);
}
function
defineSyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
wrapperSyncApi
(
name
,
fn
,
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
?
protocol
:
undefined
,
options
);
}
function
defineAsyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
promisify$1
(
name
,
wrapperAsyncApi
(
name
,
fn
,
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
?
protocol
:
undefined
,
options
));
}
const
API_UPX2PX
=
'
upx2px
'
;
...
...
@@ -582,30 +690,20 @@ function invokeGetPushCidCallbacks(cid, errMsg) {
});
getPushCidCallbacks
.
length
=
0
;
}
function
getPushClientId
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFunction
(
success
);
const
hasFail
=
isFunction
(
fail
);
const
hasComplete
=
isFunction
(
complete
);
const
API_GET_PUSH_CLIENT_ID
=
'
getPushClientId
'
;
const
getPushClientId
=
defineAsyncApi
(
API_GET_PUSH_CLIENT_ID
,
(
_
,
{
resolve
,
reject
})
=>
{
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
;
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushClientId:ok
'
,
cid
};
hasSuccess
&&
success
(
res
);
resolve
({
cid
});
}
else
{
res
=
{
errMsg
:
'
getPushClientId:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
};
hasFail
&&
fail
(
res
);
reject
(
errMsg
);
}
hasComplete
&&
complete
(
res
);
});
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
));
}
}
}
);
const
onPushMessageCallbacks
=
[];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const
onPushMessage
=
(
fn
)
=>
{
...
...
packages/uni-mp-weixin/dist/uni.api.esm.js
浏览文件 @
5b21378e
import
{
isArray
,
hasOwn
,
isString
,
isPlainObject
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isFunction
,
isPromise
,
remove
,
extend
}
from
'
@vue/shared
'
;
import
{
isArray
,
hasOwn
,
isString
,
isPlainObject
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isFunction
,
isPromise
,
extend
,
remove
}
from
'
@vue/shared
'
;
import
{
normalizeLocale
,
LOCALE_EN
}
from
'
@dcloudio/uni-i18n
'
;
import
{
Emitter
,
onCreateVueApp
,
invokeCreateVueAppHook
,
sortObject
}
from
'
@dcloudio/uni-shared
'
;
import
{
LINEFEED
,
Emitter
,
onCreateVueApp
,
invokeCreateVueAppHook
,
sortObject
}
from
'
@dcloudio/uni-shared
'
;
function
getBaseSystemInfo
()
{
return
wx
.
getSystemInfoSync
()
...
...
@@ -154,6 +154,32 @@ function tryCatch(fn) {
};
}
let
invokeCallbackId
=
1
;
const
invokeCallbacks
=
{};
function
addInvokeCallback
(
id
,
name
,
callback
,
keepAlive
=
false
)
{
invokeCallbacks
[
id
]
=
{
name
,
keepAlive
,
callback
,
};
return
id
;
}
// onNativeEventReceive((event,data)=>{}) 需要两个参数,目前写死最多两个参数
function
invokeCallback
(
id
,
res
,
extras
)
{
if
(
typeof
id
===
'
number
'
)
{
const
opts
=
invokeCallbacks
[
id
];
if
(
opts
)
{
if
(
!
opts
.
keepAlive
)
{
delete
invokeCallbacks
[
id
];
}
return
opts
.
callback
(
res
,
extras
);
}
}
return
res
;
}
const
API_SUCCESS
=
'
success
'
;
const
API_FAIL
=
'
fail
'
;
const
API_COMPLETE
=
'
complete
'
;
function
getApiCallbacks
(
args
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
args
)
{
...
...
@@ -164,6 +190,36 @@ function getApiCallbacks(args) {
}
}
return
apiCallbacks
;
}
function
normalizeErrMsg$1
(
errMsg
,
name
)
{
if
(
!
errMsg
||
errMsg
.
indexOf
(
'
:fail
'
)
===
-
1
)
{
return
name
+
'
:ok
'
;
}
return
name
+
errMsg
.
substring
(
errMsg
.
indexOf
(
'
:fail
'
));
}
function
createAsyncApiCallback
(
name
,
args
=
{},
{
beforeAll
,
beforeSuccess
}
=
{})
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFunction
(
success
);
const
hasFail
=
isFunction
(
fail
);
const
hasComplete
=
isFunction
(
complete
);
const
callbackId
=
invokeCallbackId
++
;
addInvokeCallback
(
callbackId
,
name
,
(
res
)
=>
{
res
=
res
||
{};
res
.
errMsg
=
normalizeErrMsg$1
(
res
.
errMsg
,
name
);
isFunction
(
beforeAll
)
&&
beforeAll
(
res
);
if
(
res
.
errMsg
===
name
+
'
:ok
'
)
{
isFunction
(
beforeSuccess
)
&&
beforeSuccess
(
res
,
args
);
hasSuccess
&&
success
(
res
);
}
else
{
hasFail
&&
fail
(
res
);
}
hasComplete
&&
complete
(
res
);
});
return
callbackId
;
}
const
HOOK_SUCCESS
=
'
success
'
;
...
...
@@ -265,6 +321,13 @@ function invokeApi(method, api, options, params) {
return
api
(
options
,
...
params
);
}
function
hasCallback
(
args
)
{
if
(
isPlainObject
(
args
)
&&
[
API_SUCCESS
,
API_FAIL
,
API_COMPLETE
].
find
((
cb
)
=>
isFunction
(
args
[
cb
])))
{
return
true
;
}
return
false
;
}
function
handlePromise
(
promise
)
{
// if (__UNI_FEATURE_PROMISE__) {
// return promise
...
...
@@ -274,6 +337,16 @@ function handlePromise(promise) {
// .catch((err) => [err])
// }
return
promise
;
}
function
promisify$1
(
name
,
fn
)
{
return
(
args
=
{},
...
rest
)
=>
{
if
(
hasCallback
(
args
))
{
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
fn
,
args
,
rest
));
}
return
wrapperReturnValue
(
name
,
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
invokeApi
(
name
,
fn
,
extend
(
args
,
{
success
:
resolve
,
fail
:
reject
}),
rest
);
})));
};
}
function
formatApiArgs
(
args
,
options
)
{
...
...
@@ -301,6 +374,12 @@ function formatApiArgs(args, options) {
}
}
}
function
invokeSuccess
(
id
,
name
,
res
)
{
return
invokeCallback
(
id
,
extend
(
res
||
{},
{
errMsg
:
name
+
'
:ok
'
}));
}
function
invokeFail
(
id
,
name
,
errMsg
,
errRes
)
{
return
invokeCallback
(
id
,
extend
({
errMsg
:
name
+
'
:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
},
errRes
));
}
function
beforeInvokeApi
(
name
,
args
,
protocol
,
options
)
{
if
((
process
.
env
.
NODE_ENV
!==
'
production
'
))
{
validateProtocols
(
name
,
args
,
protocol
);
...
...
@@ -316,6 +395,29 @@ function beforeInvokeApi(name, args, protocol, options) {
return
errMsg
;
}
}
function
normalizeErrMsg
(
errMsg
)
{
if
(
!
errMsg
||
isString
(
errMsg
))
{
return
errMsg
;
}
if
(
errMsg
.
stack
)
{
console
.
error
(
errMsg
.
message
+
LINEFEED
+
errMsg
.
stack
);
return
errMsg
.
message
;
}
return
errMsg
;
}
function
wrapperTaskApi
(
name
,
fn
,
protocol
,
options
)
{
return
(
args
)
=>
{
const
id
=
createAsyncApiCallback
(
name
,
args
,
options
);
const
errMsg
=
beforeInvokeApi
(
name
,
[
args
],
protocol
,
options
);
if
(
errMsg
)
{
return
invokeFail
(
id
,
name
,
errMsg
);
}
return
fn
(
args
,
{
resolve
:
(
res
)
=>
invokeSuccess
(
id
,
name
,
res
),
reject
:
(
errMsg
,
errRes
)
=>
invokeFail
(
id
,
name
,
normalizeErrMsg
(
errMsg
),
errRes
),
});
};
}
function
wrapperSyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
(...
args
)
=>
{
const
errMsg
=
beforeInvokeApi
(
name
,
args
,
protocol
,
options
);
...
...
@@ -325,8 +427,14 @@ function wrapperSyncApi(name, fn, protocol, options) {
return
fn
.
apply
(
null
,
args
);
};
}
function
wrapperAsyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
wrapperTaskApi
(
name
,
fn
,
protocol
,
options
);
}
function
defineSyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
wrapperSyncApi
(
name
,
fn
,
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
?
protocol
:
undefined
,
options
);
}
function
defineAsyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
promisify$1
(
name
,
wrapperAsyncApi
(
name
,
fn
,
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
?
protocol
:
undefined
,
options
));
}
const
API_UPX2PX
=
'
upx2px
'
;
...
...
@@ -546,30 +654,20 @@ function invokeGetPushCidCallbacks(cid, errMsg) {
});
getPushCidCallbacks
.
length
=
0
;
}
function
getPushClientId
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFunction
(
success
);
const
hasFail
=
isFunction
(
fail
);
const
hasComplete
=
isFunction
(
complete
);
const
API_GET_PUSH_CLIENT_ID
=
'
getPushClientId
'
;
const
getPushClientId
=
defineAsyncApi
(
API_GET_PUSH_CLIENT_ID
,
(
_
,
{
resolve
,
reject
})
=>
{
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
;
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushClientId:ok
'
,
cid
};
hasSuccess
&&
success
(
res
);
resolve
({
cid
});
}
else
{
res
=
{
errMsg
:
'
getPushClientId:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
};
hasFail
&&
fail
(
res
);
reject
(
errMsg
);
}
hasComplete
&&
complete
(
res
);
});
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
));
}
}
}
);
const
onPushMessageCallbacks
=
[];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const
onPushMessage
=
(
fn
)
=>
{
...
...
packages/uni-quickapp-webview/dist/uni.api.esm.js
浏览文件 @
5b21378e
import
{
isArray
,
hasOwn
,
isString
,
isPlainObject
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isFunction
,
isPromise
,
remove
,
extend
}
from
'
@vue/shared
'
;
import
{
isArray
,
hasOwn
,
isString
,
isPlainObject
,
isObject
,
capitalize
,
toRawType
,
makeMap
,
isFunction
,
isPromise
,
extend
,
remove
}
from
'
@vue/shared
'
;
import
{
normalizeLocale
,
LOCALE_EN
}
from
'
@dcloudio/uni-i18n
'
;
import
{
Emitter
,
onCreateVueApp
,
invokeCreateVueAppHook
}
from
'
@dcloudio/uni-shared
'
;
import
{
LINEFEED
,
Emitter
,
onCreateVueApp
,
invokeCreateVueAppHook
}
from
'
@dcloudio/uni-shared
'
;
const
eventChannels
=
{};
const
eventChannelStack
=
[];
...
...
@@ -190,6 +190,32 @@ function tryCatch(fn) {
};
}
let
invokeCallbackId
=
1
;
const
invokeCallbacks
=
{};
function
addInvokeCallback
(
id
,
name
,
callback
,
keepAlive
=
false
)
{
invokeCallbacks
[
id
]
=
{
name
,
keepAlive
,
callback
,
};
return
id
;
}
// onNativeEventReceive((event,data)=>{}) 需要两个参数,目前写死最多两个参数
function
invokeCallback
(
id
,
res
,
extras
)
{
if
(
typeof
id
===
'
number
'
)
{
const
opts
=
invokeCallbacks
[
id
];
if
(
opts
)
{
if
(
!
opts
.
keepAlive
)
{
delete
invokeCallbacks
[
id
];
}
return
opts
.
callback
(
res
,
extras
);
}
}
return
res
;
}
const
API_SUCCESS
=
'
success
'
;
const
API_FAIL
=
'
fail
'
;
const
API_COMPLETE
=
'
complete
'
;
function
getApiCallbacks
(
args
)
{
const
apiCallbacks
=
{};
for
(
const
name
in
args
)
{
...
...
@@ -200,6 +226,36 @@ function getApiCallbacks(args) {
}
}
return
apiCallbacks
;
}
function
normalizeErrMsg$1
(
errMsg
,
name
)
{
if
(
!
errMsg
||
errMsg
.
indexOf
(
'
:fail
'
)
===
-
1
)
{
return
name
+
'
:ok
'
;
}
return
name
+
errMsg
.
substring
(
errMsg
.
indexOf
(
'
:fail
'
));
}
function
createAsyncApiCallback
(
name
,
args
=
{},
{
beforeAll
,
beforeSuccess
}
=
{})
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFunction
(
success
);
const
hasFail
=
isFunction
(
fail
);
const
hasComplete
=
isFunction
(
complete
);
const
callbackId
=
invokeCallbackId
++
;
addInvokeCallback
(
callbackId
,
name
,
(
res
)
=>
{
res
=
res
||
{};
res
.
errMsg
=
normalizeErrMsg$1
(
res
.
errMsg
,
name
);
isFunction
(
beforeAll
)
&&
beforeAll
(
res
);
if
(
res
.
errMsg
===
name
+
'
:ok
'
)
{
isFunction
(
beforeSuccess
)
&&
beforeSuccess
(
res
,
args
);
hasSuccess
&&
success
(
res
);
}
else
{
hasFail
&&
fail
(
res
);
}
hasComplete
&&
complete
(
res
);
});
return
callbackId
;
}
const
HOOK_SUCCESS
=
'
success
'
;
...
...
@@ -301,6 +357,13 @@ function invokeApi(method, api, options, params) {
return
api
(
options
,
...
params
);
}
function
hasCallback
(
args
)
{
if
(
isPlainObject
(
args
)
&&
[
API_SUCCESS
,
API_FAIL
,
API_COMPLETE
].
find
((
cb
)
=>
isFunction
(
args
[
cb
])))
{
return
true
;
}
return
false
;
}
function
handlePromise
(
promise
)
{
// if (__UNI_FEATURE_PROMISE__) {
// return promise
...
...
@@ -310,6 +373,16 @@ function handlePromise(promise) {
// .catch((err) => [err])
// }
return
promise
;
}
function
promisify$1
(
name
,
fn
)
{
return
(
args
=
{},
...
rest
)
=>
{
if
(
hasCallback
(
args
))
{
return
wrapperReturnValue
(
name
,
invokeApi
(
name
,
fn
,
args
,
rest
));
}
return
wrapperReturnValue
(
name
,
handlePromise
(
new
Promise
((
resolve
,
reject
)
=>
{
invokeApi
(
name
,
fn
,
extend
(
args
,
{
success
:
resolve
,
fail
:
reject
}),
rest
);
})));
};
}
function
formatApiArgs
(
args
,
options
)
{
...
...
@@ -337,6 +410,12 @@ function formatApiArgs(args, options) {
}
}
}
function
invokeSuccess
(
id
,
name
,
res
)
{
return
invokeCallback
(
id
,
extend
(
res
||
{},
{
errMsg
:
name
+
'
:ok
'
}));
}
function
invokeFail
(
id
,
name
,
errMsg
,
errRes
)
{
return
invokeCallback
(
id
,
extend
({
errMsg
:
name
+
'
:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
},
errRes
));
}
function
beforeInvokeApi
(
name
,
args
,
protocol
,
options
)
{
if
((
process
.
env
.
NODE_ENV
!==
'
production
'
))
{
validateProtocols
(
name
,
args
,
protocol
);
...
...
@@ -352,6 +431,29 @@ function beforeInvokeApi(name, args, protocol, options) {
return
errMsg
;
}
}
function
normalizeErrMsg
(
errMsg
)
{
if
(
!
errMsg
||
isString
(
errMsg
))
{
return
errMsg
;
}
if
(
errMsg
.
stack
)
{
console
.
error
(
errMsg
.
message
+
LINEFEED
+
errMsg
.
stack
);
return
errMsg
.
message
;
}
return
errMsg
;
}
function
wrapperTaskApi
(
name
,
fn
,
protocol
,
options
)
{
return
(
args
)
=>
{
const
id
=
createAsyncApiCallback
(
name
,
args
,
options
);
const
errMsg
=
beforeInvokeApi
(
name
,
[
args
],
protocol
,
options
);
if
(
errMsg
)
{
return
invokeFail
(
id
,
name
,
errMsg
);
}
return
fn
(
args
,
{
resolve
:
(
res
)
=>
invokeSuccess
(
id
,
name
,
res
),
reject
:
(
errMsg
,
errRes
)
=>
invokeFail
(
id
,
name
,
normalizeErrMsg
(
errMsg
),
errRes
),
});
};
}
function
wrapperSyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
(...
args
)
=>
{
const
errMsg
=
beforeInvokeApi
(
name
,
args
,
protocol
,
options
);
...
...
@@ -361,8 +463,14 @@ function wrapperSyncApi(name, fn, protocol, options) {
return
fn
.
apply
(
null
,
args
);
};
}
function
wrapperAsyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
wrapperTaskApi
(
name
,
fn
,
protocol
,
options
);
}
function
defineSyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
wrapperSyncApi
(
name
,
fn
,
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
?
protocol
:
undefined
,
options
);
}
function
defineAsyncApi
(
name
,
fn
,
protocol
,
options
)
{
return
promisify$1
(
name
,
wrapperAsyncApi
(
name
,
fn
,
(
process
.
env
.
NODE_ENV
!==
'
production
'
)
?
protocol
:
undefined
,
options
));
}
const
API_UPX2PX
=
'
upx2px
'
;
...
...
@@ -582,30 +690,20 @@ function invokeGetPushCidCallbacks(cid, errMsg) {
});
getPushCidCallbacks
.
length
=
0
;
}
function
getPushClientId
(
args
)
{
if
(
!
isPlainObject
(
args
))
{
args
=
{};
}
const
{
success
,
fail
,
complete
}
=
getApiCallbacks
(
args
);
const
hasSuccess
=
isFunction
(
success
);
const
hasFail
=
isFunction
(
fail
);
const
hasComplete
=
isFunction
(
complete
);
const
API_GET_PUSH_CLIENT_ID
=
'
getPushClientId
'
;
const
getPushClientId
=
defineAsyncApi
(
API_GET_PUSH_CLIENT_ID
,
(
_
,
{
resolve
,
reject
})
=>
{
getPushCidCallbacks
.
push
((
cid
,
errMsg
)
=>
{
let
res
;
if
(
cid
)
{
res
=
{
errMsg
:
'
getPushClientId:ok
'
,
cid
};
hasSuccess
&&
success
(
res
);
resolve
({
cid
});
}
else
{
res
=
{
errMsg
:
'
getPushClientId:fail
'
+
(
errMsg
?
'
'
+
errMsg
:
''
)
};
hasFail
&&
fail
(
res
);
reject
(
errMsg
);
}
hasComplete
&&
complete
(
res
);
});
if
(
typeof
cid
!==
'
undefined
'
)
{
Promise
.
resolve
().
then
(()
=>
invokeGetPushCidCallbacks
(
cid
,
cidErrMsg
));
}
}
}
);
const
onPushMessageCallbacks
=
[];
// 不使用 defineOnApi 实现,是因为 defineOnApi 依赖 UniServiceJSBridge ,该对象目前在小程序上未提供,故简单实现
const
onPushMessage
=
(
fn
)
=>
{
...
...
pnpm-lock.yaml
浏览文件 @
5b21378e
...
...
@@ -5178,7 +5178,7 @@ packages:
resolution
:
{
integrity
:
sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==
}
/graceful-fs/4.2.9
:
resolution
:
{
integrity
:
sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==
,
registry
:
https
:
//registry.yarnpkg.com/
}
resolution
:
{
integrity
:
sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==
,
registry
:
https
:
//registry.yarnpkg.com/
,
tarball
:
https
:
//registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.2.9.tgz
}
dev
:
true
/has-flag/3.0.0
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录