任务列表优化

This commit is contained in:
jyuesong
2022-05-30 10:41:09 +08:00
parent 9a27ae8e69
commit 2c64038fda
2 changed files with 344 additions and 263 deletions

View File

@@ -3,95 +3,46 @@ import 'dart:io';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:qinglong_app/base/base_state_widget.dart'; import 'package:qinglong_app/base/base_state_widget.dart';
import 'package:qinglong_app/base/routes.dart'; import 'package:qinglong_app/base/routes.dart';
import 'package:qinglong_app/base/single_account_page.dart';
import 'package:qinglong_app/base/theme.dart'; import 'package:qinglong_app/base/theme.dart';
import 'package:qinglong_app/base/ui/abs_underline_tabindicator.dart';
import 'package:qinglong_app/base/ui/empty_widget.dart';
import 'package:qinglong_app/base/ui/menu.dart';
import 'package:qinglong_app/base/ui/ql_context_menu.dart';
import 'package:qinglong_app/module/task/intime_log/intime_log_page.dart'; import 'package:qinglong_app/module/task/intime_log/intime_log_page.dart';
import 'package:qinglong_app/module/task/task_bean.dart'; import 'package:qinglong_app/module/task/task_bean.dart';
import 'package:qinglong_app/module/task/task_detail/task_detail_page.dart';
import 'package:qinglong_app/module/task/task_viewmodel.dart'; import 'package:qinglong_app/module/task/task_viewmodel.dart';
import 'package:qinglong_app/utils/utils.dart'; import 'package:qinglong_app/utils/utils.dart';
class TaskPage extends StatefulWidget { class TaskPage extends ConsumerStatefulWidget {
const TaskPage({Key? key}) : super(key: key); const TaskPage({Key? key}) : super(key: key);
@override @override
_TaskPageState createState() => _TaskPageState(); _TaskPageState createState() => _TaskPageState();
} }
class _TaskPageState extends State<TaskPage> { class _TaskPageState extends ConsumerState<TaskPage> {
final TextEditingController _searchController = TextEditingController(); final TextEditingController _searchController = TextEditingController();
String currentState = TaskViewModel.allStr;
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_searchController.addListener(() {
setState(() {});
});
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BaseStateWidget<TaskViewModel>( return BaseStateWidget<TaskViewModel>(
builder: (ref, model, child) { builder: (ref, model, child) {
return Column( return body(model, getListByType(model), ref);
mainAxisSize: MainAxisSize.max,
children: [
searchCell(ref),
Expanded(
child: DefaultTabController(
length: 5,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TabBar(
tabs: const [
Tab(
text: "全部",
),
Tab(
text: "正在运行",
),
Tab(
text: "从未运行",
),
Tab(
text: "拉库脚本",
),
Tab(
text: "已禁用",
),
],
isScrollable: true,
indicator: AbsUnderlineTabIndicator(
wantWidth: 20,
borderSide: BorderSide(
color: Theme.of(context).primaryColor,
width: 2,
)),
),
Expanded(
child: TabBarView(
children: [
body(model, model.list, ref),
body(model, model.running, ref),
body(model, model.neverRunning, ref),
body(model, model.notScripts, ref),
body(model, model.disabled, ref),
],
),
),
],
),
),
),
],
);
}, },
model: taskProvider, model: taskProvider,
onReady: (viewModel) { onReady: (viewModel) {
viewModel.loadData(); viewModel.loadData(context);
}, },
); );
} }
@@ -100,26 +51,51 @@ class _TaskPageState extends State<TaskPage> {
return RefreshIndicator( return RefreshIndicator(
color: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor,
onRefresh: () async { onRefresh: () async {
return model.loadData(false); return model.loadData( false);
}, },
child: list.isEmpty child: IconTheme(
? const EmptyWidget() data: const IconThemeData(
: ListView.builder( size: 25,
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag, ),
itemBuilder: (context, index) { child: SlidableAutoCloseBehavior(
TaskBean item = list[index]; child: ListView.separated(
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
if (_searchController.text.isEmpty || itemBuilder: (context, index) {
(item.name?.toLowerCase().contains(_searchController.text.toLowerCase()) ?? false) || if (index == 0) {
(item.command?.toLowerCase().contains(_searchController.text.toLowerCase()) ?? false) || return searchCell(ref);
(item.schedule?.contains(_searchController.text.toLowerCase()) ?? false)) { }
return TaskItemCell(item, ref); TaskBean item = list[index - 1];
} else { if (_searchController.text.isEmpty ||
return const SizedBox.shrink(); (item.name?.toLowerCase().contains(_searchController.text.toLowerCase()) ?? false) ||
} (item.command?.toLowerCase().contains(_searchController.text.toLowerCase()) ?? false) ||
}, (item.schedule?.contains(_searchController.text.toLowerCase()) ?? false)) {
itemCount: list.length, return TaskItemCell(item, ref);
), } else {
return const SizedBox.shrink();
}
},
itemCount: list.length + 1,
separatorBuilder: (BuildContext context, int index) {
if (index == 0) return const SizedBox.shrink();
TaskBean item = list[index - 1];
if (_searchController.text.isEmpty ||
(item.name?.toLowerCase().contains(_searchController.text.toLowerCase()) ?? false) ||
(item.command?.toLowerCase().contains(_searchController.text.toLowerCase()) ?? false) ||
(item.schedule?.contains(_searchController.text.toLowerCase()) ?? false)) {
return Container(
color: ref.watch(themeProvider).themeColor.settingBgColor(),
child: const Divider(
height: 1,
indent: 15,
),
);
} else {
return const SizedBox.shrink();
}
},
),
),
),
); );
} }
@@ -129,41 +105,149 @@ class _TaskPageState extends State<TaskPage> {
horizontal: 15, horizontal: 15,
vertical: 10, vertical: 10,
), ),
child: CupertinoSearchTextField( child: Row(
onSubmitted: (value) { children: [
setState(() {}); Expanded(
}, child: CupertinoSearchTextField(
onSuffixTap: () { onSubmitted: (value) {
_searchController.text = ""; setState(() {});
setState(() {}); },
}, onSuffixTap: () {
controller: _searchController, _searchController.text = "";
borderRadius: BorderRadius.circular( setState(() {});
30, },
), controller: _searchController,
padding: const EdgeInsets.symmetric( borderRadius: BorderRadius.circular(
horizontal: 5, 30,
vertical: 5, ),
), padding: const EdgeInsets.symmetric(
suffixInsets: const EdgeInsets.only( horizontal: 5,
right: 15, vertical: 5,
), ),
prefixInsets: EdgeInsets.only( suffixInsets: const EdgeInsets.only(
top: Platform.isAndroid ? 10 : 6, right: 15,
bottom: 6, ),
left: 15, prefixInsets: EdgeInsets.only(
), top: Platform.isAndroid ? 10 : 6,
placeholderStyle: TextStyle( bottom: 6,
fontSize: 16, left: 15,
color: context.watch(themeProvider).themeColor.descColor(), ),
), placeholderStyle: TextStyle(
style: const TextStyle( fontSize: 16,
fontSize: 16, color: context.watch(themeProvider).themeColor.descColor(),
), ),
placeholder: "搜索", style: const TextStyle(
fontSize: 16,
),
placeholder: "搜索",
),
),
Material(
color: Colors.transparent,
child: PopupMenuButton<String>(
onSelected: (String result) {
currentState = result;
setState(() {});
},
itemBuilder: (BuildContext context) => [
PopupMenuItem(
child: Text(
TaskViewModel.allStr,
style: TextStyle(
color: currentState == TaskViewModel.allStr ? ref.watch(themeProvider).primaryColor : ref.watch(themeProvider).themeColor.titleColor(),
fontSize: 14,
),
),
value: TaskViewModel.allStr,
),
PopupMenuItem(
child: Text(
TaskViewModel.runningStr,
style: TextStyle(
color:
currentState == TaskViewModel.runningStr ? ref.watch(themeProvider).primaryColor : ref.watch(themeProvider).themeColor.titleColor(),
fontSize: 14,
),
),
value: TaskViewModel.runningStr,
),
PopupMenuItem(
child: Text(
TaskViewModel.neverStr,
style: TextStyle(
color: currentState == TaskViewModel.neverStr ? ref.watch(themeProvider).primaryColor : ref.watch(themeProvider).themeColor.titleColor(),
fontSize: 14,
),
),
value: TaskViewModel.neverStr,
),
PopupMenuItem(
child: Row(
children: [
Text(
TaskViewModel.notScriptStr,
style: TextStyle(
color: currentState == TaskViewModel.notScriptStr
? ref.watch(themeProvider).primaryColor
: ref.watch(themeProvider).themeColor.titleColor(),
fontSize: 14,
),
),
],
),
value: TaskViewModel.notScriptStr,
),
PopupMenuItem(
child: Text(
TaskViewModel.disableStr,
style: TextStyle(
fontSize: 14,
color:
currentState == TaskViewModel.disableStr ? ref.watch(themeProvider).primaryColor : ref.watch(themeProvider).themeColor.titleColor(),
),
),
value: TaskViewModel.disableStr,
),
],
child: Padding(
padding: const EdgeInsets.only(
left: 10,
),
child: Text(
"筛选",
style: TextStyle(
color: ref.watch(themeProvider).themeColor.descColor(),
fontSize: 14,
),
),
),
),
),
],
), ),
); );
} }
List<TaskBean> getListByType(TaskViewModel model) {
if (currentState == TaskViewModel.allStr) {
return model.list;
}
if (currentState == TaskViewModel.runningStr) {
return model.running;
}
if (currentState == TaskViewModel.neverStr) {
return model.neverRunning;
}
if (currentState == TaskViewModel.notScriptStr) {
return model.notScripts;
}
if (currentState == TaskViewModel.disableStr) {
return model.disabled;
}
return model.list;
}
} }
class TaskItemCell extends StatelessWidget { class TaskItemCell extends StatelessWidget {
@@ -176,93 +260,91 @@ class TaskItemCell extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ColoredBox( return ColoredBox(
color: ref.watch(themeProvider).themeColor.settingBgColor(), color: ref.watch(themeProvider).themeColor.settingBgColor(),
child: QlCupertinoContextMenu( child: Slidable(
bean: bean, key: ValueKey(bean.sId),
actions: [ endActionPane: ActionPane(
QLCupertinoContextMenuAction( motion: const StretchMotion(),
child: Text( extentRatio: 0.7,
bean.status! == 1 ? "运行" : "停止运行",
),
trailingIcon: bean.status! == 1 ? CupertinoIcons.memories : CupertinoIcons.stop_circle,
onPressed: () {
Navigator.of(context).pop();
if (bean.status! == 1) {
startCron(context, ref);
} else {
stopCron(context, ref);
}
},
),
QLCupertinoContextMenuAction(
child: const Text("查看日志"),
onPressed: () {
Navigator.of(context).pop();
logCron(context, ref);
},
trailingIcon: CupertinoIcons.clock,
),
QLCupertinoContextMenuAction(
child: const Text("编辑"),
onPressed: () {
Navigator.of(context).pop();
Navigator.of(context).pushNamed(Routes.routeAddTask, arguments: bean);
},
trailingIcon: CupertinoIcons.pencil_outline,
),
QLCupertinoContextMenuAction(
child: Text(bean.isPinned! == 0 ? "置顶" : "取消置顶"),
onPressed: () {
Navigator.of(context).pop();
pinTask();
},
trailingIcon: bean.isPinned! == 0 ? CupertinoIcons.pin : CupertinoIcons.pin_slash,
),
QLCupertinoContextMenuAction(
child: Text(bean.isDisabled! == 0 ? "禁用" : "启用"),
onPressed: () {
Navigator.of(context).pop();
enableTask();
},
isDestructiveAction: true,
trailingIcon: bean.isDisabled! == 0 ? Icons.dnd_forwardslash : Icons.check_circle_outline_sharp,
),
QLCupertinoContextMenuAction(
child: const Text("删除"),
onPressed: () {
Navigator.of(context).pop();
delTask(context, ref);
},
isDestructiveAction: true,
trailingIcon: CupertinoIcons.delete,
),
],
previewBuilder: (context, anima, child) {
bool isDark = ref.watch(themeProvider).darkMode;
return ClipRRect(
borderRadius: BorderRadius.circular(15),
child: Container(
color: isDark ? const Color(0xff333333) : Theme.of(context).scaffoldBackgroundColor,
padding: EdgeInsets.only(
left: 5,
right: 5,
top: 5,
bottom: isDark ? 5 : 20,
),
child: SizedBox(
height: 200,
child: TaskDetailPage(
bean,
hideAppbar: true,
),
),
),
);
},
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Container( SlidableAction(
backgroundColor: const Color(0xff5D5E70),
onPressed: (_) {
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
Navigator.of(context).pushNamed(Routes.routeAddTask, arguments: bean);
});
},
foregroundColor: Colors.white,
icon: CupertinoIcons.pencil_outline,
),
SlidableAction(
backgroundColor: const Color(0xffF19A39),
onPressed: (_) {
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
pinTask(context);
});
},
foregroundColor: Colors.white,
icon: bean.isPinned! == 0 ? CupertinoIcons.pin : CupertinoIcons.pin_slash,
),
SlidableAction(
backgroundColor: const Color(0xffA356D6),
onPressed: (_) {
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
enableTask(context);
});
},
foregroundColor: Colors.white,
icon: bean.isDisabled! == 0 ? Icons.dnd_forwardslash : Icons.check_circle_outline_sharp,
),
SlidableAction(
backgroundColor: const Color(0xffEA4D3E),
onPressed: (_) {
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
delTask(context, ref);
});
},
foregroundColor: Colors.white,
icon: CupertinoIcons.delete,
),
],
),
startActionPane: ActionPane(
motion: const StretchMotion(),
extentRatio: 0.4,
children: [
SlidableAction(
backgroundColor: const Color(0xffD25535),
onPressed: (_) {
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
if (bean.status! == 1) {
startCron(context, ref);
} else {
stopCron(context, ref);
}
});
},
foregroundColor: Colors.white,
icon: bean.status! == 1 ? CupertinoIcons.memories : CupertinoIcons.stop_circle,
),
SlidableAction(
backgroundColor: const Color(0xff606467),
onPressed: (_) {
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
logCron(context, ref);
});
},
foregroundColor: Colors.white,
icon: CupertinoIcons.text_justifyleft,
),
],
),
child: Material(
color: ref.watch(themeProvider).themeColor.settingBgColor(),
child: InkWell(
onTap: () {
Navigator.of(context).pushNamed(Routes.routeTaskDetail, arguments: bean);
},
child: Container(
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
color: bean.isPinned == 1 ? ref.watch(themeProvider).themeColor.pinColor() : Colors.transparent, color: bean.isPinned == 1 ? ref.watch(themeProvider).themeColor.pinColor() : Colors.transparent,
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
@@ -282,11 +364,21 @@ class TaskItemCell extends StatelessWidget {
mainAxisSize: MainAxisSize.max, mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
bean.isDisabled == 1
? const Icon(
Icons.dnd_forwardslash,
size: 18,
color: Color(0xffEA4D3E),
)
: const SizedBox.shrink(),
SizedBox(
width: bean.isDisabled == 1 ? 5 : 0,
),
bean.status == 1 bean.status == 1
? const SizedBox.shrink() ? const SizedBox.shrink()
: SizedBox( : SizedBox(
width: 15, width: 13,
height: 15, height: 13,
child: CircularProgressIndicator( child: CircularProgressIndicator(
strokeWidth: 2, strokeWidth: 2,
color: ref.watch(themeProvider).primaryColor, color: ref.watch(themeProvider).primaryColor,
@@ -305,7 +397,7 @@ class TaskItemCell extends StatelessWidget {
style: TextStyle( style: TextStyle(
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.titleColor(), color: ref.watch(themeProvider).themeColor.titleColor(),
fontSize: 18, fontSize: 16,
), ),
), ),
), ),
@@ -328,37 +420,22 @@ class TaskItemCell extends StatelessWidget {
], ],
), ),
const SizedBox( const SizedBox(
height: 8, height: 5,
), ),
Row( Material(
crossAxisAlignment: CrossAxisAlignment.start, color: Colors.transparent,
children: [ child: Text(
bean.isDisabled == 1 bean.schedule ?? "",
? const Icon( maxLines: 1,
Icons.dnd_forwardslash, style: TextStyle(
size: 12, overflow: TextOverflow.ellipsis,
color: Colors.red, color: ref.watch(themeProvider).themeColor.descColor(),
) fontSize: 12,
: const SizedBox.shrink(),
const SizedBox(
width: 5,
), ),
Material( ),
color: Colors.transparent,
child: Text(
bean.schedule ?? "",
maxLines: 1,
style: TextStyle(
overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12,
),
),
),
],
), ),
const SizedBox( const SizedBox(
height: 8, height: 5,
), ),
Material( Material(
color: Colors.transparent, color: Colors.transparent,
@@ -376,30 +453,27 @@ class TaskItemCell extends StatelessWidget {
], ],
), ),
), ),
const Divider( ),
height: 1,
indent: 15,
),
],
), ),
), ),
); );
} }
startCron(BuildContext context, WidgetRef ref) async { startCron(BuildContext context, WidgetRef ref) async {
await ref.read(taskProvider).runCrons(bean.sId!); await ref.read(taskProvider).runCrons( bean.sId!);
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) { WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
logCron(context, ref); logCron(context, ref);
}); });
} }
stopCron(BuildContext context, WidgetRef ref) { stopCron(BuildContext context, WidgetRef ref) {
ref.read(taskProvider).stopCrons(bean.sId!); ref.read(taskProvider).stopCrons( bean.sId!);
} }
logCron(BuildContext context, WidgetRef ref) { logCron(BuildContext context, WidgetRef ref) {
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) { WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
showCupertinoDialog( showCupertinoDialog(
useRootNavigator: false,
builder: (BuildContext context) { builder: (BuildContext context) {
return CupertinoAlertDialog( return CupertinoAlertDialog(
title: Text( title: Text(
@@ -416,7 +490,7 @@ class TaskItemCell extends StatelessWidget {
), ),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
ref.read(taskProvider).loadData(false); ref.read(taskProvider).loadData( false);
}, },
), ),
], ],
@@ -426,17 +500,18 @@ class TaskItemCell extends StatelessWidget {
}); });
} }
void enableTask() { void enableTask(BuildContext context) {
ref.read(taskProvider).enableTask(bean.sId!, bean.isDisabled!); ref.read(taskProvider).enableTask( bean.sId!, bean.isDisabled!);
} }
void pinTask() { void pinTask(BuildContext context) {
ref.read(taskProvider).pinTask(bean.sId!, bean.isPinned!); ref.read(taskProvider).pinTask( bean.sId!, bean.isPinned!);
} }
void delTask(BuildContext context, WidgetRef ref) { void delTask(BuildContext context, WidgetRef ref) {
showCupertinoDialog( showCupertinoDialog(
context: context, context: context,
useRootNavigator: false,
builder: (context) => CupertinoAlertDialog( builder: (context) => CupertinoAlertDialog(
title: const Text("确认删除"), title: const Text("确认删除"),
content: Text("确认删除定时任务 ${bean.name ?? ""}"), content: Text("确认删除定时任务 ${bean.name ?? ""}"),
@@ -461,7 +536,7 @@ class TaskItemCell extends StatelessWidget {
), ),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
ref.read(taskProvider).delCron(bean.sId!); ref.watch(taskProvider.notifier).delCron(bean.sId!);
}, },
), ),
], ],

