优化登录时个人信息本地持久化功能
This commit is contained in:
parent
6bdc2aae12
commit
dcabcfc392
@ -5,6 +5,7 @@ import 'package:star_lock/tools/baseGetXController.dart';
|
||||
|
||||
import '../../mine/mine/starLockMine_logic.dart';
|
||||
import '../../network/api_repository.dart';
|
||||
import '../../tools/storage.dart';
|
||||
import 'starLock_login_state.dart';
|
||||
|
||||
class StarLockLoginLogic extends BaseGetXController {
|
||||
@ -15,8 +16,7 @@ class StarLockLoginLogic extends BaseGetXController {
|
||||
var entity = await ApiRepository.to
|
||||
.login("1", state.pwd.value, "+86", state.emailOrPhone.value);
|
||||
if (entity.errorCode!.codeIsSuccessful) {
|
||||
// await StoreService.to.saveLogInInfo(entity);
|
||||
stateMyLogic.saveLoginData(entity.data);
|
||||
Storage.saveLoginData(entity.data);
|
||||
// Get.back();
|
||||
// Get.toNamed(Routers.starLockMain);
|
||||
Get.offNamedUntil(Routers.starLockMain, (route) => false);
|
||||
|
||||
@ -148,7 +148,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver, BaseWidget {
|
||||
|
||||
//暂不使用DeviceID推送
|
||||
_aliyunPush.getDeviceId().then((deviceId) async {
|
||||
final data = await Storage.getString('userLoginData');
|
||||
final data = await Storage.getString(saveUserLoginData);
|
||||
if (data!.isNotEmpty) {
|
||||
XSAliyunPushProvider()
|
||||
.pushBindDeviceID(deviceId, Platform.isAndroid ? 10 : 20);
|
||||
|
||||
@ -44,7 +44,7 @@ class _BasicInformationPageState extends State<BasicInformationPage> {
|
||||
CommonItem(
|
||||
leftTitel:
|
||||
TranslationLoader.lanKeys!.lockNumber!.tr,
|
||||
rightTitle: state.lockBasicInfo.value.lockAlias,
|
||||
rightTitle: state.lockBasicInfo.value.lockName,
|
||||
allHeight: 70.h,
|
||||
isHaveLine: true),
|
||||
CommonItem(
|
||||
|
||||
@ -24,7 +24,6 @@ import 'configuringWifi_state.dart';
|
||||
|
||||
class ConfiguringWifiLogic extends BaseGetXController{
|
||||
final ConfiguringWifiState state = ConfiguringWifiState();
|
||||
final StarLockMineState getInfostate = StarLockMineState();
|
||||
|
||||
Future<void> getWifiLockServiceIpAndPort() async {
|
||||
var entity = await ApiRepository.to.getWifiLockServiceIpAndPort();
|
||||
@ -104,7 +103,7 @@ class ConfiguringWifiLogic extends BaseGetXController{
|
||||
serversList.add(type2);
|
||||
}
|
||||
|
||||
var phoneList = [getInfostate.mobile()];
|
||||
var uidList = [Storage.getUid().toString()];
|
||||
IoSenderManage.senderConfiguringWifiCommand(
|
||||
keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
|
||||
userID: await Storage.getUid(),
|
||||
@ -112,8 +111,8 @@ class ConfiguringWifiLogic extends BaseGetXController{
|
||||
password: state.wifiPWDController.text,
|
||||
numberOfServers: state.configuringWifiEntity.value.data!.serviceNum,
|
||||
listOfServers: serversList,
|
||||
numberOfPhone: phoneList.length,
|
||||
listOfPhone: phoneList,
|
||||
numberOfPhone: uidList.length,
|
||||
listOfPhone: uidList,
|
||||
token: tokenData,
|
||||
needAuthor: 1,
|
||||
publicKey: publicKeyDataList,
|
||||
@ -192,14 +191,7 @@ class ConfiguringWifiLogic extends BaseGetXController{
|
||||
serversList.add(type2);
|
||||
}
|
||||
|
||||
String? phone = '';
|
||||
final data = await Storage.getString('userLoginData');
|
||||
if (data != null && data.isNotEmpty) {
|
||||
phone = LoginData.fromJson(jsonDecode(data)).mobile;
|
||||
}
|
||||
var phoneList = [phone!];
|
||||
print("phoneList:$phoneList");
|
||||
|
||||
var uidList = [Storage.getUid().toString()];
|
||||
IoSenderManage.senderConfiguringWifiCommand(
|
||||
keyID: state.lockSetInfoData.value.lockBasicInfo!.keyId.toString(),
|
||||
userID: await Storage.getUid(),
|
||||
@ -207,8 +199,8 @@ class ConfiguringWifiLogic extends BaseGetXController{
|
||||
password: state.wifiPWDController.text,
|
||||
numberOfServers: state.configuringWifiEntity.value.data!.serviceNum,
|
||||
listOfServers: serversList,
|
||||
numberOfPhone: phoneList.length,
|
||||
listOfPhone: phoneList,
|
||||
numberOfPhone: uidList.length,
|
||||
listOfPhone: uidList,
|
||||
token: getTokenList,
|
||||
needAuthor: 1,
|
||||
publicKey: publicKeyDataList,
|
||||
@ -266,6 +258,7 @@ class ConfiguringWifiLogic extends BaseGetXController{
|
||||
void onInit() {
|
||||
// TODO: implement onInit
|
||||
super.onInit();
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -115,6 +115,7 @@ class _ConfiguringWifiPageState extends State<ConfiguringWifiPage> with RouteAwa
|
||||
super.didPush();
|
||||
print("lockSet===didPush");
|
||||
state.ifCurrentScreen.value = true;
|
||||
|
||||
}
|
||||
|
||||
/// 返回上一个界面 当前界面即将消失
|
||||
|
||||
@ -307,6 +307,7 @@ class LockBasicInfo {
|
||||
int? indate;
|
||||
int? isLockOwner;
|
||||
String? lockAlias;
|
||||
String? lockName;
|
||||
int? groupId;
|
||||
List<GroupData>? groupData;
|
||||
String? adminPwd;
|
||||
@ -325,6 +326,7 @@ class LockBasicInfo {
|
||||
this.indate,
|
||||
this.isLockOwner,
|
||||
this.lockAlias,
|
||||
this.lockName,
|
||||
this.groupId,
|
||||
this.groupData,
|
||||
this.adminPwd,
|
||||
@ -343,6 +345,7 @@ class LockBasicInfo {
|
||||
indate = json['indate'];
|
||||
isLockOwner = json['isLockOwner'];
|
||||
lockAlias = json['lockAlias'];
|
||||
lockName = json['lockName'];
|
||||
groupId = json['groupId'];
|
||||
if (json['groupData'] != null) {
|
||||
groupData = <GroupData>[];
|
||||
@ -368,6 +371,7 @@ class LockBasicInfo {
|
||||
data['indate'] = indate;
|
||||
data['isLockOwner'] = isLockOwner;
|
||||
data['lockAlias'] = lockAlias;
|
||||
data['lockName'] = lockName;
|
||||
data['groupId'] = groupId;
|
||||
if (groupData != null) {
|
||||
data['groupData'] = groupData!.map((v) => v.toJson()).toList();
|
||||
|
||||
@ -61,7 +61,7 @@ class LockMonitoringLogic extends BaseGetXController {
|
||||
subCommand: 30,
|
||||
lockID: UDPManage().lockId,
|
||||
lockIP: UDPManage().host,
|
||||
userMobile: await state.userMobile,
|
||||
userMobile: await state.userUid,
|
||||
userMobileIP: await state.userMobileIP,
|
||||
endData: []);
|
||||
|
||||
@ -82,7 +82,7 @@ class LockMonitoringLogic extends BaseGetXController {
|
||||
subCommand: 6,
|
||||
lockID: UDPManage().lockId,
|
||||
lockIP: UDPManage().host,
|
||||
userMobile: await state.userMobile,
|
||||
userMobile: await state.userUid,
|
||||
userMobileIP: await state.userMobileIP,
|
||||
endData: []);
|
||||
}
|
||||
@ -95,7 +95,7 @@ class LockMonitoringLogic extends BaseGetXController {
|
||||
subCommand: 30,
|
||||
lockID: UDPManage().lockId,
|
||||
lockIP: UDPManage().host,
|
||||
userMobile: await state.userMobile,
|
||||
userMobile: await state.userUid,
|
||||
userMobileIP: await state.userMobileIP,
|
||||
endData: []);
|
||||
}
|
||||
@ -108,7 +108,7 @@ class LockMonitoringLogic extends BaseGetXController {
|
||||
subCommand: 10,
|
||||
lockID: UDPManage().lockId,
|
||||
lockIP: UDPManage().host,
|
||||
userMobile: await state.userMobile,
|
||||
userMobile: await state.userUid,
|
||||
userMobileIP: await state.userMobileIP,
|
||||
endData: list);
|
||||
Get.back();
|
||||
@ -139,7 +139,7 @@ class LockMonitoringLogic extends BaseGetXController {
|
||||
// "udpSendDataFrameNumber": 0,
|
||||
"lockID": UDPManage().lockId,
|
||||
"lockIP": UDPManage().host,
|
||||
"userMobile": await state.userMobile,
|
||||
"userMobile": await state.userUid,
|
||||
"userMobileIP": await state.userMobileIP,
|
||||
});
|
||||
print(sublist);
|
||||
@ -162,7 +162,7 @@ class LockMonitoringLogic extends BaseGetXController {
|
||||
// "udpSendDataFrameNumber": 0,
|
||||
"lockID": UDPManage().lockId,
|
||||
"lockIP": UDPManage().host,
|
||||
"userMobile": await state.userMobile,
|
||||
"userMobile": await state.userUid,
|
||||
"userMobileIP": await state.userMobileIP,
|
||||
});
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ class LockMonitoringState {
|
||||
// var isSenderAudioData = false.obs;// 是否要发送音频数据
|
||||
|
||||
var userMobileIP = NetworkInfo().getWifiIP();
|
||||
var userMobile = Storage.getMobile();
|
||||
var userUid = Storage.getUid();
|
||||
|
||||
var udpStatus = 0.obs; //0:初始状态 1:等待监视 2: 3:监视中 4:呼叫成功 5:主角通话中 6:被叫通话 8:被叫通话中 9:长按说话
|
||||
var passwordTF = TextEditingController();
|
||||
|
||||
@ -54,7 +54,7 @@ class RealTimePictureLogic extends BaseGetXController {
|
||||
subCommand: 1,
|
||||
lockID: state.getLockName.value,
|
||||
lockIP: UDPManage().host,
|
||||
userMobile: await state.userMobile,
|
||||
userMobile: await state.userUid,
|
||||
userMobileIP: await state.userMobileIP,
|
||||
endData: []);
|
||||
// print('得到lockName------${state.getLockName.value}');
|
||||
@ -68,7 +68,7 @@ class RealTimePictureLogic extends BaseGetXController {
|
||||
subCommand: 30,
|
||||
lockID: UDPManage().lockId,
|
||||
lockIP: UDPManage().host,
|
||||
userMobile: await state.userMobile,
|
||||
userMobile: await state.userUid,
|
||||
userMobileIP: await state.userMobileIP,
|
||||
endData: []);
|
||||
}
|
||||
@ -81,7 +81,7 @@ class RealTimePictureLogic extends BaseGetXController {
|
||||
subCommand: 10,
|
||||
lockID: UDPManage().lockId,
|
||||
lockIP: UDPManage().host,
|
||||
userMobile: await state.userMobile,
|
||||
userMobile: await state.userUid,
|
||||
userMobileIP: await state.userMobileIP,
|
||||
endData: list);
|
||||
Get.back();
|
||||
@ -112,7 +112,7 @@ class RealTimePictureLogic extends BaseGetXController {
|
||||
// "udpSendDataFrameNumber": 0,
|
||||
"lockID": UDPManage().lockId,
|
||||
"lockIP": UDPManage().host,
|
||||
"userMobile": await state.userMobile,
|
||||
"userMobile": await state.userUid,
|
||||
"userMobileIP": await state.userMobileIP,
|
||||
});
|
||||
print(sublist);
|
||||
@ -137,7 +137,7 @@ class RealTimePictureLogic extends BaseGetXController {
|
||||
// "udpSendDataFrameNumber": 0,
|
||||
"lockID": UDPManage().lockId,
|
||||
"lockIP": UDPManage().host,
|
||||
"userMobile": await state.userMobile,
|
||||
"userMobile": await state.userUid,
|
||||
"userMobileIP": await state.userMobileIP,
|
||||
});
|
||||
}
|
||||
|
||||
@ -14,7 +14,7 @@ class RealTimePictureState {
|
||||
// var isSenderAudioData = false.obs;// 是否要发送音频数据
|
||||
|
||||
var userMobileIP = NetworkInfo().getWifiIP();
|
||||
var userMobile = Storage.getMobile();
|
||||
var userUid = Storage.getUid();
|
||||
|
||||
var udpStatus =
|
||||
0.obs; //0:初始状态 1:等待监视 2: 3:监视中 4:呼叫成功 5:主角通话中 6:被叫通话 8:被叫通话中 9:长按说话
|
||||
|
||||
@ -203,9 +203,6 @@ class SaveLockLogic extends BaseGetXController {
|
||||
BlueManage().disconnect(BlueManage().connectDeviceMacAddress);
|
||||
eventBus.fire(RefreshLockListInfoDataEvent());
|
||||
Get.close(state.isFromMap == 1 ? 5 : 6);
|
||||
// Future.delayed(const Duration(milliseconds: 200), () {
|
||||
// Get.offAllNamed(Routers.starLockMain);
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -35,13 +35,13 @@ class SafeVerifyState {
|
||||
///本地存储 登录信息
|
||||
void saveLoginData(LoginData? data) async {
|
||||
print("saveLoginData:${data!.mobile}");
|
||||
await Storage.setString('userLoginData', jsonEncode(data));
|
||||
await Storage.setString(saveUserLoginData, jsonEncode(data));
|
||||
loginData.value = data;
|
||||
}
|
||||
|
||||
///初始化本地数据
|
||||
void initLoginData() async {
|
||||
final data = await Storage.getString('userLoginData');
|
||||
final data = await Storage.getString(saveUserLoginData);
|
||||
// print("getLoginData:$data");
|
||||
if (data != null && data.isNotEmpty) {
|
||||
loginData.value = LoginData.fromJson(jsonDecode(data));
|
||||
|
||||
@ -2,6 +2,7 @@ import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
||||
import 'package:star_lock/network/api_repository.dart';
|
||||
|
||||
import '../../tools/baseGetXController.dart';
|
||||
import '../../tools/storage.dart';
|
||||
import 'starLockMine_state.dart';
|
||||
|
||||
class StarLockMineLogic extends BaseGetXController {
|
||||
@ -14,17 +15,19 @@ class StarLockMineLogic extends BaseGetXController {
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
Future<void> onReady() async {
|
||||
print("ready home");
|
||||
|
||||
super.onReady();
|
||||
|
||||
state.userNickName.value = (await Storage.getNickname())!;
|
||||
state.userMobile.value = (await Storage.getMobile())!;
|
||||
state.userEmail.value = (await Storage.getEmail())!;
|
||||
}
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
print("init home");
|
||||
super.onInit();
|
||||
state.initLoginData();
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -84,7 +84,7 @@ class _StarLockMinePageState extends State<StarLockMinePage> with BaseWidget {
|
||||
SizedBox(
|
||||
height: 20.h,
|
||||
),
|
||||
Text(state.nickname(),
|
||||
Text(state.userNickName.value ?? "-",
|
||||
style: TextStyle(
|
||||
fontSize: 22.sp,
|
||||
color: Colors.white,
|
||||
@ -92,7 +92,7 @@ class _StarLockMinePageState extends State<StarLockMinePage> with BaseWidget {
|
||||
SizedBox(
|
||||
height: 10.h,
|
||||
),
|
||||
Text("${TranslationLoader.lanKeys!.accountNumber!.tr}:${state.mobile().isNotEmpty ? state.mobile() : state.email()}",
|
||||
Text("${TranslationLoader.lanKeys!.accountNumber!.tr}:${state.userMobile.value.isNotEmpty ? state.userMobile.value : state.userEmail.value}",
|
||||
style: TextStyle(
|
||||
fontSize: 18.sp,
|
||||
color: Colors.white,
|
||||
|
||||
@ -7,52 +7,11 @@ import '../../login/login/entity/LoginEntity.dart';
|
||||
import '../../tools/storage.dart';
|
||||
|
||||
class StarLockMineState {
|
||||
final loginData = LoginData().obs;
|
||||
// final loginData = LoginData().obs;
|
||||
|
||||
///本地存储 登录信息
|
||||
void saveLoginData(LoginData? data) async {
|
||||
print("saveLoginData:${data!.mobile}");
|
||||
await Storage.setString('userLoginData', jsonEncode(data));
|
||||
loginData.value = data;
|
||||
}
|
||||
|
||||
///初始化本地数据
|
||||
void initLoginData() async {
|
||||
final data = await Storage.getString('userLoginData');
|
||||
// print("getLoginData:$data");
|
||||
if (data != null && data.isNotEmpty) {
|
||||
loginData.value = LoginData.fromJson(jsonDecode(data));
|
||||
}
|
||||
}
|
||||
|
||||
///退出登录
|
||||
void logOut() async {
|
||||
await Storage.setString('userLoginData', '');
|
||||
loginData.value = LoginData();
|
||||
}
|
||||
|
||||
///用户登录token
|
||||
String token() {
|
||||
return loginData.value.accessToken ?? '';
|
||||
}
|
||||
|
||||
String mobile() {
|
||||
return loginData.value.mobile ?? '';
|
||||
}
|
||||
|
||||
String email() {
|
||||
return loginData.value.email ?? '-';
|
||||
}
|
||||
|
||||
String nickname() {
|
||||
return loginData.value.nickname ?? '-';
|
||||
}
|
||||
|
||||
///用户头像
|
||||
String headUrl() {
|
||||
return loginData.value.headUrl ?? '';
|
||||
// return "https://img2.woyaogexing.com/2022/04/14/156cdbabd5bc496abee2cd0fca527434!400x400.jpeg";
|
||||
}
|
||||
var userNickName = "".obs;
|
||||
var userMobile = "".obs;
|
||||
var userEmail = "".obs;
|
||||
|
||||
void onClose() {}
|
||||
}
|
||||
|
||||
@ -37,13 +37,13 @@ class PersonInfoEditAccountState {
|
||||
///本地存储 登录信息
|
||||
void saveLoginData(LoginData? data) async {
|
||||
print("saveLoginData:${data!.mobile}");
|
||||
await Storage.setString('userLoginData', jsonEncode(data));
|
||||
await Storage.setString(saveUserLoginData, jsonEncode(data));
|
||||
loginData.value = data;
|
||||
}
|
||||
|
||||
///初始化本地数据
|
||||
void initLoginData() async {
|
||||
final data = await Storage.getString('userLoginData');
|
||||
final data = await Storage.getString(saveUserLoginData);
|
||||
// print("getLoginData:$data");
|
||||
if (data != null && data.isNotEmpty) {
|
||||
loginData.value = LoginData.fromJson(jsonDecode(data));
|
||||
|
||||
@ -63,7 +63,6 @@ class MineSetLogic extends BaseGetXController {
|
||||
///退出登录
|
||||
void logOut() async {
|
||||
Storage.clearAll();
|
||||
// await Storage.setString('userLoginData', '');
|
||||
}
|
||||
|
||||
//更新触摸开锁
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
abstract class Api {
|
||||
static String baseAddress = "https://pre.lock.star-lock.cn:8093"; //预发布环境
|
||||
// static String baseAddress = "http://192.168.56.101:8099"; //联调环境
|
||||
// static String baseAddress = "https://pre.lock.star-lock.cn:8093"; //预发布环境
|
||||
static String baseAddress = "http://192.168.56.101:8099"; //联调环境
|
||||
// static String baseAddress = "http://192.168.1.15:8022"; //谢总本地
|
||||
|
||||
final String baseUrl = "$baseAddress/api";
|
||||
|
||||
@ -18,7 +18,7 @@ FutureOr<Request> requestInterceptor(Request request) async {
|
||||
// request.headers['token'] = StoreService.to.userToken!;
|
||||
// print("11111${StoreService.to.userToken}");
|
||||
String? xToken = '';
|
||||
final data = await Storage.getString('userLoginData');
|
||||
final data = await Storage.getString(saveUserLoginData);
|
||||
if (data != null && data.isNotEmpty) {
|
||||
xToken = LoginData.fromJson(jsonDecode(data)).accessToken;
|
||||
}
|
||||
|
||||
@ -41,10 +41,10 @@ class UdpHelp {
|
||||
}
|
||||
}
|
||||
|
||||
var mobile = await Storage.getMobile();
|
||||
var uid = await Storage.getUid();
|
||||
udpHeartTimer = Timer.periodic(1.seconds, (timer) async {
|
||||
UDPSenderManage.sendHeart(
|
||||
userName: mobile,
|
||||
userName: uid,
|
||||
ipList: serversList,
|
||||
tokenStr: "b989fa15f75c2ac02718b7c9bb64f80e",
|
||||
);
|
||||
|
||||
@ -16,6 +16,8 @@ const currentConnectionLockId = "CurrentConnectionLockId";
|
||||
const currentConnectionMacAddress = "CurrentConnectionMacAddress";
|
||||
const ifIsDemoModeOrNot = "IfIsDemoModeOrNot";
|
||||
|
||||
const saveUserLoginData = "userLoginData";
|
||||
|
||||
class Storage {
|
||||
Storage._internal();
|
||||
|
||||
@ -136,28 +138,40 @@ class Storage {
|
||||
}
|
||||
|
||||
static Future<String?> getUid() async {
|
||||
String? uid = '';
|
||||
final data = await Storage.getString('userLoginData');
|
||||
if (data != null && data.isNotEmpty) {
|
||||
uid = LoginData.fromJson(jsonDecode(data)).uid.toString();
|
||||
}
|
||||
LoginData? loginData = await getLoginData();
|
||||
String? uid = loginData!.uid.toString();
|
||||
// print("pubUid:$uid");
|
||||
return uid;
|
||||
}
|
||||
|
||||
static Future<String?> getUserid() async {
|
||||
LoginData? loginData = await getLoginData();
|
||||
String? userid = loginData!.userid.toString();
|
||||
// print("pubUid:$uid");
|
||||
return userid;
|
||||
}
|
||||
|
||||
static Future<String?> getMobile() async {
|
||||
String? mobile = '';
|
||||
final data = await Storage.getString('userLoginData');
|
||||
if (data != null && data.isNotEmpty) {
|
||||
mobile = LoginData.fromJson(jsonDecode(data)).mobile.toString();
|
||||
}
|
||||
// print("mobile:$mobile");
|
||||
LoginData? loginData = await getLoginData();
|
||||
String? mobile = loginData!.mobile;
|
||||
return mobile;
|
||||
}
|
||||
|
||||
static Future<String?> getEmail() async {
|
||||
LoginData? loginData = await getLoginData();
|
||||
String? email = loginData!.email;
|
||||
return email;
|
||||
}
|
||||
|
||||
static Future<String?> getNickname() async {
|
||||
LoginData? loginData = await getLoginData();
|
||||
String? nickname = loginData!.nickname;
|
||||
return nickname;
|
||||
}
|
||||
|
||||
static Future<LoginData?> getLoginData() async {
|
||||
LoginData? loginData;
|
||||
final data = await Storage.getString('userLoginData');
|
||||
final data = await Storage.getString(saveUserLoginData);
|
||||
if (data != null && data.isNotEmpty) {
|
||||
loginData = LoginData.fromJson(jsonDecode(data));
|
||||
}
|
||||
@ -165,5 +179,8 @@ class Storage {
|
||||
return loginData;
|
||||
}
|
||||
|
||||
static Future<void> saveLoginData(LoginData? data) async {
|
||||
await Storage.setString(saveUserLoginData, jsonEncode(data));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user