mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
add scripts
This commit is contained in:
@@ -12,7 +12,8 @@ import 'package:qinglong_app/module/task/task_detail/task_detail_bean.dart';
|
||||
import 'url.dart';
|
||||
|
||||
class Api {
|
||||
static Future<HttpResponse<LoginBean>> login(String userName, String passWord) async {
|
||||
static Future<HttpResponse<LoginBean>> login(
|
||||
String userName, String passWord) async {
|
||||
return await Http.post<LoginBean>(
|
||||
Url.login,
|
||||
{
|
||||
@@ -29,14 +30,16 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> startTasks(List<String> crons) async {
|
||||
static Future<HttpResponse<NullResponse>> startTasks(
|
||||
List<String> crons) async {
|
||||
return await Http.put<NullResponse>(
|
||||
Url.runTasks,
|
||||
crons,
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> stopTasks(List<String> crons) async {
|
||||
static Future<HttpResponse<NullResponse>> stopTasks(
|
||||
List<String> crons) async {
|
||||
return await Http.put<NullResponse>(
|
||||
Url.runTasks,
|
||||
crons,
|
||||
@@ -57,7 +60,9 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<TaskDetailBean>> addTask(String name, String command, String cron, {String? id}) async {
|
||||
static Future<HttpResponse<TaskDetailBean>> addTask(
|
||||
String name, String command, String cron,
|
||||
{String? id}) async {
|
||||
var data = {"name": name, "command": command, "schedule": cron};
|
||||
|
||||
if (id != null) {
|
||||
@@ -122,7 +127,8 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> saveFile(String name, String content) async {
|
||||
static Future<HttpResponse<NullResponse>> saveFile(
|
||||
String name, String content) async {
|
||||
return await Http.post<NullResponse>(
|
||||
Url.saveFile,
|
||||
{"content": content, "name": name},
|
||||
@@ -157,7 +163,9 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> addEnv(String name, String value, String remarks, {String? id}) async {
|
||||
static Future<HttpResponse<NullResponse>> addEnv(
|
||||
String name, String value, String remarks,
|
||||
{String? id}) async {
|
||||
var data = {
|
||||
"value": value,
|
||||
"remarks": remarks,
|
||||
@@ -177,7 +185,8 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> moveEnv(String id, int fromIndex, int toIndex) async {
|
||||
static Future<HttpResponse<NullResponse>> moveEnv(
|
||||
String id, int fromIndex, int toIndex) async {
|
||||
return await Http.put<NullResponse>(
|
||||
Url.envMove(id),
|
||||
{"fromIndex": fromIndex, "toIndex": toIndex},
|
||||
@@ -192,7 +201,8 @@ class Api {
|
||||
}
|
||||
|
||||
static Future<HttpResponse<List<TaskLogBean>>> taskLog() async {
|
||||
return await Http.get<List<TaskLogBean>>(Url.taskLog, null, serializationName: "dirs");
|
||||
return await Http.get<List<TaskLogBean>>(Url.taskLog, null,
|
||||
serializationName: "dirs");
|
||||
}
|
||||
|
||||
static Future<HttpResponse<String>> taskLogDetail(String name) async {
|
||||
@@ -209,7 +219,8 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<String>> scriptDetail(String name, String path) async {
|
||||
static Future<HttpResponse<String>> scriptDetail(
|
||||
String name, String? path) async {
|
||||
return await Http.get<String>(
|
||||
Url.scriptDetail + name,
|
||||
{
|
||||
@@ -218,7 +229,8 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<List<DependencyBean>>> dependencies(String type) async {
|
||||
static Future<HttpResponse<List<DependencyBean>>> dependencies(
|
||||
String type) async {
|
||||
return await Http.get<List<DependencyBean>>(
|
||||
Url.dependencies,
|
||||
{
|
||||
@@ -227,7 +239,8 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> dependencyReinstall(String id) async {
|
||||
static Future<HttpResponse<NullResponse>> dependencyReinstall(
|
||||
String id) async {
|
||||
return await Http.put<NullResponse>(
|
||||
Url.dependencies,
|
||||
[id],
|
||||
@@ -241,7 +254,8 @@ class Api {
|
||||
);
|
||||
}
|
||||
|
||||
static Future<HttpResponse<NullResponse>> addDependency(String name, int type) async {
|
||||
static Future<HttpResponse<NullResponse>> addDependency(
|
||||
String name, int type) async {
|
||||
return await Http.post<NullResponse>(
|
||||
Url.dependencies,
|
||||
[
|
||||
|
||||
@@ -40,7 +40,7 @@ class Http {
|
||||
|
||||
static Future<HttpResponse<T>> get<T>(
|
||||
String uri,
|
||||
Map<String, String>? json, {
|
||||
Map<String, String?>? json, {
|
||||
bool compute = true,
|
||||
String serializationName = "data",
|
||||
}) async {
|
||||
@@ -53,7 +53,10 @@ class Http {
|
||||
if (e.response?.statusCode == 401) {
|
||||
exitLogin();
|
||||
}
|
||||
return HttpResponse(success: false, message: e.response?.statusMessage ?? e.message, code: 0);
|
||||
return HttpResponse(
|
||||
success: false,
|
||||
message: e.response?.statusMessage ?? e.message,
|
||||
code: 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +79,10 @@ class Http {
|
||||
if (e.response?.statusCode == 401) {
|
||||
exitLogin();
|
||||
}
|
||||
return HttpResponse(success: false, message: e.response?.statusMessage ?? e.message, code: 0);
|
||||
return HttpResponse(
|
||||
success: false,
|
||||
message: e.response?.statusMessage ?? e.message,
|
||||
code: 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +105,10 @@ class Http {
|
||||
if (e.response?.statusCode == 401) {
|
||||
exitLogin();
|
||||
}
|
||||
return HttpResponse(success: false, message: e.response?.statusMessage ?? e.message, code: 0);
|
||||
return HttpResponse(
|
||||
success: false,
|
||||
message: e.response?.statusMessage ?? e.message,
|
||||
code: 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +130,10 @@ class Http {
|
||||
if (e.response?.statusCode == 401) {
|
||||
exitLogin();
|
||||
}
|
||||
return HttpResponse(success: false, message: e.response?.statusMessage ?? e.message, code: 0);
|
||||
return HttpResponse(
|
||||
success: false,
|
||||
message: e.response?.statusMessage ?? e.message,
|
||||
code: 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,7 +227,8 @@ class HttpResponse<T> {
|
||||
late int code;
|
||||
T? bean;
|
||||
|
||||
HttpResponse({required this.success, this.message, required this.code, this.bean});
|
||||
HttpResponse(
|
||||
{required this.success, this.message, required this.code, this.bean});
|
||||
}
|
||||
|
||||
class DeserializeAction<T> {
|
||||
|
||||
@@ -6,6 +6,8 @@ import 'package:qinglong_app/module/env/env_bean.dart';
|
||||
import 'package:qinglong_app/module/home/home_page.dart';
|
||||
import 'package:qinglong_app/module/login/login_page.dart';
|
||||
import 'package:qinglong_app/module/others/login_log/login_log_page.dart';
|
||||
import 'package:qinglong_app/module/others/scripts/script_detail_page.dart';
|
||||
import 'package:qinglong_app/module/others/scripts/script_page.dart';
|
||||
import 'package:qinglong_app/module/others/task_log/task_log_detail_page.dart';
|
||||
import 'package:qinglong_app/module/others/task_log/task_log_page.dart';
|
||||
import 'package:qinglong_app/module/task/add_task_page.dart';
|
||||
@@ -20,6 +22,8 @@ class Routes {
|
||||
static const String routeLoginLog = "/log/login";
|
||||
static const String routeTaskLog = "/log/task";
|
||||
static const String routeTaskLogDetail = "/log/taskDetail";
|
||||
static const String routeScript = "/script";
|
||||
static const String routeScriptDetail = "/script/detail";
|
||||
|
||||
static Route<dynamic>? generateRoute(RouteSettings settings) {
|
||||
switch (settings.name) {
|
||||
@@ -60,11 +64,23 @@ class Routes {
|
||||
return CupertinoPageRoute(
|
||||
builder: (context) => const TaskLogPage(),
|
||||
);
|
||||
case routeScript:
|
||||
return CupertinoPageRoute(
|
||||
builder: (context) => const ScriptPage(),
|
||||
);
|
||||
case routeTaskLogDetail:
|
||||
return CupertinoPageRoute(
|
||||
builder: (context) => TaskLogDetailPage(
|
||||
title: settings.arguments as String,
|
||||
));
|
||||
builder: (context) => TaskLogDetailPage(
|
||||
title: settings.arguments as String,
|
||||
),
|
||||
);
|
||||
case routeScriptDetail:
|
||||
return CupertinoPageRoute(
|
||||
builder: (context) => ScriptDetailPage(
|
||||
title: (settings.arguments as Map)["title"],
|
||||
path: (settings.arguments as Map)["path"],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
29
lib/base/ui/lazy_load_state.dart
Normal file
29
lib/base/ui/lazy_load_state.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
/// @author NewTab
|
||||
|
||||
mixin LazyLoadState<T extends StatefulWidget> on State<T> {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
|
||||
var route = ModalRoute.of(context);
|
||||
void handler(status) {
|
||||
if (status == AnimationStatus.completed) {
|
||||
route?.animation?.removeStatusListener(handler);
|
||||
onLazyLoad();
|
||||
}
|
||||
}
|
||||
|
||||
if (route == null ||
|
||||
route.animation == null ||
|
||||
route.animation!.status == AnimationStatus.completed) {
|
||||
onLazyLoad();
|
||||
} else {
|
||||
route.animation!.addStatusListener(handler);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void onLazyLoad();
|
||||
}
|
||||
Reference in New Issue
Block a user