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
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
178 additions
and
63 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
{
// 未绑定时,也会返回 sessionCode 和 userCode
if
(
state
.
wechatInstalled
)
{
// 已安装微信APP,直接拉起微信授权,不使用 sessionCode 和 userCode
// 设置 appleUserIdentifier 状态,通知用户需要授权微信认证
// 设置 appleUserIdentifier 状态,通知用户需要授权微信认证
emit
(
state
.
copyWith
(
appleUserIdentifier:
data
[
'appleUid'
]!,
showNeedWechatForApple:
true
));
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'
];
// 过滤出家长角色的数据
// 过滤出家长角色的数据
if
(
roles
?.
isNotEmpty
??
false
)
{
roles
.
removeWhere
((
element
)
=>
element
[
'userType'
]
!=
2
);
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'
];
// 过滤出家长角色的数据
// 过滤出家长角色的数据
if
(
roles
?.
isNotEmpty
??
false
)
{
roles
.
removeWhere
((
element
)
=>
element
[
'userType'
]
!=
2
);
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,27 +37,8 @@ class LoginMainPage extends StatelessWidget {
...
@@ -39,27 +37,8 @@ class LoginMainPage extends StatelessWidget {
SizedBox
(
height:
15
),
SizedBox
(
height:
15
),
]
]
:
[];
:
[];
var
scaffold
=
Scaffold
(
var
wechatLoginBtn
=
(!
Platform
.
isIOS
||
state
.
wechatInstalled
)
backgroundColor:
Colors
.
white
,
?
[
body:
SafeArea
(
top:
false
,
child:
SingleChildScrollView
(
child:
Column
(
children:
[
SizedBox
(
height:
100
),
Center
(
child:
Image
.
asset
(
'assets/images/login_v2/banner_1.png'
,
),
),
SizedBox
(
height:
30
),
Center
(
child:
Image
.
asset
(
'assets/images/login_v2/main.png'
,
),
),
SizedBox
(
height:
40
),
...
appleLoginBtn
,
Padding
(
Padding
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
42.5
),
padding:
EdgeInsets
.
symmetric
(
horizontal:
42.5
),
child:
SizedBox
(
child:
SizedBox
(
...
@@ -67,7 +46,7 @@ class LoginMainPage extends StatelessWidget {
...
@@ -67,7 +46,7 @@ class LoginMainPage extends StatelessWidget {
height:
50
,
height:
50
,
child:
ElevatedButton
(
child:
ElevatedButton
(
onPressed:
()
async
{
onPressed:
()
async
{
if
(
await
getIt
.
get
<
Fluwx
>().
isWeC
hatInstalled
)
{
if
(
state
.
wec
hatInstalled
)
{
loginMainCubit
.
wechatAuth
();
loginMainCubit
.
wechatAuth
();
}
else
{
}
else
{
if
(!
context
.
mounted
)
return
;
if
(!
context
.
mounted
)
return
;
...
@@ -94,6 +73,30 @@ class LoginMainPage extends StatelessWidget {
...
@@ -94,6 +73,30 @@ class LoginMainPage extends StatelessWidget {
),
),
),
),
SizedBox
(
height:
15
),
SizedBox
(
height:
15
),
]
:
[];
var
scaffold
=
Scaffold
(
backgroundColor:
Colors
.
white
,
body:
SafeArea
(
top:
false
,
child:
SingleChildScrollView
(
child:
Column
(
children:
[
SizedBox
(
height:
100
),
Center
(
child:
Image
.
asset
(
'assets/images/login_v2/banner_1.png'
,
),
),
SizedBox
(
height:
30
),
Center
(
child:
Image
.
asset
(
'assets/images/login_v2/main.png'
,
),
),
SizedBox
(
height:
40
),
...
appleLoginBtn
,
...
wechatLoginBtn
,
_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,30 +18,42 @@ class LoginPhonePage extends StatelessWidget {
...
@@ -16,30 +18,42 @@ 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
>();
return
Scaffold
(
var
iosBackHome
=
Platform
.
isIOS
backgroundColor:
Colors
.
white
,
?
[
body:
SafeArea
(
InkWell
(
top:
false
,
onTap:
()
{
child:
SingleChildScrollView
(
loginPhoneCubit
.
goLoginMain
();
child:
Column
(
},
borderRadius:
BorderRadius
.
circular
(
4
),
child:
Padding
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
8
,
vertical:
4
),
child:
Row
(
mainAxisSize:
MainAxisSize
.
min
,
children:
[
children:
[
Image
.
asset
(
Icon
(
'assets/images/login_v2/banner_2.png'
,
Icons
.
arrow_back_ios
,
width:
MediaQuery
.
of
(
context
).
size
.
width
,
size:
16
,
fit:
BoxFit
.
fitWidth
,
color:
Color
(
0xFF7691FA
)
,
),
),
SizedBox
(
height:
15.5
),
SizedBox
(
width:
4
),
Padding
(
Text
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
30
)
,
'其他方式登录'
,
child:
Column
(
children:
[
style:
TextStyle
(
_buildInputFields
(
loginPhoneCubit
,
state
)
,
fontSize:
14
,
SizedBox
(
height:
15
),
color:
Color
(
0xFF7691FA
),
_buildLoginButton
(
ctx
)
,
decoration:
TextDecoration
.
underline
,
]
),
decorationColor:
Color
(
0xFF7691FA
),
),
),
SizedBox
(
height:
15
),
strutStyle:
StrutStyle
(
height:
16
/
14
),
_buildAgreement
(
ctx
,
loginPhoneCubit
,
state
.
agreed
),
),
SizedBox
(
height:
140
),
],
),
),
),
]
:
[];
var
androidBackHome
=
Platform
.
isAndroid
?
[
Text
(
Text
(
'其他方式登录'
,
'其他方式登录'
,
style:
TextStyle
(
style:
TextStyle
(
...
@@ -71,6 +85,34 @@ class LoginPhonePage extends StatelessWidget {
...
@@ -71,6 +85,34 @@ class LoginPhonePage extends StatelessWidget {
),
),
],
],
),
),
]
:
[];
return
Scaffold
(
backgroundColor:
Colors
.
white
,
body:
SafeArea
(
top:
false
,
child:
SingleChildScrollView
(
child:
Column
(
children:
[
Image
.
asset
(
'assets/images/login_v2/banner_2.png'
,
width:
MediaQuery
.
of
(
context
).
size
.
width
,
fit:
BoxFit
.
fitWidth
,
),
SizedBox
(
height:
15.5
),
Padding
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
30
),
child:
Column
(
children:
[
_buildInputFields
(
loginPhoneCubit
,
state
),
SizedBox
(
height:
15
),
_buildLoginButton
(
ctx
),
]),
),
SizedBox
(
height:
15
),
_buildAgreement
(
ctx
,
loginPhoneCubit
,
state
.
agreed
),
SizedBox
(
height:
140
),
...
iosBackHome
,
...
androidBackHome
,
],
],
),
),
),
),
...
...
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,24 +14,44 @@ class LoginQrPage extends StatelessWidget {
...
@@ -12,24 +14,44 @@ 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
>();
return
Scaffold
(
var
iosBackHome
=
Platform
.
isIOS
backgroundColor:
Colors
.
white
,
?
[
body:
SafeArea
(
Center
(
top:
false
,
child:
InkWell
(
child:
SingleChildScrollView
(
onTap:
()
{
child:
Column
(
loginQrCubit
.
goLoginMain
();
crossAxisAlignment:
CrossAxisAlignment
.
stretch
,
},
borderRadius:
BorderRadius
.
circular
(
4
),
child:
Padding
(
padding:
EdgeInsets
.
symmetric
(
horizontal:
8
,
vertical:
4
),
child:
Row
(
mainAxisSize:
MainAxisSize
.
min
,
children:
[
children:
[
Image
.
asset
(
Icon
(
'assets/images/login_v2/banner_2.png'
,
Icons
.
arrow_back_ios
,
width:
MediaQuery
.
of
(
context
).
size
.
width
,
size:
16
,
fit:
BoxFit
.
fitWidth
,
color:
Color
(
0xFF7691FA
)
,
),
),
SizedBox
(
SizedBox
(
width:
4
),
height:
380
,
Text
(
child:
_buildQrCode
(
loginQrCubit
,
state
),
'其他方式登录'
,
style:
TextStyle
(
fontSize:
14
,
color:
Color
(
0xFF7691FA
),
decoration:
TextDecoration
.
underline
,
decorationColor:
Color
(
0xFF7691FA
),
),
),
SizedBox
(
height:
20
),
strutStyle:
StrutStyle
(
height:
16
/
14
),
),
],
),
),
),
),
]
:
[];
var
androidBackHome
=
Platform
.
isAndroid
?
[
Center
(
Center
(
child:
Text
(
child:
Text
(
'其他方式登录'
,
'其他方式登录'
,
...
@@ -54,6 +76,28 @@ class LoginQrPage extends StatelessWidget {
...
@@ -54,6 +76,28 @@ class LoginQrPage extends StatelessWidget {
),
),
],
],
),
),
]
:
[];
return
Scaffold
(
backgroundColor:
Colors
.
white
,
body:
SafeArea
(
top:
false
,
child:
SingleChildScrollView
(
child:
Column
(
crossAxisAlignment:
CrossAxisAlignment
.
stretch
,
children:
[
Image
.
asset
(
'assets/images/login_v2/banner_2.png'
,
width:
MediaQuery
.
of
(
context
).
size
.
width
,
fit:
BoxFit
.
fitWidth
,
),
SizedBox
(
height:
380
,
child:
_buildQrCode
(
loginQrCubit
,
state
),
),
SizedBox
(
height:
20
),
...
iosBackHome
,
...
androidBackHome
,
],
],
),
),
),
),
...
...
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