mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-08 20:14:51 +08:00
14
lib/models/common/login_type.dart
Normal file
14
lib/models/common/login_type.dart
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
import 'package:PiliPlus/models/common/enum_with_label.dart';
|
||||||
|
import 'package:flutter/material.dart' show Icon, Icons;
|
||||||
|
|
||||||
|
enum LoginType with EnumWithLabel {
|
||||||
|
psw('密码', Icon(Icons.password)),
|
||||||
|
qrcode('二维码', Icon(Icons.qr_code)),
|
||||||
|
cookie('Cookie', Icon(Icons.cookie_outlined));
|
||||||
|
|
||||||
|
@override
|
||||||
|
final String label;
|
||||||
|
final Icon icon;
|
||||||
|
|
||||||
|
const LoginType(this.label, this.icon);
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import 'package:PiliPlus/http/init.dart';
|
|||||||
import 'package:PiliPlus/http/loading_state.dart';
|
import 'package:PiliPlus/http/loading_state.dart';
|
||||||
import 'package:PiliPlus/http/login.dart';
|
import 'package:PiliPlus/http/login.dart';
|
||||||
import 'package:PiliPlus/models/common/account_type.dart';
|
import 'package:PiliPlus/models/common/account_type.dart';
|
||||||
|
import 'package:PiliPlus/models/common/login_type.dart';
|
||||||
import 'package:PiliPlus/models/login/model.dart';
|
import 'package:PiliPlus/models/login/model.dart';
|
||||||
import 'package:PiliPlus/pages/login/geetest/geetest_webview_dialog.dart';
|
import 'package:PiliPlus/pages/login/geetest/geetest_webview_dialog.dart';
|
||||||
import 'package:PiliPlus/utils/accounts.dart';
|
import 'package:PiliPlus/utils/accounts.dart';
|
||||||
@@ -40,7 +41,7 @@ class LoginPageController extends GetxController
|
|||||||
@override
|
@override
|
||||||
void onInit() {
|
void onInit() {
|
||||||
super.onInit();
|
super.onInit();
|
||||||
tabController = TabController(length: 3, vsync: this)
|
tabController = TabController(length: LoginType.values.length, vsync: this)
|
||||||
..addListener(_handleTabChange);
|
..addListener(_handleTabChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +96,7 @@ class LoginPageController extends GetxController
|
|||||||
}
|
}
|
||||||
|
|
||||||
void _handleTabChange() {
|
void _handleTabChange() {
|
||||||
if (tabController.index == 2) {
|
if (tabController.index == LoginType.qrcode.index) {
|
||||||
if (qrCodeTimer == null || !qrCodeTimer!.isActive) {
|
if (qrCodeTimer == null || !qrCodeTimer!.isActive) {
|
||||||
refreshQRCode();
|
refreshQRCode();
|
||||||
}
|
}
|
||||||
@@ -148,7 +149,7 @@ class LoginPageController extends GetxController
|
|||||||
);
|
);
|
||||||
if (result.data['code'] == 0) {
|
if (result.data['code'] == 0) {
|
||||||
try {
|
try {
|
||||||
await LoginAccount(
|
final account = LoginAccount(
|
||||||
BiliCookieJar.fromJson(
|
BiliCookieJar.fromJson(
|
||||||
Map.fromEntries(
|
Map.fromEntries(
|
||||||
cookieTextController.text.split(';').map((item) {
|
cookieTextController.text.split(';').map((item) {
|
||||||
@@ -159,8 +160,14 @@ class LoginPageController extends GetxController
|
|||||||
),
|
),
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
).onChange();
|
);
|
||||||
if (!Accounts.main.isLogin) await switchAccountDialog(Get.context!);
|
await account.onChange();
|
||||||
|
if (!Accounts.main.isLogin) {
|
||||||
|
await switchAccountDialog(
|
||||||
|
Get.context!,
|
||||||
|
accounts: List.filled(AccountType.values.length, account),
|
||||||
|
);
|
||||||
|
}
|
||||||
SmartDialog.showToast('登录成功');
|
SmartDialog.showToast('登录成功');
|
||||||
Get.back();
|
Get.back();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -452,16 +459,22 @@ class LoginPageController extends GetxController
|
|||||||
SmartDialog.showToast('登录成功');
|
SmartDialog.showToast('登录成功');
|
||||||
} else {
|
} else {
|
||||||
SmartDialog.showToast('登录成功, 请先设置账号模式');
|
SmartDialog.showToast('登录成功, 请先设置账号模式');
|
||||||
await switchAccountDialog(Get.context!);
|
await switchAccountDialog(
|
||||||
|
Get.context!,
|
||||||
|
accounts: List.filled(AccountType.values.length, account),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<void>? switchAccountDialog(BuildContext context) {
|
static Future<void>? switchAccountDialog(
|
||||||
|
BuildContext context, {
|
||||||
|
List<Account>? accounts,
|
||||||
|
}) {
|
||||||
if (Accounts.account.isEmpty) {
|
if (Accounts.account.isEmpty) {
|
||||||
SmartDialog.showToast('请先登录');
|
SmartDialog.showToast('请先登录');
|
||||||
return Get.toNamed('/loginPage');
|
return Get.toNamed('/loginPage');
|
||||||
}
|
}
|
||||||
final selectAccount = List.of(Accounts.accountMode);
|
final selectAccount = accounts ?? List.of(Accounts.accountMode);
|
||||||
final options = {
|
final options = {
|
||||||
AnonymousAccount(): '0',
|
AnonymousAccount(): '0',
|
||||||
...Accounts.account.toMap().map(
|
...Accounts.account.toMap().map(
|
||||||
@@ -471,6 +484,7 @@ class LoginPageController extends GetxController
|
|||||||
bool quickSelect = selectAccount.every((e) => e == selectAccount.first);
|
bool quickSelect = selectAccount.every((e) => e == selectAccount.first);
|
||||||
return showDialog(
|
return showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
|
barrierDismissible: false,
|
||||||
builder: (context) => AlertDialog(
|
builder: (context) => AlertDialog(
|
||||||
title: Row(
|
title: Row(
|
||||||
crossAxisAlignment: .start,
|
crossAxisAlignment: .start,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:PiliPlus/common/widgets/loading_widget/http_error.dart';
|
|||||||
import 'package:PiliPlus/common/widgets/loading_widget/loading_widget.dart';
|
import 'package:PiliPlus/common/widgets/loading_widget/loading_widget.dart';
|
||||||
import 'package:PiliPlus/common/widgets/scroll_physics.dart';
|
import 'package:PiliPlus/common/widgets/scroll_physics.dart';
|
||||||
import 'package:PiliPlus/http/loading_state.dart';
|
import 'package:PiliPlus/http/loading_state.dart';
|
||||||
|
import 'package:PiliPlus/models/common/login_type.dart';
|
||||||
import 'package:PiliPlus/pages/login/controller.dart';
|
import 'package:PiliPlus/pages/login/controller.dart';
|
||||||
import 'package:PiliPlus/pages/webview/view.dart';
|
import 'package:PiliPlus/pages/webview/view.dart';
|
||||||
import 'package:PiliPlus/utils/extension/size_ext.dart';
|
import 'package:PiliPlus/utils/extension/size_ext.dart';
|
||||||
@@ -54,7 +55,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
'剩余有效时间: ${_loginPageCtr.qrCodeLeftTime} 秒',
|
'剩余有效时间: ${_loginPageCtr.qrCodeLeftTime} 秒',
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
fontFeatures: const [FontFeature.tabularFigures()],
|
fontFeatures: const [FontFeature.tabularFigures()],
|
||||||
color: theme.colorScheme.primaryFixedDim,
|
color: theme.colorScheme.primary,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -368,29 +369,16 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
child: TabBar(
|
child: TabBar(
|
||||||
isScrollable: true,
|
isScrollable: true,
|
||||||
dividerHeight: 0,
|
dividerHeight: 0,
|
||||||
tabs: const [
|
tabs: LoginType.values
|
||||||
Tab(
|
.map(
|
||||||
child: Row(
|
(e) => Tab(
|
||||||
mainAxisSize: MainAxisSize.min,
|
child: Row(
|
||||||
children: [Icon(Icons.password), Text(' 密码')],
|
mainAxisSize: .min,
|
||||||
),
|
children: [e.icon, Text(' ${e.label}')],
|
||||||
),
|
),
|
||||||
Tab(
|
),
|
||||||
child: Row(
|
)
|
||||||
mainAxisSize: MainAxisSize.min,
|
.toList(),
|
||||||
children: [Icon(Icons.qr_code), Text(' 扫码')],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Tab(
|
|
||||||
child: Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Icon(Icons.cookie_outlined),
|
|
||||||
Text(' Cookie'),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
controller: _loginPageCtr.tabController,
|
controller: _loginPageCtr.tabController,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -400,11 +388,9 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
),
|
),
|
||||||
if (isPortrait)
|
if (isPortrait)
|
||||||
TabBar(
|
TabBar(
|
||||||
tabs: const [
|
tabs: LoginType.values
|
||||||
Tab(icon: Icon(Icons.password), text: '密码'),
|
.map((e) => Tab(icon: e.icon, text: e.label))
|
||||||
Tab(icon: Icon(Icons.qr_code), text: '扫码'),
|
.toList(),
|
||||||
Tab(icon: Icon(Icons.cookie_outlined), text: 'Cookie'),
|
|
||||||
],
|
|
||||||
controller: _loginPageCtr.tabController,
|
controller: _loginPageCtr.tabController,
|
||||||
),
|
),
|
||||||
Expanded(
|
Expanded(
|
||||||
|
|||||||
Reference in New Issue
Block a user