update 自定义api的返回值类型
parent
73f3a24e55
commit
6c00cfc418
22
lib/mop.dart
22
lib/mop.dart
|
@ -7,7 +7,8 @@ import 'package:mop/api.dart';
|
|||
typedef MopEventCallback = void Function(dynamic event);
|
||||
typedef MopEventErrorCallback = void Function(dynamic event);
|
||||
|
||||
typedef ExtensionApiHandler = Future Function(dynamic params);
|
||||
typedef ExtensionApiHandler = Future<Map<String, dynamic>> Function(dynamic params);
|
||||
typedef MopAppletHandler = Future Function(dynamic params);
|
||||
|
||||
class FinStoreConfig {
|
||||
///创建应用时生成的SDK Key
|
||||
|
@ -317,6 +318,8 @@ class Mop {
|
|||
late int eventId = 0;
|
||||
final List<Map<String, dynamic>> _mopEventQueye = <Map<String, dynamic>>[];
|
||||
|
||||
final Map<String, MopAppletHandler> _appletHandlerApis = {};
|
||||
|
||||
final Map<String, ExtensionApiHandler> _extensionApis = {};
|
||||
|
||||
Map<String, ExtensionApiHandler> _webExtensionApis = {};
|
||||
|
@ -360,6 +363,11 @@ class Mop {
|
|||
if (handler != null) {
|
||||
return await handler(call.arguments);
|
||||
}
|
||||
|
||||
final apiHandler = _appletHandlerApis[name];
|
||||
if (apiHandler != null) {
|
||||
return await apiHandler(call.arguments);
|
||||
}
|
||||
} else if (call.method.startsWith("webExtentionApi:")) {
|
||||
final name = call.method.substring("webExtentionApi:".length);
|
||||
final handler = _webExtensionApis[name];
|
||||
|
@ -553,13 +561,13 @@ class Mop {
|
|||
/// 注册小程序事件处理
|
||||
///
|
||||
void registerAppletHandler(AppletHandler handler) {
|
||||
_extensionApis["forwardApplet"] = (params) async {
|
||||
_appletHandlerApis["forwardApplet"] = (params) async {
|
||||
handler.forwardApplet(Map<String, dynamic>.from(params));
|
||||
};
|
||||
_extensionApis["getUserInfo"] = (params) {
|
||||
_appletHandlerApis["getUserInfo"] = (params) {
|
||||
return handler.getUserInfo();
|
||||
};
|
||||
_extensionApis["getCustomMenus"] = (params) async {
|
||||
_appletHandlerApis["getCustomMenus"] = (params) async {
|
||||
final res = await handler.getCustomMenus(params["appId"]);
|
||||
List<Map<String, dynamic>> list = [];
|
||||
res.forEach((element) {
|
||||
|
@ -573,14 +581,14 @@ class Mop {
|
|||
debugPrint("registerAppletHandler getCustomMenus list $list");
|
||||
return list;
|
||||
};
|
||||
_extensionApis["onCustomMenuClick"] = (params) async {
|
||||
_appletHandlerApis["onCustomMenuClick"] = (params) async {
|
||||
return handler.onCustomMenuClick(
|
||||
params["appId"], params["path"], params["menuId"], params["appInfo"]);
|
||||
};
|
||||
_extensionApis["appletDidOpen"] = (params) async {
|
||||
_appletHandlerApis["appletDidOpen"] = (params) async {
|
||||
return handler.appletDidOpen(params["appId"]);
|
||||
};
|
||||
_extensionApis["getPhoneNumber"] = (params) async {
|
||||
_appletHandlerApis["getPhoneNumber"] = (params) async {
|
||||
return handler.getMobileNumber((params0) =>
|
||||
{_channel.invokeMethod("getPhoneNumberResult", params0)});
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue