Skip to content

Commit be120aa

Browse files
committed
login
1 parent a303116 commit be120aa

File tree

26 files changed

+1193
-225
lines changed

26 files changed

+1193
-225
lines changed

lib/app/bloc_wrapper.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ class _BlocWrapperState extends State<BlocWrapper> {
3636
return MultiBlocProvider(
3737
providers: [
3838
// 全局 bloc : 维护应用存储状态、更新、认证
39+
BlocProvider<AuthBloc>(create: (_) => AuthBloc(repository: authRepository)..add(const AppStarted())),
3940
BlocProvider<AppBloc>(create: (_) => AppBloc(AppStateRepository())..initApp()),
4041
BlocProvider<UpdateBloc>(create: (_) => UpdateBloc()),
41-
BlocProvider<AuthBloc>(create: (_) => AuthBloc(repository: authRepository)..add(const AppStarted())),
42+
BlocProvider<UserBloc>(create: (_) => UserBloc()),
43+
4244

4345
BlocProvider<WidgetsBloc>(create: (_) => WidgetsBloc(repository: repository)),
4446
BlocProvider<CategoryBloc>(create: (_) => categoryBloc),

lib/point_system/api/category_api.dart

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,17 @@ class CategoryApi {
1111
{required String data, required String likeData}) async {
1212
String errorMsg = "";
1313

14-
var result = await HttpUtil.instance.client.post(
15-
PathUnit.categoryDataSync,
16-
data: {"data": data, "likeData": likeData}).catchError((err) {
17-
errorMsg = err.toString();
18-
});
19-
20-
if (result.data != null) {
21-
return TaskResult.success(data:result.data);
14+
try {
15+
var result = await HttpUtil.instance.client.post(
16+
PathUnit.categoryDataSync,
17+
data: {"data": data, "likeData": likeData});
18+
print(result.data);
19+
if (result.data != null) {
20+
return TaskResult.success(data:result.data['status']);
21+
}
22+
} catch (e) {
23+
print(e);
24+
errorMsg = e.toString();
2225
}
2326

2427
return TaskResult.error(msg: '请求错误: $errorMsg');

lib/widget_ui/mobile/category_page/collect_page.dart

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ class _CollectPageState extends State<CollectPage>
9494
borderSize: 1.5,
9595
),
9696
)),
97-
// backgroundColor: color,
97+
backgroundColor: Theme.of(context).primaryColor,
98+
actionsIconTheme: IconThemeData(color: Colors.white),
9899
actions: <Widget>[
99100
SizedBox(
100101
width: 32,
@@ -105,7 +106,7 @@ class _CollectPageState extends State<CollectPage>
105106
width: 32,
106107
child: AuthenticWidget.just(const SyncCategoryButton())),
107108
if(!widget.canPop)
108-
_buildAddAction(context)
109+
SizedBox(child: _buildAddAction(context))
109110
],
110111
title: const Text(
111112
'收藏集录',
@@ -144,12 +145,17 @@ class _CollectPageState extends State<CollectPage>
144145
);
145146
}
146147

147-
Widget _buildAddAction(BuildContext context) => IconButton(
148-
icon: const Icon(
149-
Icons.add,
150-
size: 30,
148+
Widget _buildAddAction(BuildContext context) => GestureDetector(
149+
behavior: HitTestBehavior.opaque,
150+
onTap: () => Scaffold.of(context).openEndDrawer(),
151+
child: SizedBox(
152+
width: 32,
153+
child: const Icon(
154+
Icons.add,
155+
size: 24,
156+
),
151157
),
152-
onPressed: () => Scaffold.of(context).openEndDrawer());
158+
);
153159

154160
List<Widget> _buildTabs() => _tabs
155161
.map(

lib/widget_ui/mobile/category_page/sync/async_button.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class _SyncCategoryButtonState extends State<SyncCategoryButton> {
6666
return FeedbackWidget(
6767
child: const Icon(
6868
TolyIcon.download,
69-
size: 28,
69+
size: 24,
7070
),
7171
onPressed: _doSync);
7272
}
@@ -104,7 +104,7 @@ class _SyncCategoryButtonState extends State<SyncCategoryButton> {
104104

105105
Widget _buildSuccess() => const Icon(
106106
TolyIcon.upload_success,
107-
size: 25,
107+
size: 22,
108108
color: Colors.green,
109109
);
110110

lib/widget_ui/mobile/category_page/sync/upload_button.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ class _UploadCategoryButtonState extends State<UploadCategoryButton> {
5656
Widget _buildError() {
5757
return const Icon(
5858
TolyIcon.error,
59-
size: 28,
60-
color: Colors.green,
59+
size: 22,
60+
color: Colors.redAccent,
6161
);
6262
}
6363

6464
Widget _buildDefault() {
6565
return FeedbackWidget(
6666
child: const Icon(
6767
TolyIcon.upload,
68-
size: 28,
68+
size: 24,
6969
),
7070
onPressed: _doUploadCategoryData);
7171
}
@@ -95,7 +95,7 @@ class _UploadCategoryButtonState extends State<UploadCategoryButton> {
9595
Widget _buildSuccess() {
9696
return const Icon(
9797
TolyIcon.upload_success,
98-
size: 25,
98+
size: 22,
9999
color: Colors.green,
100100
);
101101
}

packages/app/lib/app/cons/path_unit.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
class PathUnit{
66

7-
static const baseUrl='http://119.45.173.197:8080/api/v1';
7+
static const baseUrl='http://82.157.176.209:8080/api/v1';
88
// static const baseUrl='http://192.168.0.100:8080/api/v1';
99

1010
static const sendEmail = '/sendEmail/';

packages/authentication/lib/authentication.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export 'blocs/authentic/event.dart';
88
export 'blocs/register/event.dart';
99
export 'blocs/register/state.dart';
1010
export 'blocs/register/bloc.dart';
11+
export 'blocs/user/bloc.dart';
12+
export 'blocs/user/state.dart';
1113
export 'views/mobile/user/page_item.dart';
1214
export 'views/mobile/user/unit_drawer_header.dart';
1315
export 'views/mobile/user/user_page.dart';

packages/authentication/lib/blocs/authentic/bloc.dart

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
1717

1818
final AuthRepository repository;
1919

20-
AuthBloc({required this.repository}) : super(AuthInitial()){
20+
AuthBloc({required this.repository}) : super(const AuthInitial()){
2121
on<AppStarted>(_onAppStarted);
2222
on<AuthByPassword>(_onAuthByPassword);
23+
on<AuthByRegister>(_onAuthByRegister);
24+
on<Logout>(_onLoggedOut);
2325
}
2426

2527
void _onAppStarted(AuthEvent event, Emitter<AuthState> emit) async{
@@ -41,7 +43,7 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
4143
}
4244
}
4345

44-
if (event is LoggedOut) {
46+
if (event is Logout) {
4547

4648
}
4749
}
@@ -85,4 +87,26 @@ class AuthBloc extends Bloc<AuthEvent, AuthState> {
8587
emit (const AuthFailure('用户名和密码不匹配'));
8688
}
8789
}
90+
91+
FutureOr<void> _onAuthByRegister(AuthByRegister event, Emitter<AuthState> emit) async{
92+
emit(AuthLoading());
93+
TaskResult<bool> result = await repository.register(email: event.email, code: event.code);
94+
95+
// if(result.data == null){
96+
// emit(const RegisterError('注册失败'));
97+
// }else{
98+
// if (result.data!=null&&result.data!) {
99+
// // 注册成功
100+
// emit( RegisterSuccess(event.email));
101+
// }else{
102+
// emit( RegisterError(result.msg));
103+
// }
104+
// }
105+
}
106+
107+
FutureOr<void> _onLoggedOut(Logout event, Emitter<AuthState> emit) async{
108+
SharedPreferences prefs = await SharedPreferences.getInstance();
109+
await prefs.remove(SpKey.tokenKey);
110+
emit(const AuthInitial());
111+
}
88112
}

packages/authentication/lib/blocs/authentic/event.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,20 @@ class AuthByPassword extends AuthEvent {
2424
List<Object> get props => [username,password];
2525
}
2626

27+
// 用户注册也是认证的一部分
28+
class AuthByRegister extends AuthEvent{
29+
final String email;
30+
final String code;
2731

28-
class LoggedOut extends AuthEvent {
32+
const AuthByRegister(this.email, this.code);
33+
}
34+
35+
class Logout extends AuthEvent {
2936

3037
final bool clearUser;
3138
final bool tokenDisable;
3239

33-
const LoggedOut({this.clearUser=true,this.tokenDisable=false});
40+
const Logout({this.clearUser=true,this.tokenDisable=false});
3441
}
3542

3643
class TokenDisabled extends AuthEvent {

packages/authentication/lib/blocs/authentic/state.dart

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22
import 'package:authentication/models/user.dart';
33
import 'package:equatable/equatable.dart';
44

5+
enum AuthType{
6+
login,
7+
register,
8+
visitor
9+
}
10+
511
///********************************校验状态********************************
6-
//
712
abstract class AuthState extends Equatable {
813
const AuthState();
914
@override
1015
List<Object> get props => [];
1116
}
1217

1318
class AuthInitial extends AuthState {
14-
19+
const AuthInitial();
1520
}
1621

1722

@@ -43,4 +48,6 @@ class AuthSuccess extends AuthState {
4348
}
4449
}
4550

46-
class AuthLoading extends AuthState {}
51+
class AuthLoading extends AuthState {
52+
53+
}

0 commit comments

Comments
 (0)