处理登录添加所在学校下拉框
This commit is contained in:
parent
a7bdfe9af7
commit
8ed3b85b92
|
|
@ -230,3 +230,4 @@ marking_app/lib/pages/homework_correction/widget/answer_handwriting.g.dart
|
|||
marking_app/lib/pages/report_detail/report_history.g.dart
|
||||
marking_app/lib/common/model/report/report_student_history_record.g.dart
|
||||
marking_app/lib/common/model/report/report_student_info.g.dart
|
||||
marking_app/lib/pages/login/index.g.dart
|
||||
|
|
|
|||
|
|
@ -6,14 +6,12 @@
|
|||
* @FilePath: \marking_app\lib\common\model\UserLogin.dart
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'user_login.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable(checked: true)
|
||||
class UserLogin extends Object {
|
||||
|
||||
class UserLogin extends Object {
|
||||
@JsonKey(name: 'access_token')
|
||||
String accessToken;
|
||||
|
||||
|
|
@ -23,10 +21,28 @@ part 'user_login.g.dart';
|
|||
@JsonKey(name: 'token_type')
|
||||
String tokenType;
|
||||
|
||||
UserLogin(this.accessToken,this.expiresIn,this.tokenType,);
|
||||
UserLogin(
|
||||
this.accessToken,
|
||||
this.expiresIn,
|
||||
this.tokenType,
|
||||
);
|
||||
|
||||
factory UserLogin.fromJson(Map<String, dynamic> srcJson) => _$UserLoginFromJson(srcJson);
|
||||
|
||||
Map<String, dynamic> toJson() => _$UserLoginToJson(this);
|
||||
}
|
||||
|
||||
}
|
||||
@JsonSerializable()
|
||||
class UseLoginSchool extends Object {
|
||||
@JsonKey(name: 'schoolId')
|
||||
int schoolId;
|
||||
|
||||
@JsonKey(name: 'schoolName')
|
||||
String schoolName;
|
||||
|
||||
UseLoginSchool(this.schoolId, this.schoolName);
|
||||
|
||||
factory UseLoginSchool.fromJson(Map<String, dynamic> srcJson) => _$UseLoginSchoolFromJson(srcJson);
|
||||
|
||||
Map<String, dynamic> toJson() => _$UseLoginSchoolToJson(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,24 +6,24 @@
|
|||
* @FilePath: \marking_app\lib\common\model\user\user_login_params.dart
|
||||
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
|
||||
*/
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'user_login_params.g.dart';
|
||||
|
||||
|
||||
@JsonSerializable()
|
||||
class UserLoginParams extends Object {
|
||||
|
||||
class UserLoginParams extends Object {
|
||||
@JsonKey(name: 'loginName')
|
||||
String loginName;
|
||||
|
||||
@JsonKey(name: 'password')
|
||||
String password;
|
||||
|
||||
UserLoginParams(this.loginName,this.password,);
|
||||
@JsonKey(name: 'schoolId')
|
||||
int? schoolId;
|
||||
|
||||
UserLoginParams(this.loginName, this.password, [this.schoolId]);
|
||||
|
||||
factory UserLoginParams.fromJson(Map<String, dynamic> srcJson) => _$UserLoginParamsFromJson(srcJson);
|
||||
|
||||
Map<String, dynamic> toJson() => _$UserLoginParamsToJson(this);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,9 @@ import 'package:flutter/cupertino.dart';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:functional_widget_annotation/functional_widget_annotation.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:marking_app/common/config/request_config.dart';
|
||||
import 'package:marking_app/common/mixin/common.dart';
|
||||
|
|
@ -32,6 +34,8 @@ import 'package:marking_app/provider/user_provider.dart';
|
|||
import 'package:marking_app/routes/RouterManager.dart';
|
||||
import 'package:marking_app/utils/sys_protocol.dart';
|
||||
|
||||
part 'index.g.dart';
|
||||
|
||||
class TheLogin extends StatefulHookConsumerWidget {
|
||||
const TheLogin({Key? key}) : super(key: key);
|
||||
|
||||
|
|
@ -56,6 +60,9 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
late final TextEditingController _userNameController;
|
||||
late final TextEditingController _passwordController;
|
||||
|
||||
int? schoolId;
|
||||
List<UseLoginSchool> schools = []; // 学校数据
|
||||
|
||||
late final FocusNode _pwdFocus; // 密码
|
||||
late final FocusNode _theFocus;
|
||||
|
||||
|
|
@ -81,13 +88,7 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
});
|
||||
getShowRegister();
|
||||
super.initState();
|
||||
dio = Dio(
|
||||
BaseOptions(
|
||||
contentType: "application/json",
|
||||
connectTimeout: 8000,
|
||||
receiveTimeout: 8000,
|
||||
),
|
||||
);
|
||||
dio = Dio(BaseOptions(contentType: "application/json", connectTimeout: 8000, receiveTimeout: 8000));
|
||||
dio.interceptors.add(LogInterceptor(responseBody: true, requestBody: true)); //添加日志
|
||||
|
||||
setHttpsPEM();
|
||||
|
|
@ -109,21 +110,36 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
}
|
||||
|
||||
void getShowRegister() async {
|
||||
RestClient client = await getClientLogin();
|
||||
BaseStructureResult<dynamic> resultData = await client.showRegister();
|
||||
if (resultData.success) {
|
||||
setState(() {
|
||||
showRegister = resultData.data;
|
||||
});
|
||||
if (resultData.success) setState(() => showRegister = resultData.data);
|
||||
}
|
||||
|
||||
// 获取用户学校数据
|
||||
void getSchoolData(String loginName) async {
|
||||
var _client = await getClient();
|
||||
if (loginName.length != 0) {
|
||||
var res = await _client.toLoginGetSchools(loginName);
|
||||
if (res.success) {
|
||||
schools = res.data ?? [];
|
||||
schoolId = schools[0].schoolId;
|
||||
setState(() {});
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (schools.isNotEmpty || schoolId != null) {
|
||||
schools = [];
|
||||
schoolId = null;
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
void userNameListener() {
|
||||
String userName = _userNameController.text;
|
||||
String userName = _userNameController.text.trim();
|
||||
int useNameLength = userName.length;
|
||||
bool hasNameValNew = useNameLength > 0;
|
||||
if (hasNameValNew != hasNameVal) toUpState(setState, () => hasNameVal = hasNameValNew, mounted);
|
||||
const isProd = bool.fromEnvironment('dart.vm.product');
|
||||
getSchoolData(userName); // 获取用户学校数据
|
||||
if (!isProd && useNameLength == 11) {
|
||||
_passwordController.text = userName.substring(useNameLength - 6);
|
||||
}
|
||||
|
|
@ -234,6 +250,7 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
),
|
||||
),
|
||||
),
|
||||
$SchoolDataDropDown(schools, schoolId, (int? id) => schoolId = id),
|
||||
TextField(
|
||||
focusNode: _pwdFocus,
|
||||
controller: _passwordController,
|
||||
|
|
@ -262,9 +279,7 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
labelStyle: TextStyle(fontSize: 16.sp, color: const Color.fromRGBO(148, 163, 182, 1)),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 12.h,
|
||||
),
|
||||
SizedBox(height: 12.h),
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
|
|
@ -289,13 +304,7 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
FocusScope.of(context).requestFocus(_theFocus);
|
||||
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(),
|
||||
if (showRegister == true)
|
||||
|
|
@ -303,10 +312,7 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
onTap: () {
|
||||
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(
|
||||
|
|
@ -459,12 +465,13 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
if (userName == '') return toMsg('请填写用户账号');
|
||||
if (userPwd == '') return toMsg('请填写密码再试');
|
||||
if (!readAgreement) return toMsg('请勾选我已阅读用户协议和隐私协议');
|
||||
if (schoolId == null) return toMsg('请选择所在学校');
|
||||
|
||||
String userPwdMd5 = CommonUtils.generateMD5(userPwd);
|
||||
print('userPwdMd5=$userPwdMd5');
|
||||
EasyLoading.show(status: 'loading...');
|
||||
|
||||
BaseStructureResult<dynamic> resultData = await client.toLogin(UserLoginParams(userName, userPwdMd5));
|
||||
BaseStructureResult<dynamic> resultData = await client.toLogin(UserLoginParams(userName, userPwdMd5, schoolId!));
|
||||
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 ?? '登录失败,请重试');
|
||||
|
|
@ -525,3 +532,41 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@hwidget
|
||||
Widget $schoolDataDropDown(BuildContext context, List<UseLoginSchool> schools, int? schoolId, void Function(int? id) call) {
|
||||
var useSchool = useState(schools);
|
||||
var useSchoolId = useState(schoolId);
|
||||
|
||||
useValueChanged<List<UseLoginSchool>, void>(schools, (_, __) => useSchool.value = schools);
|
||||
useValueChanged<int?, void>(schoolId, (_, __) => useSchoolId.value = schoolId);
|
||||
|
||||
if (useSchool.value.isEmpty) return SizedBox();
|
||||
return Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 10.h),
|
||||
child: Column(
|
||||
children: [
|
||||
Container(alignment: Alignment.topLeft, child: quickText('学校', size: 12.sp, color: const Color.fromRGBO(148, 163, 182, 1))),
|
||||
Container(
|
||||
height: 40.h,
|
||||
width: double.infinity,
|
||||
child: DropdownButton<int>(
|
||||
value: useSchoolId.value,
|
||||
iconSize: 18.r,
|
||||
elevation: 16,
|
||||
isExpanded: true,
|
||||
padding: EdgeInsets.only(right: 4.w),
|
||||
icon: const Icon(Icons.keyboard_arrow_down_rounded),
|
||||
style: TextStyle(color: Colors.deepPurple),
|
||||
underline: Container(height: 0.6.h, color: const Color.fromRGBO(80, 87, 103, 1)),
|
||||
onChanged: (int? id) {
|
||||
call(id);
|
||||
useSchoolId.value = schoolId;
|
||||
},
|
||||
items: useSchool.value.map((e) => DropdownMenuItem<int>(value: e.schoolId, child: quickText(e.schoolName, size: 12.sp))).toList(),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ import 'package:marking_app/common/model/review/review_page_params.dart';
|
|||
import 'package:marking_app/common/model/review/review_tab.dart';
|
||||
import 'package:marking_app/common/model/sys/system_version.dart';
|
||||
import 'package:marking_app/common/model/user/user_info.dart';
|
||||
import 'package:marking_app/common/model/user/user_login.dart';
|
||||
import 'package:retrofit/retrofit.dart' as the_retrofit;
|
||||
import 'package:marking_app/common/model/user/user_login_params.dart';
|
||||
|
||||
|
|
@ -81,6 +82,10 @@ abstract class RestClient {
|
|||
@the_retrofit.POST("/auth/login/exam-marking/user")
|
||||
Future<BaseStructureResult<dynamic>> toLogin(@the_retrofit.Body() UserLoginParams params);
|
||||
|
||||
// 登录获取用户学校数据
|
||||
@the_retrofit.GET("/auth/login/exam-marking/user-schools")
|
||||
Future<BaseStructureResult<List<UseLoginSchool>>> toLoginGetSchools(@the_retrofit.Query("loginName") String loginName);
|
||||
|
||||
//获取图片上传秘钥
|
||||
@the_retrofit.GET("/api/img-svr/minio-cfg")
|
||||
Future<BaseStructureResult<UploadImgSecretKey>> getImageUploadKey();
|
||||
|
|
|
|||
Loading…
Reference in New Issue