查询数据
This commit is contained in:
@@ -14,8 +14,11 @@ class StorageService extends GetxService {
|
||||
// --- 定义存储时使用的键名 (Key) ---
|
||||
static const String _tokenKey = 'user_token';
|
||||
static const String _userIdKey = 'user_id';
|
||||
// 定义登录渠道的存储键名
|
||||
static const String _channelKey = 'login_channel';
|
||||
// 为新字段增加键名
|
||||
static const String _nameKey = 'user_name';
|
||||
static const String _phoneKey = 'user_phone';
|
||||
static const String _idCardKey = 'user_id_card';
|
||||
|
||||
// 提供一个静态的 'to' 方法,方便全局访问
|
||||
static StorageService get to => Get.find();
|
||||
@@ -40,6 +43,16 @@ class StorageService extends GetxService {
|
||||
/// 获取 UserId
|
||||
String? get userId => _box.read<String?>(_userIdKey);
|
||||
|
||||
/// 获取 Name
|
||||
String? get name => _box.read<String?>(_nameKey);
|
||||
|
||||
/// 获取 Phone
|
||||
String? get phone => _box.read<String?>(_phoneKey);
|
||||
|
||||
/// 获取 ID Card
|
||||
String? get idCard => _box.read<String?>(_idCardKey);
|
||||
|
||||
|
||||
///获取当前登录渠道
|
||||
/// 从存储中读取字符串,并转换为枚举类型
|
||||
LoginChannel get loginChannel {
|
||||
@@ -59,18 +72,27 @@ class StorageService extends GetxService {
|
||||
required String token,
|
||||
required String userId,
|
||||
required String channel, // 接收一个字符串类型的渠道
|
||||
String? name,
|
||||
String? phone,
|
||||
String? idCard,
|
||||
}) async {
|
||||
await _box.write(_tokenKey, token);
|
||||
await _box.write(_userIdKey, userId);
|
||||
// 将渠道字符串存入本地
|
||||
await _box.write(_channelKey, channel);
|
||||
// 保存新增的字段,如果为 null, GetStorage 会移除该键
|
||||
await _box.write(_nameKey, name);
|
||||
await _box.write(_phoneKey, phone);
|
||||
await _box.write(_idCardKey, idCard);
|
||||
}
|
||||
|
||||
///删除用户信息,增加删除渠道信息
|
||||
Future<void> clearLoginInfo() async {
|
||||
await _box.remove(_tokenKey);
|
||||
await _box.remove(_userIdKey);
|
||||
// 退出登录时,一并清除渠道信息
|
||||
await _box.remove(_channelKey);
|
||||
// 退出时一并清除新增的字段
|
||||
await _box.remove(_nameKey);
|
||||
await _box.remove(_phoneKey);
|
||||
await _box.remove(_idCardKey);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user