diff --git a/lib/base/http/api.dart b/lib/base/http/api.dart index a9fefdd..27820bd 100644 --- a/lib/base/http/api.dart +++ b/lib/base/http/api.dart @@ -59,4 +59,12 @@ class Api { static Future> unpinTask(String cron) async { return await Http.put(Url.UNPIN_TASK, [cron]); } + + static Future> enableTask(String cron) async { + return await Http.put(Url.ENABLE_TASK, [cron]); + } + + static Future> disableTask(String cron) async { + return await Http.put(Url.DISABLE_TASK, [cron]); + } } diff --git a/lib/base/http/url.dart b/lib/base/http/url.dart index cca3f84..67d8633 100644 --- a/lib/base/http/url.dart +++ b/lib/base/http/url.dart @@ -7,6 +7,8 @@ class Url { static const ADD_TASK = "/api/crons"; static const PIN_TASK = "/api/crons/pin"; static const UNPIN_TASK = "/api/crons/unpin"; + static const ENABLE_TASK = "/api/crons/enable"; + static const DISABLE_TASK = "/api/crons/disable"; static INTIME_LOG(String cronId) { return "/api/crons/$cronId/log"; diff --git a/lib/base/theme.dart b/lib/base/theme.dart index e83954f..fb46a35 100644 --- a/lib/base/theme.dart +++ b/lib/base/theme.dart @@ -31,7 +31,10 @@ ThemeData lightTheme = ThemeData.light().copyWith( abstract class ThemeColors { Color taskTitleColor(); + Color searchBarBg(); + + Color pinColor(); } class LightartThemeColors extends ThemeColors { @@ -40,11 +43,15 @@ class LightartThemeColors extends ThemeColors { return Color(0xff333333); } - @override Color searchBarBg() { return const Color(0xffF7F7F7); } + + @override + Color pinColor() { + return const Color(0xffF7F7F7); + } } class DartThemeColors extends ThemeColors { @@ -53,10 +60,13 @@ class DartThemeColors extends ThemeColors { return Colors.white; } - - @override Color searchBarBg() { return const Color(0xff2E312E); } + + @override + Color pinColor() { + return Colors.black12; + } } diff --git a/lib/module/task/task_page.dart b/lib/module/task/task_page.dart index 34f0bba..f6ed325 100644 --- a/lib/module/task/task_page.dart +++ b/lib/module/task/task_page.dart @@ -156,7 +156,7 @@ class TaskItemCell extends StatelessWidget { ], ), child: Container( - color: bean.isPinned == 1 ? ref.watch(themeProvider).themeColor.searchBarBg() : Colors.transparent, + color: bean.isPinned == 1 ? ref.watch(themeProvider).themeColor.pinColor() : Colors.transparent, padding: const EdgeInsets.symmetric( horizontal: 15, vertical: 8, @@ -310,6 +310,7 @@ class TaskItemCell extends StatelessWidget { child: Text(bean.isDisabled! == 1 ? "启用" : "禁用"), onPressed: () { Navigator.pop(context); + enableTask(); }, ), CupertinoActionSheetAction( @@ -331,6 +332,10 @@ class TaskItemCell extends StatelessWidget { ); } + void enableTask() { + ref.read(taskProvider).enableTask(bean.sId!, bean.isDisabled!); + } + void pinTask() { ref.read(taskProvider).pinTask(bean.sId!, bean.isPinned!); } diff --git a/lib/module/task/task_viewmodel.dart b/lib/module/task/task_viewmodel.dart index c41e2d9..cddbe08 100644 --- a/lib/module/task/task_viewmodel.dart +++ b/lib/module/task/task_viewmodel.dart @@ -108,4 +108,28 @@ class TaskViewModel extends BaseViewModel { } } } + + void enableTask(String sId, int isDisabled) async { + if (isDisabled == 0) { + HttpResponse response = await Api.disableTask(sId); + + if (response.success) { + list.firstWhere((element) => element.sId == sId).isDisabled = 1; + sortList(); + success(); + } else { + failToast(response.message, notify: true); + } + } else { + HttpResponse response = await Api.enableTask(sId); + + if (response.success) { + list.firstWhere((element) => element.sId == sId).isDisabled = 0; + sortList(); + success(); + } else { + failToast(response.message, notify: true); + } + } + } }