no message

This commit is contained in:
1147192855@qq.com 2024-06-21 10:03:30 +08:00
parent fc3f656c66
commit 4eb28224d3
1 changed files with 47 additions and 114 deletions

View File

@ -50,10 +50,8 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
// //
setHttpsPEM() async { setHttpsPEM() async {
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) {
(client) { client.badCertificateCallback = (X509Certificate cert, String host, int port) {
client.badCertificateCallback =
(X509Certificate cert, String host, int port) {
return true; return true;
}; };
}; };
@ -91,18 +89,13 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
}); });
getShowRegister(); getShowRegister();
super.initState(); super.initState();
dio = Dio(BaseOptions( dio = Dio(BaseOptions(contentType: "application/json", connectTimeout: 8000, receiveTimeout: 8000));
contentType: "application/json", dio.interceptors.add(LogInterceptor(responseBody: true, requestBody: true)); //
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() _userNameController = TextEditingController()..addListener(userNameListener);
..addListener(userNameListener);
_passwordController = TextEditingController(); _passwordController = TextEditingController();
_pwdFocus = FocusNode(); _pwdFocus = FocusNode();
_theFocus = FocusNode(); _theFocus = FocusNode();
@ -121,8 +114,11 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
} }
void getShowRegister() async { void getShowRegister() async {
BaseStructureResult<dynamic> resultData = await client.showRegister(); try {
if (resultData.success) setState(() => showRegister = resultData.data); var client = await getClient();
BaseStructureResult<dynamic> resultData = await client.showRegister();
if (resultData.success) setState(() => showRegister = resultData.data);
} catch (e) {}
} }
// //
@ -138,9 +134,7 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
if (res.success) { if (res.success) {
schools = res.data ?? []; schools = res.data ?? [];
UseLoginSchool? schoolElement; UseLoginSchool? schoolElement;
if (lastTimeSchoolId != null) if (lastTimeSchoolId != null) schoolElement = schools.firstWhereOrNull((e) => e.schoolId == lastTimeSchoolId);
schoolElement =
schools.firstWhereOrNull((e) => e.schoolId == lastTimeSchoolId);
if (schoolElement != null) if (schoolElement != null)
schoolId = schoolElement.schoolId; schoolId = schoolElement.schoolId;
else else
@ -162,8 +156,7 @@ 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) if (hasNameValNew != hasNameVal) toUpState(setState, () => hasNameVal = hasNameValNew, mounted);
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) {
@ -219,15 +212,12 @@ 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', child: Image.asset('assets/images/logo.png', fit: BoxFit.cover),
fit: BoxFit.cover),
), ),
), ),
Container( Container(
margin: EdgeInsets.symmetric( margin: EdgeInsets.symmetric(horizontal: 32.w, vertical: 24.h),
horizontal: 32.w, vertical: 24.h), padding: EdgeInsets.only(top: 34.h, bottom: 16.h, left: 22.w, right: 22.w),
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),
@ -256,18 +246,13 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
), ),
decoration: InputDecoration( decoration: InputDecoration(
hintText: "请输入账号", hintText: "请输入账号",
hintStyle: TextStyle( hintStyle: TextStyle(fontSize: 16.sp, color: const Color.fromRGBO(153, 153, 153, 1)),
fontSize: 16.sp,
color: const Color.fromRGBO(153, 153, 153, 1)),
labelText: "账号", labelText: "账号",
labelStyle: TextStyle( labelStyle: TextStyle(fontSize: 16.sp, color: const Color.fromRGBO(148, 163, 182, 1)),
fontSize: 16.sp,
color: const Color.fromRGBO(148, 163, 182, 1)),
suffixIcon: !hasNameVal suffixIcon: !hasNameVal
? null ? null
: Transform.translate( : Transform.translate(
offset: offset: Offset(10, 10), // padding值来设置偏移量
Offset(10, 10), // padding值来设置偏移量
child: IconButton( child: IconButton(
alignment: Alignment.center, alignment: Alignment.center,
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
@ -303,19 +288,13 @@ 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 color: !_isShowPwd ? Theme.of(context).primaryColor : Colors.grey,
? Theme.of(context).primaryColor
: Colors.grey,
), ),
), ),
hintStyle: TextStyle( hintStyle: TextStyle(fontSize: 16.sp, color: const Color.fromRGBO(153, 153, 153, 1)),
fontSize: 16.sp,
color: const Color.fromRGBO(153, 153, 153, 1)),
labelText: "密码", labelText: "密码",
isDense: true, isDense: true,
labelStyle: TextStyle( labelStyle: TextStyle(fontSize: 16.sp, color: const Color.fromRGBO(148, 163, 182, 1)),
fontSize: 16.sp,
color: const Color.fromRGBO(148, 163, 182, 1)),
), ),
), ),
$SchoolDataDropDown(schools, schoolId, (int? id) { $SchoolDataDropDown(schools, schoolId, (int? id) {
@ -333,10 +312,8 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
checkColor: Colors.white, checkColor: Colors.white,
value: keepPwd, value: keepPwd,
onChanged: (value) { onChanged: (value) {
FocusScope.of(context) FocusScope.of(context).requestFocus(_pwdFocus);
.requestFocus(_pwdFocus); FocusScope.of(context).requestFocus(_theFocus);
FocusScope.of(context)
.requestFocus(_theFocus);
setState(() { setState(() {
keepPwd = value ?? false; keepPwd = value ?? false;
}); });
@ -349,24 +326,15 @@ 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('记住密码', child: Text('记住密码', style: TextStyle(fontSize: 14.sp, color: const Color.fromRGBO(148, 163, 182, 1))),
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( RouterManager.router.navigateTo(context, RouterManager.registerPath);
context, RouterManager.registerPath);
}, },
child: Text('注册', child: Text('注册', style: TextStyle(fontSize: 14.sp, color: const Color.fromRGBO(148, 163, 182, 1)))),
style: TextStyle(
fontSize: 14.sp,
color: const Color.fromRGBO(
148, 163, 182, 1)))),
], ],
), ),
InkWell( InkWell(
@ -374,9 +342,7 @@ 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 color: canLogin ? const Color.fromRGBO(9, 105, 246, 1) : Colors.grey,
? 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),
@ -385,16 +351,14 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
spreadRadius: 0.5, // spreadRadius: 0.5, //
) )
], ],
borderRadius: borderRadius: BorderRadius.all(Radius.circular(8.w)),
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( style: TextStyle(fontSize: 16.sp, color: Colors.white),
fontSize: 16.sp, color: Colors.white),
), ),
), ),
), ),
@ -408,10 +372,8 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
checkColor: Colors.white, checkColor: Colors.white,
value: readAgreement, value: readAgreement,
onChanged: (value) { onChanged: (value) {
FocusScope.of(context) FocusScope.of(context).requestFocus(_pwdFocus);
.requestFocus(_pwdFocus); FocusScope.of(context).requestFocus(_theFocus);
FocusScope.of(context)
.requestFocus(_theFocus);
setState(() { setState(() {
readAgreement = value ?? false; readAgreement = value ?? false;
}); });
@ -487,29 +449,22 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
barrierDismissible: false, barrierDismissible: false,
builder: (BuildContext context) { builder: (BuildContext context) {
return CupertinoAlertDialog( return CupertinoAlertDialog(
title: quickText('用户协议及隐私协议', title: quickText('用户协议及隐私协议', size: 14.sp, color: Color.fromARGB(255, 53, 52, 52)),
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( style: TextStyle(color: Color.fromARGB(255, 137, 138, 139), fontSize: 11.sp),
color: Color.fromARGB(255, 137, 138, 139),
fontSize: 11.sp),
children: <TextSpan>[ children: <TextSpan>[
TextSpan( TextSpan(text: '《用户协议》《隐式协议》', style: TextStyle(color: Colors.deepOrangeAccent, fontSize: 13.sp)),
text: '《用户协议》《隐式协议》',
style: TextStyle(
color: Colors.deepOrangeAccent, fontSize: 13.sp)),
], ],
), ),
), ),
), ),
actions: <Widget>[ actions: <Widget>[
CupertinoDialogAction( CupertinoDialogAction(
child: Text("取消", child: Text("取消", style: TextStyle(color: Color.fromARGB(255, 58, 58, 58))),
style: TextStyle(color: Color.fromARGB(255, 58, 58, 58))),
onPressed: () => Navigator.of(context).pop(false), onPressed: () => Navigator.of(context).pop(false),
), ),
CupertinoDialogAction( CupertinoDialogAction(
@ -535,22 +490,16 @@ 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 BaseStructureResult<dynamic> resultData = await client.toLogin(UserLoginParams(userName, userPwdMd5, schoolId!));
.toLogin(UserLoginParams(userName, userPwdMd5, schoolId!)); UserLogin? userData = resultData.code == 200 && resultData.data != null ? UserLogin.fromJson(resultData.data) : null;
UserLogin? userData = resultData.code == 200 && resultData.data != null if (resultData.code != 200 || userData?.accessToken == null || userData?.accessToken == '') {
? 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 = BaseStructureResult<UserInfo> userRes = await client.getUserInfo('Bearer ${userData.accessToken}');
await client.getUserInfo('Bearer ${userData.accessToken}');
if (userRes.code != 200 || userRes.data == null) { if (userRes.code != 200 || userRes.data == null) {
throw Exception('登录失败,请重试'); throw Exception('登录失败,请重试');
@ -559,19 +508,14 @@ 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({ fastData.setUserPwdAndAccount({'pwd': userPwd, 'account': userName, 'schoolId': schoolId.toString()});
'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, RouterManager.router.navigateTo(context, RouterManager.root, clearStack: true, transition: getTransition());
clearStack: true, transition: getTransition());
}); });
} catch (e) { } catch (e) {
toPrint(val: e.toString()); toPrint(val: e.toString());
@ -609,25 +553,19 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
} }
@hwidget @hwidget
Widget $schoolDataDropDown(BuildContext context, List<UseLoginSchool> schools, Widget $schoolDataDropDown(BuildContext context, List<UseLoginSchool> schools, int? schoolId, void Function(int? id) call) {
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>( useValueChanged<List<UseLoginSchool>, void>(schools, (_, __) => useSchool.value = schools);
schools, (_, __) => useSchool.value = schools); useValueChanged<int?, void>(schoolId, (_, __) => useSchoolId.value = schoolId);
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( Container(alignment: Alignment.topLeft, child: quickText('登录学校', size: 12.sp, color: const Color.fromRGBO(148, 163, 182, 1))),
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,
@ -639,17 +577,12 @@ Widget $schoolDataDropDown(BuildContext context, List<UseLoginSchool> schools,
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( underline: Container(height: 0.6.h, color: const Color.fromRGBO(80, 87, 103, 1)),
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 items: useSchool.value.map((e) => DropdownMenuItem<int>(value: e.schoolId, child: quickText(e.schoolName, size: 12.sp))).toList(),
.map((e) => DropdownMenuItem<int>(
value: e.schoolId,
child: quickText(e.schoolName, size: 12.sp)))
.toList(),
), ),
) )
], ],