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 7b82321d
authored
2026-04-19 23:35:23 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
上传文件增加进度反馈
1 parent
67ac21a7
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
69 additions
and
1 deletions
lib/bloc/web_cubit.dart
lib/config/locator.dart
lib/data/repositories/message/upload_start_handler.dart
lib/services/dispatcher.dart
lib/bloc/web_cubit.dart
View file @
7b82321
...
...
@@ -408,6 +408,65 @@ class WebCubit extends Cubit<WebState> with WidgetsBindingObserver {
_controller
.
runJavaScript
(
script
);
}
/// 相应 uploadStart 指令
/// [unique] 消息唯一标识
/// [uploadId] 文件上传ID标识
///
void
sendUploadStartResponse
(
String
unique
,
String
uploadId
)
{
var
resp
=
{
'unique'
:
unique
,
'cmd'
:
'uploadFile'
,
'data'
:
{
'uploadId'
:
uploadId
,
'status'
:
1
,
'totalPart'
:
0
,
'sendedPart'
:
0
,
'totalByte'
:
0
,
'sendedByte'
:
0
,
},
'errMsg'
:
''
,
};
_sendResponse
(
resp
);
}
/// 发送上传进度到 WebView
/// [unique] 消息唯一标识
/// [uploadId] 文件上传ID标识
/// [totalPart] 总分片数
/// [sendedPart] 已上传分片数
/// [totalByte] 总字节数
/// [sendedByte] 已上传字节数
void
sendUploadProgress
(
String
unique
,
String
uploadId
,
int
totalPart
,
int
sendedPart
,
int
totalByte
,
int
sendedByte
)
{
var
resp
=
{
'unique'
:
unique
,
'cmd'
:
'uploadFileProgress'
,
'data'
:
{
'uploadId'
:
uploadId
,
'status'
:
2
,
'totalPart'
:
totalPart
,
'sendedPart'
:
sendedPart
,
'totalByte'
:
totalByte
,
'sendedByte'
:
sendedByte
,
},
'errMsg'
:
''
,
};
_sendResponse
(
resp
);
}
void
sendUploadEnd
(
String
unique
,
String
uploadId
,
String
url
)
{
var
resp
=
{
'unique'
:
''
,
'cmd'
:
'uploadFileEnd'
,
'data'
:
{
'uploadId'
:
uploadId
,
'url'
:
url
,
},
'errMsg'
:
''
};
_sendResponse
(
resp
);
}
void
finishLoading
()
{
emit
(
state
.
copyWith
(
loaded:
true
));
}
...
...
lib/config/locator.dart
View file @
7b82321
...
...
@@ -30,6 +30,7 @@ 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'
;
import
'package:appframe/data/repositories/message/upload_file.dart'
;
import
'package:appframe/data/repositories/message/upload_start_handler.dart'
;
import
'package:appframe/data/repositories/message/vibrate_short_handler.dart'
;
import
'package:appframe/data/repositories/message/video_info_handler.dart'
;
import
'package:appframe/data/repositories/message/wifi_info_handler.dart'
;
...
...
@@ -179,6 +180,7 @@ Future<void> setupLocator() async {
/// 上传文件
getIt
.
registerLazySingleton
<
MessageHandler
>(()
=>
UploadFileHandler
(),
instanceName:
'uploadFile'
);
getIt
.
registerLazySingleton
<
MessageHandler
>(()
=>
UploadStartHandler
(),
instanceName:
'uploadStart'
);
/// 下载文件
getIt
.
registerLazySingleton
<
MessageHandler
>(()
=>
DownloadFileHandler
(),
instanceName:
'downloadFile'
);
...
...
lib/data/repositories/message/upload_start_handler.dart
0 → 100644
View file @
7b82321
This diff is collapsed.
Click to expand it.
lib/services/dispatcher.dart
View file @
7b82321
...
...
@@ -4,6 +4,7 @@ import 'package:appframe/bloc/web_cubit.dart';
import
'package:appframe/config/locator.dart'
;
import
'package:appframe/data/models/message/h5_message.dart'
;
import
'package:appframe/data/models/message/h5_resp.dart'
;
import
'package:appframe/data/repositories/message/upload_start_handler.dart'
;
// 消息处理器抽象类
abstract
class
MessageHandler
{
...
...
@@ -56,11 +57,17 @@ class MessageDispatcher {
h5Message
.
cmd
==
"goLogin"
||
h5Message
.
cmd
.
startsWith
(
"setTitlebar"
)
||
h5Message
.
cmd
==
"audioPlay"
||
h5Message
.
cmd
==
"openLink"
)
{
h5Message
.
cmd
==
"openLink"
||
h5Message
.
cmd
==
"uploadStart"
)
{
handler
.
setCubit
(
webCubit
!);
handler
.
setMessage
(
message
);
}
// 针对 uploadStart 指令
if
(
h5Message
.
cmd
==
"uploadStart"
&&
handler
is
UploadStartHandler
)
{
handler
.
setCmdUnique
(
h5Message
.
unique
);
}
final
result
=
await
handler
.
handleMessage
(
h5Message
.
params
);
// 有些命令需要通过监听器调用Cubit,触发调用时不需要返回结果,不处理回调
if
(
result
==
null
)
{
...
...
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