mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
新增任务详情页
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
import 'package:json_conversion_annotation/json_conversion_annotation.dart';
|
||||
|
||||
@JsonConversion()
|
||||
class TaskDetailBean {
|
||||
String? name;
|
||||
String? command;
|
||||
String? schedule;
|
||||
bool? saved;
|
||||
String? sId;
|
||||
int? created;
|
||||
int? status;
|
||||
String? timestamp;
|
||||
int? isSystem;
|
||||
int? isDisabled;
|
||||
String? logPath;
|
||||
int? isPinned;
|
||||
|
||||
TaskDetailBean(
|
||||
{this.name,
|
||||
this.command,
|
||||
this.schedule,
|
||||
this.saved,
|
||||
this.sId,
|
||||
this.created,
|
||||
this.status,
|
||||
this.timestamp,
|
||||
this.isSystem,
|
||||
this.isDisabled,
|
||||
this.logPath,
|
||||
this.isPinned});
|
||||
|
||||
TaskDetailBean.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'];
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||
data['name'] = this.name;
|
||||
data['command'] = this.command;
|
||||
data['schedule'] = this.schedule;
|
||||
data['saved'] = this.saved;
|
||||
data['_id'] = this.sId;
|
||||
data['created'] = this.created;
|
||||
data['status'] = this.status;
|
||||
data['timestamp'] = this.timestamp;
|
||||
data['isSystem'] = this.isSystem;
|
||||
data['isDisabled'] = this.isDisabled;
|
||||
data['log_path'] = this.logPath;
|
||||
data['isPinned'] = this.isPinned;
|
||||
return data;
|
||||
}
|
||||
|
||||
static TaskDetailBean jsonConversion(Map<String, dynamic> json) {
|
||||
return TaskDetailBean.fromJson(json);
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:qinglong_app/base/base_state_widget.dart';
|
||||
import 'package:qinglong_app/base/ql_app_bar.dart';
|
||||
import 'package:qinglong_app/base/theme.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_detail/task_detail_viewmodel.dart';
|
||||
import 'package:qinglong_app/utils/utils.dart';
|
||||
|
||||
class TaskDetailPage extends ConsumerStatefulWidget {
|
||||
final TaskBean taskBean;
|
||||
@@ -20,17 +22,181 @@ class _TaskDetailPageState extends ConsumerState<TaskDetailPage> {
|
||||
return Scaffold(
|
||||
appBar: QlAppBar(
|
||||
canBack: true,
|
||||
backCall: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
title: widget.taskBean.name ?? "",
|
||||
),
|
||||
body: BaseStateWidget<TaskDetailViewModel>(
|
||||
model: taskDetailProvider,
|
||||
builder: (WidgetRef context, TaskDetailViewModel value, Widget? child) {
|
||||
return Container();
|
||||
},
|
||||
onReady: (model) {
|
||||
model.loadDetail(widget.taskBean.sId!);
|
||||
},
|
||||
body: SingleChildScrollView(
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(
|
||||
horizontal: 15,
|
||||
vertical: 10,
|
||||
),
|
||||
padding: const EdgeInsets.only(
|
||||
top: 10,
|
||||
bottom: 10,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: ref.watch(themeProvider).themeColor.settingBgColor(),
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TaskDetailCell(
|
||||
title: "ID",
|
||||
desc: widget.taskBean.sId ?? "",
|
||||
),
|
||||
TaskDetailCell(
|
||||
title: "任务",
|
||||
desc: widget.taskBean.command ?? "",
|
||||
),
|
||||
TaskDetailCell(
|
||||
title: "创建时间",
|
||||
desc: Utils.formatMessageTime(widget.taskBean.created ?? 0),
|
||||
),
|
||||
TaskDetailCell(
|
||||
title: "任务定时",
|
||||
desc: widget.taskBean.schedule ?? "",
|
||||
),
|
||||
TaskDetailCell(
|
||||
title: "最后运行时间",
|
||||
desc: Utils.formatMessageTime(widget.taskBean.lastExecutionTime ?? 0),
|
||||
),
|
||||
TaskDetailCell(
|
||||
title: "最后运行时长",
|
||||
desc: widget.taskBean.lastRunningTime == null ? "-" : "${widget.taskBean.lastRunningTime ?? "-"}秒",
|
||||
),
|
||||
GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () {
|
||||
showLog();
|
||||
},
|
||||
child: TaskDetailCell(
|
||||
title: "日志路径",
|
||||
desc: widget.taskBean.logPath ?? "-",
|
||||
taped: () {
|
||||
showLog();
|
||||
},
|
||||
),
|
||||
),
|
||||
TaskDetailCell(
|
||||
title: "运行状态",
|
||||
desc: widget.taskBean.status == 0 ? "正在运行" : "空闲",
|
||||
),
|
||||
TaskDetailCell(
|
||||
title: "脚本状态",
|
||||
desc: widget.taskBean.isDisabled == 1 ? "已禁用" : "正常",
|
||||
hideDivide: true,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void showLog() {
|
||||
showCupertinoDialog(
|
||||
builder: (BuildContext context) {
|
||||
return CupertinoAlertDialog(
|
||||
title: Text(
|
||||
"${widget.taskBean.name}运行日志",
|
||||
maxLines: 1,
|
||||
style: const TextStyle(overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
content: InTimeLogPage(widget.taskBean.sId!, widget.taskBean.status == 0),
|
||||
actions: [
|
||||
CupertinoDialogAction(
|
||||
child: Text(
|
||||
"知道了",
|
||||
style: TextStyle(color: Theme.of(context).primaryColor),
|
||||
),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
context: context);
|
||||
}
|
||||
}
|
||||
|
||||
class TaskDetailCell extends ConsumerWidget {
|
||||
final String title;
|
||||
final String? desc;
|
||||
final Widget? icon;
|
||||
final bool hideDivide;
|
||||
final Function? taped;
|
||||
|
||||
const TaskDetailCell({
|
||||
Key? key,
|
||||
required this.title,
|
||||
this.desc,
|
||||
this.icon,
|
||||
this.hideDivide = false,
|
||||
this.taped,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 10,
|
||||
left: 15,
|
||||
right: 10,
|
||||
bottom: 10,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
color: ref.watch(themeProvider).themeColor.titleColor(),
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
const SizedBox(
|
||||
width: 30,
|
||||
),
|
||||
desc != null
|
||||
? Expanded(
|
||||
child: Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: SelectableText(
|
||||
desc!,
|
||||
textAlign: TextAlign.right,
|
||||
onTap: () {
|
||||
if (taped != null) {
|
||||
taped!();
|
||||
}
|
||||
},
|
||||
style: TextStyle(
|
||||
color: ref.watch(themeProvider).themeColor.descColor(),
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
: Expanded(
|
||||
child: Align(alignment: Alignment.centerRight, child: icon!),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
hideDivide
|
||||
? const SizedBox.shrink()
|
||||
: const Divider(
|
||||
indent: 15,
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
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_detail/task_detail_bean.dart';
|
||||
|
||||
var taskDetailProvider =
|
||||
AutoDisposeChangeNotifierProvider<TaskDetailViewModel>((ref) {
|
||||
return TaskDetailViewModel();
|
||||
});
|
||||
|
||||
class TaskDetailViewModel extends BaseViewModel {
|
||||
TaskDetailBean? bean;
|
||||
|
||||
TaskDetailViewModel();
|
||||
|
||||
Future<void> loadDetail(String id) async {
|
||||
loading(notify: true);
|
||||
|
||||
HttpResponse<TaskDetailBean> response = await Api.taskDetail(id);
|
||||
|
||||
if (response.success) {
|
||||
bean = response.bean;
|
||||
success();
|
||||
} else {
|
||||
failed(response.message, notify: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user