更新登录对接
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
import 'package:easydevice/src/ble_device.dart';
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:vbvs_app/common/color/ServiceConstant.dart';
|
||||
import 'package:vbvs_app/common/color/app_uri_status.dart';
|
||||
import 'package:vbvs_app/common/util/DailyLogUtils.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/model/BleDeviceData.dart';
|
||||
import 'package:vbvs_app/model/api_response.dart';
|
||||
|
||||
part 'blueteeth_bind_controller.g.dart'; // 由json_serializable自动生成的部分
|
||||
|
||||
@@ -8,7 +19,8 @@ class BlueteethBindModel {
|
||||
int? read = 1; //是否不再提示教程 0 不再提示 1 需要提示
|
||||
double? singal = -70; //扫描信号强度
|
||||
|
||||
List? devicelist = []; //蓝牙扫描到的设备数据列表
|
||||
List<BleDeviceData>? devicelist = []; //蓝牙扫描到的设备数据列表
|
||||
List<BleDeviceData>? betDevicelist = []; //请求的
|
||||
List? blelist = []; //蓝牙扫描到的设备数据列表
|
||||
List? wifiList = [];
|
||||
|
||||
@@ -46,21 +58,122 @@ class BlueteethBindController extends GetControllerEx<BlueteethBindModel> {
|
||||
attr = GetModel(BlueteethBindModel()).obs;
|
||||
}
|
||||
|
||||
void updateDeviceStatus() {
|
||||
// try {
|
||||
Timer? _statusTimer;
|
||||
|
||||
// } catch (e) {
|
||||
// print(e);
|
||||
// EasyDartModule.logger.info("向后端请求设备绑定状态报错了:$e");
|
||||
// } finally {
|
||||
// EasyDartModule.logger.info("向后端请求设备绑定状态");
|
||||
// }
|
||||
BLEDevice? currentDevice;
|
||||
|
||||
// 启动每10秒获取设备状态
|
||||
void startStatusPolling() {
|
||||
if (_statusTimer == null) {
|
||||
_statusTimer = Timer.periodic(Duration(seconds: 10), (timer) {
|
||||
updateDeviceStatus();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future bindDevice(d) async {
|
||||
print("绑定参数:$d");
|
||||
await Future.delayed(Duration(seconds: 1));
|
||||
// return ApiService.request
|
||||
// .post("/api/device/info/bind", data: formdata.FormData.fromMap(d));
|
||||
// 停止轮询
|
||||
void stopStatusPolling() {
|
||||
_statusTimer?.cancel();
|
||||
_statusTimer = null;
|
||||
}
|
||||
|
||||
// 你的已有方法
|
||||
Future<void> updateDeviceStatus() async {
|
||||
try {
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.get_bluetooth_device_status;
|
||||
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
|
||||
|
||||
if (model.devicelist != null && model.devicelist!.isNotEmpty) {
|
||||
final macParams = model.devicelist!
|
||||
.map((device) => "mac=${Uri.encodeQueryComponent(device.mac!)}")
|
||||
.join("&");
|
||||
|
||||
if (queryUrl.contains('?')) {
|
||||
queryUrl += '&$macParams';
|
||||
} else {
|
||||
queryUrl += '?$macParams';
|
||||
}
|
||||
|
||||
var response = await EasyDartModule.dio.get(queryUrl);
|
||||
|
||||
if (response.data['data'] != null && response.data['data'] is List) {
|
||||
List<dynamic> responseList = response.data['data'];
|
||||
|
||||
Map<String, BleDeviceData> deviceMap = {
|
||||
for (var d in model.devicelist!)
|
||||
if (d.mac != null) d.mac!: d
|
||||
};
|
||||
|
||||
List<String> slaveMacsToRemove = [];
|
||||
|
||||
for (var item in responseList) {
|
||||
String mac = item['mac'];
|
||||
String? bindMac = item['bindMac'];
|
||||
bool? bind = item['bind'];
|
||||
|
||||
if (deviceMap.containsKey(mac)) {
|
||||
BleDeviceData currentDevice = deviceMap[mac]!;
|
||||
currentDevice.bind = bind;
|
||||
if (bindMac != null && deviceMap.containsKey(bindMac)) {
|
||||
BleDeviceData masterDevice = deviceMap[bindMac]!;
|
||||
masterDevice.slave = currentDevice;
|
||||
slaveMacsToRemove.add(mac);
|
||||
}
|
||||
}
|
||||
}
|
||||
model.devicelist!
|
||||
.removeWhere((device) => slaveMacsToRemove.contains(device.mac));
|
||||
}
|
||||
print("获取设备状态成功");
|
||||
updateAll();
|
||||
}
|
||||
} catch (e) {
|
||||
print("获取设备状态异常: $e");
|
||||
EasyDartModule.logger.info("获取设备状态异常: $e");
|
||||
DailyLogUtils.writeLog("获取设备状态异常: $e");
|
||||
}
|
||||
}
|
||||
|
||||
Future<ApiResponse> bindDeviceAndMAC(BleDeviceData d) async {
|
||||
try {
|
||||
ApiResponse apiResponse = ApiResponse(code: -1, msg: "蓝牙绑定.绑定失败".tr);
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.device_bind;
|
||||
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
|
||||
var data = {
|
||||
"deviceType": 1,
|
||||
"mac": d.mac,
|
||||
};
|
||||
var response =
|
||||
await EasyDartModule.dio.post(queryUrl, data: jsonEncode(data));
|
||||
if (response != null) {
|
||||
var responseData =
|
||||
response.data is String ? jsonDecode(response.data) : response.data;
|
||||
ApiResponse res =
|
||||
ApiResponse.fromJson(responseData, (object) => object);
|
||||
MyUtils.formatResponse(apiResponse, "蓝牙绑定.绑定成功".tr, "蓝牙绑定.绑定成功".tr);
|
||||
if (res.code == HttpStatusCodes.ok) {
|
||||
return res;
|
||||
}
|
||||
} else {
|
||||
return ApiResponse(code: -1, msg: "服务器.失败".tr);
|
||||
}
|
||||
return apiResponse;
|
||||
} catch (e) {
|
||||
EasyDartModule.logger.info("蓝牙绑定.绑定异常: $e");
|
||||
DailyLogUtils.writeLog("蓝牙绑定.绑定异常: $e");
|
||||
}
|
||||
return ApiResponse(code: -1, msg: "未知错误".tr); // Default return statement
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
stopStatusPolling(); // 控制器销毁时停止轮询
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
bindDevice(Map<String, dynamic> map) {}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutterflow_ui/flutterflow_ui.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/color/app_uri_status.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/controller/user_info_controller.dart';
|
||||
import 'package:vbvs_app/model/api_response.dart';
|
||||
part 'login_controller.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
@@ -13,7 +21,7 @@ class LoginModel {
|
||||
String? account = '17649984946'; //账户
|
||||
String? password = 'wyf123,.'; //密码
|
||||
|
||||
String? phone; //手机号
|
||||
String? phone; //手机号/邮箱
|
||||
String? code; //验证码
|
||||
|
||||
String? register_code;
|
||||
@@ -47,88 +55,87 @@ class LoginController extends GetControllerEx<LoginModel> {
|
||||
}
|
||||
|
||||
//登录
|
||||
Future<String> 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<ApiResponse> login(BuildContext context) async {
|
||||
ApiResponse apiResponse = ApiResponse(code: -1, msg: "其他手机登录页.登录失败".tr);
|
||||
if (model.phone == null || model.phone!.isEmpty) {
|
||||
apiResponse.msg = "其他手机登录页.请输入手机号".tr;
|
||||
return apiResponse;
|
||||
}
|
||||
if (model.code == null || model.code!.isEmpty) {
|
||||
apiResponse.msg = "其他手机登录页.请输入验证码".tr;
|
||||
return apiResponse;
|
||||
}
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.login;
|
||||
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
|
||||
var data = {
|
||||
"type": 1,
|
||||
"userName": model.phone,
|
||||
"password": model.code,
|
||||
};
|
||||
var response =
|
||||
await EasyDartModule.dio.post(queryUrl, data: jsonEncode(data));
|
||||
if (response != null) {
|
||||
var responseData =
|
||||
response.data is String ? jsonDecode(response.data) : response.data;
|
||||
ApiResponse res = ApiResponse.fromJson(responseData, (object) => object);
|
||||
MyUtils.formatResponse(apiResponse, "其他手机登录页.登陆成功".tr, "其他手机登录页.登陆失败".tr);
|
||||
if (res.code == HttpStatusCodes.ok) {
|
||||
UserInfoController userInfoController = Get.find();
|
||||
userInfoController.model.login = 1;
|
||||
String token = response.headers['token']!.first;
|
||||
EasyDartModule.dio.token = token;
|
||||
final box = GetStorage();
|
||||
box.write('token', userInfoController.model.token); // 存储 token
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
return ApiResponse(code: -1, msg: "服务器.失败".tr);
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> getCode(BuildContext context) async {
|
||||
String message = "";
|
||||
Future<ApiResponse> getCode(BuildContext context) async {
|
||||
ApiResponse apiResponse = ApiResponse(code: -1, msg: "其他手机登录页.发送失败".tr);
|
||||
if (model.register_agree == null || model.register_agree != true) {
|
||||
// message = "需要同意协议";
|
||||
// showToast(message);
|
||||
return message;
|
||||
apiResponse.msg = "登录页.未同意协议".tr;
|
||||
return apiResponse;
|
||||
}
|
||||
if (model.phone == null || model.phone!.isEmpty) {
|
||||
message = "请输入手机号";
|
||||
// showToast(message);
|
||||
return message;
|
||||
apiResponse.msg = "其他手机登录页.请输入手机号".tr;
|
||||
return apiResponse;
|
||||
}
|
||||
if (!MyUtils.isValidPhoneNumber(model.phone!)) {
|
||||
message = '请输入正确的手机号';
|
||||
showToast(message);
|
||||
return message;
|
||||
if (!MyUtils.isValidPhoneNumber(model.phone!) &&
|
||||
!MyUtils.isValidEmail(model.phone!)) {
|
||||
apiResponse.msg = '其他手机登录页.不正确手机号'.tr;
|
||||
return apiResponse;
|
||||
}
|
||||
// message = await repository.sendRegisterCode(model.phone!);
|
||||
if (message.isNotEmpty) {
|
||||
showToast(message ?? "发送失败,请稍后再试!");
|
||||
return "发送失败,请稍后再试!";
|
||||
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,
|
||||
};
|
||||
var response =
|
||||
await EasyDartModule.dio.post(queryUrl, data: jsonEncode(data));
|
||||
if (response != null) {
|
||||
var responseData =
|
||||
response.data is String ? jsonDecode(response.data) : response.data;
|
||||
ApiResponse res = ApiResponse.fromJson(responseData, (object) => object);
|
||||
if (res.code != HttpStatusCodes.ok) {
|
||||
if (res.msg == null || res.msg!.isEmpty) {
|
||||
res.msg = apiResponse.msg;
|
||||
}
|
||||
} else {
|
||||
if (res.msg == null || res.msg!.isEmpty) {
|
||||
res.msg = "其他手机登录页.发送成功".tr;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
showToast("发送验证码成功!", color: color_success);
|
||||
return ApiResponse(code: -1, msg: "服务器.失败".tr);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
//微信登录
|
||||
|
||||
@@ -7,7 +7,8 @@ part 'person_controller.g.dart'; // 由json_serializable自动生成的部分
|
||||
class PersonModel {
|
||||
int read = 1;
|
||||
|
||||
DateTime? birthday;//是否不再提示教程 0 不再提示 1 需要提示
|
||||
DateTime? birthday;
|
||||
double? weight;
|
||||
|
||||
PersonModel();
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class UserInfoModel {
|
||||
User? superbase_user;
|
||||
|
||||
String? img_bucket = 'user';
|
||||
int? login = 1; //0未登录 1 登录
|
||||
int? login = 0; //0未登录 1 登录
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user