忘记密码

This commit is contained in:
2025-11-18 17:08:46 +08:00
parent 959fe89bed
commit 6a78d186d0
2 changed files with 84 additions and 82 deletions

View File

@@ -19,41 +19,40 @@ class StorageService extends GetxService {
static const String _nameKey = 'user_name';
static const String _phoneKey = 'user_phone';
static const String _idCardKey = 'user_id_card';
// 车辆信息的键名
static const String _vehicleInfoKey = 'vehicle_info';
// 加氢站登录凭证的键名
static const String _stationAccountKey = 'station_account';
static const String _stationPasswordKey = 'station_password';
// 提供一个静态的 'to' 方法,方便全局访问
static StorageService get to => Get.find();
// Service 初始化
Future<StorageService> init() async {
_box = GetStorage();
return this;
}
/// --- Getter 方法,用于读取状态 ---
// --- Getters ---
bool get isLoggedIn => _box.read<String?>(_tokenKey)?.isNotEmpty ?? false;
String? get token => _box.read<String?>(_tokenKey);
String? get userId => _box.read<String?>(_userIdKey);
String? get name => _box.read<String?>(_nameKey);
String? get phone => _box.read<String?>(_phoneKey);
String? get idCard => _box.read<String?>(_idCardKey);
/// 判断是否已有车辆信息缓存
bool get hasVehicleInfo => _box.hasData(_vehicleInfoKey);
/// 获取已缓存的车辆信息
// 记住密码:获取加氢站账号和密码
String? get stationAccount => _box.read<String?>(_stationAccountKey);
String? get stationPassword => _box.read<String?>(_stationPasswordKey);
VehicleInfo? get vehicleInfo {
final vehicleJson = _box.read<String?>(_vehicleInfoKey);
if (vehicleJson != null) {
// 使用我们之前创建的辅助函数来解析
return vehicleInfoFromJson(vehicleJson);
}
return null;
}
///获取当前登录渠道
LoginChannel get loginChannel {
final channelString = _box.read<String?>(_channelKey);
if (channelString == 'station') {
@@ -64,7 +63,7 @@ class StorageService extends GetxService {
return LoginChannel.none;
}
/// --- 操作方法 ---
// --- Methods ---
Future<void> saveLoginInfo({
required String token,
required String userId,
@@ -81,18 +80,26 @@ class StorageService extends GetxService {
await _box.write(_idCardKey, idCard);
}
/// 保存车辆信息
Future<void> saveVehicleInfo(VehicleInfo data) async {
// 使用辅助函数将对象转换为 JSON 字符串并保存
await _box.write(_vehicleInfoKey, vehicleInfoToJson(data));
}
/// 清除车辆信息
// 保存加氢站登录凭证
Future<void> saveStationCredentials(String account, String password) async {
await _box.write(_stationAccountKey, account);
await _box.write(_stationPasswordKey, password);
}
Future<void> clearVehicleInfo() async {
await _box.remove(_vehicleInfoKey);
}
/// 删除用户信息 (登出)
// 清除加氢站登录凭证
Future<void> clearStationCredentials() async {
await _box.remove(_stationAccountKey);
await _box.remove(_stationPasswordKey);
}
Future<void> clearLoginInfo() async {
await _box.remove(_tokenKey);
await _box.remove(_userIdKey);
@@ -100,7 +107,7 @@ class StorageService extends GetxService {
await _box.remove(_nameKey);
await _box.remove(_phoneKey);
await _box.remove(_idCardKey);
// 登出时一并清除车辆信息
await clearVehicleInfo();
// 注意:登出时我们不清除“记住的密码”,以便下次用户登录时仍然可以回填
}
}