任务增加更多的筛选条件

This commit is contained in:
jyuesong
2022-01-26 16:30:16 +08:00
parent 5d5d6d2244
commit 1a055bdca7
2 changed files with 29 additions and 44 deletions

View File

@@ -41,7 +41,7 @@ class _TaskPageState extends State<TaskPage> {
searchCell(ref), searchCell(ref),
Expanded( Expanded(
child: DefaultTabController( child: DefaultTabController(
length: 3, length: 5,
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
@@ -53,6 +53,12 @@ class _TaskPageState extends State<TaskPage> {
Tab( Tab(
text: "正在运行", text: "正在运行",
), ),
Tab(
text: "从未运行",
),
Tab(
text: "非脚本类",
),
Tab( Tab(
text: "已禁用", text: "已禁用",
), ),
@@ -70,6 +76,8 @@ class _TaskPageState extends State<TaskPage> {
children: [ children: [
body(model, model.list, ref), body(model, model.list, ref),
body(model, model.running, ref), body(model, model.running, ref),
body(model, model.neverRunning, ref),
body(model, model.notScripts, ref),
body(model, model.disabled, ref), body(model, model.disabled, ref),
], ],
), ),
@@ -102,17 +110,9 @@ class _TaskPageState extends State<TaskPage> {
TaskBean item = list[index]; TaskBean item = list[index];
if (_searchController.text.isEmpty || if (_searchController.text.isEmpty ||
(item.name (item.name?.toLowerCase().contains(_searchController.text.toLowerCase()) ?? false) ||
?.toLowerCase() (item.command?.toLowerCase().contains(_searchController.text.toLowerCase()) ?? false) ||
.contains(_searchController.text.toLowerCase()) ?? (item.schedule?.contains(_searchController.text.toLowerCase()) ?? false)) {
false) ||
(item.command
?.toLowerCase()
.contains(_searchController.text.toLowerCase()) ??
false) ||
(item.schedule
?.contains(_searchController.text.toLowerCase()) ??
false)) {
return TaskItemCell(item, ref); return TaskItemCell(item, ref);
} else { } else {
return const SizedBox.shrink(); return const SizedBox.shrink();
@@ -183,9 +183,7 @@ class TaskItemCell extends StatelessWidget {
child: Text( child: Text(
bean.status! == 1 ? "运行" : "停止运行", bean.status! == 1 ? "运行" : "停止运行",
), ),
trailingIcon: bean.status! == 1 trailingIcon: bean.status! == 1 ? CupertinoIcons.memories : CupertinoIcons.stop_circle,
? CupertinoIcons.memories
: CupertinoIcons.stop_circle,
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
if (bean.status! == 1) { if (bean.status! == 1) {
@@ -207,8 +205,7 @@ class TaskItemCell extends StatelessWidget {
child: const Text("编辑"), child: const Text("编辑"),
onPressed: () { onPressed: () {
Navigator.of(context).pop(); Navigator.of(context).pop();
Navigator.of(context) Navigator.of(context).pushNamed(Routes.routeAddTask, arguments: bean);
.pushNamed(Routes.routeAddTask, arguments: bean);
}, },
trailingIcon: CupertinoIcons.pencil_outline, trailingIcon: CupertinoIcons.pencil_outline,
), ),
@@ -218,9 +215,7 @@ class TaskItemCell extends StatelessWidget {
Navigator.of(context).pop(); Navigator.of(context).pop();
pinTask(); pinTask();
}, },
trailingIcon: bean.isPinned! == 0 trailingIcon: bean.isPinned! == 0 ? CupertinoIcons.pin : CupertinoIcons.pin_slash,
? CupertinoIcons.pin
: CupertinoIcons.pin_slash,
), ),
QLCupertinoContextMenuAction( QLCupertinoContextMenuAction(
child: Text(bean.isDisabled! == 0 ? "禁用" : "启用"), child: Text(bean.isDisabled! == 0 ? "禁用" : "启用"),
@@ -229,9 +224,7 @@ class TaskItemCell extends StatelessWidget {
enableTask(); enableTask();
}, },
isDestructiveAction: true, isDestructiveAction: true,
trailingIcon: bean.isDisabled! == 0 trailingIcon: bean.isDisabled! == 0 ? Icons.dnd_forwardslash : Icons.check_circle_outline_sharp,
? Icons.dnd_forwardslash
: Icons.check_circle_outline_sharp,
), ),
QLCupertinoContextMenuAction( QLCupertinoContextMenuAction(
child: const Text("删除"), child: const Text("删除"),
@@ -248,9 +241,7 @@ class TaskItemCell extends StatelessWidget {
return ClipRRect( return ClipRRect(
borderRadius: BorderRadius.circular(15), borderRadius: BorderRadius.circular(15),
child: Container( child: Container(
color: isDark color: isDark ? const Color(0xff333333) : Theme.of(context).scaffoldBackgroundColor,
? const Color(0xff333333)
: Theme.of(context).scaffoldBackgroundColor,
padding: EdgeInsets.only( padding: EdgeInsets.only(
left: 5, left: 5,
right: 5, right: 5,
@@ -273,9 +264,7 @@ class TaskItemCell extends StatelessWidget {
children: [ children: [
Container( Container(
width: MediaQuery.of(context).size.width, width: MediaQuery.of(context).size.width,
color: bean.isPinned == 1 color: bean.isPinned == 1 ? ref.watch(themeProvider).themeColor.pinColor() : Colors.transparent,
? ref.watch(themeProvider).themeColor.pinColor()
: Colors.transparent,
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
horizontal: 15, horizontal: 15,
vertical: 8, vertical: 8,
@@ -300,8 +289,7 @@ class TaskItemCell extends StatelessWidget {
height: 15, height: 15,
child: CircularProgressIndicator( child: CircularProgressIndicator(
strokeWidth: 2, strokeWidth: 2,
color: color: ref.watch(themeProvider).primaryColor,
ref.watch(themeProvider).primaryColor,
), ),
), ),
SizedBox( SizedBox(
@@ -316,10 +304,7 @@ class TaskItemCell extends StatelessWidget {
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
style: TextStyle( style: TextStyle(
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
color: ref color: ref.watch(themeProvider).themeColor.titleColor(),
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 18, fontSize: 18,
), ),
), ),
@@ -331,16 +316,11 @@ class TaskItemCell extends StatelessWidget {
Material( Material(
color: Colors.transparent, color: Colors.transparent,
child: Text( child: Text(
(bean.lastExecutionTime == null || (bean.lastExecutionTime == null || bean.lastExecutionTime == 0) ? "-" : Utils.formatMessageTime(bean.lastExecutionTime!),
bean.lastExecutionTime == 0)
? "-"
: Utils.formatMessageTime(
bean.lastExecutionTime!),
maxLines: 1, maxLines: 1,
style: TextStyle( style: TextStyle(
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
color: color: ref.watch(themeProvider).themeColor.descColor(),
ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12, fontSize: 12,
), ),
), ),
@@ -370,8 +350,7 @@ class TaskItemCell extends StatelessWidget {
maxLines: 1, maxLines: 1,
style: TextStyle( style: TextStyle(
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
color: color: ref.watch(themeProvider).themeColor.descColor(),
ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12, fontSize: 12,
), ),
), ),

View File

@@ -10,6 +10,8 @@ var taskProvider = ChangeNotifierProvider((ref) => TaskViewModel());
class TaskViewModel extends BaseViewModel { class TaskViewModel extends BaseViewModel {
List<TaskBean> list = []; List<TaskBean> list = [];
List<TaskBean> running = []; List<TaskBean> running = [];
List<TaskBean> neverRunning = [];
List<TaskBean> notScripts = [];
List<TaskBean> disabled = []; List<TaskBean> disabled = [];
Future<void> loadData([isLoading = true]) async { Future<void> loadData([isLoading = true]) async {
@@ -40,6 +42,10 @@ class TaskViewModel extends BaseViewModel {
running.clear(); running.clear();
running.addAll(list.where((element) => element.status == 0)); running.addAll(list.where((element) => element.status == 0));
neverRunning.clear();
neverRunning.addAll(list.where((element) => element.lastRunningTime == null || element.lastRunningTime == 0));
notScripts.clear();
notScripts.addAll(list.where((element) => (element.command != null && (element.command!.startsWith("ql repo") || element.command!.startsWith("ql raw")))));
disabled.clear(); disabled.clear();
disabled.addAll(list.where((element) => element.isDisabled == 1)); disabled.addAll(list.where((element) => element.isDisabled == 1));
} }