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 0d825f57
authored
2025-11-25 18:29:19 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化调整
1 parent
df03443e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
64 deletions
lib/bloc/login_main_cubit.dart
lib/bloc/web_cubit.dart
lib/data/repositories/message/upload_file.dart
lib/bloc/login_main_cubit.dart
View file @
0d825f5
...
@@ -2,7 +2,6 @@ import 'package:appframe/config/constant.dart';
...
@@ -2,7 +2,6 @@ import 'package:appframe/config/constant.dart';
import
'package:appframe/config/locator.dart'
;
import
'package:appframe/config/locator.dart'
;
import
'package:appframe/config/routes.dart'
;
import
'package:appframe/config/routes.dart'
;
import
'package:appframe/data/repositories/wechat_auth_repository.dart'
;
import
'package:appframe/data/repositories/wechat_auth_repository.dart'
;
import
'package:appframe/services/im_service.dart'
;
import
'package:equatable/equatable.dart'
;
import
'package:equatable/equatable.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'package:fluwx/fluwx.dart'
;
import
'package:fluwx/fluwx.dart'
;
...
@@ -42,13 +41,11 @@ class LoginMainState extends Equatable {
...
@@ -42,13 +41,11 @@ class LoginMainState extends Equatable {
class
LoginMainCubit
extends
Cubit
<
LoginMainState
>
{
class
LoginMainCubit
extends
Cubit
<
LoginMainState
>
{
late
final
Fluwx
_fluwx
;
late
final
Fluwx
_fluwx
;
late
final
WechatAuthRepository
_wechatAuthRepository
;
late
final
WechatAuthRepository
_wechatAuthRepository
;
late
final
ImService
_imService
;
LoginMainCubit
(
super
.
initialState
)
{
LoginMainCubit
(
super
.
initialState
)
{
_fluwx
=
getIt
.
get
<
Fluwx
>();
_fluwx
=
getIt
.
get
<
Fluwx
>();
_fluwx
.
addSubscriber
(
_responseListener
);
_fluwx
.
addSubscriber
(
_responseListener
);
_wechatAuthRepository
=
getIt
<
WechatAuthRepository
>();
_wechatAuthRepository
=
getIt
<
WechatAuthRepository
>();
_imService
=
getIt
.
get
<
ImService
>();
}
}
void
toggleAgreed
(
bool
value
)
{
void
toggleAgreed
(
bool
value
)
{
...
@@ -89,6 +86,7 @@ class LoginMainCubit extends Cubit<LoginMainState> {
...
@@ -89,6 +86,7 @@ class LoginMainCubit extends Cubit<LoginMainState> {
void
_responseListener
(
WeChatResponse
response
)
async
{
void
_responseListener
(
WeChatResponse
response
)
async
{
if
(
response
is
WeChatAuthResponse
)
{
if
(
response
is
WeChatAuthResponse
)
{
if
(
response
.
code
==
null
||
response
.
code
==
''
)
{
if
(
response
.
code
==
null
||
response
.
code
==
''
)
{
emit
(
state
.
copyWith
(
loading:
false
));
return
;
return
;
}
}
...
@@ -111,17 +109,6 @@ class LoginMainCubit extends Cubit<LoginMainState> {
...
@@ -111,17 +109,6 @@ class LoginMainCubit extends Cubit<LoginMainState> {
sharedPreferences
.
setString
(
'auth_stuId'
,
stuId
??
''
);
sharedPreferences
.
setString
(
'auth_stuId'
,
stuId
??
''
);
sharedPreferences
.
setString
(
'auth_ip'
,
Constant
.
h5Server
);
sharedPreferences
.
setString
(
'auth_ip'
,
Constant
.
h5Server
);
if
(
Constant
.
needIM
)
{
// IM登录, 正式使用时,需要从服务端获取用户签名
var
loginResult
=
await
_imService
.
login
(
userCode
);
if
(
loginResult
)
{
print
(
"微信登录处,IM 登录成功"
);
await
_imService
.
registerPush
();
}
else
{
print
(
"微信登录处,IM 登录失败"
);
}
}
router
.
go
(
router
.
go
(
'/web'
,
'/web'
,
extra:
{
extra:
{
...
...
lib/bloc/web_cubit.dart
View file @
0d825f5
This diff is collapsed.
Click to expand it.
lib/data/repositories/message/upload_file.dart
View file @
0d825f5
...
@@ -12,29 +12,12 @@ import 'package:path_provider/path_provider.dart';
...
@@ -12,29 +12,12 @@ import 'package:path_provider/path_provider.dart';
import
'package:uuid/uuid.dart'
;
import
'package:uuid/uuid.dart'
;
class
UploadFileHandler
extends
MessageHandler
{
class
UploadFileHandler
extends
MessageHandler
{
// late Dio _dio;
// UploadFile5Handler() : _dio = Dio() {
// // _dio.httpClientAdapter = Http2Adapter(
// // ConnectionManager(idleTimeout: Duration(seconds: 10)),
// // );
//
// int connectTimeout = 30000;
// int receiveTimeout = 30000;
//
// _dio.options = BaseOptions(
// baseUrl: '',
// connectTimeout: Duration(milliseconds: connectTimeout),
// receiveTimeout: Duration(milliseconds: receiveTimeout),
// headers: {'Content-Type': '', 'Accept': ''},
// );
// }
@override
@override
Future
<
dynamic
>
handleMessage
(
params
)
async
{
Future
<
dynamic
>
handleMessage
(
params
)
async
{
if
(
params
is
!
Map
<
String
,
dynamic
>)
{
if
(
params
is
!
Map
<
String
,
dynamic
>)
{
throw
Exception
(
'参数错误'
);
throw
Exception
(
'参数错误'
);
}
}
final
String
?
tempFilePath
=
params
[
'tempFilePath'
]
as
String
?;
final
String
?
tempFilePath
=
params
[
'tempFilePath'
]
as
String
?;
if
(
tempFilePath
==
null
||
tempFilePath
.
isEmpty
)
{
if
(
tempFilePath
==
null
||
tempFilePath
.
isEmpty
)
{
throw
Exception
(
'参数错误'
);
throw
Exception
(
'参数错误'
);
...
@@ -50,18 +33,6 @@ class UploadFileHandler extends MessageHandler {
...
@@ -50,18 +33,6 @@ class UploadFileHandler extends MessageHandler {
throw
Exception
(
'参数错误'
);
throw
Exception
(
'参数错误'
);
}
}
// _dio = Dio()
// ..options = BaseOptions(
// baseUrl: '',
// connectTimeout: Duration(milliseconds: 30000),
// receiveTimeout: Duration(milliseconds: 30000),
// headers: {'Content-Type': '', 'Accept': ''},
// )
// /*..httpClientAdapter = Http2Adapter(
// ConnectionManager(idleTimeout: Duration(seconds: 10)),
// )*/
// ;
final
startTime
=
DateTime
.
now
();
final
startTime
=
DateTime
.
now
();
final
result
=
await
_handle
(
tempFilePath
,
busi
,
subBusi
);
final
result
=
await
_handle
(
tempFilePath
,
busi
,
subBusi
);
final
endTime
=
DateTime
.
now
();
final
endTime
=
DateTime
.
now
();
...
@@ -205,7 +176,6 @@ class UploadFileHandler extends MessageHandler {
...
@@ -205,7 +176,6 @@ class UploadFileHandler extends MessageHandler {
futures
.
clear
();
futures
.
clear
();
await
randomAccessFile
.
close
();
await
randomAccessFile
.
close
();
dio
.
close
(
force:
true
);
///
///
/// 7 合并
/// 7 合并
...
@@ -215,12 +185,21 @@ class UploadFileHandler extends MessageHandler {
...
@@ -215,12 +185,21 @@ class UploadFileHandler extends MessageHandler {
var
endTime2
=
DateTime
.
now
();
var
endTime2
=
DateTime
.
now
();
print
(
'====================>合并签名耗时:
${endTime2.millisecondsSinceEpoch - startTime2.millisecondsSinceEpoch}
毫秒'
);
print
(
'====================>合并签名耗时:
${endTime2.millisecondsSinceEpoch - startTime2.millisecondsSinceEpoch}
毫秒'
);
///
/// 8 针对视频生成封面
///
// if (mimeType?.startsWith('video/') ?? false) {
// await _genHwVideoCover(dio, objectKey);
// }
dio
.
close
(
force:
true
);
bxeApiService
.
close
();
bxeApiService
.
close
();
return
{
'url'
:
_addPreUrl
(
location
)};
return
{
'url'
:
_addPreUrl
(
location
)};
}
}
static
const
_bxeBaseUrl
=
'https://iotapp-dev.banxiaoer.com/iotapp'
;
static
const
_bxeBaseUrl
=
'https://iotapp-dev.banxiaoer.com/iotapp'
;
static
const
_genBaseUrl
=
'https://dev.banxiaoer.net'
;
static
const
_signatureNewUrl
=
'/api/v1/obs/multipart/signaturenew'
;
static
const
_signatureNewUrl
=
'/api/v1/obs/multipart/signaturenew'
;
static
const
_signatureNextUrl
=
'/api/v1/obs/multipart/signaturenext'
;
static
const
_signatureNextUrl
=
'/api/v1/obs/multipart/signaturenext'
;
static
const
_completeUrl
=
'/api/v1/obs/multipart/complete'
;
static
const
_completeUrl
=
'/api/v1/obs/multipart/complete'
;
...
@@ -234,12 +213,12 @@ class UploadFileHandler extends MessageHandler {
...
@@ -234,12 +213,12 @@ class UploadFileHandler extends MessageHandler {
/// 每次上传前,请求后端获取签名信息
/// 每次上传前,请求后端获取签名信息
Future
<
Map
<
String
,
dynamic
>>
_next
(
Future
<
Map
<
String
,
dynamic
>>
_next
(
ApiService
bxeApiService
,
ApiService
bxeApiService
,
String
objectKey
,
String
objectKey
,
String
bucket
,
String
bucket
,
String
uploadId
,
String
uploadId
,
int
partNum
,
int
partNum
,
)
async
{
)
async
{
var
endpoint
=
'
$_signatureNextUrl
?objectKey=
$objectKey
&bucket=
$bucket
&uploadId=
$uploadId
&partNum=
$partNum
'
;
var
endpoint
=
'
$_signatureNextUrl
?objectKey=
$objectKey
&bucket=
$bucket
&uploadId=
$uploadId
&partNum=
$partNum
'
;
final
resp
=
await
bxeApiService
.
get
(
endpoint
);
final
resp
=
await
bxeApiService
.
get
(
endpoint
);
return
resp
.
data
;
return
resp
.
data
;
...
@@ -247,12 +226,12 @@ class UploadFileHandler extends MessageHandler {
...
@@ -247,12 +226,12 @@ class UploadFileHandler extends MessageHandler {
/// 上传段,按照最大重试次数进行上传重试
/// 上传段,按照最大重试次数进行上传重试
Future
<
Map
<
String
,
dynamic
>>
_uploadChunkWithRetry
(
Future
<
Map
<
String
,
dynamic
>>
_uploadChunkWithRetry
(
Dio
dio
,
Dio
dio
,
String
signUrl
,
String
signUrl
,
int
chunkIndex
,
int
chunkIndex
,
Uint8List
chunk
,
{
Uint8List
chunk
,
{
int
maxRetries
=
3
,
int
maxRetries
=
3
,
})
async
{
})
async
{
//print('====================> 分片$chunkIndex , 开始上传 ${DateTime.now()}');
//print('====================> 分片$chunkIndex , 开始上传 ${DateTime.now()}');
for
(
int
attempt
=
0
;
attempt
<=
maxRetries
;
attempt
++)
{
for
(
int
attempt
=
0
;
attempt
<=
maxRetries
;
attempt
++)
{
try
{
try
{
...
@@ -280,7 +259,7 @@ class UploadFileHandler extends MessageHandler {
...
@@ -280,7 +259,7 @@ class UploadFileHandler extends MessageHandler {
}
}
/// 上传段
/// 上传段
Future
<
Response
>
_uploadChunk
(
Dio
dio
,
String
signUrl
,
Uint8List
chunk
,
int
chunkIndex
)
async
{
Future
<
Response
>
_uploadChunk
(
Dio
dio
,
String
signUrl
,
Uint8List
chunk
,
int
chunkIndex
)
async
{
var
url
=
signUrl
.
replaceFirst
(
'AWSAccessKeyId='
,
'AccessKeyId='
).
replaceFirst
(
':443'
,
''
);
var
url
=
signUrl
.
replaceFirst
(
'AWSAccessKeyId='
,
'AccessKeyId='
).
replaceFirst
(
':443'
,
''
);
try
{
try
{
// Response response = await _put(url, chunk);
// Response response = await _put(url, chunk);
...
@@ -301,12 +280,12 @@ class UploadFileHandler extends MessageHandler {
...
@@ -301,12 +280,12 @@ class UploadFileHandler extends MessageHandler {
/// 请求合并文件
/// 请求合并文件
Future
<
String
>
_merge
(
Future
<
String
>
_merge
(
ApiService
bxeApiService
,
ApiService
bxeApiService
,
String
objectKey
,
String
objectKey
,
String
bucket
,
String
bucket
,
String
uploadId
,
String
uploadId
,
Map
<
int
,
String
>
tagsMap
,
Map
<
int
,
String
>
tagsMap
,
)
async
{
)
async
{
final
parts
=
[];
final
parts
=
[];
for
(
int
i
=
1
;
i
<=
tagsMap
.
length
;
i
++)
{
for
(
int
i
=
1
;
i
<=
tagsMap
.
length
;
i
++)
{
parts
.
add
({
'partNumber'
:
i
,
'etag'
:
tagsMap
[
i
]});
parts
.
add
({
'partNumber'
:
i
,
'etag'
:
tagsMap
[
i
]});
...
@@ -348,4 +327,26 @@ class UploadFileHandler extends MessageHandler {
...
@@ -348,4 +327,26 @@ class UploadFileHandler extends MessageHandler {
}
}
}
}
/// 生成封面
Future
<
void
>
_genHwVideoCover
(
Dio
dio
,
String
keys
)
async
{
try
{
var
headers
=
{
"api-key"
:
'FJ9qv53Bxp'
,
};
var
params
=
{
"videoKeys"
:
keys
,
"outputSuffix"
:
"_p1"
,
};
await
dio
.
post
(
'
$_genBaseUrl
/go/mpc/create_covers'
,
data:
params
,
options:
Options
(
headers:
headers
,
contentType:
'application/json'
,
),
);
}
catch
(
e
)
{
print
(
e
);
}
}
}
}
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