From c7824c920bed69c3146553f931ee22c85d4393aa Mon Sep 17 00:00:00 2001 From: jyuesong <425698907@qq.com> Date: Thu, 2 Jun 2022 08:37:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BD=BF=E7=94=A8=E4=BD=93?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/base/http/token_interceptor.dart | 2 +- lib/base/userinfo_viewmodel.dart | 2 +- lib/module/task/add_task_page.dart | 202 ++++++++++++++------------- lib/module/task/task_viewmodel.dart | 91 +++++++++--- pubspec.yaml | 2 +- version | 2 +- 6 files changed, 175 insertions(+), 126 deletions(-) diff --git a/lib/base/http/token_interceptor.dart b/lib/base/http/token_interceptor.dart index 3daffaa..cb58241 100644 --- a/lib/base/http/token_interceptor.dart +++ b/lib/base/http/token_interceptor.dart @@ -8,7 +8,7 @@ class TokenInterceptor extends Interceptor { @override void onRequest(RequestOptions options, RequestInterceptorHandler handler) { 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"; + "qinglong_client"; options.headers["Content-Type"] = "application/json;charset=UTF-8"; diff --git a/lib/base/userinfo_viewmodel.dart b/lib/base/userinfo_viewmodel.dart index 3c6f399..66c0911 100644 --- a/lib/base/userinfo_viewmodel.dart +++ b/lib/base/userinfo_viewmodel.dart @@ -95,7 +95,7 @@ class UserInfoViewModel { historyAccounts.insert(0, UserInfoBean(userName: _userName, password: _passWord, useSecretLogined: _useSecertLogined, host: _host)); - while (historyAccounts.length > 5) { + while (historyAccounts.length > 3) { historyAccounts.removeLast(); } diff --git a/lib/module/task/add_task_page.dart b/lib/module/task/add_task_page.dart index d83a419..5e8190b 100644 --- a/lib/module/task/add_task_page.dart +++ b/lib/module/task/add_task_page.dart @@ -74,111 +74,113 @@ class _AddTaskPageState extends ConsumerState { ) ], ), - body: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.symmetric( - horizontal: 15, + body: SingleChildScrollView( + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 15, + ), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox( + height: 15, + ), + const Text( + "名称:", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + ), + ), + TextField( + focusNode: focusNode, + controller: _nameController, + decoration: const InputDecoration( + contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5), + hintText: "请输入名称", + ), + autofocus: false, + ), + ], + ), ), - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox( - height: 15, - ), - const Text( - "名称:", - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 15, + ), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox( + height: 15, ), - ), - TextField( - focusNode: focusNode, - controller: _nameController, - decoration: const InputDecoration( - contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5), - hintText: "请输入名称", + const Text( + "命令:", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + ), ), - autofocus: false, - ), - ], + TextField( + controller: _commandController, + maxLines: 4, + minLines: 1, + decoration: const InputDecoration( + contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5), + hintText: "请输入命令", + ), + autofocus: false, + ), + ], + ), ), - ), - Padding( - padding: const EdgeInsets.symmetric( - horizontal: 15, + Padding( + padding: const EdgeInsets.symmetric( + horizontal: 15, + ), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox( + height: 15, + ), + const Text( + "定时:", + style: TextStyle( + fontSize: 16, + fontWeight: FontWeight.w600, + ), + ), + TextField( + controller: _cronController, + decoration: const InputDecoration( + contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5), + hintText: "请输入定时", + ), + autofocus: false, + ), + const SizedBox( + height: 5, + ), + const Text( + "定时的cron不校验是否正确", + style: TextStyle( + fontSize: 12, + ), + ), + ], + ), ), - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox( - height: 15, - ), - const Text( - "命令:", - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, - ), - ), - TextField( - controller: _commandController, - maxLines: 4, - minLines: 1, - decoration: const InputDecoration( - contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5), - hintText: "请输入命令", - ), - autofocus: false, - ), - ], - ), - ), - Padding( - padding: const EdgeInsets.symmetric( - horizontal: 15, - ), - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - const SizedBox( - height: 15, - ), - const Text( - "定时:", - style: TextStyle( - fontSize: 16, - fontWeight: FontWeight.w600, - ), - ), - TextField( - controller: _cronController, - decoration: const InputDecoration( - contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5), - hintText: "请输入定时", - ), - autofocus: false, - ), - const SizedBox( - height: 5, - ), - const Text( - "定时的cron不校验是否正确", - style: TextStyle( - fontSize: 12, - ), - ), - ], - ), - ), - ], + ], + ), ), ); } diff --git a/lib/module/task/task_viewmodel.dart b/lib/module/task/task_viewmodel.dart index 1818cb1..6dbe4e2 100644 --- a/lib/module/task/task_viewmodel.dart +++ b/lib/module/task/task_viewmodel.dart @@ -6,13 +6,6 @@ import 'package:qinglong_app/module/task/task_bean.dart'; import 'package:qinglong_app/utils/extension.dart'; var taskProvider = ChangeNotifierProvider((ref) => TaskViewModel()); -Map sort = { - 0: 0, - 5: 1, - 3: 2, - 1: 3, - 4: 4, -}; class TaskViewModel extends BaseViewModel { static const String allStr = "全部脚本"; @@ -45,27 +38,81 @@ class TaskViewModel extends BaseViewModel { } void sortList() { - list.sort((TaskBean a, TaskBean b) { - int? sortA = (a.isPinned == 1 && a.status != 0) - ? 5 - : (a.isDisabled == 1 && a.status != 0) - ? 4 - : a.status; - int? sortB = (b.isPinned == 1 && b.status != 0) - ? 5 - : (b.isDisabled == 1 && b.status != 0) - ? 4 - : b.status; - - return sort[sortA!]! - sort[sortB!]!; - }); + List p = []; + List r = []; + List d = []; for (int i = 0; i < list.length; i++) { if (list[i].isPinned == 1) { - list.insert(0, list.removeAt(i)); + p.add(list.removeAt(i)); + i--; + continue; + } + + if (list[i].status == 0) { + r.add(list.removeAt(i)); + i--; + continue; + } + if (list[i].isDisabled == 1) { + d.add(list.removeAt(i)); + i--; + continue; } } + p.sort((TaskBean a, TaskBean b) { + bool c = DateTime.fromMillisecondsSinceEpoch(a.created ?? 0).isBefore(DateTime.fromMillisecondsSinceEpoch(b.created ?? 0)); + if (c == true) { + return 1; + } + return -1; + }); + + p.sort((a, b) { + return (a.isDisabled ?? 0) - (b.isDisabled ?? 0); + }); + + p.sort((a, b) { + if (a.status == 0 && b.status == 0) { + bool c = DateTime.fromMillisecondsSinceEpoch(a.created ?? 0).isBefore(DateTime.fromMillisecondsSinceEpoch(b.created ?? 0)); + if (c == true) { + return 1; + } + return -1; + } else { + return (a.status ?? 0) - (b.status ?? 0); + } + }); + + r.sort((a, b) { + bool c = DateTime.fromMillisecondsSinceEpoch(a.created ?? 0).isBefore(DateTime.fromMillisecondsSinceEpoch(b.created ?? 0)); + if (c == true) { + return 1; + } + return -1; + }); + + d.sort((a, b) { + bool c = DateTime.fromMillisecondsSinceEpoch(a.created ?? 0).isBefore(DateTime.fromMillisecondsSinceEpoch(b.created ?? 0)); + if (c == true) { + return 1; + } + return -1; + }); + + list.sort((a, b) { + bool c = DateTime.fromMillisecondsSinceEpoch(a.created ?? 0).isBefore(DateTime.fromMillisecondsSinceEpoch(b.created ?? 0)); + if (c == true) { + return 1; + } + return -1; + }); + + list.insertAll(0, r); + list.insertAll(0, p); + list.addAll(d); + running.clear(); running.addAll(list.where((element) => element.status == 0)); neverRunning.clear(); diff --git a/pubspec.yaml b/pubspec.yaml index 599a163..2339657 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: qinglong_app description: A new Flutter project. publish_to: 'none' # Remove this line if you wish to publish to pub.dev -version: 1.0.8+10 +version: 1.0.9+11 environment: sdk: ">=2.15.1 <3.0.0" diff --git a/version b/version index 337a6a8..e5a4a5e 100644 --- a/version +++ b/version @@ -1 +1 @@ -1.0.8 \ No newline at end of file +1.0.9 \ No newline at end of file