更新登录choice学校功能

This commit is contained in:
1147192855@qq.com 2024-06-13 17:01:15 +08:00
parent b3b58fb55f
commit 28a03f1cde
1 changed files with 19 additions and 6 deletions

View File

@ -9,6 +9,7 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:io'; import 'dart:io';
import 'package:collection/collection.dart';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:dio/adapter.dart'; import 'package:dio/adapter.dart';
@ -59,7 +60,7 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
// //
late final TextEditingController _userNameController; late final TextEditingController _userNameController;
late final TextEditingController _passwordController; late final TextEditingController _passwordController;
int? lastTimeSchoolId; // ID
int? schoolId; int? schoolId;
List<UseLoginSchool> schools = []; // List<UseLoginSchool> schools = []; //
@ -104,6 +105,9 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
setState(() { setState(() {
_passwordController.text = valMap['pwd']; _passwordController.text = valMap['pwd'];
_userNameController.text = valMap['account']; _userNameController.text = valMap['account'];
lastTimeSchoolId = int.tryParse(valMap['schoolId']);
print('原始学校ID $schoolId');
keepPwd = true; keepPwd = true;
}); });
}); });
@ -121,7 +125,12 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
var res = await _client.toLoginGetSchools(loginName); var res = await _client.toLoginGetSchools(loginName);
if (res.success) { if (res.success) {
schools = res.data ?? []; schools = res.data ?? [];
schoolId = schools[0].schoolId; UseLoginSchool? schoolElement;
if (lastTimeSchoolId != null) schoolElement = schools.firstWhereOrNull((e) => e.schoolId == lastTimeSchoolId);
if (schoolElement != null)
schoolId = schoolElement.schoolId;
else
schoolId = schools[0].schoolId;
setState(() {}); setState(() {});
return; return;
} }
@ -137,6 +146,7 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
String userName = _userNameController.text.trim(); String userName = _userNameController.text.trim();
int useNameLength = userName.length; int useNameLength = userName.length;
bool hasNameValNew = useNameLength > 0; bool hasNameValNew = useNameLength > 0;
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); //
@ -250,7 +260,6 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
), ),
), ),
), ),
$SchoolDataDropDown(schools, schoolId, (int? id) => schoolId = id),
TextField( TextField(
focusNode: _pwdFocus, focusNode: _pwdFocus,
controller: _passwordController, controller: _passwordController,
@ -279,6 +288,10 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
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) {
schoolId = id;
lastTimeSchoolId = null;
}),
SizedBox(height: 12.h), SizedBox(height: 12.h),
Row( Row(
children: [ children: [
@ -489,7 +502,7 @@ 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}); fastData.setUserPwdAndAccount({'pwd': userPwd, 'account': userName, 'schoolId': schoolId.toString()});
} }
// //
ref.read(userProvider.notifier).initUserInfo(); ref.read(userProvider.notifier).initUserInfo();
@ -543,10 +556,10 @@ Widget $schoolDataDropDown(BuildContext context, List<UseLoginSchool> schools, i
if (useSchool.value.isEmpty) return SizedBox(); if (useSchool.value.isEmpty) return SizedBox();
return Padding( return Padding(
padding: EdgeInsets.symmetric(vertical: 10.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,