diff --git a/lib/controller/mine/auth_controller.dart b/lib/controller/mine/auth_controller.dart index 343b58e..deb28d1 100644 --- a/lib/controller/mine/auth_controller.dart +++ b/lib/controller/mine/auth_controller.dart @@ -6,8 +6,11 @@ import '../../network/user_api.dart'; class AuthController extends GetxController { final isLoading = false.obs; final List dataList = []; -// 是否正在登录中 + // 是否正在登录中 final isLoggingIn = false.obs; + final name = ''.obs; + final idcard = ''.obs; + final agree = false.obs; // 从GetX依赖注入中获取UserApi实例 late UserApi _userApi; @@ -18,33 +21,90 @@ class AuthController extends GetxController { _userApi = Get.find(); _loadInitialData(); } - void _loadInitialData() { - isLoading.value = true; - dataList.assignAll([ - AuthCard( title: '手机绑定', desc: '防止账号丢失', index: 1, authed: true), - AuthCard( title: '真实头像', desc: '提高交友成功率', index: 2, authed: false), - AuthCard( title: '实名认证', desc: '提高交友成功率', index: 3, authed: false), - ]); - isLoading.value = false; - } // 登录方法 - Future login() async { + Future _loadInitialData() async { + try { + isLoading.value = true; + final one = AuthCard( title: '手机绑定', desc: '防止账号丢失', index: 1, authed: true); + dataList.assignAll([ + one, + AuthCard( title: '真实头像', desc: '提高交友成功率', index: 2, authed: false), + AuthCard( title: '实名认证', desc: '提高交友成功率', index: 3, authed: false), + ]); + // 调用登录接口 + // final response = await _userApi.login({}); + // 处理响应 + // if (response.data.isSuccess) { + // + // } + } catch (e) { + SmartDialog.showToast('网络请求失败,请检查网络连接'); + } finally { + isLoading.value = false; + } + } + + bool validateChineseID(String id) { + if (id.length != 18) return false; + + // 系数表 + final coefficients = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]; + + // 校验码对应表 + final checkCodeMap = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2']; + + int sum = 0; + + try { + for (int i = 0; i < 17; i++) { + int digit = int.parse(id[i]); + sum += digit * coefficients[i]; + } + } catch (e) { + return false; // 包含非数字字符 + } + + int remainder = sum % 11; + String checkCode = checkCodeMap[remainder]; + + return id[17].toUpperCase() == checkCode; + } + + Future startAuthing() async { + if (name.value.isEmpty) { + SmartDialog.showToast('请输入姓名'); + return; + } + if (idcard.value.isEmpty) { + SmartDialog.showToast('请输入身份证号'); + return; + } + if (!validateChineseID(idcard.value)) { + SmartDialog.showToast('请输入正确的身份证号'); + return; + } + if (!agree.value) { + SmartDialog.showToast('请同意用户认证协议'); + return; + } try { // 调用登录接口 final response = await _userApi.login({}); // 处理响应 if (response.data.isSuccess) { - - } else { - SmartDialog.showToast(response.data.message); - } + SmartDialog.showToast('认证成功'); + Get.back(); + } else { + SmartDialog.showToast(response.data.message); + } } catch (e) { SmartDialog.showToast('网络请求失败,请检查网络连接'); } finally { } } + } class AuthCard { diff --git a/lib/pages/mine/real_name_page.dart b/lib/pages/mine/real_name_page.dart index a95463b..aaadc8c 100644 --- a/lib/pages/mine/real_name_page.dart +++ b/lib/pages/mine/real_name_page.dart @@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:get/get.dart'; +import 'package:tdesign_flutter/tdesign_flutter.dart'; import '../../controller/mine/auth_controller.dart'; @@ -9,7 +10,6 @@ class RealNamePage extends StatelessWidget { RealNamePage({super.key}); final AuthController controller = Get.put(AuthController()); // 是否同意协议 - final agreeTerms = Rx(false); @override Widget build(BuildContext context) { return Scaffold( @@ -87,6 +87,9 @@ class RealNamePage extends StatelessWidget { fontSize: 15, height: 1.2, // 控制文字垂直位置 ), + onChanged: (value) { + controller.name.value = value; + }, ), ), ), @@ -138,6 +141,9 @@ class RealNamePage extends StatelessWidget { fontSize: 15, height: 1.2, // 控制文字垂直位置 ), + onChanged: (value) { + controller.idcard.value = value; + }, ), ), ), @@ -151,9 +157,9 @@ class RealNamePage extends StatelessWidget { children: [ SizedBox(width: 8), Obx(() => Checkbox( - value: agreeTerms.value, + value: controller.agree.value, onChanged: (value) { - agreeTerms.value = value ?? false; + controller.agree.value = value ?? false; }, activeColor: Color(0xff7562F9), side: const BorderSide(color: Colors.grey), @@ -163,53 +169,25 @@ class RealNamePage extends StatelessWidget { ConstrainedBox( constraints: BoxConstraints(maxWidth: 300), // 限制最大宽度 child: Text( - '前排吃瓜,这里的瓜包新鲜,这里的人士有料有梗有灼见~,这里的瓜包新鲜,这里的人士有料有梗有灼见~', + '依据法律法规的要求,我们将收集您的真实姓名,身份证号用于实名认证,认证信息将用于直播连麦、收益提现、依据证件信息更正性别等,与账号唯一绑定,我们会使用加密方式对您的认证信息进行严格保密。', style: TextStyle( fontSize: 13, color: Colors.grey ), ), ) ], ), SizedBox(height: 48), - Container( - padding: const EdgeInsets.only(left: 24, right: 24), - child: ElevatedButton( - onPressed: controller.isLoggingIn.value - ? null - : () { - // 登录逻辑 - if (!agreeTerms.value) { - SmartDialog.showToast('请同意用户协议和隐私政策'); - return; - } - // 调用控制器的登录方法 - controller.login(); - }, - style: ElevatedButton.styleFrom( - minimumSize: const Size(double.infinity, 50), - backgroundColor: agreeTerms.value ? const Color(0xff7562F9) : Colors.grey.shade300, - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(25), - ), - elevation: 0, - ), - child: controller.isLoggingIn.value ? const SizedBox( - width: 20, - height: 20, - child: CircularProgressIndicator( - color: Colors.white, - strokeWidth: 1, - ), - ) - : const Text( - '立即认证', - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.bold, - color: Colors.white, - ), - ), - ), - ) + + TDButton( + text: '立即认证', + width: MediaQuery.of(context).size.width - 40, + size: TDButtonSize.large, + type: TDButtonType.fill, + shape: TDButtonShape.round, + theme: TDButtonTheme.primary, + onTap: (){ + controller.startAuthing(); + }, + ), ], ), );