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:
@@ -1,3 +1,5 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:json_conversion_annotation/json_conversion_annotation.dart';
|
||||
|
||||
@JsonConversion()
|
||||
@@ -7,14 +9,14 @@ class TaskBean {
|
||||
String? schedule;
|
||||
bool? saved;
|
||||
String? sId;
|
||||
int? created;
|
||||
num? created;
|
||||
int? status;
|
||||
String? timestamp;
|
||||
int? isSystem;
|
||||
int? isDisabled;
|
||||
String? logPath;
|
||||
int? isPinned;
|
||||
int? lastExecutionTime;
|
||||
num? lastExecutionTime;
|
||||
int? lastRunningTime;
|
||||
String? pid;
|
||||
|
||||
@@ -36,21 +38,26 @@ class TaskBean {
|
||||
this.pid});
|
||||
|
||||
TaskBean.fromJson(Map<String, dynamic> json) {
|
||||
name = json['name'];
|
||||
command = json['command'];
|
||||
schedule = json['schedule'];
|
||||
saved = json['saved'];
|
||||
sId = json['_id'];
|
||||
created = json['created'];
|
||||
status = json['status'];
|
||||
timestamp = json['timestamp'];
|
||||
isSystem = json['isSystem'];
|
||||
isDisabled = json['isDisabled'];
|
||||
logPath = json['log_path'];
|
||||
isPinned = json['isPinned'];
|
||||
lastExecutionTime = json['last_execution_time'];
|
||||
lastRunningTime = json['last_running_time'];
|
||||
pid = json['pid'];
|
||||
try {
|
||||
name = json['name'].toString();
|
||||
command = json['command'].toString();
|
||||
schedule = json['schedule'].toString();
|
||||
saved = json['saved'];
|
||||
sId = json['_id'].toString();
|
||||
created = json['created'];
|
||||
status = json['status'];
|
||||
timestamp = json['timestamp'].toString();
|
||||
isSystem = json['isSystem'];
|
||||
isDisabled = json['isDisabled'];
|
||||
logPath = json['log_path'].toString();
|
||||
isPinned = json['isPinned'];
|
||||
lastExecutionTime = json['last_execution_time'];
|
||||
lastRunningTime = json['last_running_time'];
|
||||
pid = json['pid'].toString();
|
||||
} catch (e) {
|
||||
print(jsonEncode(json));
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
|
||||
@@ -3,6 +3,8 @@ import 'package:flutter/material.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/theme.dart';
|
||||
import 'package:qinglong_app/module/task/task_bean.dart';
|
||||
import 'package:qinglong_app/module/task/task_viewmodel.dart';
|
||||
|
||||
class TaskPage extends StatefulWidget {
|
||||
@@ -19,18 +21,18 @@ class _TaskPageState extends State<TaskPage> {
|
||||
builder: (context, model, child) {
|
||||
return RefreshIndicator(
|
||||
onRefresh: () async {
|
||||
return Future.delayed(Duration(seconds: 1), () {});
|
||||
return model.loadData(false);
|
||||
},
|
||||
child: ListView.separated(
|
||||
padding: EdgeInsets.symmetric(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 15,
|
||||
),
|
||||
itemBuilder: (context, index) {
|
||||
return TaskItemCell();
|
||||
return TaskItemCell(model.list[index]);
|
||||
},
|
||||
itemCount: model.list.length,
|
||||
separatorBuilder: (BuildContext context, int index) {
|
||||
return SizedBox(
|
||||
return const SizedBox(
|
||||
height: 10,
|
||||
);
|
||||
},
|
||||
@@ -45,11 +47,13 @@ class _TaskPageState extends State<TaskPage> {
|
||||
}
|
||||
}
|
||||
|
||||
class TaskItemCell extends StatelessWidget {
|
||||
const TaskItemCell({Key? key}) : super(key: key);
|
||||
class TaskItemCell extends ConsumerWidget {
|
||||
final TaskBean bean;
|
||||
|
||||
const TaskItemCell(this.bean, {Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Slidable(
|
||||
key: const ValueKey(0),
|
||||
startActionPane: ActionPane(
|
||||
@@ -98,34 +102,49 @@ class TaskItemCell extends StatelessWidget {
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: const [
|
||||
children: [
|
||||
Text(
|
||||
"东东农场",
|
||||
bean.name ?? "",
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w500,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
color: bean.isDisabled == 1 ? Color(0xffF85152) : ref.watch(themeProvider).themeColor.taskTitleColor(),
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
const SizedBox(
|
||||
width: 5,
|
||||
),
|
||||
SizedBox(
|
||||
width: 15,
|
||||
height: 15,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
bean.status == 1
|
||||
? const SizedBox.shrink()
|
||||
: const SizedBox(
|
||||
width: 15,
|
||||
height: 15,
|
||||
child: CircularProgressIndicator(
|
||||
strokeWidth: 2,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Text(
|
||||
"${bean.lastRunningTime ?? "-"}",
|
||||
maxLines: 1,
|
||||
style: const TextStyle(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
color: Color(0xff999999),
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
Spacer(),
|
||||
Text("2020/12/12 12:23"),
|
||||
],
|
||||
),
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
const Text(
|
||||
"12/12/12",
|
||||
style: TextStyle(
|
||||
Text(
|
||||
bean.schedule ?? "",
|
||||
maxLines: 1,
|
||||
style: const TextStyle(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
color: Color(0xff999999),
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,31 +1,37 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:qinglong_app/base/base_viewmodel.dart';
|
||||
import 'package:qinglong_app/base/http/api.dart';
|
||||
import 'package:qinglong_app/base/http/http.dart';
|
||||
import 'package:qinglong_app/module/task/task_bean.dart';
|
||||
|
||||
var taskProvider = ChangeNotifierProvider((ref) => TaskViewModel());
|
||||
|
||||
class TaskViewModel extends BaseViewModel {
|
||||
List<String> list = [];
|
||||
List<TaskBean> list = [];
|
||||
|
||||
void loadData() {
|
||||
loading(notify: true);
|
||||
Future<void> loadData([isLoading = true]) async {
|
||||
if (isLoading) {
|
||||
loading(notify: true);
|
||||
}
|
||||
|
||||
HttpResponse<List<TaskBean>> result = await Api.crons();
|
||||
|
||||
if (result.success && result.bean != null) {
|
||||
list.clear();
|
||||
list.addAll(result.bean!);
|
||||
|
||||
list.sort((a, b) {
|
||||
return a.isDisabled! - b.isDisabled!;
|
||||
});
|
||||
|
||||
list.sort((a, b) {
|
||||
return a.status! - b.status!;
|
||||
});
|
||||
|
||||
Future.delayed(Duration(seconds: 2), () {
|
||||
list.add("sdfsf");
|
||||
list.add("sdfsf");
|
||||
list.add("sdfsf");
|
||||
list.add("sdfsf");
|
||||
list.add("sdfsf");
|
||||
list.add("sdfsf");
|
||||
list.add("sdfsf");
|
||||
list.add("sdfsf");
|
||||
list.add("sdfsf");
|
||||
list.add("sdfsf");
|
||||
list.add("sdfsf");
|
||||
list.add("sdfsf");
|
||||
list.add("sdfsf");
|
||||
list.add("sdfsf");
|
||||
list.add("sdfsf");
|
||||
success();
|
||||
});
|
||||
} else {
|
||||
list.clear();
|
||||
failed(result.message, notify: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user