mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-06-08 12:04:50 +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/login.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/pages/login/geetest/geetest_webview_dialog.dart';
|
||||
import 'package:PiliPlus/utils/accounts.dart';
|
||||
@@ -40,7 +41,7 @@ class LoginPageController extends GetxController
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
tabController = TabController(length: 3, vsync: this)
|
||||
tabController = TabController(length: LoginType.values.length, vsync: this)
|
||||
..addListener(_handleTabChange);
|
||||
}
|
||||
|
||||
@@ -95,7 +96,7 @@ class LoginPageController extends GetxController
|
||||
}
|
||||
|
||||
void _handleTabChange() {
|
||||
if (tabController.index == 2) {
|
||||
if (tabController.index == LoginType.qrcode.index) {
|
||||
if (qrCodeTimer == null || !qrCodeTimer!.isActive) {
|
||||
refreshQRCode();
|
||||
}
|
||||
@@ -148,7 +149,7 @@ class LoginPageController extends GetxController
|
||||
);
|
||||
if (result.data['code'] == 0) {
|
||||
try {
|
||||
await LoginAccount(
|
||||
final account = LoginAccount(
|
||||
BiliCookieJar.fromJson(
|
||||
Map.fromEntries(
|
||||
cookieTextController.text.split(';').map((item) {
|
||||
@@ -159,8 +160,14 @@ class LoginPageController extends GetxController
|
||||
),
|
||||
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('登录成功');
|
||||
Get.back();
|
||||
} catch (e) {
|
||||
@@ -452,16 +459,22 @@ class LoginPageController extends GetxController
|
||||
SmartDialog.showToast('登录成功');
|
||||
} else {
|
||||
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) {
|
||||
SmartDialog.showToast('请先登录');
|
||||
return Get.toNamed('/loginPage');
|
||||
}
|
||||
final selectAccount = List.of(Accounts.accountMode);
|
||||
final selectAccount = accounts ?? List.of(Accounts.accountMode);
|
||||
final options = {
|
||||
AnonymousAccount(): '0',
|
||||
...Accounts.account.toMap().map(
|
||||
@@ -471,6 +484,7 @@ class LoginPageController extends GetxController
|
||||
bool quickSelect = selectAccount.every((e) => e == selectAccount.first);
|
||||
return showDialog(
|
||||
context: context,
|
||||
barrierDismissible: false,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Row(
|
||||
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/scroll_physics.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/webview/view.dart';
|
||||
import 'package:PiliPlus/utils/extension/size_ext.dart';
|
||||
@@ -54,7 +55,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
'剩余有效时间: ${_loginPageCtr.qrCodeLeftTime} 秒',
|
||||
style: TextStyle(
|
||||
fontFeatures: const [FontFeature.tabularFigures()],
|
||||
color: theme.colorScheme.primaryFixedDim,
|
||||
color: theme.colorScheme.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -368,29 +369,16 @@ class _LoginPageState extends State<LoginPage> {
|
||||
child: TabBar(
|
||||
isScrollable: true,
|
||||
dividerHeight: 0,
|
||||
tabs: const [
|
||||
Tab(
|
||||
tabs: LoginType.values
|
||||
.map(
|
||||
(e) => Tab(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [Icon(Icons.password), Text(' 密码')],
|
||||
mainAxisSize: .min,
|
||||
children: [e.icon, Text(' ${e.label}')],
|
||||
),
|
||||
),
|
||||
Tab(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [Icon(Icons.qr_code), Text(' 扫码')],
|
||||
),
|
||||
),
|
||||
Tab(
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.cookie_outlined),
|
||||
Text(' Cookie'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
.toList(),
|
||||
controller: _loginPageCtr.tabController,
|
||||
),
|
||||
),
|
||||
@@ -400,11 +388,9 @@ class _LoginPageState extends State<LoginPage> {
|
||||
),
|
||||
if (isPortrait)
|
||||
TabBar(
|
||||
tabs: const [
|
||||
Tab(icon: Icon(Icons.password), text: '密码'),
|
||||
Tab(icon: Icon(Icons.qr_code), text: '扫码'),
|
||||
Tab(icon: Icon(Icons.cookie_outlined), text: 'Cookie'),
|
||||
],
|
||||
tabs: LoginType.values
|
||||
.map((e) => Tab(icon: e.icon, text: e.label))
|
||||
.toList(),
|
||||
controller: _loginPageCtr.tabController,
|
||||
),
|
||||
Expanded(
|
||||
|
||||
Reference in New Issue
Block a user