mod: 首次登录时自动加载黑名单
This commit is contained in:
@ -1,7 +1,9 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.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/black.dart';
|
||||||
import 'package:pilipala/models/common/tab_type.dart';
|
import 'package:pilipala/models/common/tab_type.dart';
|
||||||
|
import 'package:pilipala/models/user/black.dart';
|
||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
|
||||||
class HomeController extends GetxController with GetTickerProviderStateMixin {
|
class HomeController extends GetxController with GetTickerProviderStateMixin {
|
||||||
@ -15,6 +17,13 @@ class HomeController extends GetxController with GetTickerProviderStateMixin {
|
|||||||
RxBool userLogin = false.obs;
|
RxBool userLogin = false.obs;
|
||||||
RxString userFace = ''.obs;
|
RxString userFace = ''.obs;
|
||||||
var userInfo;
|
var userInfo;
|
||||||
|
static Box setting = GStrorage.setting;
|
||||||
|
late List<int> blackMidsList;
|
||||||
|
|
||||||
|
int currentPage = 1;
|
||||||
|
int pageSize = 50;
|
||||||
|
int total = 0;
|
||||||
|
List<BlackListItem> blackList = [BlackListItem()];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@ -51,7 +60,33 @@ class HomeController extends GetxController with GetTickerProviderStateMixin {
|
|||||||
void updateLoginStatus(val) async {
|
void updateLoginStatus(val) async {
|
||||||
userInfo = await userInfoCache.get('userInfoCache');
|
userInfo = await userInfoCache.get('userInfoCache');
|
||||||
userLogin.value = val ?? false;
|
userLogin.value = val ?? false;
|
||||||
if (val) return;
|
if (val) {
|
||||||
|
// 获取黑名单
|
||||||
|
await queryBlacklist();
|
||||||
|
blackMidsList = blackList.map<int>((e) => e.mid!).toList();
|
||||||
|
setting.put(SettingBoxKey.blackMidsList, blackMidsList);
|
||||||
|
return;
|
||||||
|
}
|
||||||
userFace.value = userInfo != null ? userInfo.face : '';
|
userFace.value = userInfo != null ? userInfo.face : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future queryBlacklist({type = 'init'}) async {
|
||||||
|
if (type == 'init') {
|
||||||
|
currentPage = 1;
|
||||||
|
}
|
||||||
|
var result = await BlackHttp.blackList(pn: currentPage, ps: pageSize);
|
||||||
|
if (result['status']) {
|
||||||
|
if (type == 'init') {
|
||||||
|
blackList = result['data'].list;
|
||||||
|
total = result['data'].total;
|
||||||
|
} else {
|
||||||
|
blackList.addAll(result['data'].list);
|
||||||
|
}
|
||||||
|
currentPage += 1;
|
||||||
|
if (blackList.length < total) {
|
||||||
|
await queryBlacklist(type: 'onLoad');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user