提交1888账号登陆
This commit is contained in:
parent
c9edeb662f
commit
fc3f656c66
|
|
@ -50,8 +50,10 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
|
||||
//添加证书
|
||||
setHttpsPEM() async {
|
||||
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) {
|
||||
client.badCertificateCallback = (X509Certificate cert, String host, int port) {
|
||||
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
|
||||
(client) {
|
||||
client.badCertificateCallback =
|
||||
(X509Certificate cert, String host, int port) {
|
||||
return true;
|
||||
};
|
||||
};
|
||||
|
|
@ -89,13 +91,18 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
});
|
||||
getShowRegister();
|
||||
super.initState();
|
||||
dio = Dio(BaseOptions(contentType: "application/json", connectTimeout: 8000, receiveTimeout: 8000));
|
||||
dio.interceptors.add(LogInterceptor(responseBody: true, requestBody: true)); //添加日志
|
||||
dio = Dio(BaseOptions(
|
||||
contentType: "application/json",
|
||||
connectTimeout: 8000,
|
||||
receiveTimeout: 8000));
|
||||
dio.interceptors
|
||||
.add(LogInterceptor(responseBody: true, requestBody: true)); //添加日志
|
||||
|
||||
setHttpsPEM();
|
||||
client = RestClient(dio, baseUrl: RequestConfig().loginBaseUrl);
|
||||
|
||||
_userNameController = TextEditingController()..addListener(userNameListener);
|
||||
_userNameController = TextEditingController()
|
||||
..addListener(userNameListener);
|
||||
_passwordController = TextEditingController();
|
||||
_pwdFocus = FocusNode();
|
||||
_theFocus = FocusNode();
|
||||
|
|
@ -122,12 +129,18 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
void getSchoolData(String loginName) async {
|
||||
if (loginName.length != 0) {
|
||||
try {
|
||||
if (loginName == '18888888888') {
|
||||
schoolId = 10079;
|
||||
return;
|
||||
}
|
||||
var _client = await getClient();
|
||||
var res = await _client.toLoginGetSchools(loginName);
|
||||
if (res.success) {
|
||||
schools = res.data ?? [];
|
||||
UseLoginSchool? schoolElement;
|
||||
if (lastTimeSchoolId != null) schoolElement = schools.firstWhereOrNull((e) => e.schoolId == lastTimeSchoolId);
|
||||
if (lastTimeSchoolId != null)
|
||||
schoolElement =
|
||||
schools.firstWhereOrNull((e) => e.schoolId == lastTimeSchoolId);
|
||||
if (schoolElement != null)
|
||||
schoolId = schoolElement.schoolId;
|
||||
else
|
||||
|
|
@ -149,7 +162,8 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
int useNameLength = userName.length;
|
||||
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');
|
||||
getSchoolData(userName); // 获取用户学校数据
|
||||
if (!isProd && useNameLength == 11) {
|
||||
|
|
@ -205,12 +219,15 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
child: SizedBox(
|
||||
height: 86.w,
|
||||
width: 86.w,
|
||||
child: Image.asset('assets/images/logo.png', fit: BoxFit.cover),
|
||||
child: Image.asset('assets/images/logo.png',
|
||||
fit: BoxFit.cover),
|
||||
),
|
||||
),
|
||||
Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 32.w, vertical: 24.h),
|
||||
padding: EdgeInsets.only(top: 34.h, bottom: 16.h, left: 22.w, right: 22.w),
|
||||
margin: EdgeInsets.symmetric(
|
||||
horizontal: 32.w, vertical: 24.h),
|
||||
padding: EdgeInsets.only(
|
||||
top: 34.h, bottom: 16.h, left: 22.w, right: 22.w),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
border: Border.all(width: 1.w, color: Colors.white),
|
||||
|
|
@ -239,13 +256,18 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
),
|
||||
decoration: InputDecoration(
|
||||
hintText: "请输入账号",
|
||||
hintStyle: TextStyle(fontSize: 16.sp, color: const Color.fromRGBO(153, 153, 153, 1)),
|
||||
hintStyle: TextStyle(
|
||||
fontSize: 16.sp,
|
||||
color: const Color.fromRGBO(153, 153, 153, 1)),
|
||||
labelText: "账号",
|
||||
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)),
|
||||
suffixIcon: !hasNameVal
|
||||
? null
|
||||
: Transform.translate(
|
||||
offset: Offset(10, 10), // 根据原始组件的padding值来设置偏移量
|
||||
offset:
|
||||
Offset(10, 10), // 根据原始组件的padding值来设置偏移量
|
||||
child: IconButton(
|
||||
alignment: Alignment.center,
|
||||
padding: EdgeInsets.zero,
|
||||
|
|
@ -281,13 +303,19 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
onTap: _showPassword,
|
||||
child: Icon(
|
||||
Icons.remove_red_eye,
|
||||
color: !_isShowPwd ? Theme.of(context).primaryColor : Colors.grey,
|
||||
color: !_isShowPwd
|
||||
? Theme.of(context).primaryColor
|
||||
: Colors.grey,
|
||||
),
|
||||
),
|
||||
hintStyle: TextStyle(fontSize: 16.sp, color: const Color.fromRGBO(153, 153, 153, 1)),
|
||||
hintStyle: TextStyle(
|
||||
fontSize: 16.sp,
|
||||
color: const Color.fromRGBO(153, 153, 153, 1)),
|
||||
labelText: "密码",
|
||||
isDense: true,
|
||||
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) {
|
||||
|
|
@ -305,8 +333,10 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
checkColor: Colors.white,
|
||||
value: keepPwd,
|
||||
onChanged: (value) {
|
||||
FocusScope.of(context).requestFocus(_pwdFocus);
|
||||
FocusScope.of(context).requestFocus(_theFocus);
|
||||
FocusScope.of(context)
|
||||
.requestFocus(_pwdFocus);
|
||||
FocusScope.of(context)
|
||||
.requestFocus(_theFocus);
|
||||
setState(() {
|
||||
keepPwd = value ?? false;
|
||||
});
|
||||
|
|
@ -319,15 +349,24 @@ 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)
|
||||
InkWell(
|
||||
onTap: () {
|
||||
RouterManager.router.navigateTo(context, RouterManager.registerPath);
|
||||
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(
|
||||
|
|
@ -335,7 +374,9 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
child: Container(
|
||||
margin: EdgeInsets.symmetric(vertical: 10.h),
|
||||
decoration: BoxDecoration(
|
||||
color: canLogin ? const Color.fromRGBO(9, 105, 246, 1) : Colors.grey,
|
||||
color: canLogin
|
||||
? const Color.fromRGBO(9, 105, 246, 1)
|
||||
: Colors.grey,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: const Color.fromRGBO(46, 91, 255, 0.5),
|
||||
|
|
@ -344,14 +385,16 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
spreadRadius: 0.5, //阴影扩散程度
|
||||
)
|
||||
],
|
||||
borderRadius: BorderRadius.all(Radius.circular(8.w)),
|
||||
borderRadius:
|
||||
BorderRadius.all(Radius.circular(8.w)),
|
||||
),
|
||||
alignment: Alignment.center,
|
||||
width: double.infinity,
|
||||
height: 50.h,
|
||||
child: Text(
|
||||
'登 录',
|
||||
style: TextStyle(fontSize: 16.sp, color: Colors.white),
|
||||
style: TextStyle(
|
||||
fontSize: 16.sp, color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
@ -365,8 +408,10 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
checkColor: Colors.white,
|
||||
value: readAgreement,
|
||||
onChanged: (value) {
|
||||
FocusScope.of(context).requestFocus(_pwdFocus);
|
||||
FocusScope.of(context).requestFocus(_theFocus);
|
||||
FocusScope.of(context)
|
||||
.requestFocus(_pwdFocus);
|
||||
FocusScope.of(context)
|
||||
.requestFocus(_theFocus);
|
||||
setState(() {
|
||||
readAgreement = value ?? false;
|
||||
});
|
||||
|
|
@ -442,22 +487,29 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
return CupertinoAlertDialog(
|
||||
title: quickText('用户协议及隐私协议', size: 14.sp, color: Color.fromARGB(255, 53, 52, 52)),
|
||||
title: quickText('用户协议及隐私协议',
|
||||
size: 14.sp, color: Color.fromARGB(255, 53, 52, 52)),
|
||||
content: SingleChildScrollView(
|
||||
padding: EdgeInsets.only(top: 4.h),
|
||||
child: RichText(
|
||||
text: TextSpan(
|
||||
text: '为了更好地保障您的合法权益,请您阅读并同意以下协议',
|
||||
style: TextStyle(color: Color.fromARGB(255, 137, 138, 139), fontSize: 11.sp),
|
||||
style: TextStyle(
|
||||
color: Color.fromARGB(255, 137, 138, 139),
|
||||
fontSize: 11.sp),
|
||||
children: <TextSpan>[
|
||||
TextSpan(text: '《用户协议》《隐式协议》', style: TextStyle(color: Colors.deepOrangeAccent, fontSize: 13.sp)),
|
||||
TextSpan(
|
||||
text: '《用户协议》《隐式协议》',
|
||||
style: TextStyle(
|
||||
color: Colors.deepOrangeAccent, fontSize: 13.sp)),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: <Widget>[
|
||||
CupertinoDialogAction(
|
||||
child: Text("取消", style: TextStyle(color: Color.fromARGB(255, 58, 58, 58))),
|
||||
child: Text("取消",
|
||||
style: TextStyle(color: Color.fromARGB(255, 58, 58, 58))),
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
|
|
@ -483,16 +535,22 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
print('userPwdMd5=$userPwdMd5');
|
||||
EasyLoading.show(status: 'loading...');
|
||||
|
||||
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 == '') {
|
||||
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 ?? '登录失败,请重试');
|
||||
}
|
||||
|
||||
FastData fastData = FastData.getInstance();
|
||||
fastData.setToken(userData!.accessToken);
|
||||
|
||||
BaseStructureResult<UserInfo> userRes = await client.getUserInfo('Bearer ${userData.accessToken}');
|
||||
BaseStructureResult<UserInfo> userRes =
|
||||
await client.getUserInfo('Bearer ${userData.accessToken}');
|
||||
|
||||
if (userRes.code != 200 || userRes.data == null) {
|
||||
throw Exception('登录失败,请重试');
|
||||
|
|
@ -501,14 +559,19 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
fastData.setUser(userRes.data!).then((value) {
|
||||
// 记住密码
|
||||
if (keepPwd) {
|
||||
fastData.setUserPwdAndAccount({'pwd': userPwd, 'account': userName, 'schoolId': schoolId.toString()});
|
||||
fastData.setUserPwdAndAccount({
|
||||
'pwd': userPwd,
|
||||
'account': userName,
|
||||
'schoolId': schoolId.toString()
|
||||
});
|
||||
}
|
||||
// 更新
|
||||
ref.read(userProvider.notifier).initUserInfo();
|
||||
ref.read(userTokenProvider.notifier).initToken();
|
||||
|
||||
// 跳转登录页
|
||||
RouterManager.router.navigateTo(context, RouterManager.root, clearStack: true, transition: getTransition());
|
||||
RouterManager.router.navigateTo(context, RouterManager.root,
|
||||
clearStack: true, transition: getTransition());
|
||||
});
|
||||
} catch (e) {
|
||||
toPrint(val: e.toString());
|
||||
|
|
@ -546,19 +609,25 @@ class _TheLoginState extends ConsumerState<TheLogin> with CommonMixin {
|
|||
}
|
||||
|
||||
@hwidget
|
||||
Widget $schoolDataDropDown(BuildContext context, List<UseLoginSchool> schools, int? schoolId, void Function(int? id) call) {
|
||||
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);
|
||||
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.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,
|
||||
|
|
@ -570,12 +639,17 @@ Widget $schoolDataDropDown(BuildContext context, List<UseLoginSchool> schools, i
|
|||
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)),
|
||||
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(),
|
||||
items: useSchool.value
|
||||
.map((e) => DropdownMenuItem<int>(
|
||||
value: e.schoolId,
|
||||
child: quickText(e.schoolName, size: 12.sp)))
|
||||
.toList(),
|
||||
),
|
||||
)
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in New Issue