feat: 登录信息缓存
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
class Api {
|
class Api {
|
||||||
// 推荐视频
|
// 推荐视频
|
||||||
static const String recommendList = '/x/web-interface/index/top/rcmd';
|
static const String recommendList = '/x/web-interface/index/top/feed/rcmd';
|
||||||
|
|
||||||
// 热门视频
|
// 热门视频
|
||||||
static const String hotList = '/x/web-interface/popular';
|
static const String hotList = '/x/web-interface/popular';
|
||||||
|
|||||||
@ -19,8 +19,7 @@ class VideoHttp {
|
|||||||
var res = await Request().get(
|
var res = await Request().get(
|
||||||
Api.recommendList,
|
Api.recommendList,
|
||||||
data: {
|
data: {
|
||||||
'user-agent': Request().headerUa('mob'),
|
'feed_version': 'V3',
|
||||||
'feed_version': 'V4',
|
|
||||||
'ps': ps,
|
'ps': ps,
|
||||||
'fresh_idx': freshIdx,
|
'fresh_idx': freshIdx,
|
||||||
},
|
},
|
||||||
@ -203,21 +202,20 @@ class VideoHttp {
|
|||||||
int? root,
|
int? root,
|
||||||
int? parent,
|
int? parent,
|
||||||
}) async {
|
}) async {
|
||||||
if(message == ''){
|
if (message == '') {
|
||||||
return {'status': false, 'data': [], 'msg': '请输入评论内容'};
|
return {'status': false, 'data': [], 'msg': '请输入评论内容'};
|
||||||
}
|
}
|
||||||
print('root:$root');
|
print('root:$root');
|
||||||
print('parent: $parent');
|
print('parent: $parent');
|
||||||
|
|
||||||
var res = await Request()
|
var res = await Request().post(Api.replyAdd, queryParameters: {
|
||||||
.post(Api.replyAdd, queryParameters: {
|
'type': type.index,
|
||||||
'type': type.index,
|
'oid': oid,
|
||||||
'oid': oid,
|
'root': root ?? '',
|
||||||
'root': root ?? '',
|
'parent': parent == null || parent == 0 ? '' : parent,
|
||||||
'parent': parent == null || parent == 0 ? '' : parent,
|
'message': message,
|
||||||
'message': message,
|
'csrf': await Request.getCsrf(),
|
||||||
'csrf': await Request.getCsrf(),
|
});
|
||||||
});
|
|
||||||
log(res.toString());
|
log(res.toString());
|
||||||
if (res.data['code'] == 0) {
|
if (res.data['code'] == 0) {
|
||||||
return {'status': true, 'data': res.data['data']};
|
return {'status': true, 'data': res.data['data']};
|
||||||
|
|||||||
@ -1,3 +1,8 @@
|
|||||||
|
import 'package:hive/hive.dart';
|
||||||
|
|
||||||
|
part 'info.g.dart';
|
||||||
|
|
||||||
|
@HiveType(typeId: 4)
|
||||||
class UserInfoData {
|
class UserInfoData {
|
||||||
UserInfoData({
|
UserInfoData({
|
||||||
this.isLogin,
|
this.isLogin,
|
||||||
@ -25,30 +30,53 @@ class UserInfoData {
|
|||||||
this.hasShop,
|
this.hasShop,
|
||||||
this.shopUrl,
|
this.shopUrl,
|
||||||
});
|
});
|
||||||
|
@HiveField(0)
|
||||||
bool? isLogin;
|
bool? isLogin;
|
||||||
|
@HiveField(1)
|
||||||
int? emailVerified;
|
int? emailVerified;
|
||||||
|
@HiveField(2)
|
||||||
String? face;
|
String? face;
|
||||||
|
@HiveField(3)
|
||||||
LevelInfo? levelInfo;
|
LevelInfo? levelInfo;
|
||||||
|
@HiveField(4)
|
||||||
int? mid;
|
int? mid;
|
||||||
|
@HiveField(5)
|
||||||
int? mobileVerified;
|
int? mobileVerified;
|
||||||
|
@HiveField(6)
|
||||||
int? money;
|
int? money;
|
||||||
|
@HiveField(7)
|
||||||
int? moral;
|
int? moral;
|
||||||
|
@HiveField(8)
|
||||||
Map? official;
|
Map? official;
|
||||||
|
@HiveField(9)
|
||||||
Map? officialVerify;
|
Map? officialVerify;
|
||||||
|
@HiveField(10)
|
||||||
Map? pendant;
|
Map? pendant;
|
||||||
|
@HiveField(11)
|
||||||
int? scores;
|
int? scores;
|
||||||
|
@HiveField(12)
|
||||||
String? uname;
|
String? uname;
|
||||||
|
@HiveField(13)
|
||||||
int? vipDueDate;
|
int? vipDueDate;
|
||||||
|
@HiveField(14)
|
||||||
int? vipStatus;
|
int? vipStatus;
|
||||||
|
@HiveField(15)
|
||||||
int? vipType;
|
int? vipType;
|
||||||
|
@HiveField(16)
|
||||||
int? vipPayType;
|
int? vipPayType;
|
||||||
|
@HiveField(17)
|
||||||
int? vipThemeType;
|
int? vipThemeType;
|
||||||
|
@HiveField(18)
|
||||||
Map? vipLabel;
|
Map? vipLabel;
|
||||||
|
@HiveField(19)
|
||||||
int? vipAvatarSub;
|
int? vipAvatarSub;
|
||||||
|
@HiveField(20)
|
||||||
String? vipNicknameColor;
|
String? vipNicknameColor;
|
||||||
|
@HiveField(21)
|
||||||
Map? wallet;
|
Map? wallet;
|
||||||
|
@HiveField(22)
|
||||||
bool? hasShop;
|
bool? hasShop;
|
||||||
|
@HiveField(23)
|
||||||
String? shopUrl;
|
String? shopUrl;
|
||||||
|
|
||||||
UserInfoData.fromJson(Map<String, dynamic> json) {
|
UserInfoData.fromJson(Map<String, dynamic> json) {
|
||||||
@ -81,6 +109,7 @@ class UserInfoData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@HiveType(typeId: 5)
|
||||||
class LevelInfo {
|
class LevelInfo {
|
||||||
LevelInfo({
|
LevelInfo({
|
||||||
this.currentLevel,
|
this.currentLevel,
|
||||||
@ -88,10 +117,13 @@ class LevelInfo {
|
|||||||
this.currentExp,
|
this.currentExp,
|
||||||
this.nextExp,
|
this.nextExp,
|
||||||
});
|
});
|
||||||
|
@HiveField(0)
|
||||||
int? currentLevel;
|
int? currentLevel;
|
||||||
|
@HiveField(1)
|
||||||
int? currentMin;
|
int? currentMin;
|
||||||
|
@HiveField(2)
|
||||||
int? currentExp;
|
int? currentExp;
|
||||||
|
@HiveField(3)
|
||||||
int? nextExp;
|
int? nextExp;
|
||||||
|
|
||||||
LevelInfo.fromJson(Map<String, dynamic> json) {
|
LevelInfo.fromJson(Map<String, dynamic> json) {
|
||||||
|
|||||||
153
lib/models/user/info.g.dart
Normal file
153
lib/models/user/info.g.dart
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||||
|
|
||||||
|
part of 'info.dart';
|
||||||
|
|
||||||
|
// **************************************************************************
|
||||||
|
// TypeAdapterGenerator
|
||||||
|
// **************************************************************************
|
||||||
|
|
||||||
|
class UserInfoDataAdapter extends TypeAdapter<UserInfoData> {
|
||||||
|
@override
|
||||||
|
final int typeId = 4;
|
||||||
|
|
||||||
|
@override
|
||||||
|
UserInfoData read(BinaryReader reader) {
|
||||||
|
final numOfFields = reader.readByte();
|
||||||
|
final fields = <int, dynamic>{
|
||||||
|
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||||
|
};
|
||||||
|
return UserInfoData(
|
||||||
|
isLogin: fields[0] as bool?,
|
||||||
|
emailVerified: fields[1] as int?,
|
||||||
|
face: fields[2] as String?,
|
||||||
|
levelInfo: fields[3] as LevelInfo?,
|
||||||
|
mid: fields[4] as int?,
|
||||||
|
mobileVerified: fields[5] as int?,
|
||||||
|
money: fields[6] as int?,
|
||||||
|
moral: fields[7] as int?,
|
||||||
|
official: (fields[8] as Map?)?.cast<dynamic, dynamic>(),
|
||||||
|
officialVerify: (fields[9] as Map?)?.cast<dynamic, dynamic>(),
|
||||||
|
pendant: (fields[10] as Map?)?.cast<dynamic, dynamic>(),
|
||||||
|
scores: fields[11] as int?,
|
||||||
|
uname: fields[12] as String?,
|
||||||
|
vipDueDate: fields[13] as int?,
|
||||||
|
vipStatus: fields[14] as int?,
|
||||||
|
vipType: fields[15] as int?,
|
||||||
|
vipPayType: fields[16] as int?,
|
||||||
|
vipThemeType: fields[17] as int?,
|
||||||
|
vipLabel: (fields[18] as Map?)?.cast<dynamic, dynamic>(),
|
||||||
|
vipAvatarSub: fields[19] as int?,
|
||||||
|
vipNicknameColor: fields[20] as String?,
|
||||||
|
wallet: (fields[21] as Map?)?.cast<dynamic, dynamic>(),
|
||||||
|
hasShop: fields[22] as bool?,
|
||||||
|
shopUrl: fields[23] as String?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void write(BinaryWriter writer, UserInfoData obj) {
|
||||||
|
writer
|
||||||
|
..writeByte(24)
|
||||||
|
..writeByte(0)
|
||||||
|
..write(obj.isLogin)
|
||||||
|
..writeByte(1)
|
||||||
|
..write(obj.emailVerified)
|
||||||
|
..writeByte(2)
|
||||||
|
..write(obj.face)
|
||||||
|
..writeByte(3)
|
||||||
|
..write(obj.levelInfo)
|
||||||
|
..writeByte(4)
|
||||||
|
..write(obj.mid)
|
||||||
|
..writeByte(5)
|
||||||
|
..write(obj.mobileVerified)
|
||||||
|
..writeByte(6)
|
||||||
|
..write(obj.money)
|
||||||
|
..writeByte(7)
|
||||||
|
..write(obj.moral)
|
||||||
|
..writeByte(8)
|
||||||
|
..write(obj.official)
|
||||||
|
..writeByte(9)
|
||||||
|
..write(obj.officialVerify)
|
||||||
|
..writeByte(10)
|
||||||
|
..write(obj.pendant)
|
||||||
|
..writeByte(11)
|
||||||
|
..write(obj.scores)
|
||||||
|
..writeByte(12)
|
||||||
|
..write(obj.uname)
|
||||||
|
..writeByte(13)
|
||||||
|
..write(obj.vipDueDate)
|
||||||
|
..writeByte(14)
|
||||||
|
..write(obj.vipStatus)
|
||||||
|
..writeByte(15)
|
||||||
|
..write(obj.vipType)
|
||||||
|
..writeByte(16)
|
||||||
|
..write(obj.vipPayType)
|
||||||
|
..writeByte(17)
|
||||||
|
..write(obj.vipThemeType)
|
||||||
|
..writeByte(18)
|
||||||
|
..write(obj.vipLabel)
|
||||||
|
..writeByte(19)
|
||||||
|
..write(obj.vipAvatarSub)
|
||||||
|
..writeByte(20)
|
||||||
|
..write(obj.vipNicknameColor)
|
||||||
|
..writeByte(21)
|
||||||
|
..write(obj.wallet)
|
||||||
|
..writeByte(22)
|
||||||
|
..write(obj.hasShop)
|
||||||
|
..writeByte(23)
|
||||||
|
..write(obj.shopUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => typeId.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) ||
|
||||||
|
other is UserInfoDataAdapter &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
typeId == other.typeId;
|
||||||
|
}
|
||||||
|
|
||||||
|
class LevelInfoAdapter extends TypeAdapter<LevelInfo> {
|
||||||
|
@override
|
||||||
|
final int typeId = 5;
|
||||||
|
|
||||||
|
@override
|
||||||
|
LevelInfo read(BinaryReader reader) {
|
||||||
|
final numOfFields = reader.readByte();
|
||||||
|
final fields = <int, dynamic>{
|
||||||
|
for (int i = 0; i < numOfFields; i++) reader.readByte(): reader.read(),
|
||||||
|
};
|
||||||
|
return LevelInfo(
|
||||||
|
currentLevel: fields[0] as int?,
|
||||||
|
currentMin: fields[1] as int?,
|
||||||
|
currentExp: fields[2] as int?,
|
||||||
|
nextExp: fields[3] as int?,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void write(BinaryWriter writer, LevelInfo obj) {
|
||||||
|
writer
|
||||||
|
..writeByte(4)
|
||||||
|
..writeByte(0)
|
||||||
|
..write(obj.currentLevel)
|
||||||
|
..writeByte(1)
|
||||||
|
..write(obj.currentMin)
|
||||||
|
..writeByte(2)
|
||||||
|
..write(obj.currentExp)
|
||||||
|
..writeByte(3)
|
||||||
|
..write(obj.nextExp);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => typeId.hashCode;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) =>
|
||||||
|
identical(this, other) ||
|
||||||
|
other is LevelInfoAdapter &&
|
||||||
|
runtimeType == other.runtimeType &&
|
||||||
|
typeId == other.typeId;
|
||||||
|
}
|
||||||
@ -1,10 +1,8 @@
|
|||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:hive/hive.dart';
|
import 'package:hive/hive.dart';
|
||||||
import 'package:pilipala/http/user.dart';
|
import 'package:pilipala/http/user.dart';
|
||||||
import 'package:pilipala/models/user/info.dart';
|
import 'package:pilipala/models/user/info.dart';
|
||||||
import 'package:pilipala/models/user/stat.dart';
|
import 'package:pilipala/models/user/stat.dart';
|
||||||
import 'package:pilipala/pages/main/controller.dart';
|
|
||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
|
||||||
class MineController extends GetxController {
|
class MineController extends GetxController {
|
||||||
@ -14,6 +12,17 @@ class MineController extends GetxController {
|
|||||||
Rx<UserStat> userStat = UserStat().obs;
|
Rx<UserStat> userStat = UserStat().obs;
|
||||||
Box user = GStrorage.user;
|
Box user = GStrorage.user;
|
||||||
RxBool userLogin = false.obs;
|
RxBool userLogin = false.obs;
|
||||||
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
|
|
||||||
|
@override
|
||||||
|
onInit() {
|
||||||
|
super.onInit();
|
||||||
|
|
||||||
|
if (userInfoCache.get('userInfoCache') != null) {
|
||||||
|
print(userInfoCache.get('userInfoCache'));
|
||||||
|
userInfo.value = userInfoCache.get('userInfoCache');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onLogin() {
|
onLogin() {
|
||||||
Get.toNamed(
|
Get.toNamed(
|
||||||
@ -34,6 +43,7 @@ class MineController extends GetxController {
|
|||||||
if (res['status']) {
|
if (res['status']) {
|
||||||
if (res['data'].isLogin) {
|
if (res['data'].isLogin) {
|
||||||
userInfo.value = res['data'];
|
userInfo.value = res['data'];
|
||||||
|
userInfoCache.put('userInfoCache', res['data']);
|
||||||
user.put(UserBoxKey.userName, res['data'].uname);
|
user.put(UserBoxKey.userName, res['data'].uname);
|
||||||
user.put(UserBoxKey.userFace, res['data'].face);
|
user.put(UserBoxKey.userFace, res['data'].face);
|
||||||
user.put(UserBoxKey.userMid, res['data'].mid);
|
user.put(UserBoxKey.userMid, res['data'].mid);
|
||||||
|
|||||||
@ -3,10 +3,12 @@ import 'package:hive_flutter/hive_flutter.dart';
|
|||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:pilipala/models/model_owner.dart';
|
import 'package:pilipala/models/model_owner.dart';
|
||||||
import 'package:pilipala/models/model_rec_video_item.dart';
|
import 'package:pilipala/models/model_rec_video_item.dart';
|
||||||
|
import 'package:pilipala/models/user/info.dart';
|
||||||
|
|
||||||
class GStrorage {
|
class GStrorage {
|
||||||
static late final Box user;
|
static late final Box user;
|
||||||
static late final Box recVideo;
|
static late final Box recVideo;
|
||||||
|
static late final Box userInfo;
|
||||||
|
|
||||||
static Future<void> init() async {
|
static Future<void> init() async {
|
||||||
final dir = await getApplicationDocumentsDirectory();
|
final dir = await getApplicationDocumentsDirectory();
|
||||||
@ -17,11 +19,15 @@ class GStrorage {
|
|||||||
Hive.registerAdapter(RcmdReasonAdapter());
|
Hive.registerAdapter(RcmdReasonAdapter());
|
||||||
Hive.registerAdapter(StatAdapter());
|
Hive.registerAdapter(StatAdapter());
|
||||||
Hive.registerAdapter(OwnerAdapter());
|
Hive.registerAdapter(OwnerAdapter());
|
||||||
|
Hive.registerAdapter(UserInfoDataAdapter());
|
||||||
|
Hive.registerAdapter(LevelInfoAdapter());
|
||||||
|
|
||||||
// 用户信息
|
// 用户信息
|
||||||
user = await Hive.openBox('user');
|
user = await Hive.openBox('user');
|
||||||
// 首页推荐视频
|
// 首页推荐视频
|
||||||
recVideo = await Hive.openBox('recVideo');
|
recVideo = await Hive.openBox('recVideo');
|
||||||
|
// 登录用户信息
|
||||||
|
userInfo = await Hive.openBox('userInfo');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user