This commit is contained in:
wyf
2025-08-04 18:19:53 +08:00
parent 4c4f324c56
commit 00215e99d2
13 changed files with 879 additions and 134 deletions

View File

@@ -0,0 +1,183 @@
import 'dart:convert';
import 'package:EasyDartModule/EasyDartModule.dart';
import 'package:ef/ef.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:get_storage/get_storage.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:vbvs_app/common/color/ServiceConstant.dart';
import 'package:vbvs_app/common/util/DailyLogUtils.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/common/util/requestWithLog.dart';
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
import 'package:vbvs_app/model/api_response.dart';
import 'package:vbvs_app/model/user_data.dart';
part 'bind_tel_controller.g.dart';
@JsonSerializable()
class AuthBindTelModel {
String? authUserInfo; //授权用户信息
String? phone; //电话
String? code; //验证码
AuthBindTelModel();
static AuthBindTelModel fromJson(Map<String, dynamic> json) =>
_$AuthBindTelModelFromJson(json);
Map<String, dynamic> toJson() => _$AuthBindTelModelToJson(this);
}
class AuthBindTelController extends GetControllerEx<AuthBindTelModel> {
AuthBindTelController() {
attr = GetModel(AuthBindTelModel()).obs;
}
bindTel() async {
String message = "";
if (model.phone == null || model.phone!.isEmpty) {
message = "请输入手机号".tr;
TopSlideNotification.show(Get.context!, text: message);
return message;
}
if (!MyUtils.isValidPhoneNumber(model.phone!)) {
message = '请输入正确的手机号'.tr;
TopSlideNotification.show(Get.context!, text: message);
return message;
}
if (model.code == null || model.code!.isEmpty) {
message = "请输入验证码".tr;
TopSlideNotification.show(Get.context!, text: message);
return message;
}
final Map<String, dynamic> requestBody = {
"tel": model.phone,
"wxInfo": model.authUserInfo,
"verifyCode": model.code,
};
// var response = await ApiService.request
// .post("/api/auth/account/info/wxLoginBindTel", data: requestBody);
// if (response.data != null) {
// try {
// ApiResponse<UserModel> apiResponse = ApiResponse.fromJson(response.data,
// (json) => UserModel.fromJson(json as Map<String, dynamic>));
// if (apiResponse.code == HttpStatusCodes.ok) {
// final UserInfoController userInfoController = Get.find();
// userInfoController.model.user = apiResponse.data;
// userInfoController.model.token = response.headers['token']!.first;
// String efPd = await getValueBySysConfigKey(CommonVariables.efKey);
// if (efPd != null && efPd.isNotEmpty) {
// await initDataEf(key: efPd);
// } else {
// print("efPD为空初始化失败");
// return '登录失败';
// }
// final box = GetStorage();
// box.write('user', userInfoController.model.user!.toJson()); // 存储用户信息
// box.write('token', userInfoController.model.token); // 存储 token
// final AuthResponse res = await ef.client.auth.signInWithPassword(
// phone: userInfoController.model.user!.tel,
// password: userInfoController.model.user!.exp1!,
// );
// userInfoController.model.superbase_session = res.session;
// userInfoController.model.superbase_user = res.user;
// userInfoController.updateAll();
// return '';
// }
// return apiResponse.msg ?? '登录失败';
// } catch (e) {
// print(e);
// return '登录失败';
// }
// }
}
getCode(BuildContext context) async {
String message = "";
if (model.phone == null || model.phone!.isEmpty) {
message = "请输入手机号".tr;
TopSlideNotification.show(context,
text: message, textColor: stringToColor("#FF7159"));
return message;
}
if (!MyUtils.isValidPhoneNumber(model.phone!)) {
message = '请输入正确的手机号'.tr;
TopSlideNotification.show(context,
text: message, textColor: stringToColor("#FF7159"));
return message;
}
String serviceAddress = ServiceConstant.service_address;
String serviceName = ServiceConstant.server_service;
String serviceApi = ServiceConstant.send_code;
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
var data = {
"userName": model.phone!,
'type': 5,
};
data['code'] = "mht";
await requestWithLog(
logTitle: "获取验证码".tr,
method: MyHttpMethod.post,
queryUrl: queryUrl,
data: data,
onSuccess: (res) {
TopSlideNotification.show(context, text: '发送验证码成功'.tr);
},
onFailure: (res) {
message = res.msg!;
TopSlideNotification.show(
context,
text: message.tr,
textColor: themeController.currentColor.sc9,
);
},
);
return message;
}
Future<ApiResponse> updateUserPhone() async {
EasyDartModule.logger.info("更新用户资料");
DailyLogUtils.writeLog("更新用户资料");
try {
ApiResponse apiResponse = ApiResponse(code: -1, msg: "保存失败".tr);
String serviceAddress = ServiceConstant.service_address;
String serviceName = ServiceConstant.server_service;
String serviceApi = ServiceConstant.user_info;
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
String? language = "";
if (languageController.selectLanguage != null) {
language = languageController.selectLanguage.value!.language_code;
}
if (language != null && language.isNotEmpty) {
if (queryUrl.contains("?")) {
queryUrl += "&lang=$language";
} else {
queryUrl += "?lang=$language";
}
}
final data = {
'phone': model.phone,
'verify': model.code,
};
var response =
await EasyDartModule.dio.put(queryUrl, data: jsonEncode(data));
if (apiResponse != null) {
var responseData =
response.data is String ? jsonDecode(response.data) : response.data;
ApiResponse res =
ApiResponse.fromJson(responseData, (object) => object);
MyUtils.formatResponse(res, "保存成功".tr, "保存失败".tr);
return res;
} else {
return ApiResponse(code: -1, msg: "服务器失败".tr);
}
} catch (e) {
EasyDartModule.logger.info("更新用户资料失败->$e");
DailyLogUtils.writeLog("更新用户资料失败->$e");
return ApiResponse(code: -1, msg: "服务器失败".tr);
}
}
}

