mod: 本地缓存字段修改、登录状态
This commit is contained in:
@ -20,7 +20,7 @@ class Request {
|
|||||||
|
|
||||||
/// 设置cookie
|
/// 设置cookie
|
||||||
static setCookie() async {
|
static setCookie() async {
|
||||||
Box user = GStrorage.user;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
var cookiePath = await Utils.getCookiePath();
|
var cookiePath = await Utils.getCookiePath();
|
||||||
var cookieJar = PersistCookieJar(
|
var cookieJar = PersistCookieJar(
|
||||||
ignoreExpires: true,
|
ignoreExpires: true,
|
||||||
@ -30,7 +30,8 @@ class Request {
|
|||||||
dio.interceptors.add(cookieManager);
|
dio.interceptors.add(cookieManager);
|
||||||
var cookie = await cookieManager.cookieJar
|
var cookie = await cookieManager.cookieJar
|
||||||
.loadForRequest(Uri.parse(HttpString.baseUrl));
|
.loadForRequest(Uri.parse(HttpString.baseUrl));
|
||||||
if (user.get(UserBoxKey.userMid) != null) {
|
var userInfo = userInfoCache.get('userInfoCache');
|
||||||
|
if (userInfo != null && userInfo.mid != null) {
|
||||||
var cookie2 = await cookieManager.cookieJar
|
var cookie2 = await cookieManager.cookieJar
|
||||||
.loadForRequest(Uri.parse(HttpString.tUrl));
|
.loadForRequest(Uri.parse(HttpString.tUrl));
|
||||||
if (cookie2.isEmpty) {
|
if (cookie2.isEmpty) {
|
||||||
@ -86,9 +87,10 @@ class Request {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
Box user = GStrorage.user;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
if (user.get(UserBoxKey.userMid) != null) {
|
var userInfo = userInfoCache.get('userInfoCache');
|
||||||
options.headers['x-bili-mid'] = user.get(UserBoxKey.userMid).toString();
|
if (userInfo != null && userInfo.mid != null) {
|
||||||
|
options.headers['x-bili-mid'] = userInfo.mid.toString();
|
||||||
options.headers['env'] = 'prod';
|
options.headers['env'] = 'prod';
|
||||||
options.headers['app-key'] = 'android64';
|
options.headers['app-key'] = 'android64';
|
||||||
options.headers['x-bili-aurora-eid'] = 'UlMFQVcABlAH';
|
options.headers['x-bili-aurora-eid'] = 'UlMFQVcABlAH';
|
||||||
|
|||||||
@ -17,7 +17,7 @@ class ApiInterceptor extends Interceptor {
|
|||||||
handler.next(options);
|
handler.next(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
Box user = GStrorage.user;
|
Box localCache = GStrorage.localCache;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onResponse(Response response, ResponseInterceptorHandler handler) {
|
void onResponse(Response response, ResponseInterceptorHandler handler) {
|
||||||
@ -29,7 +29,8 @@ class ApiInterceptor extends Interceptor {
|
|||||||
final uri = Uri.parse(locations.first);
|
final uri = Uri.parse(locations.first);
|
||||||
final accessKey = uri.queryParameters['access_key'];
|
final accessKey = uri.queryParameters['access_key'];
|
||||||
final mid = uri.queryParameters['mid'];
|
final mid = uri.queryParameters['mid'];
|
||||||
user.put(UserBoxKey.accessKey, {'mid': mid, 'value': accessKey});
|
localCache
|
||||||
|
.put(LocalCacheKey.accessKey, {'mid': mid, 'value': accessKey});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:pilipala/common/constants.dart';
|
import 'package:pilipala/common/constants.dart';
|
||||||
import 'package:pilipala/http/api.dart';
|
import 'package:pilipala/http/api.dart';
|
||||||
import 'package:pilipala/http/init.dart';
|
import 'package:pilipala/http/init.dart';
|
||||||
@ -197,8 +198,12 @@ class UserHttp {
|
|||||||
'sign': Constants.thirdSign,
|
'sign': Constants.thirdSign,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (res.data['code'] == 0 && res.data['data']['has_login'] == 1) {
|
try {
|
||||||
Request().get(res.data['data']['confirm_uri']);
|
if (res.data['code'] == 0 && res.data['data']['has_login'] == 1) {
|
||||||
|
Request().get(res.data['data']['confirm_uri']);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
SmartDialog.showNotify(msg: '获取用户凭证: $err', notifyType: NotifyType.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,7 +18,7 @@ import 'package:pilipala/utils/storage.dart';
|
|||||||
/// 返回{'status': bool, 'data': List}
|
/// 返回{'status': bool, 'data': List}
|
||||||
/// view层根据 status 判断渲染逻辑
|
/// view层根据 status 判断渲染逻辑
|
||||||
class VideoHttp {
|
class VideoHttp {
|
||||||
static Box user = GStrorage.user;
|
static Box localCache = GStrorage.localCache;
|
||||||
static Box setting = GStrorage.setting;
|
static Box setting = GStrorage.setting;
|
||||||
|
|
||||||
// 首页推荐视频
|
// 首页推荐视频
|
||||||
@ -61,8 +61,9 @@ class VideoHttp {
|
|||||||
'device_name': 'vivo',
|
'device_name': 'vivo',
|
||||||
'pull': freshIdx == 0 ? 'true' : 'false',
|
'pull': freshIdx == 0 ? 'true' : 'false',
|
||||||
'appkey': Constants.appKey,
|
'appkey': Constants.appKey,
|
||||||
'access_key':
|
'access_key': localCache
|
||||||
user.get(UserBoxKey.accessKey, defaultValue: {})['value'] ?? ''
|
.get(LocalCacheKey.accessKey, defaultValue: {})['value'] ??
|
||||||
|
''
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
if (res.data['code'] == 0) {
|
if (res.data['code'] == 0) {
|
||||||
|
|||||||
@ -93,7 +93,7 @@ class UserInfoData {
|
|||||||
official = json['official'];
|
official = json['official'];
|
||||||
officialVerify = json['officialVerify'];
|
officialVerify = json['officialVerify'];
|
||||||
pendant = json['pendant'];
|
pendant = json['pendant'];
|
||||||
scores = json['scores'];
|
// scores = json['scores'];
|
||||||
uname = json['uname'];
|
uname = json['uname'];
|
||||||
vipDueDate = json['vipDueDate'];
|
vipDueDate = json['vipDueDate'];
|
||||||
vipStatus = json['vipStatus'];
|
vipStatus = json['vipStatus'];
|
||||||
@ -130,6 +130,8 @@ class LevelInfo {
|
|||||||
currentLevel = json['current_level'];
|
currentLevel = json['current_level'];
|
||||||
currentMin = json['current_min'];
|
currentMin = json['current_min'];
|
||||||
currentExp = json['current_exp'];
|
currentExp = json['current_exp'];
|
||||||
nextExp = json['next_exp'];
|
// nextExp = json['next_exp'];
|
||||||
|
nextExp =
|
||||||
|
json['current_level'] == 6 ? json['current_exp'] : json['next_exp'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,17 +11,19 @@ class BangumiController extends GetxController {
|
|||||||
RxList<BangumiListItemModel> bangumiFollowList = [BangumiListItemModel()].obs;
|
RxList<BangumiListItemModel> bangumiFollowList = [BangumiListItemModel()].obs;
|
||||||
int _currentPage = 1;
|
int _currentPage = 1;
|
||||||
bool isLoadingMore = true;
|
bool isLoadingMore = true;
|
||||||
Box user = GStrorage.user;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
RxBool userLogin = false.obs;
|
RxBool userLogin = false.obs;
|
||||||
late int mid;
|
late int mid;
|
||||||
|
var userInfo;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
if (user.get(UserBoxKey.userMid) != null) {
|
userInfo = userInfoCache.get('userInfoCache');
|
||||||
mid = int.parse(user.get(UserBoxKey.userMid).toString());
|
if (userInfo != null) {
|
||||||
|
mid = userInfo.mid;
|
||||||
}
|
}
|
||||||
userLogin.value = user.get(UserBoxKey.userLogin) != null;
|
userLogin.value = userInfo != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future queryBangumiListFeed({type = 'init'}) async {
|
Future queryBangumiListFeed({type = 'init'}) async {
|
||||||
|
|||||||
@ -49,7 +49,7 @@ class BangumiIntroController extends GetxController {
|
|||||||
RxBool hasCoin = false.obs;
|
RxBool hasCoin = false.obs;
|
||||||
// 是否收藏
|
// 是否收藏
|
||||||
RxBool hasFav = false.obs;
|
RxBool hasFav = false.obs;
|
||||||
Box user = GStrorage.user;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
bool userLogin = false;
|
bool userLogin = false;
|
||||||
Rx<FavFolderData> favFolderData = FavFolderData().obs;
|
Rx<FavFolderData> favFolderData = FavFolderData().obs;
|
||||||
List addMediaIdsNew = [];
|
List addMediaIdsNew = [];
|
||||||
@ -57,6 +57,7 @@ class BangumiIntroController extends GetxController {
|
|||||||
// 关注状态 默认未关注
|
// 关注状态 默认未关注
|
||||||
RxMap followStatus = {}.obs;
|
RxMap followStatus = {}.obs;
|
||||||
int _tempThemeValue = -1;
|
int _tempThemeValue = -1;
|
||||||
|
var userInfo;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
@ -82,7 +83,8 @@ class BangumiIntroController extends GetxController {
|
|||||||
// videoItem!['owner'] = args.owner;
|
// videoItem!['owner'] = args.owner;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
userLogin = user.get(UserBoxKey.userLogin) != null;
|
userInfo = userInfoCache.get('userInfoCache');
|
||||||
|
userLogin = userInfo != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取番剧简介&选集
|
// 获取番剧简介&选集
|
||||||
@ -142,7 +144,7 @@ class BangumiIntroController extends GetxController {
|
|||||||
|
|
||||||
// 投币
|
// 投币
|
||||||
Future actionCoinVideo() async {
|
Future actionCoinVideo() async {
|
||||||
if (user.get(UserBoxKey.userMid) == null) {
|
if (userInfo == null) {
|
||||||
SmartDialog.showToast('账号未登录');
|
SmartDialog.showToast('账号未登录');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -283,7 +285,7 @@ class BangumiIntroController extends GetxController {
|
|||||||
|
|
||||||
Future queryVideoInFolder() async {
|
Future queryVideoInFolder() async {
|
||||||
var result = await VideoHttp.videoInFolder(
|
var result = await VideoHttp.videoInFolder(
|
||||||
mid: user.get(UserBoxKey.userMid), rid: IdUtils.bv2av(bvid));
|
mid: userInfo.mid, rid: IdUtils.bv2av(bvid));
|
||||||
if (result['status']) {
|
if (result['status']) {
|
||||||
favFolderData.value = result['data'];
|
favFolderData.value = result['data'];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -121,7 +121,7 @@ class _BangumiInfoState extends State<BangumiInfo> {
|
|||||||
|
|
||||||
// 收藏
|
// 收藏
|
||||||
showFavBottomSheet() {
|
showFavBottomSheet() {
|
||||||
if (bangumiIntroController.user.get(UserBoxKey.userMid) == null) {
|
if (bangumiIntroController.userInfo.mid == null) {
|
||||||
SmartDialog.showToast('账号未登录');
|
SmartDialog.showToast('账号未登录');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,12 +51,14 @@ class DynamicsController extends GetxController {
|
|||||||
];
|
];
|
||||||
bool flag = false;
|
bool flag = false;
|
||||||
RxInt initialValue = 1.obs;
|
RxInt initialValue = 1.obs;
|
||||||
Box user = GStrorage.user;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
RxBool userLogin = false.obs;
|
RxBool userLogin = false.obs;
|
||||||
|
var userInfo;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
userLogin.value = user.get(UserBoxKey.userLogin, defaultValue: false);
|
userInfo = userInfoCache.get('userInfoCache');
|
||||||
|
userLogin.value = userInfo != null;
|
||||||
super.onInit();
|
super.onInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -30,7 +30,7 @@ class _DynamicsPageState extends State<DynamicsPage>
|
|||||||
late Future _futureBuilderFuture;
|
late Future _futureBuilderFuture;
|
||||||
late Future _futureBuilderFutureUp;
|
late Future _futureBuilderFutureUp;
|
||||||
bool _isLoadingMore = false;
|
bool _isLoadingMore = false;
|
||||||
Box user = GStrorage.user;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
EventBus eventBus = EventBus();
|
EventBus eventBus = EventBus();
|
||||||
late ScrollController scrollController;
|
late ScrollController scrollController;
|
||||||
|
|
||||||
|
|||||||
@ -24,7 +24,8 @@ class _UpPanelState extends State<UpPanel> {
|
|||||||
List<UpItem> upList = [];
|
List<UpItem> upList = [];
|
||||||
List<LiveUserItem> liveList = [];
|
List<LiveUserItem> liveList = [];
|
||||||
static const itemPadding = EdgeInsets.symmetric(horizontal: 5, vertical: 0);
|
static const itemPadding = EdgeInsets.symmetric(horizontal: 5, vertical: 0);
|
||||||
Box user = GStrorage.user;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
|
var userInfo;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -36,12 +37,13 @@ class _UpPanelState extends State<UpPanel> {
|
|||||||
UpItem(
|
UpItem(
|
||||||
face: 'https://files.catbox.moe/8uc48f.png', uname: '全部动态', mid: -1),
|
face: 'https://files.catbox.moe/8uc48f.png', uname: '全部动态', mid: -1),
|
||||||
);
|
);
|
||||||
|
userInfo = userInfoCache.get('userInfoCache');
|
||||||
upList.insert(
|
upList.insert(
|
||||||
1,
|
1,
|
||||||
UpItem(
|
UpItem(
|
||||||
face: user.get(UserBoxKey.userFace),
|
face: userInfo.face,
|
||||||
uname: '我',
|
uname: '我',
|
||||||
mid: user.get(UserBoxKey.userMid),
|
mid: userInfo.mid,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,19 +5,22 @@ import 'package:pilipala/models/fans/result.dart';
|
|||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
|
||||||
class FansController extends GetxController {
|
class FansController extends GetxController {
|
||||||
Box user = GStrorage.user;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
int pn = 1;
|
int pn = 1;
|
||||||
int total = 0;
|
int total = 0;
|
||||||
RxList<FansItemModel> fansList = [FansItemModel()].obs;
|
RxList<FansItemModel> fansList = [FansItemModel()].obs;
|
||||||
late int mid;
|
late int mid;
|
||||||
late String name;
|
late String name;
|
||||||
|
var userInfo;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
mid = int.parse(
|
userInfo = userInfoCache.get('userInfoCache');
|
||||||
Get.parameters['mid'] ?? user.get(UserBoxKey.userMid).toString());
|
mid = Get.parameters['mid'] != null
|
||||||
name = Get.parameters['name'] ?? user.get(UserBoxKey.userName);
|
? int.parse(Get.parameters['mid']!)
|
||||||
|
: userInfo.mid;
|
||||||
|
name = Get.parameters['name'] ?? userInfo.uname;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future queryFans(type) async {
|
Future queryFans(type) async {
|
||||||
|
|||||||
@ -1,16 +1,24 @@
|
|||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
|
import 'package:hive/hive.dart';
|
||||||
import 'package:pilipala/http/user.dart';
|
import 'package:pilipala/http/user.dart';
|
||||||
import 'package:pilipala/models/user/fav_folder.dart';
|
import 'package:pilipala/models/user/fav_folder.dart';
|
||||||
|
import 'package:pilipala/models/user/info.dart';
|
||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
|
||||||
class FavController extends GetxController {
|
class FavController extends GetxController {
|
||||||
Rx<FavFolderData> favFolderData = FavFolderData().obs;
|
Rx<FavFolderData> favFolderData = FavFolderData().obs;
|
||||||
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
|
UserInfoData? userInfo;
|
||||||
|
|
||||||
Future<dynamic> queryFavFolder() async {
|
Future<dynamic> queryFavFolder() async {
|
||||||
|
userInfo = userInfoCache.get('userInfoCache');
|
||||||
|
if (userInfo == null) {
|
||||||
|
return {'status': false, 'msg': '账号未登录'};
|
||||||
|
}
|
||||||
var res = await await UserHttp.userfavFolder(
|
var res = await await UserHttp.userfavFolder(
|
||||||
pn: 1,
|
pn: 1,
|
||||||
ps: 10,
|
ps: 10,
|
||||||
mid: GStrorage.user.get(UserBoxKey.userMid) ?? 0,
|
mid: userInfo!.mid!,
|
||||||
);
|
);
|
||||||
if (res['status']) {
|
if (res['status']) {
|
||||||
favFolderData.value = res['data'];
|
favFolderData.value = res['data'];
|
||||||
|
|||||||
@ -5,19 +5,22 @@ import 'package:pilipala/models/follow/result.dart';
|
|||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
|
||||||
class FollowController extends GetxController {
|
class FollowController extends GetxController {
|
||||||
Box user = GStrorage.user;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
int pn = 1;
|
int pn = 1;
|
||||||
int total = 0;
|
int total = 0;
|
||||||
RxList<FollowItemModel> followList = [FollowItemModel()].obs;
|
RxList<FollowItemModel> followList = [FollowItemModel()].obs;
|
||||||
late int mid;
|
late int mid;
|
||||||
late String name;
|
late String name;
|
||||||
|
var userInfo;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
mid = int.parse(
|
userInfo = userInfoCache.get('userInfoCache');
|
||||||
Get.parameters['mid'] ?? user.get(UserBoxKey.userMid).toString());
|
mid = Get.parameters['mid'] != null
|
||||||
name = Get.parameters['name'] ?? user.get(UserBoxKey.userName);
|
? int.parse(Get.parameters['mid']!)
|
||||||
|
: userInfo.mid;
|
||||||
|
name = Get.parameters['name'] ?? userInfo.uname;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future queryFollowings(type) async {
|
Future queryFollowings(type) async {
|
||||||
|
|||||||
@ -11,16 +11,17 @@ class HomeController extends GetxController with GetTickerProviderStateMixin {
|
|||||||
late TabController tabController;
|
late TabController tabController;
|
||||||
late List tabsCtrList;
|
late List tabsCtrList;
|
||||||
late List<Widget> tabsPageList;
|
late List<Widget> tabsPageList;
|
||||||
Box user = GStrorage.user;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
RxBool userLogin = false.obs;
|
RxBool userLogin = false.obs;
|
||||||
RxString userFace = ''.obs;
|
RxString userFace = ''.obs;
|
||||||
|
var userInfo;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
|
userInfo = userInfoCache.get('userInfoCache');
|
||||||
userLogin.value = user.get(UserBoxKey.userLogin) ?? false;
|
userLogin.value = userInfo != null;
|
||||||
userFace.value = user.get(UserBoxKey.userFace) ?? '';
|
userFace.value = userInfo != null ? userInfo.face : '';
|
||||||
|
|
||||||
// 进行tabs配置
|
// 进行tabs配置
|
||||||
tabs = tabsConfig;
|
tabs = tabsConfig;
|
||||||
@ -48,7 +49,8 @@ class HomeController extends GetxController with GetTickerProviderStateMixin {
|
|||||||
|
|
||||||
// 更新登录状态
|
// 更新登录状态
|
||||||
void updateLoginStatus(val) {
|
void updateLoginStatus(val) {
|
||||||
|
userInfo = userInfoCache.get('userInfoCache');
|
||||||
userLogin.value = val ?? false;
|
userLogin.value = val ?? false;
|
||||||
userFace.value = user.get(UserBoxKey.userFace) ?? '';
|
userFace.value = userInfo != null ? userInfo.face : '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,13 +6,14 @@ import 'package:pilipala/common/widgets/network_img_layer.dart';
|
|||||||
import 'package:pilipala/pages/mine/view.dart';
|
import 'package:pilipala/pages/mine/view.dart';
|
||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
|
||||||
Box user = GStrorage.user;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
|
|
||||||
class HomeAppBar extends StatelessWidget {
|
class HomeAppBar extends StatelessWidget {
|
||||||
const HomeAppBar({super.key});
|
const HomeAppBar({super.key});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
var userInfo = userInfoCache.get('userInfoCache');
|
||||||
return SliverAppBar(
|
return SliverAppBar(
|
||||||
// forceElevated: true,
|
// forceElevated: true,
|
||||||
scrolledUnderElevation: 0,
|
scrolledUnderElevation: 0,
|
||||||
@ -55,7 +56,7 @@ class HomeAppBar extends StatelessWidget {
|
|||||||
const SizedBox(width: 6),
|
const SizedBox(width: 6),
|
||||||
|
|
||||||
/// TODO
|
/// TODO
|
||||||
if (user.get(UserBoxKey.userLogin)) ...[
|
if (userInfo != null) ...[
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () => showModalBottomSheet(
|
onTap: () => showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
@ -70,7 +71,7 @@ class HomeAppBar extends StatelessWidget {
|
|||||||
type: 'avatar',
|
type: 'avatar',
|
||||||
width: 32,
|
width: 32,
|
||||||
height: 32,
|
height: 32,
|
||||||
src: user.get(UserBoxKey.userMid),
|
src: userInfo.face,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import 'package:pilipala/utils/storage.dart';
|
|||||||
|
|
||||||
class MediaController extends GetxController {
|
class MediaController extends GetxController {
|
||||||
Rx<FavFolderData> favFolderData = FavFolderData().obs;
|
Rx<FavFolderData> favFolderData = FavFolderData().obs;
|
||||||
Box user = GStrorage.user;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
RxBool userLogin = false.obs;
|
RxBool userLogin = false.obs;
|
||||||
List list = [
|
List list = [
|
||||||
{
|
{
|
||||||
@ -34,21 +34,23 @@ class MediaController extends GetxController {
|
|||||||
'onTap': () => Get.toNamed('/later'),
|
'onTap': () => Get.toNamed('/later'),
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
var userInfo;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
userLogin.value = user.get(UserBoxKey.userLogin) ?? false;
|
userInfo = userInfoCache.get('userInfoCache');
|
||||||
|
userLogin.value = userInfo != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<dynamic> queryFavFolder() async {
|
Future<dynamic> queryFavFolder() async {
|
||||||
if (!userLogin.value || GStrorage.user.get(UserBoxKey.userMid) == null) {
|
if (!userLogin.value || GStrorage.userInfo.get('userInfoCache') == null) {
|
||||||
return {'status': false, 'data': [], 'msg': '未登录'};
|
return {'status': false, 'data': [], 'msg': '未登录'};
|
||||||
}
|
}
|
||||||
var res = await await UserHttp.userfavFolder(
|
var res = await await UserHttp.userfavFolder(
|
||||||
pn: 1,
|
pn: 1,
|
||||||
ps: 5,
|
ps: 5,
|
||||||
mid: GStrorage.user.get(UserBoxKey.userMid),
|
mid: GStrorage.userInfo.get('userInfoCache').mid,
|
||||||
);
|
);
|
||||||
favFolderData.value = res['data'];
|
favFolderData.value = res['data'];
|
||||||
return res;
|
return res;
|
||||||
|
|||||||
@ -14,16 +14,18 @@ class MemberController extends GetxController {
|
|||||||
Map? userStat;
|
Map? userStat;
|
||||||
String? face;
|
String? face;
|
||||||
String? heroTag;
|
String? heroTag;
|
||||||
Box user = GStrorage.user;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
late int ownerMid;
|
late int ownerMid;
|
||||||
// 投稿列表
|
// 投稿列表
|
||||||
RxList<VListItemModel>? archiveList = [VListItemModel()].obs;
|
RxList<VListItemModel>? archiveList = [VListItemModel()].obs;
|
||||||
|
var userInfo;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
mid = int.parse(Get.parameters['mid']!);
|
mid = int.parse(Get.parameters['mid']!);
|
||||||
ownerMid = user.get(UserBoxKey.userMid) ?? -1;
|
userInfo = userInfoCache.get('userInfoCache');
|
||||||
|
ownerMid = userInfo != null ? userInfo.mid : -1;
|
||||||
face = Get.arguments['face'] ?? '';
|
face = Get.arguments['face'] ?? '';
|
||||||
heroTag = Get.arguments['heroTag'] ?? '';
|
heroTag = Get.arguments['heroTag'] ?? '';
|
||||||
}
|
}
|
||||||
@ -57,7 +59,7 @@ class MemberController extends GetxController {
|
|||||||
|
|
||||||
// 关注/取关up
|
// 关注/取关up
|
||||||
Future actionRelationMod() async {
|
Future actionRelationMod() async {
|
||||||
if (user.get(UserBoxKey.userMid) == null) {
|
if (userInfo == null) {
|
||||||
SmartDialog.showToast('账号未登录');
|
SmartDialog.showToast('账号未登录');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,9 +13,8 @@ class MineController extends GetxController {
|
|||||||
// 用户状态 动态、关注、粉丝
|
// 用户状态 动态、关注、粉丝
|
||||||
Rx<UserStat> userStat = UserStat().obs;
|
Rx<UserStat> userStat = UserStat().obs;
|
||||||
RxBool userLogin = false.obs;
|
RxBool userLogin = false.obs;
|
||||||
Box user = GStrorage.user;
|
|
||||||
Box setting = GStrorage.setting;
|
|
||||||
Box userInfoCache = GStrorage.userInfo;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
|
Box setting = GStrorage.setting;
|
||||||
Rx<ThemeType> themeType = ThemeType.system.obs;
|
Rx<ThemeType> themeType = ThemeType.system.obs;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -24,6 +23,7 @@ class MineController extends GetxController {
|
|||||||
|
|
||||||
if (userInfoCache.get('userInfoCache') != null) {
|
if (userInfoCache.get('userInfoCache') != null) {
|
||||||
userInfo.value = userInfoCache.get('userInfoCache');
|
userInfo.value = userInfoCache.get('userInfoCache');
|
||||||
|
userLogin.value = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
themeType.value = ThemeType.values[setting.get(SettingBoxKey.themeMode,
|
themeType.value = ThemeType.values[setting.get(SettingBoxKey.themeMode,
|
||||||
@ -41,8 +41,8 @@ class MineController extends GetxController {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
int mid = user.get(UserBoxKey.userMid);
|
int mid = userInfo.value.mid!;
|
||||||
String face = user.get(UserBoxKey.userFace);
|
String face = userInfo.value.face!;
|
||||||
Get.toNamed(
|
Get.toNamed(
|
||||||
'/member?mid=$mid',
|
'/member?mid=$mid',
|
||||||
arguments: {'face': face},
|
arguments: {'face': face},
|
||||||
@ -51,7 +51,7 @@ class MineController extends GetxController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future queryUserInfo() async {
|
Future queryUserInfo() async {
|
||||||
if (user.get(UserBoxKey.userLogin) == null) {
|
if (!userLogin.value) {
|
||||||
return {'status': false};
|
return {'status': false};
|
||||||
}
|
}
|
||||||
var res = await UserHttp.userInfo();
|
var res = await UserHttp.userInfo();
|
||||||
@ -59,18 +59,12 @@ class MineController extends GetxController {
|
|||||||
if (res['data'].isLogin) {
|
if (res['data'].isLogin) {
|
||||||
userInfo.value = res['data'];
|
userInfo.value = res['data'];
|
||||||
userInfoCache.put('userInfoCache', res['data']);
|
userInfoCache.put('userInfoCache', res['data']);
|
||||||
user.put(UserBoxKey.userName, res['data'].uname);
|
|
||||||
user.put(UserBoxKey.userFace, res['data'].face);
|
|
||||||
user.put(UserBoxKey.userMid, res['data'].mid);
|
|
||||||
user.put(UserBoxKey.userLogin, true);
|
|
||||||
userLogin.value = true;
|
userLogin.value = true;
|
||||||
// Get.find<MainController>().readuUserFace();
|
|
||||||
} else {
|
} else {
|
||||||
resetUserInfo();
|
resetUserInfo();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resetUserInfo();
|
resetUserInfo();
|
||||||
// SmartDialog.showToast(res['msg']);
|
|
||||||
}
|
}
|
||||||
await queryUserStatOwner();
|
await queryUserStatOwner();
|
||||||
return res;
|
return res;
|
||||||
@ -87,12 +81,8 @@ class MineController extends GetxController {
|
|||||||
Future resetUserInfo() async {
|
Future resetUserInfo() async {
|
||||||
userInfo.value = UserInfoData();
|
userInfo.value = UserInfoData();
|
||||||
userStat.value = UserStat();
|
userStat.value = UserStat();
|
||||||
await user.delete(UserBoxKey.userName);
|
userInfoCache.delete('userInfoCache');
|
||||||
await user.delete(UserBoxKey.userFace);
|
|
||||||
await user.delete(UserBoxKey.userMid);
|
|
||||||
await user.delete(UserBoxKey.userLogin);
|
|
||||||
userLogin.value = false;
|
userLogin.value = false;
|
||||||
// Get.find<MainController>().resetLast();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
onChangeTheme() {
|
onChangeTheme() {
|
||||||
|
|||||||
@ -11,19 +11,22 @@ import 'package:pilipala/utils/feed_back.dart';
|
|||||||
import 'package:pilipala/utils/storage.dart';
|
import 'package:pilipala/utils/storage.dart';
|
||||||
|
|
||||||
class SettingController extends GetxController {
|
class SettingController extends GetxController {
|
||||||
Box user = GStrorage.user;
|
|
||||||
Box setting = GStrorage.setting;
|
|
||||||
Box userInfoCache = GStrorage.userInfo;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
|
Box setting = GStrorage.setting;
|
||||||
|
// Box userInfoCache = GStrorage.userInfo;
|
||||||
|
Box localCache = GStrorage.localCache;
|
||||||
|
|
||||||
RxBool userLogin = false.obs;
|
RxBool userLogin = false.obs;
|
||||||
RxBool feedBackEnable = false.obs;
|
RxBool feedBackEnable = false.obs;
|
||||||
RxInt picQuality = 10.obs;
|
RxInt picQuality = 10.obs;
|
||||||
Rx<ThemeType> themeType = ThemeType.system.obs;
|
Rx<ThemeType> themeType = ThemeType.system.obs;
|
||||||
|
var userInfo;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
userLogin.value = user.get(UserBoxKey.userLogin) ?? false;
|
userInfo = userInfoCache.get('userInfoCache');
|
||||||
|
userLogin.value = userInfo != null;
|
||||||
feedBackEnable.value =
|
feedBackEnable.value =
|
||||||
setting.get(SettingBoxKey.feedBackEnable, defaultValue: false);
|
setting.get(SettingBoxKey.feedBackEnable, defaultValue: false);
|
||||||
picQuality.value =
|
picQuality.value =
|
||||||
@ -53,7 +56,8 @@ class SettingController extends GetxController {
|
|||||||
|
|
||||||
// 清空本地存储的用户标识
|
// 清空本地存储的用户标识
|
||||||
userInfoCache.put('userInfoCache', null);
|
userInfoCache.put('userInfoCache', null);
|
||||||
user.put(UserBoxKey.accessKey, {'mid': -1, 'value': ''});
|
localCache
|
||||||
|
.put(LocalCacheKey.accessKey, {'mid': -1, 'value': ''});
|
||||||
|
|
||||||
// 更改我的页面登录状态
|
// 更改我的页面登录状态
|
||||||
await Get.find<MineController>().resetUserInfo();
|
await Get.find<MineController>().resetUserInfo();
|
||||||
|
|||||||
@ -13,12 +13,14 @@ class PrivacySetting extends StatefulWidget {
|
|||||||
|
|
||||||
class _PrivacySettingState extends State<PrivacySetting> {
|
class _PrivacySettingState extends State<PrivacySetting> {
|
||||||
bool userLogin = false;
|
bool userLogin = false;
|
||||||
Box user = GStrorage.user;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
|
var userInfo;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
userLogin = user.get(UserBoxKey.userLogin) ?? false;
|
userInfo = userInfoCache.get('userInfoCache');
|
||||||
|
userLogin = userInfo != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@ -51,7 +51,7 @@ class VideoDetailController extends GetxController
|
|||||||
RxBool enableHA = true.obs;
|
RxBool enableHA = true.obs;
|
||||||
|
|
||||||
/// 本地存储
|
/// 本地存储
|
||||||
Box user = GStrorage.user;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
Box localCache = GStrorage.localCache;
|
Box localCache = GStrorage.localCache;
|
||||||
Box setting = GStrorage.setting;
|
Box setting = GStrorage.setting;
|
||||||
|
|
||||||
@ -70,11 +70,13 @@ class VideoDetailController extends GetxController
|
|||||||
late Duration defaultST;
|
late Duration defaultST;
|
||||||
// 默认记录历史记录
|
// 默认记录历史记录
|
||||||
bool enableHeart = true;
|
bool enableHeart = true;
|
||||||
|
var userInfo;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
Map argMap = Get.arguments;
|
Map argMap = Get.arguments;
|
||||||
|
userInfo = userInfoCache.get('userInfoCache');
|
||||||
var keys = argMap.keys.toList();
|
var keys = argMap.keys.toList();
|
||||||
if (keys.isNotEmpty) {
|
if (keys.isNotEmpty) {
|
||||||
if (keys.contains('videoItem')) {
|
if (keys.contains('videoItem')) {
|
||||||
@ -92,7 +94,7 @@ class VideoDetailController extends GetxController
|
|||||||
setting.get(SettingBoxKey.autoPlayEnable, defaultValue: true);
|
setting.get(SettingBoxKey.autoPlayEnable, defaultValue: true);
|
||||||
enableHA.value = setting.get(SettingBoxKey.enableHA, defaultValue: true);
|
enableHA.value = setting.get(SettingBoxKey.enableHA, defaultValue: true);
|
||||||
|
|
||||||
if (user.get(UserBoxKey.userMid) == null ||
|
if (userInfo == null ||
|
||||||
localCache.get(LocalCacheKey.historyPause) == true) {
|
localCache.get(LocalCacheKey.historyPause) == true) {
|
||||||
enableHeart = false;
|
enableHeart = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -42,7 +42,7 @@ class VideoIntroController extends GetxController {
|
|||||||
RxBool hasCoin = false.obs;
|
RxBool hasCoin = false.obs;
|
||||||
// 是否收藏
|
// 是否收藏
|
||||||
RxBool hasFav = false.obs;
|
RxBool hasFav = false.obs;
|
||||||
Box user = GStrorage.user;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
bool userLogin = false;
|
bool userLogin = false;
|
||||||
Rx<FavFolderData> favFolderData = FavFolderData().obs;
|
Rx<FavFolderData> favFolderData = FavFolderData().obs;
|
||||||
List addMediaIdsNew = [];
|
List addMediaIdsNew = [];
|
||||||
@ -52,10 +52,12 @@ class VideoIntroController extends GetxController {
|
|||||||
int _tempThemeValue = -1;
|
int _tempThemeValue = -1;
|
||||||
|
|
||||||
RxInt lastPlayCid = 0.obs;
|
RxInt lastPlayCid = 0.obs;
|
||||||
|
var userInfo;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
|
userInfo = userInfoCache.get('userInfoCache');
|
||||||
if (Get.arguments.isNotEmpty) {
|
if (Get.arguments.isNotEmpty) {
|
||||||
if (Get.arguments.containsKey('videoItem')) {
|
if (Get.arguments.containsKey('videoItem')) {
|
||||||
preRender = true;
|
preRender = true;
|
||||||
@ -77,7 +79,7 @@ class VideoIntroController extends GetxController {
|
|||||||
videoItem!['owner'] = args.owner;
|
videoItem!['owner'] = args.owner;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
userLogin = user.get(UserBoxKey.userLogin) != null;
|
userLogin = userInfo == null;
|
||||||
lastPlayCid.value = int.parse(Get.parameters['cid']!);
|
lastPlayCid.value = int.parse(Get.parameters['cid']!);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,7 +145,7 @@ class VideoIntroController extends GetxController {
|
|||||||
|
|
||||||
// 一键三连
|
// 一键三连
|
||||||
Future actionOneThree() async {
|
Future actionOneThree() async {
|
||||||
if (user.get(UserBoxKey.userMid) == null) {
|
if (userInfo == null) {
|
||||||
SmartDialog.showToast('账号未登录');
|
SmartDialog.showToast('账号未登录');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -206,7 +208,7 @@ class VideoIntroController extends GetxController {
|
|||||||
|
|
||||||
// 投币
|
// 投币
|
||||||
Future actionCoinVideo() async {
|
Future actionCoinVideo() async {
|
||||||
if (user.get(UserBoxKey.userMid) == null) {
|
if (userInfo == null) {
|
||||||
SmartDialog.showToast('账号未登录');
|
SmartDialog.showToast('账号未登录');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -302,7 +304,7 @@ class VideoIntroController extends GetxController {
|
|||||||
|
|
||||||
Future queryVideoInFolder() async {
|
Future queryVideoInFolder() async {
|
||||||
var result = await VideoHttp.videoInFolder(
|
var result = await VideoHttp.videoInFolder(
|
||||||
mid: user.get(UserBoxKey.userMid), rid: IdUtils.bv2av(bvid));
|
mid: userInfo.mid, rid: IdUtils.bv2av(bvid));
|
||||||
if (result['status']) {
|
if (result['status']) {
|
||||||
favFolderData.value = result['data'];
|
favFolderData.value = result['data'];
|
||||||
}
|
}
|
||||||
@ -337,7 +339,7 @@ class VideoIntroController extends GetxController {
|
|||||||
// 关注/取关up
|
// 关注/取关up
|
||||||
Future actionRelationMod() async {
|
Future actionRelationMod() async {
|
||||||
feedBack();
|
feedBack();
|
||||||
if (user.get(UserBoxKey.userMid) == null) {
|
if (userInfo == null) {
|
||||||
SmartDialog.showToast('账号未登录');
|
SmartDialog.showToast('账号未登录');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -127,7 +127,7 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
|
|||||||
|
|
||||||
// 收藏
|
// 收藏
|
||||||
showFavBottomSheet() {
|
showFavBottomSheet() {
|
||||||
if (videoIntroController.user.get(UserBoxKey.userMid) == null) {
|
if (videoIntroController.userInfo == null) {
|
||||||
SmartDialog.showToast('账号未登录');
|
SmartDialog.showToast('账号未登录');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
// ignore_for_file: avoid_print
|
// ignore_for_file: avoid_print
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
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';
|
||||||
@ -14,7 +15,7 @@ import 'package:webview_flutter/webview_flutter.dart';
|
|||||||
|
|
||||||
class WebviewController extends GetxController {
|
class WebviewController extends GetxController {
|
||||||
String url = '';
|
String url = '';
|
||||||
String type = '';
|
RxString type = ''.obs;
|
||||||
String pageTitle = '';
|
String pageTitle = '';
|
||||||
final WebViewController controller = WebViewController();
|
final WebViewController controller = WebViewController();
|
||||||
RxInt loadProgress = 0.obs;
|
RxInt loadProgress = 0.obs;
|
||||||
@ -25,10 +26,10 @@ class WebviewController extends GetxController {
|
|||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
url = Get.parameters['url']!;
|
url = Get.parameters['url']!;
|
||||||
type = Get.parameters['type']!;
|
type.value = Get.parameters['type']!;
|
||||||
pageTitle = Get.parameters['pageTitle']!;
|
pageTitle = Get.parameters['pageTitle']!;
|
||||||
|
|
||||||
if (type == 'login') {
|
if (type.value == 'login') {
|
||||||
controller.clearCache();
|
controller.clearCache();
|
||||||
controller.clearLocalStorage();
|
controller.clearLocalStorage();
|
||||||
WebViewCookieManager().clearCookies();
|
WebViewCookieManager().clearCookies();
|
||||||
@ -52,54 +53,11 @@ class WebviewController extends GetxController {
|
|||||||
onUrlChange: (UrlChange urlChange) async {
|
onUrlChange: (UrlChange urlChange) async {
|
||||||
loadShow.value = false;
|
loadShow.value = false;
|
||||||
String url = urlChange.url ?? '';
|
String url = urlChange.url ?? '';
|
||||||
if (type == 'login' &&
|
if (type.value == 'login' &&
|
||||||
(url.startsWith(
|
(url.startsWith(
|
||||||
'https://passport.bilibili.com/web/sso/exchange_cookie') ||
|
'https://passport.bilibili.com/web/sso/exchange_cookie') ||
|
||||||
url.startsWith('https://m.bilibili.com/'))) {
|
url.startsWith('https://m.bilibili.com/'))) {
|
||||||
try {
|
confirmLogin(url);
|
||||||
await SetCookie.onSet();
|
|
||||||
var result = await UserHttp.userInfo();
|
|
||||||
UserHttp.thirdLogin();
|
|
||||||
print('网页登录: $result');
|
|
||||||
if (result['status'] && result['data'].isLogin) {
|
|
||||||
SmartDialog.showToast('登录成功');
|
|
||||||
try {
|
|
||||||
Box user = GStrorage.user;
|
|
||||||
user.put(UserBoxKey.userLogin, true);
|
|
||||||
user.put(UserBoxKey.userName, result['data'].uname);
|
|
||||||
user.put(UserBoxKey.userFace, result['data'].face);
|
|
||||||
user.put(UserBoxKey.userMid, result['data'].mid);
|
|
||||||
|
|
||||||
Box userInfoCache = GStrorage.userInfo;
|
|
||||||
userInfoCache.put('userInfoCache', result['data']);
|
|
||||||
|
|
||||||
// 通知更新
|
|
||||||
eventBus.emit(EventName.loginEvent, {'status': true});
|
|
||||||
|
|
||||||
HomeController homeCtr = Get.find<HomeController>();
|
|
||||||
homeCtr.updateLoginStatus(true);
|
|
||||||
} catch (err) {
|
|
||||||
SmartDialog.show(builder: (context) {
|
|
||||||
return AlertDialog(
|
|
||||||
title: const Text('登录遇到问题'),
|
|
||||||
content: Text(err.toString()),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => controller.reload(),
|
|
||||||
child: const Text('确认'),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Get.back();
|
|
||||||
} else {
|
|
||||||
// 获取用户信息失败
|
|
||||||
SmartDialog.showToast(result.msg);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
print(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onWebResourceError: (WebResourceError error) {},
|
onWebResourceError: (WebResourceError error) {},
|
||||||
@ -113,4 +71,51 @@ class WebviewController extends GetxController {
|
|||||||
)
|
)
|
||||||
..loadRequest(Uri.parse(url));
|
..loadRequest(Uri.parse(url));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
confirmLogin(url) async {
|
||||||
|
var content = '';
|
||||||
|
if (url != null) {
|
||||||
|
content = '${content + url}; \n';
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await SetCookie.onSet();
|
||||||
|
var result = await UserHttp.userInfo();
|
||||||
|
UserHttp.thirdLogin();
|
||||||
|
if (result['status'] && result['data'].isLogin) {
|
||||||
|
SmartDialog.showToast('登录成功');
|
||||||
|
try {
|
||||||
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
|
await userInfoCache.put('userInfoCache', result['data']);
|
||||||
|
|
||||||
|
// 通知更新
|
||||||
|
eventBus.emit(EventName.loginEvent, {'status': true});
|
||||||
|
|
||||||
|
HomeController homeCtr = Get.find<HomeController>();
|
||||||
|
homeCtr.updateLoginStatus(true);
|
||||||
|
} catch (err) {
|
||||||
|
SmartDialog.show(builder: (context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: const Text('登录遇到问题'),
|
||||||
|
content: Text(err.toString()),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => controller.reload(),
|
||||||
|
child: const Text('确认'),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Get.back();
|
||||||
|
} else {
|
||||||
|
// 获取用户信息失败
|
||||||
|
SmartDialog.showToast(result.msg);
|
||||||
|
Clipboard.setData(ClipboardData(text: result.msg.toString()));
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
SmartDialog.showNotify(msg: e.toString(), notifyType: NotifyType.warning);
|
||||||
|
content = content + e.toString();
|
||||||
|
}
|
||||||
|
Clipboard.setData(ClipboardData(text: content));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,19 +18,25 @@ class _WebviewPageState extends State<WebviewPage> {
|
|||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
centerTitle: false,
|
centerTitle: false,
|
||||||
|
titleSpacing: 0,
|
||||||
title: Text(
|
title: Text(
|
||||||
_webviewController.pageTitle,
|
_webviewController.pageTitle,
|
||||||
style: Theme.of(context).textTheme.titleMedium,
|
style: Theme.of(context).textTheme.titleMedium,
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
IconButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
_webviewController.controller.reload();
|
_webviewController.controller.reload();
|
||||||
},
|
},
|
||||||
icon: const Icon(
|
child: const Text('刷新'),
|
||||||
Icons.refresh,
|
),
|
||||||
size: 22,
|
Obx(
|
||||||
),
|
() => _webviewController.type.value == 'login'
|
||||||
|
? TextButton(
|
||||||
|
onPressed: () => _webviewController.confirmLogin(null),
|
||||||
|
child: const Text('刷新登录状态'),
|
||||||
|
)
|
||||||
|
: const SizedBox(),
|
||||||
),
|
),
|
||||||
const SizedBox(width: 10)
|
const SizedBox(width: 10)
|
||||||
],
|
],
|
||||||
@ -48,6 +54,13 @@ class _WebviewPageState extends State<WebviewPage> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
Container(
|
||||||
|
width: double.infinity,
|
||||||
|
color: Theme.of(context).colorScheme.onInverseSurface,
|
||||||
|
padding:
|
||||||
|
const EdgeInsets.only(left: 12, right: 12, top: 6, bottom: 6),
|
||||||
|
child: const Text('登录成功未自动跳转? 请点击右上角「刷新登录状态」'),
|
||||||
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
child: WebViewWidget(controller: _webviewController.controller),
|
child: WebViewWidget(controller: _webviewController.controller),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -10,8 +10,8 @@ class Data {
|
|||||||
|
|
||||||
static Future historyStatus() async {
|
static Future historyStatus() async {
|
||||||
Box localCache = GStrorage.localCache;
|
Box localCache = GStrorage.localCache;
|
||||||
Box user = GStrorage.user;
|
Box userInfoCache = GStrorage.userInfo;
|
||||||
if (user.get(UserBoxKey.userMid) == null) {
|
if (userInfoCache.get('userInfoCache') == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var res = await UserHttp.historyStatus();
|
var res = await UserHttp.historyStatus();
|
||||||
|
|||||||
@ -7,7 +7,6 @@ import 'package:pilipala/models/search/hot.dart';
|
|||||||
import 'package:pilipala/models/user/info.dart';
|
import 'package:pilipala/models/user/info.dart';
|
||||||
|
|
||||||
class GStrorage {
|
class GStrorage {
|
||||||
static late final Box user;
|
|
||||||
static late final Box recVideo;
|
static late final Box recVideo;
|
||||||
static late final Box userInfo;
|
static late final Box userInfo;
|
||||||
static late final Box hotKeyword;
|
static late final Box hotKeyword;
|
||||||
@ -21,13 +20,6 @@ class GStrorage {
|
|||||||
final path = dir.path;
|
final path = dir.path;
|
||||||
await Hive.initFlutter('$path/hive');
|
await Hive.initFlutter('$path/hive');
|
||||||
regAdapter();
|
regAdapter();
|
||||||
// 用户信息
|
|
||||||
user = await Hive.openBox(
|
|
||||||
'user',
|
|
||||||
compactionStrategy: (entries, deletedEntries) {
|
|
||||||
return deletedEntries > 10;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
// 首页推荐视频
|
// 首页推荐视频
|
||||||
recVideo = await Hive.openBox(
|
recVideo = await Hive.openBox(
|
||||||
'recVideo',
|
'recVideo',
|
||||||
@ -36,7 +28,12 @@ class GStrorage {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
// 登录用户信息
|
// 登录用户信息
|
||||||
userInfo = await Hive.openBox('userInfo');
|
userInfo = await Hive.openBox(
|
||||||
|
'userInfo',
|
||||||
|
compactionStrategy: (entries, deletedEntries) {
|
||||||
|
return deletedEntries > 2;
|
||||||
|
},
|
||||||
|
);
|
||||||
// 本地缓存
|
// 本地缓存
|
||||||
localCache = await Hive.openBox('localCache');
|
localCache = await Hive.openBox('localCache');
|
||||||
// 设置
|
// 设置
|
||||||
@ -75,8 +72,8 @@ class GStrorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Future<void> close() async {
|
static Future<void> close() async {
|
||||||
user.compact();
|
// user.compact();
|
||||||
user.close();
|
// user.close();
|
||||||
recVideo.compact();
|
recVideo.compact();
|
||||||
recVideo.close();
|
recVideo.close();
|
||||||
userInfo.compact();
|
userInfo.compact();
|
||||||
@ -94,19 +91,6 @@ class GStrorage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 约定 key
|
|
||||||
class UserBoxKey {
|
|
||||||
static const String userName = 'userName';
|
|
||||||
// 头像
|
|
||||||
static const String userFace = 'userFace';
|
|
||||||
// mid
|
|
||||||
static const String userMid = 'userMid';
|
|
||||||
// 登录状态
|
|
||||||
static const String userLogin = 'userLogin';
|
|
||||||
// 凭证
|
|
||||||
static const String accessKey = 'accessKey';
|
|
||||||
}
|
|
||||||
|
|
||||||
class SettingBoxKey {
|
class SettingBoxKey {
|
||||||
static const String themeMode = 'themeMode';
|
static const String themeMode = 'themeMode';
|
||||||
static const String feedBackEnable = 'feedBackEnable';
|
static const String feedBackEnable = 'feedBackEnable';
|
||||||
@ -130,6 +114,12 @@ class SettingBoxKey {
|
|||||||
class LocalCacheKey {
|
class LocalCacheKey {
|
||||||
// 历史记录暂停状态 默认false 记录
|
// 历史记录暂停状态 默认false 记录
|
||||||
static const String historyPause = 'historyPause';
|
static const String historyPause = 'historyPause';
|
||||||
|
// access_key
|
||||||
|
static const String accessKey = 'accessKey';
|
||||||
|
|
||||||
|
//
|
||||||
|
static const String wbiKeys = 'wbiKeys';
|
||||||
|
static const String timeStamp = 'timeStamp';
|
||||||
}
|
}
|
||||||
|
|
||||||
class VideoBoxKey {
|
class VideoBoxKey {
|
||||||
|
|||||||
@ -109,8 +109,10 @@ class WbiSign {
|
|||||||
// 获取最新的 img_key 和 sub_key 可以从缓存中获取
|
// 获取最新的 img_key 和 sub_key 可以从缓存中获取
|
||||||
static Future<Map<String, dynamic>> getWbiKeys() async {
|
static Future<Map<String, dynamic>> getWbiKeys() async {
|
||||||
DateTime nowDate = DateTime.now();
|
DateTime nowDate = DateTime.now();
|
||||||
if (localCache.get('wbiKeys') != null &&
|
if (localCache.get(LocalCacheKey.wbiKeys) != null &&
|
||||||
DateTime.fromMillisecondsSinceEpoch(localCache.get('timeStamp')).day ==
|
DateTime.fromMillisecondsSinceEpoch(
|
||||||
|
localCache.get(LocalCacheKey.timeStamp))
|
||||||
|
.day ==
|
||||||
nowDate.day) {
|
nowDate.day) {
|
||||||
Map cacheWbiKeys = localCache.get('wbiKeys');
|
Map cacheWbiKeys = localCache.get('wbiKeys');
|
||||||
return Map<String, dynamic>.from(cacheWbiKeys);
|
return Map<String, dynamic>.from(cacheWbiKeys);
|
||||||
@ -129,8 +131,8 @@ class WbiSign {
|
|||||||
.substring(subUrl.lastIndexOf('/') + 1, subUrl.length)
|
.substring(subUrl.lastIndexOf('/') + 1, subUrl.length)
|
||||||
.split('.')[0]
|
.split('.')[0]
|
||||||
};
|
};
|
||||||
localCache.put('wbiKeys', wbiKeys);
|
localCache.put(LocalCacheKey.wbiKeys, wbiKeys);
|
||||||
localCache.put('timeStamp', nowDate.millisecondsSinceEpoch);
|
localCache.put(LocalCacheKey.timeStamp, nowDate.millisecondsSinceEpoch);
|
||||||
return wbiKeys;
|
return wbiKeys;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user