mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
添加任务详情
This commit is contained in:
@@ -71,115 +71,113 @@ class _AddTaskPageState extends ConsumerState<AddTaskPage> {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
body: Container(
|
body: Column(
|
||||||
child: Column(
|
mainAxisSize: MainAxisSize.min,
|
||||||
mainAxisSize: MainAxisSize.min,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
children: [
|
||||||
children: [
|
Padding(
|
||||||
Padding(
|
padding: const EdgeInsets.symmetric(
|
||||||
padding: const EdgeInsets.symmetric(
|
horizontal: 15,
|
||||||
horizontal: 15,
|
|
||||||
),
|
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
const SizedBox(
|
|
||||||
height: 10,
|
|
||||||
),
|
|
||||||
const Text(
|
|
||||||
"名称:",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 10,
|
|
||||||
),
|
|
||||||
TextField(
|
|
||||||
controller: _nameController,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
|
|
||||||
hintText: "请输入名称",
|
|
||||||
),
|
|
||||||
autofocus: false,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
Padding(
|
child: Column(
|
||||||
padding: const EdgeInsets.symmetric(
|
mainAxisSize: MainAxisSize.min,
|
||||||
horizontal: 15,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
),
|
children: [
|
||||||
child: Column(
|
const SizedBox(
|
||||||
mainAxisSize: MainAxisSize.min,
|
height: 10,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
),
|
||||||
children: [
|
const Text(
|
||||||
const SizedBox(
|
"名称:",
|
||||||
height: 10,
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
),
|
),
|
||||||
const Text(
|
),
|
||||||
"命令:",
|
const SizedBox(
|
||||||
style: TextStyle(
|
height: 10,
|
||||||
fontSize: 16,
|
),
|
||||||
fontWeight: FontWeight.w600,
|
TextField(
|
||||||
),
|
controller: _nameController,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
|
||||||
|
hintText: "请输入名称",
|
||||||
),
|
),
|
||||||
const SizedBox(
|
autofocus: false,
|
||||||
height: 10,
|
),
|
||||||
),
|
],
|
||||||
TextField(
|
|
||||||
controller: _commandController,
|
|
||||||
maxLines: 4,
|
|
||||||
minLines: 1,
|
|
||||||
inputFormatters: [
|
|
||||||
FilteringTextInputFormatter.allow(RegExp(scheduleCron)),
|
|
||||||
],
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
|
|
||||||
hintText: "请输入命令",
|
|
||||||
),
|
|
||||||
autofocus: false,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
Padding(
|
),
|
||||||
padding: const EdgeInsets.symmetric(
|
Padding(
|
||||||
horizontal: 15,
|
padding: const EdgeInsets.symmetric(
|
||||||
),
|
horizontal: 15,
|
||||||
child: Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
const SizedBox(
|
|
||||||
height: 10,
|
|
||||||
),
|
|
||||||
const Text(
|
|
||||||
"定时:",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
fontWeight: FontWeight.w600,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const SizedBox(
|
|
||||||
height: 10,
|
|
||||||
),
|
|
||||||
TextField(
|
|
||||||
controller: _cronController,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
|
|
||||||
hintText: "请输入定时",
|
|
||||||
),
|
|
||||||
autofocus: false,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
],
|
child: Column(
|
||||||
),
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
const SizedBox(
|
||||||
|
height: 10,
|
||||||
|
),
|
||||||
|
const Text(
|
||||||
|
"命令:",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 10,
|
||||||
|
),
|
||||||
|
TextField(
|
||||||
|
controller: _commandController,
|
||||||
|
maxLines: 4,
|
||||||
|
minLines: 1,
|
||||||
|
inputFormatters: [
|
||||||
|
FilteringTextInputFormatter.allow(RegExp(scheduleCron)),
|
||||||
|
],
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
|
||||||
|
hintText: "请输入命令",
|
||||||
|
),
|
||||||
|
autofocus: false,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 15,
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
const SizedBox(
|
||||||
|
height: 10,
|
||||||
|
),
|
||||||
|
const Text(
|
||||||
|
"定时:",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 10,
|
||||||
|
),
|
||||||
|
TextField(
|
||||||
|
controller: _cronController,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
|
||||||
|
hintText: "请输入定时",
|
||||||
|
),
|
||||||
|
autofocus: false,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,14 @@ 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:qinglong_app/base/ql_app_bar.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/base/theme.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/utils/utils.dart';
|
import 'package:qinglong_app/utils/utils.dart';
|
||||||
|
|
||||||
|
import '../task_viewmodel.dart';
|
||||||
|
|
||||||
class TaskDetailPage extends ConsumerStatefulWidget {
|
class TaskDetailPage extends ConsumerStatefulWidget {
|
||||||
final TaskBean taskBean;
|
final TaskBean taskBean;
|
||||||
|
|
||||||
@@ -17,8 +20,132 @@ class TaskDetailPage extends ConsumerStatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _TaskDetailPageState extends ConsumerState<TaskDetailPage> {
|
class _TaskDetailPageState extends ConsumerState<TaskDetailPage> {
|
||||||
|
List<Widget> actions = [];
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
actions.clear();
|
||||||
|
actions.addAll(
|
||||||
|
[
|
||||||
|
GestureDetector(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onTap: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
startCron(context, ref);
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 15,
|
||||||
|
),
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: Text(
|
||||||
|
widget.taskBean.status! == 1 ? "运行" : "停止运行",
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
GestureDetector(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onTap: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
showLog();
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 15,
|
||||||
|
),
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: const Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: Text(
|
||||||
|
"查看日志",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
GestureDetector(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onTap: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
Navigator.of(context).pushNamed(Routes.routeAddTask, arguments: widget.taskBean);
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 15,
|
||||||
|
),
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: const Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: Text(
|
||||||
|
"编辑",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
GestureDetector(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onTap: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
pinTask();
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 15,
|
||||||
|
),
|
||||||
|
color: Colors.transparent,
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: Text(
|
||||||
|
widget.taskBean.isPinned! == 0 ? "置顶" : "取消置顶",
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
GestureDetector(
|
||||||
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onTap: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
enableTask();
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 15,
|
||||||
|
),
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: Text(
|
||||||
|
widget.taskBean.isDisabled! == 0 ? "禁用" : "启用",
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.red,
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: QlAppBar(
|
appBar: QlAppBar(
|
||||||
canBack: true,
|
canBack: true,
|
||||||
@@ -26,78 +153,221 @@ class _TaskDetailPageState extends ConsumerState<TaskDetailPage> {
|
|||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
},
|
},
|
||||||
title: widget.taskBean.name ?? "",
|
title: widget.taskBean.name ?? "",
|
||||||
),
|
actions: [
|
||||||
body: SingleChildScrollView(
|
InkWell(
|
||||||
child: Container(
|
onTap: () {
|
||||||
margin: const EdgeInsets.symmetric(
|
showCupertinoModalPopup(
|
||||||
horizontal: 15,
|
context: context,
|
||||||
vertical: 10,
|
builder: (context) {
|
||||||
),
|
return CupertinoActionSheet(
|
||||||
padding: const EdgeInsets.only(
|
title: Container(
|
||||||
top: 10,
|
alignment: Alignment.center,
|
||||||
bottom: 10,
|
child: const Material(
|
||||||
),
|
color: Colors.transparent,
|
||||||
decoration: BoxDecoration(
|
child: Text(
|
||||||
color: ref.watch(themeProvider).themeColor.settingBgColor(),
|
"更多操作",
|
||||||
borderRadius: BorderRadius.circular(15),
|
style: TextStyle(
|
||||||
),
|
fontSize: 16,
|
||||||
child: Column(
|
),
|
||||||
mainAxisSize: MainAxisSize.min,
|
),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
),
|
||||||
children: [
|
),
|
||||||
TaskDetailCell(
|
actions: actions,
|
||||||
title: "ID",
|
cancelButton: GestureDetector(
|
||||||
desc: widget.taskBean.sId ?? "",
|
behavior: HitTestBehavior.opaque,
|
||||||
|
onTap: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
alignment: Alignment.center,
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 10,
|
||||||
|
),
|
||||||
|
child: const Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: Text(
|
||||||
|
"取消",
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.red,
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: const Padding(
|
||||||
|
padding: EdgeInsets.symmetric(
|
||||||
|
horizontal: 15,
|
||||||
),
|
),
|
||||||
TaskDetailCell(
|
child: Center(
|
||||||
title: "任务",
|
child: Icon(
|
||||||
desc: widget.taskBean.command ?? "",
|
Icons.more_horiz,
|
||||||
),
|
color: Colors.white,
|
||||||
TaskDetailCell(
|
size: 26,
|
||||||
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 ? "正在运行" : "空闲",
|
],
|
||||||
|
),
|
||||||
|
body: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
margin: const EdgeInsets.symmetric(
|
||||||
|
horizontal: 15,
|
||||||
|
vertical: 10,
|
||||||
),
|
),
|
||||||
TaskDetailCell(
|
padding: const EdgeInsets.only(
|
||||||
title: "脚本状态",
|
top: 10,
|
||||||
desc: widget.taskBean.isDisabled == 1 ? "已禁用" : "正常",
|
bottom: 10,
|
||||||
hideDivide: true,
|
|
||||||
),
|
),
|
||||||
],
|
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: Utils.formatGMTTime(widget.taskBean.timestamp ?? ""),
|
||||||
|
),
|
||||||
|
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 ? "已禁用" : "已启用",
|
||||||
|
),
|
||||||
|
TaskDetailCell(
|
||||||
|
title: "是否置顶",
|
||||||
|
desc: widget.taskBean.isPinned == 1 ? "已置顶" : "未置顶",
|
||||||
|
hideDivide: true,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 30,
|
||||||
|
),
|
||||||
|
SizedBox(
|
||||||
|
width: MediaQuery.of(context).size.width - 80,
|
||||||
|
child: CupertinoButton(
|
||||||
|
padding: const EdgeInsets.symmetric(
|
||||||
|
vertical: 5,
|
||||||
|
),
|
||||||
|
color: Colors.red,
|
||||||
|
child: const Text(
|
||||||
|
"删 除",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 16,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
onPressed: () {
|
||||||
|
delTask(context, ref);
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
height: 30,
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
startCron(BuildContext context, WidgetRef ref) async {
|
||||||
|
await ref.read(taskProvider).runCrons(widget.taskBean.sId!);
|
||||||
|
setState(() {});
|
||||||
|
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
|
||||||
|
showLog();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
stopCron(BuildContext context, WidgetRef ref) async {
|
||||||
|
await ref.read(taskProvider).stopCrons(widget.taskBean.sId!);
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
void enableTask() async {
|
||||||
|
await ref.read(taskProvider).enableTask(widget.taskBean.sId!, widget.taskBean.isDisabled!);
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
void pinTask() async {
|
||||||
|
await ref.read(taskProvider).pinTask(widget.taskBean.sId!, widget.taskBean.isPinned!);
|
||||||
|
setState(() {});
|
||||||
|
}
|
||||||
|
|
||||||
|
void delTask(BuildContext context, WidgetRef ref) {
|
||||||
|
showCupertinoDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) => CupertinoAlertDialog(
|
||||||
|
title: const Text("确认删除"),
|
||||||
|
content: Text("确认删除定时任务 ${widget.taskBean.name ?? ""} 吗"),
|
||||||
|
actions: [
|
||||||
|
CupertinoDialogAction(
|
||||||
|
child: const Text("取消"),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
CupertinoDialogAction(
|
||||||
|
child: const Text("确定"),
|
||||||
|
onPressed: () async {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
await ref.read(taskProvider).delCron(widget.taskBean.sId!);
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
void showLog() {
|
void showLog() {
|
||||||
showCupertinoDialog(
|
showCupertinoDialog(
|
||||||
builder: (BuildContext context) {
|
builder: (BuildContext context) {
|
||||||
@@ -116,6 +386,7 @@ class _TaskDetailPageState extends ConsumerState<TaskDetailPage> {
|
|||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
|
ref.read(taskProvider).loadData(false);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -354,8 +354,11 @@ class TaskItemCell extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
startCron(BuildContext context, WidgetRef ref) {
|
startCron(BuildContext context, WidgetRef ref) async {
|
||||||
ref.read(taskProvider).runCrons(bean.sId!);
|
await ref.read(taskProvider).runCrons(bean.sId!);
|
||||||
|
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
|
||||||
|
logCron(context, ref);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
stopCron(BuildContext context, WidgetRef ref) {
|
stopCron(BuildContext context, WidgetRef ref) {
|
||||||
@@ -381,6 +384,7 @@ class TaskItemCell extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
|
ref.read(taskProvider).loadData(false);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import 'package:qinglong_app/base/base_viewmodel.dart';
|
|||||||
import 'package:qinglong_app/base/http/api.dart';
|
import 'package:qinglong_app/base/http/api.dart';
|
||||||
import 'package:qinglong_app/base/http/http.dart';
|
import 'package:qinglong_app/base/http/http.dart';
|
||||||
import 'package:qinglong_app/module/task/task_bean.dart';
|
import 'package:qinglong_app/module/task/task_bean.dart';
|
||||||
|
import 'package:qinglong_app/utils/extension.dart';
|
||||||
|
|
||||||
var taskProvider = ChangeNotifierProvider((ref) => TaskViewModel());
|
var taskProvider = ChangeNotifierProvider((ref) => TaskViewModel());
|
||||||
|
|
||||||
@@ -30,7 +31,6 @@ class TaskViewModel extends BaseViewModel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sortList() {
|
void sortList() {
|
||||||
|
|
||||||
for (int i = 0; i < list.length; i++) {
|
for (int i = 0; i < list.length; i++) {
|
||||||
if (list[i].isPinned == 1) {
|
if (list[i].isPinned == 1) {
|
||||||
final TaskBean item = list.removeAt(i);
|
final TaskBean item = list.removeAt(i);
|
||||||
@@ -68,6 +68,7 @@ class TaskViewModel extends BaseViewModel {
|
|||||||
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);
|
list.removeWhere((element) => element.sId == id);
|
||||||
|
"删除成功".toast();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
} else {
|
} else {
|
||||||
failToast(result.message, notify: true);
|
failToast(result.message, notify: true);
|
||||||
@@ -86,12 +87,11 @@ class TaskViewModel extends BaseViewModel {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
void pinTask(String sId, int isPinned) async {
|
Future<void> pinTask(String sId, int isPinned) async {
|
||||||
if (isPinned == 1) {
|
if (isPinned == 1) {
|
||||||
HttpResponse<NullResponse> response = await Api.unpinTask(sId);
|
HttpResponse<NullResponse> response = await Api.unpinTask(sId);
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
list.firstWhere((element) => element.sId == sId).isPinned = 0;
|
|
||||||
sortList();
|
sortList();
|
||||||
success();
|
success();
|
||||||
} else {
|
} else {
|
||||||
@@ -101,7 +101,6 @@ class TaskViewModel extends BaseViewModel {
|
|||||||
HttpResponse<NullResponse> response = await Api.pinTask(sId);
|
HttpResponse<NullResponse> response = await Api.pinTask(sId);
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
list.firstWhere((element) => element.sId == sId).isPinned = 1;
|
|
||||||
sortList();
|
sortList();
|
||||||
success();
|
success();
|
||||||
} else {
|
} else {
|
||||||
@@ -110,7 +109,7 @@ class TaskViewModel extends BaseViewModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void enableTask(String sId, int isDisabled) async {
|
Future<void> enableTask(String sId, int isDisabled) async {
|
||||||
if (isDisabled == 0) {
|
if (isDisabled == 0) {
|
||||||
HttpResponse<NullResponse> response = await Api.disableTask(sId);
|
HttpResponse<NullResponse> response = await Api.disableTask(sId);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user