View File

@@ -0,0 +1,20 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'bind_tel_controller.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
AuthBindTelModel _$AuthBindTelModelFromJson(Map<String, dynamic> json) =>
AuthBindTelModel()
..authUserInfo = json['authUserInfo'] as String?
..phone = json['phone'] as String?
..code = json['code'] as String?;
Map<String, dynamic> _$AuthBindTelModelToJson(AuthBindTelModel instance) =>
<String, dynamic>{
'authUserInfo': instance.authUserInfo,
'phone': instance.phone,
'code': instance.code,
};

View File

@@ -271,14 +271,30 @@ class MHTLoginController extends GetControllerEx<LoginModel> {
queryUrl: queryUrl,
data: data);
if (apiResponse.code == HttpStatusCodes.ok) {
// UserInfoController userInfoController = Get.find();
// if (userInfoController.model.user!.phone == null ||
// userInfoController.model.user!.phone!.isEmpty) {
// Get.toNamed("/auth_bind_tel");
// return;
// }
UserInfoController userInfoController = Get.find();
userInfoController.model.login = 1;
userInfoController.model.user = UserModel.fromJson(apiResponse.data);
userInfoController.model.login = 1;
String token = apiResponse.rawResponse.headers['token']!.first;
EasyDartModule.dio.token = token;
final box = GetStorage();
box.write('token', token); // 存储 token
box.write('user', userInfoController.model.user!.toJson()); // 存储用户信息
if (userInfoController.model.user!.phone == null ||
userInfoController.model.user!.phone!.isEmpty) {
await Get.toNamed("/auth_bind_tel");
}
if (userInfoController.model.user!.phone == null ||
userInfoController.model.user!.phone!.isEmpty) {
userInfoController.model.login = 0;
}
} else {
EasyDartModule.logger.error("[微信登录]:失败-》${apiResponse}");
}
return apiResponse.code!;
}

View File

