更新登录choice学校功能
This commit is contained in:
parent
b3b58fb55f
commit
28a03f1cde
|
|
@ -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,6 +125,11 @@ 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 ?? [];
|
||||||
|
UseLoginSchool? schoolElement;
|
||||||
|
if (lastTimeSchoolId != null) schoolElement = schools.firstWhereOrNull((e) => e.schoolId == lastTimeSchoolId);
|
||||||
|
if (schoolElement != null)
|
||||||
|
schoolId = schoolElement.schoolId;
|
||||||
|
else
|
||||||
schoolId = schools[0].schoolId;
|
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,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue