opt: 登录逻辑
This commit is contained in:
@ -62,7 +62,10 @@ class Request {
|
||||
// for (var i in cookies) {
|
||||
// print(i);
|
||||
// }
|
||||
var token = cookies.firstWhere((e) => e.name == 'bili_jct').value;
|
||||
String token = '';
|
||||
if (cookies.where((e) => e.name == 'bili_jct').isNotEmpty) {
|
||||
token = cookies.firstWhere((e) => e.name == 'bili_jct').value;
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
@ -91,8 +94,8 @@ class Request {
|
||||
..add(ApiInterceptor())
|
||||
// 日志拦截器 输出请求、响应内容
|
||||
..add(LogInterceptor(
|
||||
request: true,
|
||||
requestHeader: true,
|
||||
request: false,
|
||||
requestHeader: false,
|
||||
responseHeader: false,
|
||||
));
|
||||
dio.transformer = BackgroundTransformer();
|
||||
|
@ -3,7 +3,12 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/common/widgets/network_img_layer.dart';
|
||||
import 'package:pilipala/pages/mine/view.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
|
||||
Box userInfoCache = GStrorage.userInfo;
|
||||
|
||||
class HomeAppBar extends StatelessWidget {
|
||||
const HomeAppBar({super.key});
|
||||
@ -49,21 +54,40 @@ class HomeAppBar extends StatelessWidget {
|
||||
// onPressed: () {},
|
||||
// icon: const Icon(CupertinoIcons.bell, size: 22),
|
||||
// ),
|
||||
IconButton(
|
||||
onPressed: () {
|
||||
Get.bottomSheet(
|
||||
Builder(builder: (context) {
|
||||
return const SizedBox(
|
||||
height: 450,
|
||||
child: MinePage(),
|
||||
);
|
||||
}),
|
||||
/// TODO
|
||||
if (userInfoCache.get('userInfoCache') != null) ...[
|
||||
GestureDetector(
|
||||
onTap: () => showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (_) => const SizedBox(
|
||||
height: 450,
|
||||
child: MinePage(),
|
||||
),
|
||||
clipBehavior: Clip.hardEdge,
|
||||
isScrollControlled: true,
|
||||
);
|
||||
},
|
||||
icon: const Icon(CupertinoIcons.person, size: 22),
|
||||
),
|
||||
),
|
||||
child: NetworkImgLayer(
|
||||
type: 'avatar',
|
||||
width: 32,
|
||||
height: 32,
|
||||
src: userInfoCache.get('userInfoCache').face,
|
||||
),
|
||||
),
|
||||
] else ...[
|
||||
IconButton(
|
||||
onPressed: () => showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (_) => const SizedBox(
|
||||
height: 450,
|
||||
child: MinePage(),
|
||||
),
|
||||
clipBehavior: Clip.hardEdge,
|
||||
isScrollControlled: true,
|
||||
),
|
||||
icon: const Icon(CupertinoIcons.person, size: 22),
|
||||
),
|
||||
],
|
||||
|
||||
const SizedBox(width: 10)
|
||||
],
|
||||
elevation: 0,
|
||||
|
@ -19,13 +19,15 @@ class MineController extends GetxController {
|
||||
super.onInit();
|
||||
|
||||
if (userInfoCache.get('userInfoCache') != null) {
|
||||
print(userInfoCache.get('userInfoCache'));
|
||||
userInfo.value = userInfoCache.get('userInfoCache');
|
||||
}
|
||||
}
|
||||
|
||||
onLogin() {
|
||||
onLogin() async {
|
||||
if (!userLogin.value) {
|
||||
/// TODO
|
||||
Get.back();
|
||||
await Future.delayed(const Duration(milliseconds: 150));
|
||||
Get.toNamed(
|
||||
'/webview',
|
||||
parameters: {
|
||||
|
@ -3,22 +3,22 @@ import 'package:hive/hive.dart';
|
||||
import 'package:pilipala/http/init.dart';
|
||||
import 'package:pilipala/pages/mine/controller.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
|
||||
|
||||
class SettingController extends GetxController {
|
||||
Box user = GStrorage.user;
|
||||
RxBool userLogin = false.obs;
|
||||
Box userInfoCache = GStrorage.userInfo;
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
userLogin.value = user.get(UserBoxKey.userLogin) ?? false;
|
||||
print(userLogin.value);
|
||||
}
|
||||
|
||||
loginOut() async {
|
||||
await Request.removeCookie();
|
||||
await Get.find<MineController>().resetUserInfo();
|
||||
userLogin.value = user.get(UserBoxKey.userLogin) ?? false;
|
||||
userInfoCache.put('userInfoCache', null);
|
||||
}
|
||||
}
|
||||
|
@ -128,6 +128,10 @@ class VideoIntroController extends GetxController {
|
||||
|
||||
// 一键三连
|
||||
Future actionOneThree() async {
|
||||
if (user.get(UserBoxKey.userMid) == null) {
|
||||
SmartDialog.showToast('账号未登录');
|
||||
return;
|
||||
}
|
||||
if (hasLike.value && hasCoin.value && hasFav.value) {
|
||||
// 已点赞、投币、收藏
|
||||
SmartDialog.showToast('🙏 UP已经收到了~');
|
||||
@ -185,6 +189,10 @@ class VideoIntroController extends GetxController {
|
||||
|
||||
// 投币
|
||||
Future actionCoinVideo() async {
|
||||
if (user.get(UserBoxKey.userMid) == null) {
|
||||
SmartDialog.showToast('账号未登录');
|
||||
return;
|
||||
}
|
||||
showDialog(
|
||||
context: Get.context!,
|
||||
builder: (context) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
@ -12,6 +13,7 @@ import 'package:pilipala/common/widgets/stat/danmu.dart';
|
||||
import 'package:pilipala/common/widgets/stat/view.dart';
|
||||
import 'package:pilipala/models/video_detail_res.dart';
|
||||
import 'package:pilipala/pages/video/detail/introduction/controller.dart';
|
||||
import 'package:pilipala/utils/storage.dart';
|
||||
import 'package:pilipala/utils/utils.dart';
|
||||
|
||||
class VideoIntroPanel extends StatefulWidget {
|
||||
@ -109,6 +111,10 @@ class _VideoInfoState extends State<VideoInfo> with TickerProviderStateMixin {
|
||||
}
|
||||
|
||||
showFavBottomSheet() {
|
||||
if (videoIntroController.user.get(UserBoxKey.userMid) == null) {
|
||||
SmartDialog.showToast('账号未登录');
|
||||
return;
|
||||
}
|
||||
Get.bottomSheet(
|
||||
useRootNavigator: true,
|
||||
isScrollControlled: true,
|
||||
|
@ -67,7 +67,10 @@ class WebviewController extends GetxController {
|
||||
SmartDialog.showToast('登录成功');
|
||||
Box user = GStrorage.user;
|
||||
user.put(UserBoxKey.userLogin, true);
|
||||
Box userInfoCache = GStrorage.userInfo;
|
||||
userInfoCache.put('userInfoCache', result['data']);
|
||||
Get.find<MineController>().userInfo.value = result['data'];
|
||||
Get.find<MineController>().onInit();
|
||||
Get.find<HomeController>().queryRcmdFeed('onRefresh');
|
||||
Get.back();
|
||||
}
|
||||
|
Reference in New Issue
Block a user