@@ -0,0 +1,515 @@
import 'package:ef/ef.dart';
import 'package:flutter/material.dart';
import 'package:get_storage/get_storage.dart';
import 'package:vbvs_app/common/color/appConstants.dart';
import 'package:vbvs_app/common/color/appFontsize.dart';
import 'package:vbvs_app/common/color/app_uri_status.dart';
import 'package:vbvs_app/common/util/CheckNetwork.dart';
import 'package:vbvs_app/common/util/FitTool.dart';
import 'package:vbvs_app/common/util/MyUtils.dart';
import 'package:vbvs_app/component/tool/CustomCard.dart';
import 'package:vbvs_app/component/tool/TopSlideNotification.dart';
import 'package:vbvs_app/controller/time/countdown_controller.dart';
import 'package:vbvs_app/controller/user_info_controller.dart';
import 'package:vbvs_app/model/api_response.dart';
import 'package:vbvs_app/pages/mh_page/user/controller/bind_tel_controller.dart';
import 'package:vbvs_app/pages/mh_page/user/controller/mht_login_controller.dart';
class BindTelWidget extends GetView<AuthBindTelController> {
BoxConstraints? bodysize;
final scaffoldKey = GlobalKey<ScaffoldState>();
@override
Widget build(BuildContext context) {
return LayoutBuilder(builder: (context, cc) {
bodysize = cc;
return Container(
// onTap: () => FocusScope.of(context).unfocus(),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/new_background.png'),
fit: BoxFit.fill,
),
),
child: Scaffold(
resizeToAvoidBottomInset: false,
key: scaffoldKey,
backgroundColor: Colors.transparent,
appBar: AppBar(
backgroundColor: Colors.transparent,
automaticallyImplyLeading: false,
iconTheme: IconThemeData(color: Colors.white),
title: Container(
width: double.infinity,
height: 180.rpx,
child: Stack(
alignment: Alignment.center,
children: [
Text(
'绑定手机号码'.tr,
style: TextStyle(
fontFamily: 'Readex Pro',
color: themeController.currentColor.sc3,
letterSpacing: 0,
fontSize: 30.rpx,
),
),
Positioned(
left: 0.rpx,
child: returnIconButtomNew(),
),
],
),
),
actions: [],
centerTitle: false,
),
body: Container(
width: bodysize!.maxWidth,
height: bodysize!.maxHeight * 1,
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Expanded(
child: Padding(
padding:
EdgeInsetsDirectional.fromSTEB(49.rpx, 0, 49.rpx, 0),
child: Container(
width: bodysize!.maxWidth,
height: bodysize!.maxHeight * 0.886,
decoration: BoxDecoration(),
child: Container(
width: bodysize!.maxWidth,
height: bodysize!.maxHeight * 1,
decoration: BoxDecoration(),
child: Column(
mainAxisSize: MainAxisSize.max,
children: [
Padding(
padding:
EdgeInsetsDirectional.fromSTEB(0, 92, 0, 0),
child: Container(
width: bodysize!.maxWidth,
height: bodysize!.maxHeight * 0.05,
decoration: BoxDecoration(),
child: Align(
alignment: AlignmentDirectional(-1, 0),
child: Text(
'绑定手机号码'.tr,
style: TextStyle(
fontFamily: 'Readex Pro',
color: stringToColor("#84F5FF"),
fontSize: 24,
letterSpacing: 0.0,
),
),
),
),
),
Flexible(
child: Container(
width: bodysize!.maxWidth,
height: bodysize!.maxHeight * 0.06,
decoration: BoxDecoration(),
child: Column(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'为了您的账号安全,验证手机号码后,可直接使用此手机号登录。'.tr,
style: TextStyle(
fontFamily: 'Readex Pro',
color: Colors.white,
letterSpacing: 0.0,
),
),
// Text(
// '',
// style: TextStyle(
// fontFamily: 'Readex Pro',
// color: Colors.white,
// letterSpacing: 0.0,
// ),
// ),
],
),
),
),
Padding(
padding:
EdgeInsetsDirectional.fromSTEB(0, 16, 0, 0),
child: Container(
width: bodysize!.maxWidth,
height: bodysize!.maxHeight * 0.06,
decoration: BoxDecoration(),
child: Container(
width: bodysize!.maxWidth,
height: bodysize!.maxHeight * 0.06,
decoration: BoxDecoration(
color: Color(0xFFF3F5F6),
borderRadius: BorderRadius.circular(12),
),
child: Align(
alignment: AlignmentDirectional(0, 0),
child: TextFormField(
onChanged: (value) {
controller.model.phone = value;
},
obscureText: false,
decoration: InputDecoration(
labelStyle: TextStyle(
fontFamily: 'Readex Pro',
fontSize:
AppFontsize.normal_text_size,
letterSpacing: 0.0,
),
hintText: '请输入手机号'.tr,
hintStyle: TextStyle(
fontFamily: 'Readex Pro',
color: Color(0xFFD2D2D2),
fontSize:
AppFontsize.normal_text_size,
letterSpacing: 0.0,
),
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
errorBorder: InputBorder.none,
focusedErrorBorder: InputBorder.none,
contentPadding:
EdgeInsetsDirectional.fromSTEB(
10, 0, 0, 5),
),
style: TextStyle(
fontFamily: 'Readex Pro',
fontSize: 13,
letterSpacing: 0.0,
),
),
),
),
),
),
Obx(() {
controller.model.code;
return Visibility(
visible: true,
child: Padding(
padding: EdgeInsetsDirectional.fromSTEB(
0, 17, 0, 0),
child: Container(
width: bodysize!.maxWidth,
height: bodysize!.maxHeight * 0.06,
decoration: BoxDecoration(),
child: Stack(
children: [
Align(
alignment: AlignmentDirectional(0, 0),
child: Container(
width: MediaQuery.sizeOf(context)
.width,
height: bodysize!.maxHeight * 0.06,
decoration: BoxDecoration(
color: Color(0xFFF3F5F6),
borderRadius:
BorderRadius.circular(12),
),
child: Align(
alignment:
AlignmentDirectional(0, 0),
child: TextFormField(
// focusNode: _focusNode4,
onChanged: (value) {
controller.model.code = value;
},
obscureText: false,
decoration: InputDecoration(
labelStyle: TextStyle(
fontFamily: 'Readex Pro',
fontSize: AppFontsize
.normal_text_size,
letterSpacing: 0,
),
hintText: '请输入验证码',
hintStyle: TextStyle(
fontFamily: 'Readex Pro',
color: Color(0xFFD2D2D2),
fontSize: AppFontsize
.normal_text_size,
letterSpacing: 0,
),
enabledBorder:
InputBorder.none,
focusedBorder:
InputBorder.none,
errorBorder: InputBorder.none,
focusedErrorBorder:
InputBorder.none,
contentPadding:
EdgeInsetsDirectional
.fromSTEB(
10, 0, 0, 5),
),
style: TextStyle(
fontFamily: 'Readex Pro',
fontSize: AppFontsize
.normal_text_size,
letterSpacing: 0,
),
),
),
),
),
Align(
alignment:
AlignmentDirectional(0.2, 0.1),
child: Container(
width: 3,
height: 30,
decoration: BoxDecoration(
color: Color(0xFFD3D3D3),
),
),
),
Align(
alignment:
AlignmentDirectional(0.9, 0),
child: Container(
width: MediaQuery.sizeOf(context)
.width *
0.157,
height: MediaQuery.sizeOf(context)
.height *
0.014,
constraints: BoxConstraints(
minWidth: 118,
minHeight: 30,
),
decoration: BoxDecoration(),
child: Align(
alignment:
AlignmentDirectional(0, 0),
child: Obx(() {
final CountdownController
countdownController =
Get.find<
CountdownController>();
return InkWell(
onTap: () async {
if (countdownController
.countdown.value !=
0) {
return;
}
String msg =
await controller
.getCode(context);
if (msg.isNotEmpty) {
return;
}
countdownController
.countdown
.value ==
0
? countdownController
.startCountdown(
AppConstants
.code_time)
: null;
},
child: Text(
countdownController
.countdown
.value ==
0
? '获取验证码'
: '${countdownController.countdown.value}',
style: TextStyle(
fontFamily: 'Readex Pro',
color: Color(0xFF333333),
fontSize: AppFontsize
.normal_text_size,
letterSpacing: 0,
),
),
);
}),
),
),
),
],
),
),
),
);
}),
Padding(
padding:
EdgeInsetsDirectional.fromSTEB(0, 19, 0, 0),
child: Container(
width: bodysize!.maxWidth,
height: bodysize!.maxHeight * 0.022,
constraints: BoxConstraints(
minWidth: 466,
minHeight: 30,
),
decoration: BoxDecoration(),
),
),
Padding(
padding:
EdgeInsetsDirectional.fromSTEB(0, 29, 0, 0),
child: Container(
width: bodysize!.maxWidth,
height: bodysize!.maxHeight * 0.056,
decoration: BoxDecoration(),
child: Container(
width: bodysize!.maxWidth,
height: bodysize!.maxHeight * 0.056,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(0),
),
// child: FFButtonWidget(
// onPressed: () async {
// //todo 提交绑定请求
// String msg = await controller.bindTel();
// if (msg == null || msg.isEmpty) {
// MHTLoginController loginController =
// Get.find();
// //TODO 微信回调监听操作全部跳转页面前成功以后移除监听,防止重复监听,其他方式登录成功也需要移出监听
// loginController.fluwxCancelable
// ?.cancel();
// // 登录成功移出网络检查监听
// Checknetwork.subscription?.cancel();
// final box = GetStorage();
// box.remove('countdown');
// CountdownController
// countdownController = Get.find();
// countdownController.countdown = 0.obs;
// Get.offAndToNamed(
// "/mianPageBottomChange");
// } else {
// showToast(msg);
// }
// },
// text: '确定',
// options: FFButtonOptions(
// height: 40,
// padding: EdgeInsetsDirectional.fromSTEB(
// 24, 0, 24, 0),
// iconPadding:
// EdgeInsetsDirectional.fromSTEB(
// 0, 0, 0, 0),
// color: stringToColor("#84F5FF"),
// textStyle: TextStyle(
// fontFamily: 'Readex Pro',
// color: Colors.white,
// fontSize: 13,
// letterSpacing: 0.0,
// ),
// elevation: 3,
// borderSide: BorderSide(
// color: Colors.transparent,
// width: 1,
// ),
// borderRadius:
// BorderRadius.circular(20.rpx),
// ),
// ),
child: CustomCard(
borderRadius: 16.rpx,
gradientDirection:
GradientDirection.vertical,
onTap: () async {
// String msg = await controller.bindTel();
// if (msg == null || msg.isEmpty) {
// MHTLoginController loginController =
// Get.find();
// //TODO 微信回调监听操作全部跳转页面前成功以后移除监听,防止重复监听,其他方式登录成功也需要移出监听
// loginController.fluwxCancelable
// ?.cancel();
// // 登录成功移出网络检查监听
// Checknetwork.subscription?.cancel();
// final box = GetStorage();
// box.remove('countdown');
// CountdownController
// countdownController = Get.find();
// countdownController.countdown = 0.obs;
// Get.offAndToNamed(
// "/mianPageBottomChange");
// } else {
// showToast(msg);
// }
ApiResponse apiResponse =
await controller.updateUserPhone();
if (apiResponse.code ==
HttpStatusCodes.ok) {
UserInfoController userInfoController =
Get.find();
await userInfoController.getUserInfo();
MHTLoginController loginController =
Get.find();
//TODO 微信回调监听操作全部跳转页面前成功以后移除监听,防止重复监听,其他方式登录成功也需要移出监听
loginController.fluwxCancelable
?.cancel();
// 登录成功移出网络检查监听
Checknetwork.subscription?.cancel();
final box = GetStorage();
box.remove('countdown');
CountdownController
countdownController = Get.find();
countdownController.countdown = 0.obs;
Get.offAndToNamed(
"/mianPageBottomChange");
} else {
TopSlideNotification.show(context,
textColor: themeController
.currentColor.sc9,
text: apiResponse.msg ?? '失败'.tr);
}
},
colors: const [
Color(0xFFFCFCFC),
Color(0xFFF8FAF9),
Color(0XFFECF6F3),
Color(0XFFD9F0E9),
Color(0xFFCEECE3)
],
child: Container(
width: double.infinity,
height: 90.rpx,
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(16.rpx),
),
child: Text(
"提交".tr,
style: TextStyle(
fontFamily: 'Readex Pro',
color: Color(0XFF003058),
letterSpacing: 0,
fontSize: 26.rpx,
),
),
),
),
),
),
),
],
),
),
),
),
),
],
),
),
),
);
});
}
}