支持上传脚本

This commit is contained in:
jyuesong
2022-06-16 14:37:47 +08:00
parent 2005083d2e
commit 1298dba590
58 changed files with 1702 additions and 774 deletions

View File

@@ -207,8 +207,11 @@ class _AddTaskPageState extends ConsumerState<AddTaskPage> {
taskBean.command = _commandController.text;
taskBean.schedule = _cronController.text;
HttpResponse<NullResponse> response = await Api.addTask(
_nameController.text, _commandController.text, _cronController.text,
id: taskBean.id,);
_nameController.text,
_commandController.text,
_cronController.text,
id: taskBean.id,
);
if (response.success) {
(widget.taskBean?.sId == null) ? "新增成功" : "修改成功".toast();

View File

@@ -39,8 +39,7 @@ class _InTimeLogPageState extends State<InTimeLogPage>
if (!canRequest) return;
if (isRequest) return;
isRequest = true;
HttpResponse<String> response =
await Api.inTimeLog(widget.cronId);
HttpResponse<String> response = await Api.inTimeLog(widget.cronId);
if (response.success) {
content = response.bean;
setState(() {});
@@ -161,7 +160,7 @@ class _InTimeLogPageState extends State<InTimeLogPage>
if (widget.needTimer) {
_timer = Timer.periodic(
const Duration(seconds: 2),
(timer) {
(timer) {
getLogData();
},
);

View File

@@ -26,20 +26,20 @@ class TaskBean {
TaskBean(
{this.name,
this.command,
this.schedule,
this.saved,
this.sId,
this.created,
this.status,
this.timestamp,
this.isSystem,
this.isDisabled,
this.logPath,
this.isPinned,
this.lastExecutionTime,
this.lastRunningTime,
this.pid});
this.command,
this.schedule,
this.saved,
this.sId,
this.created,
this.status,
this.timestamp,
this.isSystem,
this.isDisabled,
this.logPath,
this.isPinned,
this.lastExecutionTime,
this.lastRunningTime,
this.pid});
get nId => _id;
@@ -51,7 +51,9 @@ class TaskBean {
saved = json['saved'];
id = json['id'];
_id = json['_id'];
sId = json.containsKey('_id') ? json['_id'].toString() : (json.containsKey('id') ? json['id'].toString() : "");
sId = json.containsKey('_id')
? json['_id'].toString()
: (json.containsKey('id') ? json['id'].toString() : "");
created = int.tryParse(json['created'].toString());
status = json['status'];
timestamp = json['timestamp'].toString();

View File

@@ -17,7 +17,8 @@ class TaskDetailPage extends ConsumerStatefulWidget {
final TaskBean taskBean;
final bool hideAppbar;
const TaskDetailPage(this.taskBean, {Key? key, this.hideAppbar = false}) : super(key: key);
const TaskDetailPage(this.taskBean, {Key? key, this.hideAppbar = false})
: super(key: key);
@override
_TaskDetailPageState createState() => _TaskDetailPageState();
@@ -71,11 +72,13 @@ class _TaskDetailPageState extends ConsumerState<TaskDetailPage> {
),
TaskDetailCell(
title: "创建时间",
desc: Utils.formatMessageTime(widget.taskBean.created ?? 0),
desc:
Utils.formatMessageTime(widget.taskBean.created ?? 0),
),
TaskDetailCell(
title: "更新时间",
desc: Utils.formatGMTTime(widget.taskBean.timestamp ?? ""),
desc:
Utils.formatGMTTime(widget.taskBean.timestamp ?? ""),
),
TaskDetailCell(
title: "任务定时",
@@ -83,11 +86,14 @@ class _TaskDetailPageState extends ConsumerState<TaskDetailPage> {
),
TaskDetailCell(
title: "最后运行时间",
desc: Utils.formatMessageTime(widget.taskBean.lastExecutionTime ?? 0),
desc: Utils.formatMessageTime(
widget.taskBean.lastExecutionTime ?? 0),
),
TaskDetailCell(
title: "最后运行时长",
desc: widget.taskBean.lastRunningTime == null ? "-" : "${widget.taskBean.lastRunningTime ?? "-"}",
desc: widget.taskBean.lastRunningTime == null
? "-"
: "${widget.taskBean.lastRunningTime ?? "-"}",
),
GestureDetector(
behavior: HitTestBehavior.opaque,
@@ -205,7 +211,8 @@ class _TaskDetailPageState extends ConsumerState<TaskDetailPage> {
behavior: HitTestBehavior.opaque,
onTap: () {
Navigator.of(context).pop();
Navigator.of(context).pushNamed(Routes.routeAddTask, arguments: widget.taskBean);
Navigator.of(context)
.pushNamed(Routes.routeAddTask, arguments: widget.taskBean);
},
child: Container(
padding: const EdgeInsets.symmetric(
@@ -357,12 +364,16 @@ class _TaskDetailPageState extends ConsumerState<TaskDetailPage> {
}
void enableTask() async {
await ref.read(taskProvider).enableTask(widget.taskBean.sId!, widget.taskBean.isDisabled!);
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!);
await ref
.read(taskProvider)
.pinTask(widget.taskBean.sId!, widget.taskBean.isPinned!);
setState(() {});
}
@@ -472,14 +483,16 @@ class TaskDetailCell extends ConsumerWidget {
}
},
style: TextStyle(
color: ref.watch(themeProvider).themeColor.descColor(),
color:
ref.watch(themeProvider).themeColor.descColor(),
fontSize: 14,
),
),
),
)
: Expanded(
child: Align(alignment: Alignment.centerRight, child: icon!),
child:
Align(alignment: Alignment.centerRight, child: icon!),
),
],
),

View File

@@ -67,9 +67,17 @@ class _TaskPageState extends ConsumerState<TaskPage> {
}
TaskBean item = list[index - 1];
if (_searchController.text.isEmpty ||
(item.name?.toLowerCase().contains(_searchController.text.toLowerCase()) ?? false) ||
(item.command?.toLowerCase().contains(_searchController.text.toLowerCase()) ?? false) ||
(item.schedule?.contains(_searchController.text.toLowerCase()) ?? false)) {
(item.name
?.toLowerCase()
.contains(_searchController.text.toLowerCase()) ??
false) ||
(item.command
?.toLowerCase()
.contains(_searchController.text.toLowerCase()) ??
false) ||
(item.schedule
?.contains(_searchController.text.toLowerCase()) ??
false)) {
return TaskItemCell(item, ref);
} else {
return const SizedBox.shrink();
@@ -80,9 +88,17 @@ class _TaskPageState extends ConsumerState<TaskPage> {
if (index == 0) return const SizedBox.shrink();
TaskBean item = list[index - 1];
if (_searchController.text.isEmpty ||
(item.name?.toLowerCase().contains(_searchController.text.toLowerCase()) ?? false) ||
(item.command?.toLowerCase().contains(_searchController.text.toLowerCase()) ?? false) ||
(item.schedule?.contains(_searchController.text.toLowerCase()) ?? false)) {
(item.name
?.toLowerCase()
.contains(_searchController.text.toLowerCase()) ??
false) ||
(item.command
?.toLowerCase()
.contains(_searchController.text.toLowerCase()) ??
false) ||
(item.schedule
?.contains(_searchController.text.toLowerCase()) ??
false)) {
return Container(
color: ref.watch(themeProvider).themeColor.settingBgColor(),
child: const Divider(
@@ -130,7 +146,9 @@ class _TaskPageState extends ConsumerState<TaskPage> {
child: Text(
TaskViewModel.allStr,
style: TextStyle(
color: currentState == TaskViewModel.allStr ? ref.watch(themeProvider).primaryColor : ref.watch(themeProvider).themeColor.titleColor(),
color: currentState == TaskViewModel.allStr
? ref.watch(themeProvider).primaryColor
: ref.watch(themeProvider).themeColor.titleColor(),
fontSize: 14,
),
),
@@ -140,8 +158,9 @@ class _TaskPageState extends ConsumerState<TaskPage> {
child: Text(
TaskViewModel.runningStr,
style: TextStyle(
color:
currentState == TaskViewModel.runningStr ? ref.watch(themeProvider).primaryColor : ref.watch(themeProvider).themeColor.titleColor(),
color: currentState == TaskViewModel.runningStr
? ref.watch(themeProvider).primaryColor
: ref.watch(themeProvider).themeColor.titleColor(),
fontSize: 14,
),
),
@@ -151,7 +170,9 @@ class _TaskPageState extends ConsumerState<TaskPage> {
child: Text(
TaskViewModel.neverStr,
style: TextStyle(
color: currentState == TaskViewModel.neverStr ? ref.watch(themeProvider).primaryColor : ref.watch(themeProvider).themeColor.titleColor(),
color: currentState == TaskViewModel.neverStr
? ref.watch(themeProvider).primaryColor
: ref.watch(themeProvider).themeColor.titleColor(),
fontSize: 14,
),
),
@@ -165,7 +186,10 @@ class _TaskPageState extends ConsumerState<TaskPage> {
style: TextStyle(
color: currentState == TaskViewModel.notScriptStr
? ref.watch(themeProvider).primaryColor
: ref.watch(themeProvider).themeColor.titleColor(),
: ref
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 14,
),
),
@@ -178,8 +202,9 @@ class _TaskPageState extends ConsumerState<TaskPage> {
TaskViewModel.disableStr,
style: TextStyle(
fontSize: 14,
color:
currentState == TaskViewModel.disableStr ? ref.watch(themeProvider).primaryColor : ref.watch(themeProvider).themeColor.titleColor(),
color: currentState == TaskViewModel.disableStr
? ref.watch(themeProvider).primaryColor
: ref.watch(themeProvider).themeColor.titleColor(),
),
),
value: TaskViewModel.disableStr,
@@ -236,7 +261,9 @@ class TaskItemCell extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ColoredBox(
color: bean.isPinned == 1 ? ref.watch(themeProvider).themeColor.pinColor() : ref.watch(themeProvider).themeColor.settingBgColor(),
color: bean.isPinned == 1
? ref.watch(themeProvider).themeColor.pinColor()
: ref.watch(themeProvider).themeColor.settingBgColor(),
child: Slidable(
key: ValueKey(bean.sId),
endActionPane: ActionPane(
@@ -247,7 +274,8 @@ class TaskItemCell extends StatelessWidget {
backgroundColor: const Color(0xff5D5E70),
onPressed: (_) {
WidgetsBinding.instance.endOfFrame.then((timeStamp) {
Navigator.of(context).pushNamed(Routes.routeAddTask, arguments: bean);
Navigator.of(context)
.pushNamed(Routes.routeAddTask, arguments: bean);
});
},
foregroundColor: Colors.white,
@@ -259,7 +287,9 @@ class TaskItemCell extends StatelessWidget {
pinTask(context);
},
foregroundColor: Colors.white,
icon: (bean.isPinned ?? 0) == 0 ? CupertinoIcons.pin : CupertinoIcons.pin_slash,
icon: (bean.isPinned ?? 0) == 0
? CupertinoIcons.pin
: CupertinoIcons.pin_slash,
),
SlidableAction(
backgroundColor: const Color(0xffA356D6),
@@ -267,7 +297,9 @@ class TaskItemCell extends StatelessWidget {
enableTask(context);
},
foregroundColor: Colors.white,
icon: bean.isDisabled! == 0 ? Icons.dnd_forwardslash : Icons.check_circle_outline_sharp,
icon: bean.isDisabled! == 0
? Icons.dnd_forwardslash
: Icons.check_circle_outline_sharp,
),
SlidableAction(
backgroundColor: const Color(0xffEA4D3E),
@@ -299,7 +331,9 @@ class TaskItemCell extends StatelessWidget {
}
},
foregroundColor: Colors.white,
icon: bean.status! == 1 ? CupertinoIcons.memories : CupertinoIcons.stop_circle,
icon: bean.status! == 1
? CupertinoIcons.memories
: CupertinoIcons.stop_circle,
),
SlidableAction(
backgroundColor: const Color(0xff606467),
@@ -317,10 +351,13 @@ class TaskItemCell extends StatelessWidget {
],
),
child: Material(
color: bean.isPinned == 1 ? ref.watch(themeProvider).themeColor.pinColor() : ref.watch(themeProvider).themeColor.settingBgColor(),
color: bean.isPinned == 1
? ref.watch(themeProvider).themeColor.pinColor()
: ref.watch(themeProvider).themeColor.settingBgColor(),
child: InkWell(
onTap: () {
Navigator.of(context).pushNamed(Routes.routeTaskDetail, arguments: bean);
Navigator.of(context)
.pushNamed(Routes.routeTaskDetail, arguments: bean);
},
child: Container(
width: MediaQuery.of(context).size.width,
@@ -356,7 +393,10 @@ class TaskItemCell extends StatelessWidget {
overflow: TextOverflow.ellipsis,
style: TextStyle(
overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.titleColor(),
color: ref
.watch(themeProvider)
.themeColor
.titleColor(),
fontSize: 16,
),
),
@@ -392,11 +432,16 @@ class TaskItemCell extends StatelessWidget {
Material(
color: Colors.transparent,
child: Text(
(bean.lastExecutionTime == null || bean.lastExecutionTime == 0) ? "-" : Utils.formatMessageTime(bean.lastExecutionTime!),
(bean.lastExecutionTime == null ||
bean.lastExecutionTime == 0)
? "-"
: Utils.formatMessageTime(
bean.lastExecutionTime!),
maxLines: 1,
style: TextStyle(
overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.descColor(),
color:
ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12,
),
),

View File

@@ -62,7 +62,8 @@ class TaskViewModel extends BaseViewModel {
}
p.sort((TaskBean a, TaskBean b) {
bool c = DateTime.fromMillisecondsSinceEpoch(a.created ?? 0).isBefore(DateTime.fromMillisecondsSinceEpoch(b.created ?? 0));
bool c = DateTime.fromMillisecondsSinceEpoch(a.created ?? 0)
.isBefore(DateTime.fromMillisecondsSinceEpoch(b.created ?? 0));
if (c == true) {
return 1;
}
@@ -75,7 +76,8 @@ class TaskViewModel extends BaseViewModel {
p.sort((a, b) {
if (a.status == 0 && b.status == 0) {
bool c = DateTime.fromMillisecondsSinceEpoch(a.created ?? 0).isBefore(DateTime.fromMillisecondsSinceEpoch(b.created ?? 0));
bool c = DateTime.fromMillisecondsSinceEpoch(a.created ?? 0)
.isBefore(DateTime.fromMillisecondsSinceEpoch(b.created ?? 0));
if (c == true) {
return 1;
}
@@ -86,7 +88,8 @@ class TaskViewModel extends BaseViewModel {
});
r.sort((a, b) {
bool c = DateTime.fromMillisecondsSinceEpoch(a.created ?? 0).isBefore(DateTime.fromMillisecondsSinceEpoch(b.created ?? 0));
bool c = DateTime.fromMillisecondsSinceEpoch(a.created ?? 0)
.isBefore(DateTime.fromMillisecondsSinceEpoch(b.created ?? 0));
if (c == true) {
return 1;
}
@@ -94,7 +97,8 @@ class TaskViewModel extends BaseViewModel {
});
d.sort((a, b) {
bool c = DateTime.fromMillisecondsSinceEpoch(a.created ?? 0).isBefore(DateTime.fromMillisecondsSinceEpoch(b.created ?? 0));
bool c = DateTime.fromMillisecondsSinceEpoch(a.created ?? 0)
.isBefore(DateTime.fromMillisecondsSinceEpoch(b.created ?? 0));
if (c == true) {
return 1;
}
@@ -102,7 +106,8 @@ class TaskViewModel extends BaseViewModel {
});
list.sort((a, b) {
bool c = DateTime.fromMillisecondsSinceEpoch(a.created ?? 0).isBefore(DateTime.fromMillisecondsSinceEpoch(b.created ?? 0));
bool c = DateTime.fromMillisecondsSinceEpoch(a.created ?? 0)
.isBefore(DateTime.fromMillisecondsSinceEpoch(b.created ?? 0));
if (c == true) {
return 1;
}
@@ -116,9 +121,12 @@ class TaskViewModel extends BaseViewModel {
running.clear();
running.addAll(list.where((element) => element.status == 0));
neverRunning.clear();
neverRunning.addAll(list.where((element) => element.lastRunningTime == null));
neverRunning
.addAll(list.where((element) => element.lastRunningTime == null));
notScripts.clear();
notScripts.addAll(list.where((element) => (element.command != null && (element.command!.startsWith("ql repo") || element.command!.startsWith("ql raw")))));
notScripts.addAll(list.where((element) => (element.command != null &&
(element.command!.startsWith("ql repo") ||
element.command!.startsWith("ql raw")))));
disabled.clear();
disabled.addAll(list.where((element) => element.isDisabled == 1));
}