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 e477d911
authored
2026-01-22 16:30:51 +0800
by
tanghuan
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
调整通过Apple登录的流程
1 parent
a293b024
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
213 additions
and
98 deletions
lib/bloc/login_main_cubit.dart
lib/bloc/login_phone_cubit.dart
lib/ui/pages/login_main_page.dart
lib/ui/pages/login_phone_page.dart
lib/ui/pages/login_qr_page.dart
lib/bloc/login_main_cubit.dart
View file @
e477d91
...
@@ -18,6 +18,7 @@ class LoginMainState extends Equatable {
...
@@ -18,6 +18,7 @@ class LoginMainState extends Equatable {
final
int
loginType
;
// 1=Wechat,2=Apple
final
int
loginType
;
// 1=Wechat,2=Apple
final
String
appleUserIdentifier
;
final
String
appleUserIdentifier
;
final
bool
loading
;
final
bool
loading
;
final
bool
wechatInstalled
;
const
LoginMainState
({
const
LoginMainState
({
this
.
agreed
=
false
,
this
.
agreed
=
false
,
...
@@ -26,6 +27,7 @@ class LoginMainState extends Equatable {
...
@@ -26,6 +27,7 @@ class LoginMainState extends Equatable {
this
.
loginType
=
0
,
this
.
loginType
=
0
,
this
.
appleUserIdentifier
=
''
,
this
.
appleUserIdentifier
=
''
,
this
.
loading
=
false
,
this
.
loading
=
false
,
this
.
wechatInstalled
=
false
,
});
});
LoginMainState
copyWith
({
LoginMainState
copyWith
({
...
@@ -33,16 +35,18 @@ class LoginMainState extends Equatable {
...
@@ -33,16 +35,18 @@ class LoginMainState extends Equatable {
bool
?
showAgreed
,
bool
?
showAgreed
,
bool
?
showNeedWechatForApple
,
bool
?
showNeedWechatForApple
,
int
?
loginType
,
int
?
loginType
,
bool
?
loading
,
String
?
appleUserIdentifier
,
String
?
appleUserIdentifier
,
bool
?
loading
,
bool
?
wechatInstalled
,
})
{
})
{
return
LoginMainState
(
return
LoginMainState
(
agreed:
agreed
??
this
.
agreed
,
agreed:
agreed
??
this
.
agreed
,
showAgreed:
showAgreed
??
this
.
showAgreed
,
showAgreed:
showAgreed
??
this
.
showAgreed
,
showNeedWechatForApple:
showNeedWechatForApple
??
this
.
showNeedWechatForApple
,
showNeedWechatForApple:
showNeedWechatForApple
??
this
.
showNeedWechatForApple
,
loginType:
loginType
??
this
.
loginType
,
loginType:
loginType
??
this
.
loginType
,
loading:
loading
??
this
.
loading
,
appleUserIdentifier:
appleUserIdentifier
??
this
.
appleUserIdentifier
,
appleUserIdentifier:
appleUserIdentifier
??
this
.
appleUserIdentifier
,
loading:
loading
??
this
.
loading
,
wechatInstalled:
wechatInstalled
??
this
.
wechatInstalled
,
);
);
}
}
...
@@ -50,10 +54,11 @@ class LoginMainState extends Equatable {
...
@@ -50,10 +54,11 @@ class LoginMainState extends Equatable {
List
<
Object
?>
get
props
=>
[
List
<
Object
?>
get
props
=>
[
agreed
,
agreed
,
showAgreed
,
showAgreed
,
loading
,
showNeedWechatForApple
,
showNeedWechatForApple
,
loginType
,
loginType
,
appleUserIdentifier
,
appleUserIdentifier
,
loading
,
wechatInstalled
,
];
];
}
}
...
@@ -65,6 +70,12 @@ class LoginMainCubit extends Cubit<LoginMainState> {
...
@@ -65,6 +70,12 @@ class LoginMainCubit extends Cubit<LoginMainState> {
LoginMainCubit
(
super
.
initialState
)
{
LoginMainCubit
(
super
.
initialState
)
{
_fluwx
=
getIt
.
get
<
Fluwx
>();
_fluwx
=
getIt
.
get
<
Fluwx
>();
// 处理微信安装检测
_fluwx
.
isWeChatInstalled
.
then
((
value
)
{
emit
(
state
.
copyWith
(
wechatInstalled:
value
));
});
_fluwxCancelable
=
_fluwx
.
addSubscriber
(
_responseListener
);
_fluwxCancelable
=
_fluwx
.
addSubscriber
(
_responseListener
);
_wechatAuthRepository
=
getIt
.
get
<
WechatAuthRepository
>();
_wechatAuthRepository
=
getIt
.
get
<
WechatAuthRepository
>();
_userAuthRepository
=
getIt
.
get
<
UserAuthRepository
>();
_userAuthRepository
=
getIt
.
get
<
UserAuthRepository
>();
...
@@ -136,8 +147,15 @@ class LoginMainCubit extends Cubit<LoginMainState> {
...
@@ -136,8 +147,15 @@ class LoginMainCubit extends Cubit<LoginMainState> {
if
(
binding
==
1
)
{
if
(
binding
==
1
)
{
_handleLoginSuccess
(
data
);
_handleLoginSuccess
(
data
);
}
else
{
}
else
{
// 设置 appleUserIdentifier 状态,通知用户需要授权微信认证
// 未绑定时,也会返回 sessionCode 和 userCode
emit
(
state
.
copyWith
(
appleUserIdentifier:
data
[
'appleUid'
]!,
showNeedWechatForApple:
true
));
if
(
state
.
wechatInstalled
)
{
// 已安装微信APP,直接拉起微信授权,不使用 sessionCode 和 userCode
// 设置 appleUserIdentifier 状态,通知用户需要授权微信认证
emit
(
state
.
copyWith
(
appleUserIdentifier:
data
[
'appleUid'
]!,
showNeedWechatForApple:
true
));
}
else
{
// 未安装微信APP,使用 sessionCode 和 userCode
_handleLoginSuccess
(
data
);
}
}
}
}
}
...
@@ -215,7 +233,11 @@ class LoginMainCubit extends Cubit<LoginMainState> {
...
@@ -215,7 +233,11 @@ class LoginMainCubit extends Cubit<LoginMainState> {
void
_handleLoginSuccess
(
Map
<
String
,
dynamic
>
data
)
{
void
_handleLoginSuccess
(
Map
<
String
,
dynamic
>
data
)
{
var
roles
=
data
[
'roles'
];
var
roles
=
data
[
'roles'
];
// 过滤出家长角色的数据
// 过滤出家长角色的数据
roles
.
removeWhere
((
element
)
=>
element
[
'userType'
]
!=
2
);
if
(
roles
?.
isNotEmpty
??
false
)
{
roles
.
removeWhere
((
element
)
=>
element
[
'userType'
]
!=
2
);
}
else
{
roles
=
[];
}
var
sessionCode
=
data
[
'sessionCode'
];
var
sessionCode
=
data
[
'sessionCode'
];
var
userCode
=
data
[
'userCode'
];
var
userCode
=
data
[
'userCode'
];
...
...
lib/bloc/login_phone_cubit.dart
View file @
e477d91
...
@@ -146,7 +146,11 @@ class LoginPhoneCubit extends Cubit<LoginPhoneState> {
...
@@ -146,7 +146,11 @@ class LoginPhoneCubit extends Cubit<LoginPhoneState> {
void
_handleLoginSuccess
(
Map
<
String
,
dynamic
>
data
)
{
void
_handleLoginSuccess
(
Map
<
String
,
dynamic
>
data
)
{
var
roles
=
data
[
'roles'
];
var
roles
=
data
[
'roles'
];
// 过滤出家长角色的数据
// 过滤出家长角色的数据
roles
.
removeWhere
((
element
)
=>
element
[
'userType'
]
!=
2
);
if
(
roles
?.
isNotEmpty
??
false
)
{
roles
.
removeWhere
((
element
)
=>
element
[
'userType'
]
!=
2
);
}
else
{
roles
=
[];
}
var
sessionCode
=
data
[
'sessionCode'
];
var
sessionCode
=
data
[
'sessionCode'
];
var
userCode
=
data
[
'userCode'
];
var
userCode
=
data
[
'userCode'
];
...
...
lib/ui/pages/login_main_page.dart
View file @
e477d91
import
'dart:io'
;
import
'dart:io'
;
import
'package:appframe/bloc/login_main_cubit.dart'
;
import
'package:appframe/bloc/login_main_cubit.dart'
;
import
'package:appframe/config/locator.dart'
;
import
'package:appframe/config/routes.dart'
;
import
'package:appframe/config/routes.dart'
;
import
'package:appframe/ui/widgets/login/login_page_agreed_widget.dart'
;
import
'package:appframe/ui/widgets/login/login_page_agreed_widget.dart'
;
import
'package:flutter/gestures.dart'
;
import
'package:flutter/gestures.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'package:fluwx/fluwx.dart'
;
import
'package:sign_in_with_apple/sign_in_with_apple.dart'
;
import
'package:sign_in_with_apple/sign_in_with_apple.dart'
;
class
LoginMainPage
extends
StatelessWidget
{
class
LoginMainPage
extends
StatelessWidget
{
...
@@ -39,6 +37,44 @@ class LoginMainPage extends StatelessWidget {
...
@@ -39,6 +37,44 @@ class LoginMainPage extends StatelessWidget {
SizedBox
(
height:
15
),
SizedBox
(
height:
15
),
]
]
:
[];
:
[];
var
wechatLoginBtn
=
(!
Platform
.
isIOS
||
state
.
wechatInstalled
)
?
[
Padding
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
42.5
),
child:
SizedBox
(
width:
double
.
infinity
,
height:
50
,
child:
ElevatedButton
(
onPressed:
()
async
{
if
(
state
.
wechatInstalled
)
{
loginMainCubit
.
wechatAuth
();
}
else
{
if
(!
context
.
mounted
)
return
;
_showWechatNotInstallDialog
(
context
);
}
},
style:
ElevatedButton
.
styleFrom
(
backgroundColor:
Color
(
0xFF26C445
),
foregroundColor:
Colors
.
white
,
textStyle:
TextStyle
(
fontSize:
19
),
shape:
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
circular
(
27
),
),
),
child:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
Image
.
asset
(
'assets/images/login_v2/wechat_white_icon.png'
),
SizedBox
(
width:
4.5
),
Text
(
'微信登录'
),
],
),
),
),
),
SizedBox
(
height:
15
),
]
:
[];
var
scaffold
=
Scaffold
(
var
scaffold
=
Scaffold
(
backgroundColor:
Colors
.
white
,
backgroundColor:
Colors
.
white
,
body:
SafeArea
(
body:
SafeArea
(
...
@@ -60,40 +96,7 @@ class LoginMainPage extends StatelessWidget {
...
@@ -60,40 +96,7 @@ class LoginMainPage extends StatelessWidget {
),
),
SizedBox
(
height:
40
),
SizedBox
(
height:
40
),
...
appleLoginBtn
,
...
appleLoginBtn
,
Padding
(
...
wechatLoginBtn
,
padding:
EdgeInsets
.
symmetric
(
horizontal:
42.5
),
child:
SizedBox
(
width:
double
.
infinity
,
height:
50
,
child:
ElevatedButton
(
onPressed:
()
async
{
if
(
await
getIt
.
get
<
Fluwx
>().
isWeChatInstalled
)
{
loginMainCubit
.
wechatAuth
();
}
else
{
if
(!
context
.
mounted
)
return
;
_showWechatNotInstallDialog
(
context
);
}
},
style:
ElevatedButton
.
styleFrom
(
backgroundColor:
Color
(
0xFF26C445
),
foregroundColor:
Colors
.
white
,
textStyle:
TextStyle
(
fontSize:
19
),
shape:
RoundedRectangleBorder
(
borderRadius:
BorderRadius
.
circular
(
27
),
),
),
child:
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
Image
.
asset
(
'assets/images/login_v2/wechat_white_icon.png'
),
SizedBox
(
width:
4.5
),
Text
(
'微信登录'
),
],
),
),
),
),
SizedBox
(
height:
15
),
_buildAgreement
(
context
,
loginMainCubit
,
state
.
agreed
),
_buildAgreement
(
context
,
loginMainCubit
,
state
.
agreed
),
SizedBox
(
height:
82.5
),
SizedBox
(
height:
82.5
),
Text
(
Text
(
...
...
lib/ui/pages/login_phone_page.dart
View file @
e477d91
import
'dart:io'
;
import
'package:appframe/bloc/login_phone_cubit.dart'
;
import
'package:appframe/bloc/login_phone_cubit.dart'
;
import
'package:appframe/config/routes.dart'
;
import
'package:appframe/config/routes.dart'
;
import
'package:appframe/ui/widgets/login/login_page_agreed_widget.dart'
;
import
'package:appframe/ui/widgets/login/login_page_agreed_widget.dart'
;
...
@@ -16,6 +18,75 @@ class LoginPhonePage extends StatelessWidget {
...
@@ -16,6 +18,75 @@ class LoginPhonePage extends StatelessWidget {
child:
BlocConsumer
<
LoginPhoneCubit
,
LoginPhoneState
>(
child:
BlocConsumer
<
LoginPhoneCubit
,
LoginPhoneState
>(
builder:
(
ctx
,
state
)
{
builder:
(
ctx
,
state
)
{
var
loginPhoneCubit
=
ctx
.
read
<
LoginPhoneCubit
>();
var
loginPhoneCubit
=
ctx
.
read
<
LoginPhoneCubit
>();
var
iosBackHome
=
Platform
.
isIOS
?
[
InkWell
(
onTap:
()
{
loginPhoneCubit
.
goLoginMain
();
},
borderRadius:
BorderRadius
.
circular
(
4
),
child:
Padding
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
8
,
vertical:
4
),
child:
Row
(
mainAxisSize:
MainAxisSize
.
min
,
children:
[
Icon
(
Icons
.
arrow_back_ios
,
size:
16
,
color:
Color
(
0xFF7691FA
),
),
SizedBox
(
width:
4
),
Text
(
'其他方式登录'
,
style:
TextStyle
(
fontSize:
14
,
color:
Color
(
0xFF7691FA
),
decoration:
TextDecoration
.
underline
,
decorationColor:
Color
(
0xFF7691FA
),
),
strutStyle:
StrutStyle
(
height:
16
/
14
),
),
],
),
),
),
]
:
[];
var
androidBackHome
=
Platform
.
isAndroid
?
[
Text
(
'其他方式登录'
,
style:
TextStyle
(
fontSize:
14
,
color:
Color
(
0xFF999999
),
),
strutStyle:
StrutStyle
(
height:
16
/
14
),
),
SizedBox
(
height:
15
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
InkWell
(
onTap:
()
{
loginPhoneCubit
.
goLoginMain
();
},
child:
Image
.
asset
(
'assets/images/login_v2/wechat_green_icon.png'
,
),
),
SizedBox
(
width:
25
),
InkWell
(
onTap:
()
{
loginPhoneCubit
.
goLoginQr
();
},
child:
Image
.
asset
(
'assets/images/login_v2/qr_green_icon.png'
,
),
),
],
),
]
:
[];
return
Scaffold
(
return
Scaffold
(
backgroundColor:
Colors
.
white
,
backgroundColor:
Colors
.
white
,
body:
SafeArea
(
body:
SafeArea
(
...
@@ -40,37 +111,8 @@ class LoginPhonePage extends StatelessWidget {
...
@@ -40,37 +111,8 @@ class LoginPhonePage extends StatelessWidget {
SizedBox
(
height:
15
),
SizedBox
(
height:
15
),
_buildAgreement
(
ctx
,
loginPhoneCubit
,
state
.
agreed
),
_buildAgreement
(
ctx
,
loginPhoneCubit
,
state
.
agreed
),
SizedBox
(
height:
140
),
SizedBox
(
height:
140
),
Text
(
...
iosBackHome
,
'其他方式登录'
,
...
androidBackHome
,
style:
TextStyle
(
fontSize:
14
,
color:
Color
(
0xFF999999
),
),
strutStyle:
StrutStyle
(
height:
16
/
14
),
),
SizedBox
(
height:
15
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
InkWell
(
onTap:
()
{
loginPhoneCubit
.
goLoginMain
();
},
child:
Image
.
asset
(
'assets/images/login_v2/wechat_green_icon.png'
,
),
),
SizedBox
(
width:
25
),
InkWell
(
onTap:
()
{
loginPhoneCubit
.
goLoginQr
();
},
child:
Image
.
asset
(
'assets/images/login_v2/qr_green_icon.png'
,
),
),
],
),
],
],
),
),
),
),
...
...
lib/ui/pages/login_qr_page.dart
View file @
e477d91
import
'dart:io'
;
import
'package:appframe/bloc/login_qr_cubit.dart'
;
import
'package:appframe/bloc/login_qr_cubit.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
import
'package:flutter_bloc/flutter_bloc.dart'
;
...
@@ -12,6 +14,70 @@ class LoginQrPage extends StatelessWidget {
...
@@ -12,6 +14,70 @@ class LoginQrPage extends StatelessWidget {
child:
BlocConsumer
<
LoginQrCubit
,
LoginQrState
>(
child:
BlocConsumer
<
LoginQrCubit
,
LoginQrState
>(
builder:
(
context
,
state
)
{
builder:
(
context
,
state
)
{
var
loginQrCubit
=
context
.
read
<
LoginQrCubit
>();
var
loginQrCubit
=
context
.
read
<
LoginQrCubit
>();
var
iosBackHome
=
Platform
.
isIOS
?
[
Center
(
child:
InkWell
(
onTap:
()
{
loginQrCubit
.
goLoginMain
();
},
borderRadius:
BorderRadius
.
circular
(
4
),
child:
Padding
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
8
,
vertical:
4
),
child:
Row
(
mainAxisSize:
MainAxisSize
.
min
,
children:
[
Icon
(
Icons
.
arrow_back_ios
,
size:
16
,
color:
Color
(
0xFF7691FA
),
),
SizedBox
(
width:
4
),
Text
(
'其他方式登录'
,
style:
TextStyle
(
fontSize:
14
,
color:
Color
(
0xFF7691FA
),
decoration:
TextDecoration
.
underline
,
decorationColor:
Color
(
0xFF7691FA
),
),
strutStyle:
StrutStyle
(
height:
16
/
14
),
),
],
),
),
),
),
]
:
[];
var
androidBackHome
=
Platform
.
isAndroid
?
[
Center
(
child:
Text
(
'其他方式登录'
,
style:
TextStyle
(
fontSize:
14
,
color:
Color
(
0xFF999999
),
),
strutStyle:
StrutStyle
(
height:
16
/
14
),
),
),
SizedBox
(
height:
15
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
InkWell
(
onTap:
()
{
loginQrCubit
.
goLoginMain
();
},
child:
Image
.
asset
(
'assets/images/login_v2/wechat_green_icon.png'
,
),
),
],
),
]
:
[];
return
Scaffold
(
return
Scaffold
(
backgroundColor:
Colors
.
white
,
backgroundColor:
Colors
.
white
,
body:
SafeArea
(
body:
SafeArea
(
...
@@ -30,30 +96,8 @@ class LoginQrPage extends StatelessWidget {
...
@@ -30,30 +96,8 @@ class LoginQrPage extends StatelessWidget {
child:
_buildQrCode
(
loginQrCubit
,
state
),
child:
_buildQrCode
(
loginQrCubit
,
state
),
),
),
SizedBox
(
height:
20
),
SizedBox
(
height:
20
),
Center
(
...
iosBackHome
,
child:
Text
(
...
androidBackHome
,
'其他方式登录'
,
style:
TextStyle
(
fontSize:
14
,
color:
Color
(
0xFF999999
),
),
strutStyle:
StrutStyle
(
height:
16
/
14
),
),
),
SizedBox
(
height:
15
),
Row
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
InkWell
(
onTap:
()
{
loginQrCubit
.
goLoginMain
();
},
child:
Image
.
asset
(
'assets/images/login_v2/wechat_green_icon.png'
,
),
),
],
),
],
],
),
),
),
),
...
...
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