From 130459d6464c4f6a5bd89b799fc6bc6c86a41276 Mon Sep 17 00:00:00 2001 From: jyuesong <425698907@qq.com> Date: Thu, 20 Jan 2022 13:33:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/base/http/api.dart | 15 +++ lib/base/http/http.dart | 11 +- lib/base/http/token_interceptor.dart | 2 +- lib/base/http/url.dart | 1 + lib/base/theme.dart | 10 ++ lib/module/env/env_detail_page.dart | 14 ++- lib/module/env/env_page.dart | 58 +++++----- lib/module/login/login_page.dart | 106 ++++++++++++++---- .../others/dependencies/dependency_page.dart | 14 ++- lib/module/others/other_page.dart | 16 ++- .../others/scripts/script_detail_page.dart | 14 ++- .../task/task_detail/task_detail_page.dart | 14 ++- lib/module/task/task_page.dart | 32 +++++- 13 files changed, 241 insertions(+), 66 deletions(-) diff --git a/lib/base/http/api.dart b/lib/base/http/api.dart index 8629278..508a26e 100644 --- a/lib/base/http/api.dart +++ b/lib/base/http/api.dart @@ -25,6 +25,21 @@ class Api { ); } + static Future> loginTwo( + String userName, + String passWord, + String code, + ) async { + return await Http.put( + Url.loginTwo, + { + "username": userName, + "password": passWord, + "code": code, + }, + ); + } + static Future> loginByClientId( String id, String secret, diff --git a/lib/base/http/http.dart b/lib/base/http/http.dart index 500cb61..f6d0133 100644 --- a/lib/base/http/http.dart +++ b/lib/base/http/http.dart @@ -130,9 +130,14 @@ class Http { if (!getIt().useSecretLogined) { exitLogin(); } - return HttpResponse(success: false, message: "没有该模块的访问权限", code: 0); + return HttpResponse(success: false, message: "没有该模块的访问权限", code: 401); + } + + if (e.response != null && e.response!.data != null) { + return HttpResponse(success: false, message: e.response?.data["message"] ?? e.message, code: e.response?.data["code"] ?? 0); + } else { + return HttpResponse(success: false, message: e.message, code: e.response?.statusCode ?? 0); } - return HttpResponse(success: false, message: e.message, code: 0); } static HttpResponse decodeResponse( @@ -187,7 +192,7 @@ class Http { } else { return HttpResponse( success: false, - code: -1000, + code: response.data["code"], message: response.data["message"], ); } diff --git a/lib/base/http/token_interceptor.dart b/lib/base/http/token_interceptor.dart index db27d7e..294e872 100644 --- a/lib/base/http/token_interceptor.dart +++ b/lib/base/http/token_interceptor.dart @@ -16,7 +16,7 @@ class TokenInterceptor extends Interceptor { options.headers["User-Agent"] = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1"; options.headers["Content-Type"] = "application/json;charset=UTF-8"; - if (options.path != Url.loginByClientId) { + if (options.path != Url.loginByClientId && options.path!= Url.loginTwo) { options.queryParameters["t"] = (DateTime.now().millisecondsSinceEpoch ~/ 1000).toString(); } diff --git a/lib/base/http/url.dart b/lib/base/http/url.dart index f3c0788..7bd8cb4 100644 --- a/lib/base/http/url.dart +++ b/lib/base/http/url.dart @@ -3,6 +3,7 @@ import '../userinfo_viewmodel.dart'; class Url { static get login => "/api/user/login"; + static get loginTwo => "/api/user/two-factor/login"; static const loginByClientId = "/open/auth/token"; static const user = "/api/user"; diff --git a/lib/base/theme.dart b/lib/base/theme.dart index 6736283..7d78418 100644 --- a/lib/base/theme.dart +++ b/lib/base/theme.dart @@ -106,6 +106,11 @@ ThemeData darkTheme = ThemeData.dark().copyWith( }, ), ), + cupertinoOverrideTheme: const NoDefaultCupertinoThemeData( + brightness: Brightness.dark, + primaryColor: Color(0xffffffff), + scaffoldBackgroundColor: Colors.black, + ), ); ThemeData lightTheme = ThemeData.light().copyWith( brightness: Brightness.light, @@ -176,6 +181,11 @@ ThemeData lightTheme = ThemeData.light().copyWith( }, ), ), + cupertinoOverrideTheme: const NoDefaultCupertinoThemeData( + brightness: Brightness.light, + primaryColor: _primaryColor, + scaffoldBackgroundColor: Color(0xfff5f5f5), + ), ); abstract class ThemeColors { diff --git a/lib/module/env/env_detail_page.dart b/lib/module/env/env_detail_page.dart index 85e2e98..fdc3540 100644 --- a/lib/module/env/env_detail_page.dart +++ b/lib/module/env/env_detail_page.dart @@ -235,13 +235,23 @@ class _TaskDetailPageState extends ConsumerState { content: Text("确认删除环境变量 ${widget.envBean.name ?? ""} 吗"), actions: [ CupertinoDialogAction( - child: const Text("取消"), + child: const Text( + "取消", + style: TextStyle( + color: Color(0xff999999), + ), + ), onPressed: () { Navigator.of(context).pop(); }, ), CupertinoDialogAction( - child: const Text("确定"), + child: Text( + "确定", + style: TextStyle( + color: primaryColor, + ), + ), onPressed: () async { Navigator.of(context).pop(); await ref.read(envProvider).delEnv(widget.envBean.sId!); diff --git a/lib/module/env/env_page.dart b/lib/module/env/env_page.dart index 1ad1403..0ba5be8 100644 --- a/lib/module/env/env_page.dart +++ b/lib/module/env/env_page.dart @@ -208,17 +208,6 @@ class EnvItemCell extends StatelessWidget { ), ), ), - const SizedBox( - width: 5, - ), - bean.status == 1 - ? const Icon( - Icons.dnd_forwardslash, - size: 16, - color: Colors.red, - ) - : const SizedBox.shrink(), - const Spacer(), ], ), ), @@ -259,21 +248,30 @@ class EnvItemCell extends StatelessWidget { const SizedBox( width: 5, ), - Expanded( - child: Material( - color: Colors.transparent, - child: Text( - bean.remarks ?? "-", - maxLines: 1, - style: TextStyle( - height: 1, - overflow: TextOverflow.ellipsis, - color: ref.watch(themeProvider).themeColor.descColor(), - fontSize: 12, - ), + Material( + color: Colors.transparent, + child: Text( + bean.remarks ?? "-", + maxLines: 1, + style: TextStyle( + height: 1, + overflow: TextOverflow.ellipsis, + color: ref.watch(themeProvider).themeColor.descColor(), + fontSize: 12, ), ), ), + const SizedBox( + width: 5, + ), + bean.status == 1 + ? const Icon( + Icons.dnd_forwardslash, + size: 12, + color: Colors.red, + ) + : const SizedBox.shrink(), + const Spacer(), ], ), ), @@ -319,13 +317,23 @@ class EnvItemCell extends StatelessWidget { content: Text("确认删除环境变量 ${bean.name ?? ""} 吗"), actions: [ CupertinoDialogAction( - child: const Text("取消"), + child: const Text( + "取消", + style: TextStyle( + color: Color(0xff999999), + ), + ), onPressed: () { Navigator.of(context).pop(); }, ), CupertinoDialogAction( - child: const Text("确定"), + child: Text( + "确定", + style: TextStyle( + color: primaryColor, + ), + ), onPressed: () { Navigator.of(context).pop(); ref.read(envProvider).delEnv(bean.sId!); diff --git a/lib/module/login/login_page.dart b/lib/module/login/login_page.dart index f811ed6..4e041db 100644 --- a/lib/module/login/login_page.dart +++ b/lib/module/login/login_page.dart @@ -362,37 +362,95 @@ class _LoginPageState extends ConsumerState { response = await Api.loginByClientId(userName, password); } if (response.success) { - getIt().updateToken(response.bean?.token ?? ""); - getIt().useSecretLogin(!loginByUserName()); - if (rememberPassword) { - getIt().updateUserName(userName, password); - } - - if (!loginByUserName()) { - Navigator.of(context).pushReplacementNamed(Routes.routeHomePage); - } else { - HttpResponse userResponse = await Api.user(); - if (userResponse.success) { - if (userResponse.bean != null && userResponse.bean!.twoFactorActivated != null && userResponse.bean!.twoFactorActivated!) { - ("你已开启两步验证,App暂不支持").toast(); + loginSuccess(response, userName, password); + } else { + print(response.code); + (response.message ?? "请检查网络情况").toast(); + //420代表需要2步验证 + if (response.code == 420) { + 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: primaryColor, + ), + ), + onPressed: () async { + Navigator.of(context).pop(true); + HttpResponse response = await Api.loginTwo(userName, password, twoFact); + if (response.success) { + loginSuccess(response, userName, password); + } else { + loginFailed(response); + } + }, + ), + ], + )).then((value) { + if (value == null) { isLoading = false; setState(() {}); - } else { - Navigator.of(context).pushReplacementNamed(Routes.routeHomePage); } - } else { - (response.message ?? "请检查网络情况").toast(); - isLoading = false; - setState(() {}); - } + }); + } else { + isLoading = false; + setState(() {}); } - } else { - (response.message ?? "请检查网络情况").toast(); - isLoading = false; - setState(() {}); } } + void loginFailed(HttpResponse response) { + (response.message ?? "请检查网络情况").toast(); + isLoading = false; + setState(() {}); + } + + void loginSuccess(HttpResponse response, String userName, String password) { + getIt().updateToken(response.bean?.token ?? ""); + getIt().useSecretLogin(!loginByUserName()); + if (rememberPassword) { + getIt().updateUserName(userName, password); + } + Navigator.of(context).pushReplacementNamed(Routes.routeHomePage); + } + bool canClickLoginBtn() { if (isLoading) return false; diff --git a/lib/module/others/dependencies/dependency_page.dart b/lib/module/others/dependencies/dependency_page.dart index 9e4948c..594e9a7 100644 --- a/lib/module/others/dependencies/dependency_page.dart +++ b/lib/module/others/dependencies/dependency_page.dart @@ -334,13 +334,23 @@ class DependencyCell extends ConsumerWidget { content: Text("确认删除依赖 ${bean.name ?? ""} 吗"), actions: [ CupertinoDialogAction( - child: const Text("取消"), + child: const Text( + "取消", + style: TextStyle( + color: Color(0xff999999), + ), + ), onPressed: () { Navigator.of(context).pop(); }, ), CupertinoDialogAction( - child: const Text("确定"), + child: Text( + "确定", + style: TextStyle( + color: primaryColor, + ), + ), onPressed: () { Navigator.of(context).pop(); ref.read(dependencyProvider).del(type.name.toLowerCase(), sId ?? ""); diff --git a/lib/module/others/other_page.dart b/lib/module/others/other_page.dart index f1b0063..7a5a660 100644 --- a/lib/module/others/other_page.dart +++ b/lib/module/others/other_page.dart @@ -297,16 +297,26 @@ class _OtherPageState extends ConsumerState { showCupertinoDialog( context: context, builder: (context) => CupertinoAlertDialog( - title: const Text("确定退出登录吗?"), + title: const Text("确认退出登录吗?"), actions: [ CupertinoDialogAction( - child: const Text("取消"), + child: const Text( + "取消", + style: TextStyle( + color: Color(0xff999999), + ), + ), onPressed: () { Navigator.of(context).pop(); }, ), CupertinoDialogAction( - child: const Text("确定"), + child: Text( + "确定", + style: TextStyle( + color: primaryColor, + ), + ), onPressed: () { getIt().updateToken(""); Navigator.of(context).pushReplacementNamed(Routes.routeLogin); diff --git a/lib/module/others/scripts/script_detail_page.dart b/lib/module/others/scripts/script_detail_page.dart index 648c815..2a1c06c 100644 --- a/lib/module/others/scripts/script_detail_page.dart +++ b/lib/module/others/scripts/script_detail_page.dart @@ -84,13 +84,23 @@ class _ScriptDetailPageState extends ConsumerState with LazyLo content: const Text("确认删除该脚本吗"), actions: [ CupertinoDialogAction( - child: const Text("取消"), + child: const Text( + "取消", + style: TextStyle( + color: Color(0xff999999), + ), + ), onPressed: () { Navigator.of(context).pop(); }, ), CupertinoDialogAction( - child: const Text("确定"), + child: Text( + "确定", + style: TextStyle( + color: primaryColor, + ), + ), onPressed: () async { Navigator.of(context).pop(); HttpResponse result = await Api.delScript(widget.title, widget.path ?? ""); diff --git a/lib/module/task/task_detail/task_detail_page.dart b/lib/module/task/task_detail/task_detail_page.dart index dffda53..bdcb8a9 100644 --- a/lib/module/task/task_detail/task_detail_page.dart +++ b/lib/module/task/task_detail/task_detail_page.dart @@ -367,13 +367,23 @@ class _TaskDetailPageState extends ConsumerState { content: Text("确认删除定时任务 ${widget.taskBean.name ?? ""} 吗"), actions: [ CupertinoDialogAction( - child: const Text("取消"), + child: const Text( + "取消", + style: TextStyle( + color: Color(0xff999999), + ), + ), onPressed: () { Navigator.of(context).pop(); }, ), CupertinoDialogAction( - child: const Text("确定"), + child: Text( + "确定", + style: TextStyle( + color: primaryColor, + ), + ), onPressed: () async { Navigator.of(context).pop(); await ref.read(taskProvider).delCron(widget.taskBean.sId!); diff --git a/lib/module/task/task_page.dart b/lib/module/task/task_page.dart index e878295..cf5c532 100644 --- a/lib/module/task/task_page.dart +++ b/lib/module/task/task_page.dart @@ -251,6 +251,7 @@ class TaskItemCell extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( + width: MediaQuery.of(context).size.width, color: bean.isPinned == 1 ? ref.watch(themeProvider).themeColor.pinColor() : Colors.transparent, padding: const EdgeInsets.symmetric( horizontal: 15, @@ -307,6 +308,7 @@ class TaskItemCell extends StatelessWidget { height: 8, ), Row( + crossAxisAlignment: CrossAxisAlignment.start, children: [ Material( color: Colors.transparent, @@ -332,6 +334,22 @@ class TaskItemCell extends StatelessWidget { : const SizedBox.shrink(), ], ), + const SizedBox( + height: 8, + ), + Material( + color: Colors.transparent, + child: Text( + bean.command ?? "", + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: TextStyle( + overflow: TextOverflow.ellipsis, + color: ref.watch(themeProvider).themeColor.descColor(), + fontSize: 12, + ), + ), + ), ], ), ), @@ -401,13 +419,23 @@ class TaskItemCell extends StatelessWidget { content: Text("确认删除定时任务 ${bean.name ?? ""} 吗"), actions: [ CupertinoDialogAction( - child: const Text("取消"), + child: const Text( + "取消", + style: TextStyle( + color: Color(0xff999999), + ), + ), onPressed: () { Navigator.of(context).pop(); }, ), CupertinoDialogAction( - child: const Text("确定"), + child: Text( + "确定", + style: TextStyle( + color: primaryColor, + ), + ), onPressed: () { Navigator.of(context).pop(); ref.read(taskProvider).delCron(bean.sId!);