提交1888账号登陆

This commit is contained in:
豌杂 2024-06-18 11:48:51 +08:00
parent c9edeb662f
commit fc3f656c66
1 changed files with 116 additions and 42 deletions

View File

@ -50,8 +50,10 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
// //
setHttpsPEM() async { setHttpsPEM() async {
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) { (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
client.badCertificateCallback = (X509Certificate cert, String host, int port) { (client) {
client.badCertificateCallback =
(X509Certificate cert, String host, int port) {
return true; return true;
}; };
}; };
@ -89,13 +91,18 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
}); });
getShowRegister(); getShowRegister();
super.initState(); super.initState();
dio = Dio(BaseOptions(contentType: "application/json", connectTimeout: 8000, receiveTimeout: 8000)); dio = Dio(BaseOptions(
dio.interceptors.add(LogInterceptor(responseBody: true, requestBody: true)); // contentType: "application/json",
connectTimeout: 8000,
receiveTimeout: 8000));
dio.interceptors
.add(LogInterceptor(responseBody: true, requestBody: true)); //
setHttpsPEM(); setHttpsPEM();
client = RestClient(dio, baseUrl: RequestConfig().loginBaseUrl); client = RestClient(dio, baseUrl: RequestConfig().loginBaseUrl);
_userNameController = TextEditingController()..addListener(userNameListener); _userNameController = TextEditingController()
..addListener(userNameListener);
_passwordController = TextEditingController(); _passwordController = TextEditingController();
_pwdFocus = FocusNode(); _pwdFocus = FocusNode();
_theFocus = FocusNode(); _theFocus = FocusNode();
@ -122,12 +129,18 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
void getSchoolData(String loginName) async { void getSchoolData(String loginName) async {
if (loginName.length != 0) { if (loginName.length != 0) {
try { try {
if (loginName == '18888888888') {
schoolId = 10079;
return;
}
var _client = await getClient(); var _client = await getClient();
var res = await _client.toLoginGetSchools(loginName); var res = await _client.toLoginGetSchools(loginName);
if (res.success) { if (res.success) {
schools = res.data ?? []; schools = res.data ?? [];
UseLoginSchool? schoolElement; UseLoginSchool? schoolElement;
if (lastTimeSchoolId != null) schoolElement = schools.firstWhereOrNull((e) => e.schoolId == lastTimeSchoolId); if (lastTimeSchoolId != null)
schoolElement =
schools.firstWhereOrNull((e) => e.schoolId == lastTimeSchoolId);
if (schoolElement != null) if (schoolElement != null)
schoolId = schoolElement.schoolId; schoolId = schoolElement.schoolId;
else else
@ -149,7 +162,8 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
int useNameLength = userName.length; int useNameLength = userName.length;
bool hasNameValNew = useNameLength > 0; bool hasNameValNew = useNameLength > 0;
if (!hasNameValNew) lastTimeSchoolId = null; if (!hasNameValNew) lastTimeSchoolId = null;
if (hasNameValNew != hasNameVal) toUpState(setState, () => hasNameVal = hasNameValNew, mounted); if (hasNameValNew != hasNameVal)
toUpState(setState, () => hasNameVal = hasNameValNew, mounted);
const isProd = bool.fromEnvironment('dart.vm.product'); const isProd = bool.fromEnvironment('dart.vm.product');
getSchoolData(userName); // getSchoolData(userName); //
if (!isProd && useNameLength == 11) { if (!isProd && useNameLength == 11) {
@ -205,12 +219,15 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
child: SizedBox( child: SizedBox(
height: 86.w, height: 86.w,
width: 86.w, width: 86.w,
child: Image.asset('assets/images/logo.png', fit: BoxFit.cover), child: Image.asset('assets/images/logo.png',
fit: BoxFit.cover),
), ),
), ),
Container( Container(
margin: EdgeInsets.symmetric(horizontal: 32.w, vertical: 24.h), margin: EdgeInsets.symmetric(
padding: EdgeInsets.only(top: 34.h, bottom: 16.h, left: 22.w, right: 22.w), horizontal: 32.w, vertical: 24.h),
padding: EdgeInsets.only(
top: 34.h, bottom: 16.h, left: 22.w, right: 22.w),
decoration: BoxDecoration( decoration: BoxDecoration(
color: Colors.white, color: Colors.white,
border: Border.all(width: 1.w, color: Colors.white), border: Border.all(width: 1.w, color: Colors.white),
@ -239,13 +256,18 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
), ),
decoration: InputDecoration( decoration: InputDecoration(
hintText: "请输入账号", hintText: "请输入账号",
hintStyle: TextStyle(fontSize: 16.sp, color: const Color.fromRGBO(153, 153, 153, 1)), hintStyle: TextStyle(
fontSize: 16.sp,
color: const Color.fromRGBO(153, 153, 153, 1)),
labelText: "账号", labelText: "账号",
labelStyle: TextStyle(fontSize: 16.sp, color: const Color.fromRGBO(148, 163, 182, 1)), labelStyle: TextStyle(
fontSize: 16.sp,
color: const Color.fromRGBO(148, 163, 182, 1)),
suffixIcon: !hasNameVal suffixIcon: !hasNameVal
? null ? null
: Transform.translate( : Transform.translate(
offset: Offset(10, 10), // padding值来设置偏移量 offset:
Offset(10, 10), // padding值来设置偏移量
child: IconButton( child: IconButton(
alignment: Alignment.center, alignment: Alignment.center,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
@ -281,13 +303,19 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
onTap: _showPassword, onTap: _showPassword,
child: Icon( child: Icon(
Icons.remove_red_eye, Icons.remove_red_eye,
color: !_isShowPwd ? Theme.of(context).primaryColor : Colors.grey, color: !_isShowPwd
? Theme.of(context).primaryColor
: Colors.grey,
), ),
), ),
hintStyle: TextStyle(fontSize: 16.sp, color: const Color.fromRGBO(153, 153, 153, 1)), hintStyle: TextStyle(
fontSize: 16.sp,
color: const Color.fromRGBO(153, 153, 153, 1)),
labelText: "密码", labelText: "密码",
isDense: true, isDense: true,
labelStyle: TextStyle(fontSize: 16.sp, color: const Color.fromRGBO(148, 163, 182, 1)), labelStyle: TextStyle(
fontSize: 16.sp,
color: const Color.fromRGBO(148, 163, 182, 1)),
), ),
), ),
$SchoolDataDropDown(schools, schoolId, (int? id) { $SchoolDataDropDown(schools, schoolId, (int? id) {
@ -305,8 +333,10 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
checkColor: Colors.white, checkColor: Colors.white,
value: keepPwd, value: keepPwd,
onChanged: (value) { onChanged: (value) {
FocusScope.of(context).requestFocus(_pwdFocus); FocusScope.of(context)
FocusScope.of(context).requestFocus(_theFocus); .requestFocus(_pwdFocus);
FocusScope.of(context)
.requestFocus(_theFocus);
setState(() { setState(() {
keepPwd = value ?? false; keepPwd = value ?? false;
}); });
@ -319,15 +349,24 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
FocusScope.of(context).requestFocus(_theFocus); FocusScope.of(context).requestFocus(_theFocus);
setState(() => keepPwd = !keepPwd); setState(() => keepPwd = !keepPwd);
}, },
child: Text('记住密码', style: TextStyle(fontSize: 14.sp, color: const Color.fromRGBO(148, 163, 182, 1))), child: Text('记住密码',
style: TextStyle(
fontSize: 14.sp,
color: const Color.fromRGBO(
148, 163, 182, 1))),
), ),
Spacer(), Spacer(),
if (showRegister == true) if (showRegister == true)
InkWell( InkWell(
onTap: () { onTap: () {
RouterManager.router.navigateTo(context, RouterManager.registerPath); RouterManager.router.navigateTo(
context, RouterManager.registerPath);
}, },
child: Text('注册', style: TextStyle(fontSize: 14.sp, color: const Color.fromRGBO(148, 163, 182, 1)))), child: Text('注册',
style: TextStyle(
fontSize: 14.sp,
color: const Color.fromRGBO(
148, 163, 182, 1)))),
], ],
), ),
InkWell( InkWell(
@ -335,7 +374,9 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
child: Container( child: Container(
margin: EdgeInsets.symmetric(vertical: 10.h), margin: EdgeInsets.symmetric(vertical: 10.h),
decoration: BoxDecoration( decoration: BoxDecoration(
color: canLogin ? const Color.fromRGBO(9, 105, 246, 1) : Colors.grey, color: canLogin
? const Color.fromRGBO(9, 105, 246, 1)
: Colors.grey,
boxShadow: [ boxShadow: [
BoxShadow( BoxShadow(
color: const Color.fromRGBO(46, 91, 255, 0.5), color: const Color.fromRGBO(46, 91, 255, 0.5),
@ -344,14 +385,16 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
spreadRadius: 0.5, // spreadRadius: 0.5, //
) )
], ],
borderRadius: BorderRadius.all(Radius.circular(8.w)), borderRadius:
BorderRadius.all(Radius.circular(8.w)),
), ),
alignment: Alignment.center, alignment: Alignment.center,
width: double.infinity, width: double.infinity,
height: 50.h, height: 50.h,
child: Text( child: Text(
'登 录', '登 录',
style: TextStyle(fontSize: 16.sp, color: Colors.white), style: TextStyle(
fontSize: 16.sp, color: Colors.white),
), ),
), ),
), ),
@ -365,8 +408,10 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
checkColor: Colors.white, checkColor: Colors.white,
value: readAgreement, value: readAgreement,
onChanged: (value) { onChanged: (value) {
FocusScope.of(context).requestFocus(_pwdFocus); FocusScope.of(context)
FocusScope.of(context).requestFocus(_theFocus); .requestFocus(_pwdFocus);
FocusScope.of(context)
.requestFocus(_theFocus);
setState(() { setState(() {
readAgreement = value ?? false; readAgreement = value ?? false;
}); });
@ -442,22 +487,29 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
barrierDismissible: false, barrierDismissible: false,
builder: (BuildContext context) { builder: (BuildContext context) {
return CupertinoAlertDialog( return CupertinoAlertDialog(
title: quickText('用户协议及隐私协议', size: 14.sp, color: Color.fromARGB(255, 53, 52, 52)), title: quickText('用户协议及隐私协议',
size: 14.sp, color: Color.fromARGB(255, 53, 52, 52)),
content: SingleChildScrollView( content: SingleChildScrollView(
padding: EdgeInsets.only(top: 4.h), padding: EdgeInsets.only(top: 4.h),
child: RichText( child: RichText(
text: TextSpan( text: TextSpan(
text: '为了更好地保障您的合法权益,请您阅读并同意以下协议', text: '为了更好地保障您的合法权益,请您阅读并同意以下协议',
style: TextStyle(color: Color.fromARGB(255, 137, 138, 139), fontSize: 11.sp), style: TextStyle(
color: Color.fromARGB(255, 137, 138, 139),
fontSize: 11.sp),
children: <TextSpan>[ children: <TextSpan>[
TextSpan(text: '《用户协议》《隐式协议》', style: TextStyle(color: Colors.deepOrangeAccent, fontSize: 13.sp)), TextSpan(
text: '《用户协议》《隐式协议》',
style: TextStyle(
color: Colors.deepOrangeAccent, fontSize: 13.sp)),
], ],
), ),
), ),
), ),
actions: <Widget>[ actions: <Widget>[
CupertinoDialogAction( CupertinoDialogAction(
child: Text("取消", style: TextStyle(color: Color.fromARGB(255, 58, 58, 58))), child: Text("取消",
style: TextStyle(color: Color.fromARGB(255, 58, 58, 58))),
onPressed: () => Navigator.of(context).pop(false), onPressed: () => Navigator.of(context).pop(false),
), ),
CupertinoDialogAction( CupertinoDialogAction(
@ -483,16 +535,22 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
print('userPwdMd5=$userPwdMd5'); print('userPwdMd5=$userPwdMd5');
EasyLoading.show(status: 'loading...'); EasyLoading.show(status: 'loading...');
BaseStructureResult<dynamic> resultData = await client.toLogin(UserLoginParams(userName, userPwdMd5, schoolId!)); BaseStructureResult<dynamic> resultData = await client
UserLogin? userData = resultData.code == 200 && resultData.data != null ? UserLogin.fromJson(resultData.data) : null; .toLogin(UserLoginParams(userName, userPwdMd5, schoolId!));
if (resultData.code != 200 || userData?.accessToken == null || userData?.accessToken == '') { UserLogin? userData = resultData.code == 200 && resultData.data != null
? UserLogin.fromJson(resultData.data)
: null;
if (resultData.code != 200 ||
userData?.accessToken == null ||
userData?.accessToken == '') {
return toMsg(resultData.message ?? '登录失败,请重试'); return toMsg(resultData.message ?? '登录失败,请重试');
} }
FastData fastData = FastData.getInstance(); FastData fastData = FastData.getInstance();
fastData.setToken(userData!.accessToken); fastData.setToken(userData!.accessToken);
BaseStructureResult<UserInfo> userRes = await client.getUserInfo('Bearer ${userData.accessToken}'); BaseStructureResult<UserInfo> userRes =
await client.getUserInfo('Bearer ${userData.accessToken}');
if (userRes.code != 200 || userRes.data == null) { if (userRes.code != 200 || userRes.data == null) {
throw Exception('登录失败,请重试'); throw Exception('登录失败,请重试');
@ -501,14 +559,19 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
fastData.setUser(userRes.data!).then((value) { fastData.setUser(userRes.data!).then((value) {
// //
if (keepPwd) { if (keepPwd) {
fastData.setUserPwdAndAccount({'pwd': userPwd, 'account': userName, 'schoolId': schoolId.toString()}); fastData.setUserPwdAndAccount({
'pwd': userPwd,
'account': userName,
'schoolId': schoolId.toString()
});
} }
// //
ref.read(userProvider.notifier).initUserInfo(); ref.read(userProvider.notifier).initUserInfo();
ref.read(userTokenProvider.notifier).initToken(); ref.read(userTokenProvider.notifier).initToken();
// //
RouterManager.router.navigateTo(context, RouterManager.root, clearStack: true, transition: getTransition()); RouterManager.router.navigateTo(context, RouterManager.root,
clearStack: true, transition: getTransition());
}); });
} catch (e) { } catch (e) {
toPrint(val: e.toString()); toPrint(val: e.toString());
@ -546,19 +609,25 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
} }
@hwidget @hwidget
Widget $schoolDataDropDown(BuildContext context, List<UseLoginSchool> schools, int? schoolId, void Function(int? id) call) { Widget $schoolDataDropDown(BuildContext context, List<UseLoginSchool> schools,
int? schoolId, void Function(int? id) call) {
var useSchool = useState(schools); var useSchool = useState(schools);
var useSchoolId = useState(schoolId); var useSchoolId = useState(schoolId);
useValueChanged<List<UseLoginSchool>, void>(schools, (_, __) => useSchool.value = schools); useValueChanged<List<UseLoginSchool>, void>(
useValueChanged<int?, void>(schoolId, (_, __) => useSchoolId.value = schoolId); schools, (_, __) => useSchool.value = schools);
useValueChanged<int?, void>(
schoolId, (_, __) => useSchoolId.value = schoolId);
if (useSchool.value.isEmpty) return SizedBox(); if (useSchool.value.isEmpty) return SizedBox();
return Padding( return Padding(
padding: EdgeInsets.only(top: 24.h), padding: EdgeInsets.only(top: 24.h),
child: Column( child: Column(
children: [ children: [
Container(alignment: Alignment.topLeft, child: quickText('登录学校', size: 12.sp, color: const Color.fromRGBO(148, 163, 182, 1))), Container(
alignment: Alignment.topLeft,
child: quickText('登录学校',
size: 12.sp, color: const Color.fromRGBO(148, 163, 182, 1))),
Container( Container(
height: 40.h, height: 40.h,
width: double.infinity, width: double.infinity,
@ -570,12 +639,17 @@ Widget $schoolDataDropDown(BuildContext context, List<UseLoginSchool> schools, i
padding: EdgeInsets.only(right: 4.w), padding: EdgeInsets.only(right: 4.w),
icon: const Icon(Icons.keyboard_arrow_down_rounded), icon: const Icon(Icons.keyboard_arrow_down_rounded),
style: TextStyle(color: Colors.deepPurple), style: TextStyle(color: Colors.deepPurple),
underline: Container(height: 0.6.h, color: const Color.fromRGBO(80, 87, 103, 1)), underline: Container(
height: 0.6.h, color: const Color.fromRGBO(80, 87, 103, 1)),
onChanged: (int? id) { onChanged: (int? id) {
call(id); call(id);
useSchoolId.value = schoolId; useSchoolId.value = schoolId;
}, },
items: useSchool.value.map((e) => DropdownMenuItem<int>(value: e.schoolId, child: quickText(e.schoolName, size: 12.sp))).toList(), items: useSchool.value
.map((e) => DropdownMenuItem<int>(
value: e.schoolId,
child: quickText(e.schoolName, size: 12.sp)))
.toList(),
), ),
) )
], ],