View File

@@ -15,6 +15,11 @@ Map<int, int> sort = {
}; };
class TaskViewModel extends BaseViewModel { class TaskViewModel extends BaseViewModel {
static const String allStr = "全部脚本";
static const String runningStr = "正在运行";
static const String neverStr = "从未运行";
static const String notScriptStr = "拉库脚本";
static const String disableStr = "禁用脚本";
List<TaskBean> list = []; List<TaskBean> list = [];
List<TaskBean> running = []; List<TaskBean> running = [];
List<TaskBean> neverRunning = []; List<TaskBean> neverRunning = [];
@@ -41,12 +46,26 @@ class TaskViewModel extends BaseViewModel {
void sortList() { void sortList() {
list.sort((TaskBean a, TaskBean b) { 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? sortA = (a.isPinned == 1 && a.status != 0)
int? sortB = (b.isPinned == 1 && b.status != 0) ? 5 : ((b.isDisabled == 1 && b.status != 0) ? 4 : b.status); ? 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!]!; return sort[sortA!]! - sort[sortB!]!;
}); });
for (int i = 0; i < list.length; i++) {
if (list[i].isPinned == 1) {
list.insert(0, list.removeAt(i));
}
}
running.clear(); running.clear();
running.addAll(list.where((element) => element.status == 0)); running.addAll(list.where((element) => element.status == 0));
neverRunning.clear(); neverRunning.clear();
@@ -60,9 +79,7 @@ class TaskViewModel extends BaseViewModel {
Future<void> runCrons(String cron) async { Future<void> runCrons(String cron) async {
HttpResponse<NullResponse> result = await Api.startTasks([cron]); HttpResponse<NullResponse> result = await Api.startTasks([cron]);
if (result.success) { if (result.success) {
list.firstWhere((element) => element.sId == cron).status = 0; loadData(false);
sortList();
notifyListeners();
} else { } else {
failToast(result.message, notify: true); failToast(result.message, notify: true);
} }
@@ -71,9 +88,7 @@ class TaskViewModel extends BaseViewModel {
Future<void> stopCrons(String cron) async { Future<void> stopCrons(String cron) async {
HttpResponse<NullResponse> result = await Api.stopTasks([cron]); HttpResponse<NullResponse> result = await Api.stopTasks([cron]);
if (result.success) { if (result.success) {
list.firstWhere((element) => element.sId == cron).status = 1; loadData(false);
sortList();
notifyListeners();
} else { } else {
failToast(result.message, notify: true); failToast(result.message, notify: true);
} }
@@ -82,9 +97,8 @@ class TaskViewModel extends BaseViewModel {
Future<void> delCron(String id) async { Future<void> delCron(String id) async {
HttpResponse<NullResponse> result = await Api.delTask(id); HttpResponse<NullResponse> result = await Api.delTask(id);
if (result.success) { if (result.success) {
list.removeWhere((element) => element.sId == id);
"删除成功".toast(); "删除成功".toast();
notifyListeners(); loadData(false);
} else { } else {
failToast(result.message, notify: true); failToast(result.message, notify: true);
} }
@@ -108,9 +122,7 @@ class TaskViewModel extends BaseViewModel {
if (response.success) { if (response.success) {
"取消置顶成功".toast(); "取消置顶成功".toast();
list.firstWhere((element) => element.sId == sId).isPinned = 0; loadData(false);
sortList();
success();
} else { } else {
failToast(response.message, notify: true); failToast(response.message, notify: true);
} }
@@ -119,9 +131,7 @@ class TaskViewModel extends BaseViewModel {
if (response.success) { if (response.success) {
"置顶成功".toast(); "置顶成功".toast();
list.firstWhere((element) => element.sId == sId).isPinned = 1; loadData(false);
sortList();
success();
} else { } else {
failToast(response.message, notify: true); failToast(response.message, notify: true);
} }
@@ -134,9 +144,7 @@ class TaskViewModel extends BaseViewModel {
if (response.success) { if (response.success) {
"禁用成功".toast(); "禁用成功".toast();
list.firstWhere((element) => element.sId == sId).isDisabled = 1; loadData(false);
sortList();
success();
} else { } else {
failToast(response.message, notify: true); failToast(response.message, notify: true);
} }
@@ -145,9 +153,7 @@ class TaskViewModel extends BaseViewModel {
if (response.success) { if (response.success) {
"启用成功".toast(); "启用成功".toast();
list.firstWhere((element) => element.sId == sId).isDisabled = 0; loadData(false);
sortList();
success();
} else { } else {
failToast(response.message, notify: true); failToast(response.message, notify: true);
} }