mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
add task
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:qinglong_app/base/ql_app_bar.dart';
|
||||
import 'package:qinglong_app/base/routes.dart';
|
||||
import 'package:qinglong_app/base/theme.dart';
|
||||
import 'package:qinglong_app/module/config/config_page.dart';
|
||||
import 'package:qinglong_app/module/env/env_page.dart';
|
||||
@@ -30,20 +31,44 @@ class _HomePageState extends State<HomePage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
List<Widget> actions = [];
|
||||
|
||||
if (_index == 0) {
|
||||
actions.add(InkWell(
|
||||
onTap: () {
|
||||
Navigator.of(context).pushNamed(
|
||||
Routes.route_AddTask,
|
||||
);
|
||||
},
|
||||
child: const Padding(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 15,
|
||||
),
|
||||
child: Center(
|
||||
child: Icon(
|
||||
CupertinoIcons.add,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
actions.add(
|
||||
Consumer(builder: (context, ref, child) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
ref.read(themeProvider).changeTheme();
|
||||
},
|
||||
child: const Center(child: Text("改变主题")),
|
||||
);
|
||||
}),
|
||||
);
|
||||
return Scaffold(
|
||||
appBar: QlAppBar(
|
||||
canBack: false,
|
||||
title: _title,
|
||||
actions: [
|
||||
Consumer(builder: (context, ref, child) {
|
||||
return InkWell(
|
||||
onTap: () {
|
||||
ref.read(themeProvider).changeTheme();
|
||||
},
|
||||
child: const Center(child: Text("改变主题")),
|
||||
);
|
||||
}),
|
||||
],
|
||||
actions: actions,
|
||||
),
|
||||
body: IndexedStack(
|
||||
index: _index,
|
||||
|
||||
@@ -79,7 +79,7 @@ class _AddTaskPageState extends State<AddTaskPage> {
|
||||
height: 10,
|
||||
),
|
||||
const Text(
|
||||
"任务名称:",
|
||||
"名称:",
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500,
|
||||
@@ -92,7 +92,7 @@ class _AddTaskPageState extends State<AddTaskPage> {
|
||||
controller: _nameController,
|
||||
decoration: const InputDecoration(
|
||||
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
|
||||
hintText: "请输入任务名称",
|
||||
hintText: "请输入名称",
|
||||
),
|
||||
autofocus: false,
|
||||
),
|
||||
|
||||
@@ -9,7 +9,7 @@ class TaskBean {
|
||||
String? schedule;
|
||||
bool? saved;
|
||||
String? sId;
|
||||
num? created;
|
||||
int? created;
|
||||
int? status;
|
||||
String? timestamp;
|
||||
int? isSystem;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
@@ -31,6 +33,7 @@ class _TaskPageState extends State<TaskPage> {
|
||||
Widget build(BuildContext context) {
|
||||
return BaseStateWidget<TaskViewModel>(
|
||||
builder: (ref, model, child) {
|
||||
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
return model.loadData(false);
|
||||
@@ -335,6 +338,7 @@ class _TaskItemCellState extends ConsumerState<TaskItemCell> {
|
||||
child: const Text('删除'),
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
delTask(context, ref);
|
||||
},
|
||||
),
|
||||
CupertinoActionSheetAction(
|
||||
@@ -347,4 +351,29 @@ class _TaskItemCellState extends ConsumerState<TaskItemCell> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void delTask(BuildContext context, WidgetRef ref) {
|
||||
showCupertinoDialog(
|
||||
context: context,
|
||||
builder: (context) => CupertinoAlertDialog(
|
||||
title: const Text("确认删除"),
|
||||
content: Text("确认删除定时任务 ${bean.name ?? ""} 吗"),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
child: const Text("取消"),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
CupertinoDialogAction(
|
||||
child: const Text("确定"),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
ref.read(taskProvider).delCron(bean.sId!);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:qinglong_app/base/base_viewmodel.dart';
|
||||
import 'package:qinglong_app/base/http/api.dart';
|
||||
@@ -9,6 +12,8 @@ var taskProvider = ChangeNotifierProvider((ref) => TaskViewModel());
|
||||
class TaskViewModel extends BaseViewModel {
|
||||
List<TaskBean> list = [];
|
||||
|
||||
String temp = "sadad";
|
||||
|
||||
Future<void> loadData([isLoading = true]) async {
|
||||
if (isLoading) {
|
||||
loading(notify: true);
|
||||
@@ -19,7 +24,6 @@ class TaskViewModel extends BaseViewModel {
|
||||
if (result.success && result.bean != null) {
|
||||
list.clear();
|
||||
list.addAll(result.bean!);
|
||||
|
||||
sortList();
|
||||
success();
|
||||
} else {
|
||||
@@ -30,11 +34,14 @@ class TaskViewModel extends BaseViewModel {
|
||||
|
||||
void sortList() {
|
||||
list.sort((a, b) {
|
||||
return a.isDisabled! - b.isDisabled!;
|
||||
return b.created!.compareTo(a.created!);
|
||||
});
|
||||
list.sort((a, b) {
|
||||
return a.isDisabled!.compareTo(b.isDisabled!);
|
||||
});
|
||||
|
||||
list.sort((a, b) {
|
||||
return a.status! - b.status!;
|
||||
return a.status!.compareTo(b.status!);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -43,6 +50,8 @@ class TaskViewModel extends BaseViewModel {
|
||||
if (result.success) {
|
||||
list.firstWhere((element) => element.sId == cron).status = 0;
|
||||
notifyListeners();
|
||||
} else {
|
||||
failed(result.message, notify: true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +60,18 @@ class TaskViewModel extends BaseViewModel {
|
||||
if (result.success) {
|
||||
list.firstWhere((element) => element.sId == cron).status = 1;
|
||||
notifyListeners();
|
||||
} else {
|
||||
failed(result.message, notify: true);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> delCron(String id) async {
|
||||
HttpResponse<NullResponse> result = await Api.delTask(id);
|
||||
if (result.success) {
|
||||
list.removeWhere((element) => element.sId == id);
|
||||
notifyListeners();
|
||||
} else {
|
||||
failed(result.message, notify: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user