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