From 817ad978e21a57608ba23556b6ef0916132e8f26 Mon Sep 17 00:00:00 2001 From: jyuesong <425698907@qq.com> Date: Mon, 30 May 2022 16:41:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9logo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/base/routes.dart | 6 - lib/module/others/change_account_page.dart | 316 --------------------- lib/module/others/other_page.dart | 35 --- 3 files changed, 357 deletions(-) delete mode 100644 lib/module/others/change_account_page.dart diff --git a/lib/base/routes.dart b/lib/base/routes.dart index 8200f7f..2c9111a 100644 --- a/lib/base/routes.dart +++ b/lib/base/routes.dart @@ -7,7 +7,6 @@ import 'package:qinglong_app/module/env/env_detail_page.dart'; import 'package:qinglong_app/module/home/home_page.dart'; import 'package:qinglong_app/module/login/login_page.dart'; import 'package:qinglong_app/module/others/about_page.dart'; -import 'package:qinglong_app/module/others/change_account_page.dart'; import 'package:qinglong_app/module/others/dependencies/add_dependency_page.dart'; import 'package:qinglong_app/module/others/dependencies/dependency_page.dart'; import 'package:qinglong_app/module/others/login_log/login_log_page.dart'; @@ -42,7 +41,6 @@ class Routes { static const String routeUpdatePassword = "/updatePassword"; static const String routeAbout = "/about"; static const String routeTheme = "/theme"; - static const String routeChangeAccount = "/changeAccount"; static Route? generateRoute(RouteSettings settings) { switch (settings.name) { @@ -140,10 +138,6 @@ class Routes { return CupertinoPageRoute( builder: (context) => const ThemePage(), ); - case routeChangeAccount: - return CupertinoPageRoute( - builder: (context) => const ChangeAccountPage(), - ); case routeScriptUpdate: return CupertinoPageRoute( builder: (context) => ScriptEditPage( diff --git a/lib/module/others/change_account_page.dart b/lib/module/others/change_account_page.dart deleted file mode 100644 index 1585d8a..0000000 --- a/lib/module/others/change_account_page.dart +++ /dev/null @@ -1,316 +0,0 @@ -import 'package:flutter/cupertino.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_riverpod/flutter_riverpod.dart'; -import 'package:flutter_slidable/flutter_slidable.dart'; -import 'package:qinglong_app/base/http/api.dart'; -import 'package:qinglong_app/base/http/http.dart'; -import 'package:qinglong_app/base/ql_app_bar.dart'; -import 'package:qinglong_app/base/routes.dart'; -import 'package:qinglong_app/base/theme.dart'; -import 'package:qinglong_app/base/userinfo_viewmodel.dart'; -import 'package:qinglong_app/utils/extension.dart'; -import 'package:qinglong_app/utils/login_helper.dart'; - -import '../../main.dart'; - -class ChangeAccountPage extends ConsumerStatefulWidget { - const ChangeAccountPage({Key? key}) : super(key: key); - - @override - _ChangeAccountPageState createState() => _ChangeAccountPageState(); -} - -class _ChangeAccountPageState extends ConsumerState { - String isLoginingHost = ""; - String preHost = ""; - - @override - void initState() { - super.initState(); - preHost = getIt().historyAccounts.first.host ?? ""; - } - - @override - Widget build(BuildContext context) { - return Scaffold( - appBar: QlAppBar( - canBack: true, - title: "切换账号", - ), - body: SingleChildScrollView( - child: SizedBox( - width: MediaQuery.of(context).size.width, - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - SizedBox( - height: MediaQuery.of(context).size.height / 10, - ), - Text( - "轻触账号以切换登录", - style: TextStyle( - color: ref.watch(themeProvider).themeColor.titleColor(), - fontSize: 22, - ), - ), - const SizedBox( - height: 30, - ), - Padding( - padding: const EdgeInsets.symmetric( - horizontal: 15, - ), - child: ListView.separated( - shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), - itemBuilder: (context, index) { - if (index == getIt().historyAccounts.length) { - return addAccount(); - } - return ClipRRect( - borderRadius: BorderRadius.circular(10), - child: Container( - color: ref.watch(themeProvider).themeColor.settingBordorColor(), - child: buildCell(index), - ), - ); - }, - separatorBuilder: (_, __) { - return const SizedBox( - height: 10, - ); - }, - itemCount: getIt().historyAccounts.length + 1), - ), - ], - ), - ), - ), - ); - } - - Widget buildCell(int index) { - Widget child = ListTile( - title: Text( - getIt().historyAccounts[index].host ?? "", - maxLines: 1, - overflow: TextOverflow.ellipsis, - ), - contentPadding: const EdgeInsets.symmetric( - horizontal: 15, - ), - minVerticalPadding: 10, - subtitle: Padding( - padding: const EdgeInsets.only(top: 10.0), - child: Text( - getIt().historyAccounts[index].userName ?? "", - ), - ), - trailing: index == 0 - ? Container( - padding: const EdgeInsets.symmetric( - horizontal: 5, - ), - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(5), - border: Border.all(color: ref.watch(themeProvider).primaryColor, width: 1), - ), - child: Text( - "已登录", - style: TextStyle(color: ref.watch(themeProvider).primaryColor, fontSize: 12), - ), - ) - : (isLoginingHost.isNotEmpty - ? SizedBox( - width: 15, - height: 15, - child: CircularProgressIndicator( - strokeWidth: 2, - color: ref.watch(themeProvider).primaryColor, - ), - ) - : const SizedBox.shrink()), - ); - - if (getIt().historyAccounts[index].host == getIt().host) { - return child; - } - - return Slidable( - key: ValueKey(index), - endActionPane: ActionPane( - motion: const ScrollMotion(), - extentRatio: 0.15, - children: [ - SlidableAction( - backgroundColor: Colors.red, - flex: 1, - onPressed: (_) { - getIt().removeHistoryAccount(getIt().historyAccounts[index].host); - setState(() {}); - }, - foregroundColor: Colors.white, - icon: CupertinoIcons.delete, - ), - ], - ), - child: GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - loginNewByBean(getIt().historyAccounts[index]); - }, - child: child), - ); - } - - LoginHelper? helper; - - void loginNewByBean(UserInfoBean historyAccount) async { - isLoginingHost = historyAccount.host ?? ""; - setState(() {}); - helper = LoginHelper( - historyAccount.useSecretLogined, - historyAccount.host ?? "", - historyAccount.userName ?? "", - historyAccount.password ?? "", - true, - ); - var response = await helper!.login(); - dealLoginResponse(response); - } - - void dealLoginResponse(int response) { - if (response == LoginHelper.success) { - Navigator.of(context).pushNamedAndRemoveUntil(Routes.routeHomePage, (_) => false); - } else if (response == LoginHelper.failed) { - loginFailed(); - } else { - twoFact(); - } - } - - void loginFailed() { - isLoginingHost = ""; - Http.clear(); - getIt().updateHost(preHost); - setState(() {}); - } - - void twoFact() { - String twoFact = ""; - showCupertinoDialog( - context: context, - builder: (_) => CupertinoAlertDialog( - title: const Text("两步验证"), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - Material( - color: Colors.transparent, - child: TextField( - onChanged: (value) { - twoFact = value; - }, - maxLines: 1, - keyboardType: TextInputType.number, - decoration: const InputDecoration( - contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5), - hintText: "请输入code", - ), - autofocus: true, - ), - ), - ], - ), - actions: [ - CupertinoDialogAction( - child: const Text( - "取消", - style: TextStyle( - color: Color(0xff999999), - ), - ), - onPressed: () { - Navigator.of(context).pop(); - }, - ), - CupertinoDialogAction( - child: Text( - "确定", - style: TextStyle( - color: ref.watch(themeProvider).primaryColor, - ), - ), - onPressed: () async { - Navigator.of(context).pop(true); - if (helper != null) { - var response = await helper!.loginTwice(twoFact); - dealLoginResponse(response); - } else { - "状态异常".toast(); - } - }, - ), - ], - )).then((value) { - if (value == null) { - isLoginingHost = ""; - setState(() {}); - } - }); - } - - Widget addAccount() { - return GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - Navigator.of(context).pushNamedAndRemoveUntil( - Routes.routeLogin, - (_) => false, - arguments: true, - ); - }, - child: ClipRRect( - borderRadius: BorderRadius.circular(10), - child: Container( - padding: const EdgeInsets.symmetric( - vertical: 15, - horizontal: 15, - ), - decoration: BoxDecoration( - color: ref.watch(themeProvider).themeColor.settingBordorColor(), - borderRadius: BorderRadius.circular(15), - ), - child: Row( - children: [ - Container( - width: 40, - height: 40, - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(5), - border: Border.all( - color: ref.watch(themeProvider).themeColor.descColor(), - ), - ), - child: Icon( - CupertinoIcons.add, - color: ref.watch(themeProvider).themeColor.descColor(), - ), - ), - const SizedBox( - width: 15, - ), - Text( - "添加账号", - style: TextStyle( - color: ref.watch(themeProvider).themeColor.titleColor(), - fontSize: 16, - ), - ), - ], - ), - ), - ), - ); - } -} diff --git a/lib/module/others/other_page.dart b/lib/module/others/other_page.dart index b251824..e65d464 100644 --- a/lib/module/others/other_page.dart +++ b/lib/module/others/other_page.dart @@ -304,41 +304,6 @@ class _OtherPageState extends ConsumerState { const Divider( indent: 15, ), - GestureDetector( - behavior: HitTestBehavior.opaque, - onTap: () { - Navigator.of(context).pushNamed(Routes.routeChangeAccount); - }, - child: Padding( - padding: const EdgeInsets.only( - left: 15, - right: 15, - top: 5, - bottom: 5, - ), - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - "切换账号", - style: TextStyle( - color: ref.watch(themeProvider).themeColor.titleColor(), - fontSize: 16, - ), - ), - const Spacer(), - const Icon( - CupertinoIcons.right_chevron, - size: 16, - ), - ], - ), - ), - ), - const Divider( - indent: 15, - ), GestureDetector( behavior: HitTestBehavior.opaque, onTap: () {