Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
ethan
/
appframe
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit 7a9ce324
authored
2025-12-16 09:19:07 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
增加分享小程序指令
1 parent
21a37bfd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
0 deletions
lib/config/locator.dart
lib/data/repositories/message/share_handler.dart
lib/config/locator.dart
View file @
7a9ce32
...
...
@@ -24,6 +24,7 @@ import 'package:appframe/data/repositories/message/role_info_handler.dart';
import
'package:appframe/data/repositories/message/save_file_to_disk_handler.dart'
;
import
'package:appframe/data/repositories/message/save_to_album_handler.dart'
;
import
'package:appframe/data/repositories/message/scan_code_handler.dart'
;
import
'package:appframe/data/repositories/message/share_handler.dart'
;
import
'package:appframe/data/repositories/message/share_to_wx_handler.dart'
;
import
'package:appframe/data/repositories/message/storage_handler.dart'
;
import
'package:appframe/data/repositories/message/title_bar_handler.dart'
;
...
...
@@ -71,6 +72,9 @@ Future<void> setupLocator() async {
/// 打开小程序
getIt
.
registerLazySingleton
<
MessageHandler
>(()
=>
OpenWeappHandler
(),
instanceName:
'openWeapp'
);
/// 分享微信小程序卡片
getIt
.
registerLazySingleton
<
MessageHandler
>(()
=>
ShareHandler
(),
instanceName:
'share'
);
/// 分享微信会话
getIt
.
registerLazySingleton
<
MessageHandler
>(()
=>
ShareToWxHandler
(),
instanceName:
'sharetowx'
);
...
...
lib/data/repositories/message/share_handler.dart
0 → 100644
View file @
7a9ce32
import
'package:appframe/config/locator.dart'
;
import
'package:appframe/services/dispatcher.dart'
;
import
'package:fluwx/fluwx.dart'
;
class
ShareHandler
extends
MessageHandler
{
@override
Future
<
bool
>
handleMessage
(
params
)
async
{
if
(
params
is
!
Map
<
String
,
dynamic
>)
{
throw
Exception
(
'参数错误'
);
}
var
weapp
=
params
[
'weapp'
]
as
Map
<
String
,
dynamic
>?;
try
{
Fluwx
fluwx
=
getIt
.
get
<
Fluwx
>();
return
await
fluwx
.
share
(
WeChatShareMiniProgramModel
(
title:
weapp
?[
'title'
]
as
String
,
webPageUrl:
weapp
?[
'imageUrl'
]
as
String
,
path:
weapp
?[
'path'
]
as
String
,
userName:
weapp
?[
'appid'
]
as
String
,
miniProgramType:
_getWXMiniProgramType
(
weapp
?[
'envVersion'
]
as
String
?),
));
}
catch
(
e
)
{
print
(
e
);
return
false
;
}
}
WXMiniProgramType
_getWXMiniProgramType
(
String
?
envVersion
)
{
switch
(
envVersion
)
{
case
'release'
:
return
WXMiniProgramType
.
release
;
case
'trial'
:
return
WXMiniProgramType
.
preview
;
case
'develop'
:
return
WXMiniProgramType
.
test
;
default
:
return
WXMiniProgramType
.
preview
;
}
}
}
Write
Preview
Styling with
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment