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