import 'package:ef/ef.dart'; import 'package:flutter/material.dart'; import 'package:flutterflow_ui/flutterflow_ui.dart'; import 'package:json_annotation/json_annotation.dart'; import 'package:vbvs_app/common/util/MyUtils.dart'; part 'login_controller.g.dart'; @JsonSerializable() class LoginModel { //版本id int? loginStyle = 1; //1.密码登录 2.短信登录 String? account = '17649984946'; //账户 String? password = 'wyf123,.'; //密码 String? phone; //手机号 String? code; //验证码 String? register_code; bool? showPd = true; int? forceLogin = 0; bool? isIos; //是否为ios设备 bool? isWeChatNotInstalled; //是否安装微信 bool? register_agree = false; //是否同意协议 LoginModel(); static LoginModel fromJson(Map json) => _$LoginModelFromJson(json); Map toJson() => _$LoginModelToJson(this); } class LoginController extends GetControllerEx { // 初始化实例 // final Fluwx fluwx = Fluwx(); // 微信监听返回值 // FluwxCancelable? fluwxCancelable; // final UserRepository repository = UserRepository(); LoginController() { attr = GetModel(LoginModel()).obs; } //登录 Future login(BuildContext context) async { // return ''; String message = ''; String account = ''; String password = ''; // if (model.loginStyle == 1) { // //账号登录 // if (model.account == null || model.account!.isEmpty) { // message = '账户不能为空'; // showToast(message); // return message; // } // if (model.password == null || model.password!.isEmpty) { // message = '密码不能为空'; // showToast(message); // return message; // } // account = model.account!; // password = model.password!; // } // if (model.loginStyle == 2) { // //账号登录 // if (model.phone == null || model.phone!.isEmpty) { // message = '手机号不能为空'; // showToast(message); // return message; // } // if (!MyUtils.isValidPhoneNumber(model.phone!)) { // message = '请输入正确的手机号'; // showToast(message); // return message; // } // if (model.code == null || model.code!.isEmpty) { // message = '验证码不能为空'; // showToast(message); // return message; // } // account = model.phone!; // password = model.code!; // } // RegisterController registerController = Get.find(); // if (registerController.model.register_agree == null || // registerController.model.register_agree != true) { // message = "需要同意协议"; // showToast(message); // return message; // } // message = await repository.login( // model.loginStyle!, account, password, model.forceLogin); // model.forceLogin = 0; return message; } Future getCode(BuildContext context) async { String message = ""; if (model.register_agree == null || model.register_agree != true) { // message = "需要同意协议"; // showToast(message); return message; } if (model.phone == null || model.phone!.isEmpty) { message = "请输入手机号"; // showToast(message); return message; } if (!MyUtils.isValidPhoneNumber(model.phone!)) { message = '请输入正确的手机号'; showToast(message); return message; } // message = await repository.sendRegisterCode(model.phone!); if (message.isNotEmpty) { showToast(message ?? "发送失败,请稍后再试!"); return "发送失败,请稍后再试!"; } else { showToast("发送验证码成功!", color: color_success); } return ''; } //微信登录 // Future wxLoginSendAuth() async { // /* // 1、目前移动应用上微信登录只提供原生的登录方式,需要用户安装微信客户端才能配合使用。 // 2、对于Android应用,建议总是显示微信登录按钮,当用户手机没有安装微信客户端时,请引导用户下载安装微信客户端。 // 3、对于iOS应用,考虑到iOS应用商店审核指南中的相关规定,建议开发者接入微信登录时,先检测用户手机是否已安装微信客户端 // (使用sdk中isWXAppInstalled函数 ),对未安装的用户隐藏微信登录按钮,只提供其他登录方式(比如手机号注册登录、游客登录等) // */ // if (isAndroid) { // bool isWeChatInstalled = await fluwx.isWeChatInstalled; // debugPrint('is wechat installed: $isWeChatInstalled'); // if (!isWeChatInstalled) { // showToast("请先安装微信APP,再使用微信登录"); // return; // } // } // fluwx // .authBy( // which: NormalAuth( // scope: 'snsapi_userinfo', // state: 'wechat_sdk_zhmht_wxlogin', // )) // .then((data) { // //返回true表示成功或者false表示失败,这边没有意义从login_controller页面构造函数监听中去处理 // debugPrint('msg:$data'); // }); // } //退出登录 // Future logout() async { // await repository.logout(); // } // loginByWechatCode(String code) async { // return await repository.loginByWechatCode(code); // } //注销账号 // deletedAccount() async { // return await repository.deletedAccount(); // } }