mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-21 08:38:37 +00:00
opt: login/logout
Signed-off-by: bggRGjQaUbCoE <githubaccount56556@proton.me>
This commit is contained in:
@@ -14,14 +14,13 @@ class MineController extends GetxController {
|
||||
Rx<UserInfoData> userInfo = UserInfoData().obs;
|
||||
// 用户状态 动态、关注、粉丝
|
||||
Rx<UserStat> userStat = UserStat().obs;
|
||||
RxBool userLogin = false.obs;
|
||||
|
||||
RxBool isLogin = false.obs;
|
||||
|
||||
Rx<ThemeType> themeType = ThemeType.system.obs;
|
||||
|
||||
static Box get setting => GStorage.setting;
|
||||
|
||||
static RxBool anonymity =
|
||||
(setting.get(SettingBoxKey.anonymity, defaultValue: false) as bool).obs;
|
||||
|
||||
ThemeType get nextThemeType =>
|
||||
ThemeType.values[(themeType.value.index + 1) % ThemeType.values.length];
|
||||
|
||||
@@ -32,23 +31,12 @@ class MineController extends GetxController {
|
||||
dynamic userInfoCache = GStorage.userInfo.get('userInfoCache');
|
||||
if (userInfoCache != null) {
|
||||
userInfo.value = userInfoCache;
|
||||
userLogin.value = true;
|
||||
isLogin.value = true;
|
||||
}
|
||||
|
||||
// themeType.value = ThemeType.values[GlobalData().themeMode];
|
||||
// anonymity = setting.get(SettingBoxKey.anonymity, defaultValue: false);
|
||||
}
|
||||
|
||||
onLogin() async {
|
||||
if (!userLogin.value) {
|
||||
// Get.toNamed(
|
||||
// '/webview',
|
||||
// parameters: {
|
||||
// 'url': 'https://passport.bilibili.com/h5-app/passport/login',
|
||||
// 'type': 'login',
|
||||
// 'pageTitle': '登录bilibili',
|
||||
// },
|
||||
// );
|
||||
if (!isLogin.value) {
|
||||
Get.toNamed('/loginPage', preventDuplicates: false);
|
||||
} else {
|
||||
int mid = userInfo.value.mid!;
|
||||
@@ -59,7 +47,7 @@ class MineController extends GetxController {
|
||||
}
|
||||
|
||||
Future queryUserInfo() async {
|
||||
if (!userLogin.value) {
|
||||
if (!isLogin.value) {
|
||||
return {'status': false};
|
||||
}
|
||||
var res = await UserHttp.userInfo();
|
||||
@@ -67,12 +55,9 @@ class MineController extends GetxController {
|
||||
if (res['data'].isLogin) {
|
||||
userInfo.value = res['data'];
|
||||
GStorage.userInfo.put('userInfoCache', res['data']);
|
||||
userLogin.value = true;
|
||||
} else {
|
||||
resetUserInfo();
|
||||
isLogin.value = true;
|
||||
}
|
||||
} else {
|
||||
// resetUserInfo();
|
||||
SmartDialog.showToast(res['msg']);
|
||||
}
|
||||
await queryUserStatOwner();
|
||||
@@ -87,14 +72,6 @@ class MineController extends GetxController {
|
||||
return res;
|
||||
}
|
||||
|
||||
Future resetUserInfo() async {
|
||||
userInfo.value = UserInfoData();
|
||||
userStat.value = UserStat();
|
||||
GStorage.userInfo.delete('userInfoCache');
|
||||
userLogin.value = false;
|
||||
anonymity.value = false;
|
||||
}
|
||||
|
||||
static onChangeAnonymity(BuildContext context) {
|
||||
anonymity.value = !anonymity.value;
|
||||
if (anonymity.value) {
|
||||
@@ -216,7 +193,7 @@ class MineController extends GetxController {
|
||||
}
|
||||
|
||||
pushFollow() {
|
||||
if (!userLogin.value) {
|
||||
if (!isLogin.value) {
|
||||
SmartDialog.showToast('账号未登录');
|
||||
return;
|
||||
}
|
||||
@@ -224,7 +201,7 @@ class MineController extends GetxController {
|
||||
}
|
||||
|
||||
pushFans() {
|
||||
if (!userLogin.value) {
|
||||
if (!isLogin.value) {
|
||||
SmartDialog.showToast('账号未登录');
|
||||
return;
|
||||
}
|
||||
@@ -232,7 +209,7 @@ class MineController extends GetxController {
|
||||
}
|
||||
|
||||
pushDynamic() {
|
||||
if (!userLogin.value) {
|
||||
if (!isLogin.value) {
|
||||
SmartDialog.showToast('账号未登录');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:PiliPlus/utils/storage.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -18,29 +16,9 @@ class MinePage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _MinePageState extends State<MinePage> {
|
||||
final MineController mineController = Get.put(MineController())
|
||||
..themeType.value = ThemeType.values[GStorage.themeTypeInt];
|
||||
late Future _futureBuilderFuture;
|
||||
StreamSubscription? _listener;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_futureBuilderFuture = mineController.queryUserInfo();
|
||||
|
||||
_listener = mineController.userLogin.listen((status) {
|
||||
if (mounted) {
|
||||
_futureBuilderFuture = mineController.queryUserInfo();
|
||||
_futureBuilderFuture.then((value) => setState(() {}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_listener?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
final MineController _mineController = Get.put(MineController())
|
||||
..themeType.value = ThemeType.values[GStorage.themeTypeInt]
|
||||
..queryUserInfo();
|
||||
|
||||
Widget get _header => FittedBox(
|
||||
child: Row(
|
||||
@@ -85,14 +63,14 @@ class _MinePageState extends State<MinePage> {
|
||||
tapTargetSize:
|
||||
MaterialTapTargetSize.shrinkWrap, // the '2023' part
|
||||
),
|
||||
tooltip: '切换至${switch (mineController.nextThemeType) {
|
||||
tooltip: '切换至${switch (_mineController.nextThemeType) {
|
||||
ThemeType.light => '浅色',
|
||||
ThemeType.dark => '深色',
|
||||
ThemeType.system => '跟随系统',
|
||||
}}主题',
|
||||
onPressed: mineController.onChangeTheme,
|
||||
onPressed: _mineController.onChangeTheme,
|
||||
icon: Icon(
|
||||
switch (mineController.themeType.value) {
|
||||
switch (_mineController.themeType.value) {
|
||||
ThemeType.light => MdiIcons.weatherSunny,
|
||||
ThemeType.dark => MdiIcons.weatherNight,
|
||||
ThemeType.system => MdiIcons.themeLightDark,
|
||||
@@ -132,25 +110,13 @@ class _MinePageState extends State<MinePage> {
|
||||
const SizedBox(height: 8),
|
||||
_header,
|
||||
const SizedBox(height: 10),
|
||||
FutureBuilder(
|
||||
future: _futureBuilderFuture,
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.done) {
|
||||
if (snapshot.data == null || !snapshot.data['status']) {
|
||||
return userInfoBuild(mineController, context);
|
||||
}
|
||||
return Obx(() => userInfoBuild(mineController, context));
|
||||
} else {
|
||||
return userInfoBuild(mineController, context);
|
||||
}
|
||||
},
|
||||
),
|
||||
Obx(userInfoBuild),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget userInfoBuild(_mineController, context) {
|
||||
Widget userInfoBuild() {
|
||||
LevelInfo? levelInfo = _mineController.userInfo.value.levelInfo;
|
||||
TextStyle style = TextStyle(
|
||||
fontSize: Theme.of(context).textTheme.titleMedium!.fontSize,
|
||||
|
||||
Reference in New Issue
Block a user