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();
|
||||
}
|
||||
123
lib/json.jc.dart
123
lib/json.jc.dart
@@ -10,10 +10,8 @@ import 'package:qinglong_app/module/others/task_log/task_log_bean.dart';
|
||||
import 'package:qinglong_app/module/task/task_bean.dart';
|
||||
import 'package:qinglong_app/module/task/task_detail/task_detail_bean.dart';
|
||||
|
||||
|
||||
class JsonConversion$Json {
|
||||
|
||||
static M fromJson<M>(dynamic json) {
|
||||
static M fromJson<M>(dynamic json) {
|
||||
if (json is List) {
|
||||
return _getListChildType<M>(json);
|
||||
} else {
|
||||
@@ -22,85 +20,96 @@ class JsonConversion$Json {
|
||||
}
|
||||
|
||||
static M _fromJsonSingle<M>(dynamic json) {
|
||||
|
||||
String type = M.toString();
|
||||
|
||||
if(type == (ConfigBean).toString()){
|
||||
return ConfigBean.jsonConversion(json) as M;
|
||||
if (type == (ConfigBean).toString()) {
|
||||
return ConfigBean.jsonConversion(json) as M;
|
||||
}
|
||||
|
||||
if(type == (EnvBean).toString()){
|
||||
return EnvBean.jsonConversion(json) as M;
|
||||
|
||||
if (type == (EnvBean).toString()) {
|
||||
return EnvBean.jsonConversion(json) as M;
|
||||
}
|
||||
|
||||
if(type == (LoginBean).toString()){
|
||||
return LoginBean.jsonConversion(json) as M;
|
||||
|
||||
if (type == (LoginBean).toString()) {
|
||||
return LoginBean.jsonConversion(json) as M;
|
||||
}
|
||||
|
||||
if(type == (DependencyBean).toString()){
|
||||
return DependencyBean.jsonConversion(json) as M;
|
||||
|
||||
if (type == (DependencyBean).toString()) {
|
||||
return DependencyBean.jsonConversion(json) as M;
|
||||
}
|
||||
|
||||
if(type == (LoginLogBean).toString()){
|
||||
return LoginLogBean.jsonConversion(json) as M;
|
||||
|
||||
if (type == (LoginLogBean).toString()) {
|
||||
return LoginLogBean.jsonConversion(json) as M;
|
||||
}
|
||||
|
||||
if(type == (ScriptBean).toString()){
|
||||
return ScriptBean.jsonConversion(json) as M;
|
||||
|
||||
if (type == (ScriptBean).toString()) {
|
||||
return ScriptBean.jsonConversion(json) as M;
|
||||
}
|
||||
|
||||
if(type == (TaskLogBean).toString()){
|
||||
return TaskLogBean.jsonConversion(json) as M;
|
||||
|
||||
if (type == (TaskLogBean).toString()) {
|
||||
return TaskLogBean.jsonConversion(json) as M;
|
||||
}
|
||||
|
||||
if(type == (TaskBean).toString()){
|
||||
return TaskBean.jsonConversion(json) as M;
|
||||
|
||||
if (type == (TaskBean).toString()) {
|
||||
return TaskBean.jsonConversion(json) as M;
|
||||
}
|
||||
|
||||
if(type == (TaskDetailBean).toString()){
|
||||
return TaskDetailBean.jsonConversion(json) as M;
|
||||
|
||||
if (type == (TaskDetailBean).toString()) {
|
||||
return TaskDetailBean.jsonConversion(json) as M;
|
||||
}
|
||||
|
||||
|
||||
throw Exception("not found");
|
||||
}
|
||||
|
||||
static M _getListChildType<M>(List<dynamic> data) {
|
||||
if(<ConfigBean>[] is M){
|
||||
return data.map<ConfigBean>((e) => ConfigBean.jsonConversion(e)).toList() as M;
|
||||
if (<ConfigBean>[] is M) {
|
||||
return data.map<ConfigBean>((e) => ConfigBean.jsonConversion(e)).toList()
|
||||
as M;
|
||||
}
|
||||
|
||||
if(<EnvBean>[] is M){
|
||||
|
||||
if (<EnvBean>[] is M) {
|
||||
return data.map<EnvBean>((e) => EnvBean.jsonConversion(e)).toList() as M;
|
||||
}
|
||||
|
||||
if(<LoginBean>[] is M){
|
||||
return data.map<LoginBean>((e) => LoginBean.jsonConversion(e)).toList() as M;
|
||||
|
||||
if (<LoginBean>[] is M) {
|
||||
return data.map<LoginBean>((e) => LoginBean.jsonConversion(e)).toList()
|
||||
as M;
|
||||
}
|
||||
|
||||
if(<DependencyBean>[] is M){
|
||||
return data.map<DependencyBean>((e) => DependencyBean.jsonConversion(e)).toList() as M;
|
||||
|
||||
if (<DependencyBean>[] is M) {
|
||||
return data
|
||||
.map<DependencyBean>((e) => DependencyBean.jsonConversion(e))
|
||||
.toList() as M;
|
||||
}
|
||||
|
||||
if(<LoginLogBean>[] is M){
|
||||
return data.map<LoginLogBean>((e) => LoginLogBean.jsonConversion(e)).toList() as M;
|
||||
|
||||
if (<LoginLogBean>[] is M) {
|
||||
return data
|
||||
.map<LoginLogBean>((e) => LoginLogBean.jsonConversion(e))
|
||||
.toList() as M;
|
||||
}
|
||||
|
||||
if(<ScriptBean>[] is M){
|
||||
return data.map<ScriptBean>((e) => ScriptBean.jsonConversion(e)).toList() as M;
|
||||
|
||||
if (<ScriptBean>[] is M) {
|
||||
return data.map<ScriptBean>((e) => ScriptBean.jsonConversion(e)).toList()
|
||||
as M;
|
||||
}
|
||||
|
||||
if(<TaskLogBean>[] is M){
|
||||
return data.map<TaskLogBean>((e) => TaskLogBean.jsonConversion(e)).toList() as M;
|
||||
|
||||
if (<TaskLogBean>[] is M) {
|
||||
return data
|
||||
.map<TaskLogBean>((e) => TaskLogBean.jsonConversion(e))
|
||||
.toList() as M;
|
||||
}
|
||||
|
||||
if(<TaskBean>[] is M){
|
||||
return data.map<TaskBean>((e) => TaskBean.jsonConversion(e)).toList() as M;
|
||||
|
||||
if (<TaskBean>[] is M) {
|
||||
return data.map<TaskBean>((e) => TaskBean.jsonConversion(e)).toList()
|
||||
as M;
|
||||
}
|
||||
|
||||
if(<TaskDetailBean>[] is M){
|
||||
return data.map<TaskDetailBean>((e) => TaskDetailBean.jsonConversion(e)).toList() as M;
|
||||
|
||||
if (<TaskDetailBean>[] is M) {
|
||||
return data
|
||||
.map<TaskDetailBean>((e) => TaskDetailBean.jsonConversion(e))
|
||||
.toList() as M;
|
||||
}
|
||||
|
||||
|
||||
throw Exception("not found");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ class LoginPage extends ConsumerStatefulWidget {
|
||||
}
|
||||
|
||||
class _LoginPageState extends ConsumerState<LoginPage> {
|
||||
final TextEditingController _hostController = TextEditingController(text: getIt<UserInfoViewModel>().host);
|
||||
final TextEditingController _hostController =
|
||||
TextEditingController(text: getIt<UserInfoViewModel>().host);
|
||||
final TextEditingController _userNameController = TextEditingController();
|
||||
final TextEditingController _passwordController = TextEditingController();
|
||||
|
||||
@@ -30,13 +31,15 @@ class _LoginPageState extends ConsumerState<LoginPage> {
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
if (getIt<UserInfoViewModel>().userName != null && getIt<UserInfoViewModel>().userName!.isNotEmpty) {
|
||||
if (getIt<UserInfoViewModel>().userName != null &&
|
||||
getIt<UserInfoViewModel>().userName!.isNotEmpty) {
|
||||
_userNameController.text = getIt<UserInfoViewModel>().userName!;
|
||||
rememberPassword = true;
|
||||
} else {
|
||||
rememberPassword = false;
|
||||
}
|
||||
if (getIt<UserInfoViewModel>().passWord != null && getIt<UserInfoViewModel>().passWord!.isNotEmpty) {
|
||||
if (getIt<UserInfoViewModel>().passWord != null &&
|
||||
getIt<UserInfoViewModel>().passWord!.isNotEmpty) {
|
||||
_passwordController.text = getIt<UserInfoViewModel>().passWord!;
|
||||
}
|
||||
getIt<UserInfoViewModel>().updateToken("");
|
||||
@@ -196,15 +199,25 @@ class _LoginPageState extends ConsumerState<LoginPage> {
|
||||
SizedBox(
|
||||
width: MediaQuery.of(context).size.width - 80,
|
||||
child: IgnorePointer(
|
||||
ignoring: _hostController.text.isEmpty || _userNameController.text.isEmpty || _passwordController.text.isEmpty || isLoading,
|
||||
ignoring: _hostController.text.isEmpty ||
|
||||
_userNameController.text.isEmpty ||
|
||||
_passwordController.text.isEmpty ||
|
||||
isLoading,
|
||||
child: CupertinoButton(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
vertical: 5,
|
||||
),
|
||||
color:
|
||||
(_hostController.text.isNotEmpty && _userNameController.text.isNotEmpty && _passwordController.text.isNotEmpty && !isLoading)
|
||||
? ref.watch(themeProvider).themeColor.buttonBgColor()
|
||||
: Theme.of(context).primaryColor.withOpacity(0.4),
|
||||
color: (_hostController.text.isNotEmpty &&
|
||||
_userNameController.text.isNotEmpty &&
|
||||
_passwordController.text.isNotEmpty &&
|
||||
!isLoading)
|
||||
? ref
|
||||
.watch(themeProvider)
|
||||
.themeColor
|
||||
.buttonBgColor()
|
||||
: Theme.of(context)
|
||||
.primaryColor
|
||||
.withOpacity(0.4),
|
||||
child: isLoading
|
||||
? const CupertinoActivityIndicator()
|
||||
: const Text(
|
||||
@@ -215,13 +228,17 @@ class _LoginPageState extends ConsumerState<LoginPage> {
|
||||
),
|
||||
onPressed: () {
|
||||
if (rememberPassword) {
|
||||
getIt<UserInfoViewModel>().updateUserName(_userNameController.text, _passwordController.text);
|
||||
getIt<UserInfoViewModel>().updateUserName(
|
||||
_userNameController.text,
|
||||
_passwordController.text);
|
||||
}
|
||||
|
||||
Http.pushedLoginPage = false;
|
||||
Utils.hideKeyBoard(context);
|
||||
getIt<UserInfoViewModel>().updateHost(_hostController.text);
|
||||
login(_userNameController.text, _passwordController.text);
|
||||
getIt<UserInfoViewModel>()
|
||||
.updateHost(_hostController.text);
|
||||
login(_userNameController.text,
|
||||
_passwordController.text);
|
||||
}),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -14,13 +14,13 @@ class DependencyBean {
|
||||
|
||||
DependencyBean(
|
||||
{this.sId,
|
||||
this.created,
|
||||
this.status,
|
||||
this.type,
|
||||
this.timestamp,
|
||||
this.name,
|
||||
this.log,
|
||||
this.remark});
|
||||
this.created,
|
||||
this.status,
|
||||
this.type,
|
||||
this.timestamp,
|
||||
this.name,
|
||||
this.log,
|
||||
this.remark});
|
||||
|
||||
DependencyBean.fromJson(Map<String, dynamic> json) {
|
||||
sId = json['_id'];
|
||||
@@ -45,6 +45,7 @@ class DependencyBean {
|
||||
data['remark'] = this.remark;
|
||||
return data;
|
||||
}
|
||||
|
||||
static DependencyBean jsonConversion(Map<String, dynamic> json) {
|
||||
return DependencyBean.fromJson(json);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ class LoginLogBean {
|
||||
String? platform;
|
||||
int? status; //0代表成功,1代表失败
|
||||
|
||||
LoginLogBean({this.timestamp, this.address, this.ip, this.platform, this.status});
|
||||
LoginLogBean(
|
||||
{this.timestamp, this.address, this.ip, this.platform, this.status});
|
||||
|
||||
LoginLogBean.fromJson(Map<String, dynamic> json) {
|
||||
timestamp = json['timestamp'];
|
||||
|
||||
@@ -38,28 +38,39 @@ class _OtherPageState extends ConsumerState<OtherPage> {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 12,
|
||||
bottom: 8,
|
||||
left: 15,
|
||||
right: 15,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
"脚本管理",
|
||||
style: TextStyle(
|
||||
color: ref.watch(themeProvider).themeColor.taskTitleColor(),
|
||||
fontSize: 16,
|
||||
GestureDetector(
|
||||
behavior: HitTestBehavior.opaque,
|
||||
onTap: () {
|
||||
Navigator.of(context).pushNamed(
|
||||
Routes.routeScript,
|
||||
);
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(
|
||||
top: 12,
|
||||
bottom: 8,
|
||||
left: 15,
|
||||
right: 15,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Text(
|
||||
"脚本管理",
|
||||
style: TextStyle(
|
||||
color: ref
|
||||
.watch(themeProvider)
|
||||
.themeColor
|
||||
.taskTitleColor(),
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
const Icon(
|
||||
CupertinoIcons.right_chevron,
|
||||
size: 16,
|
||||
),
|
||||
],
|
||||
const Spacer(),
|
||||
const Icon(
|
||||
CupertinoIcons.right_chevron,
|
||||
size: 16,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const Divider(
|
||||
@@ -75,7 +86,10 @@ class _OtherPageState extends ConsumerState<OtherPage> {
|
||||
Text(
|
||||
"依赖管理",
|
||||
style: TextStyle(
|
||||
color: ref.watch(themeProvider).themeColor.taskTitleColor(),
|
||||
color: ref
|
||||
.watch(themeProvider)
|
||||
.themeColor
|
||||
.taskTitleColor(),
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
@@ -107,7 +121,10 @@ class _OtherPageState extends ConsumerState<OtherPage> {
|
||||
Text(
|
||||
"任务日志",
|
||||
style: TextStyle(
|
||||
color: ref.watch(themeProvider).themeColor.taskTitleColor(),
|
||||
color: ref
|
||||
.watch(themeProvider)
|
||||
.themeColor
|
||||
.taskTitleColor(),
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
@@ -141,7 +158,10 @@ class _OtherPageState extends ConsumerState<OtherPage> {
|
||||
Text(
|
||||
"登录日志",
|
||||
style: TextStyle(
|
||||
color: ref.watch(themeProvider).themeColor.taskTitleColor(),
|
||||
color: ref
|
||||
.watch(themeProvider)
|
||||
.themeColor
|
||||
.taskTitleColor(),
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
@@ -186,7 +206,10 @@ class _OtherPageState extends ConsumerState<OtherPage> {
|
||||
Text(
|
||||
"夜间模式",
|
||||
style: TextStyle(
|
||||
color: ref.watch(themeProvider).themeColor.taskTitleColor(),
|
||||
color: ref
|
||||
.watch(themeProvider)
|
||||
.themeColor
|
||||
.taskTitleColor(),
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
@@ -218,7 +241,8 @@ class _OtherPageState extends ConsumerState<OtherPage> {
|
||||
),
|
||||
onPressed: () {
|
||||
getIt<UserInfoViewModel>().updateToken("");
|
||||
Navigator.of(context).pushReplacementNamed(Routes.routeLogin);
|
||||
Navigator.of(context)
|
||||
.pushReplacementNamed(Routes.routeLogin);
|
||||
}),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -12,11 +12,11 @@ class ScriptBean {
|
||||
|
||||
ScriptBean(
|
||||
{this.title,
|
||||
this.value,
|
||||
this.key,
|
||||
this.mtime,
|
||||
this.disabled,
|
||||
this.children});
|
||||
this.value,
|
||||
this.key,
|
||||
this.mtime,
|
||||
this.disabled,
|
||||
this.children});
|
||||
|
||||
ScriptBean.fromJson(Map<String, dynamic> json) {
|
||||
title = json['title'];
|
||||
@@ -44,10 +44,10 @@ class ScriptBean {
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
static ScriptBean jsonConversion(Map<String, dynamic> json) {
|
||||
return ScriptBean.fromJson(json);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ScriptChildren {
|
||||
|
||||
94
lib/module/others/scripts/script_detail_page.dart
Normal file
94
lib/module/others/scripts/script_detail_page.dart
Normal file
@@ -0,0 +1,94 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_highlight/flutter_highlight.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:qinglong_app/base/http/api.dart';
|
||||
import 'package:qinglong_app/base/http/http.dart';
|
||||
import 'package:qinglong_app/base/ql_app_bar.dart';
|
||||
import 'package:qinglong_app/base/theme.dart';
|
||||
import 'package:qinglong_app/base/ui/lazy_load_state.dart';
|
||||
import 'package:qinglong_app/module/others/task_log/task_log_bean.dart';
|
||||
import 'package:qinglong_app/utils/extension.dart';
|
||||
|
||||
/// @author NewTab
|
||||
class ScriptDetailPage extends ConsumerStatefulWidget {
|
||||
final String title;
|
||||
final String? path;
|
||||
|
||||
const ScriptDetailPage({
|
||||
Key? key,
|
||||
required this.title,
|
||||
this.path,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ScriptDetailPageState createState() => _ScriptDetailPageState();
|
||||
}
|
||||
|
||||
class _ScriptDetailPageState extends ConsumerState<ScriptDetailPage>
|
||||
with LazyLoadState<ScriptDetailPage> {
|
||||
String? content;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: QlAppBar(
|
||||
canBack: true,
|
||||
backCall: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
title: "脚本详情",
|
||||
),
|
||||
body: SingleChildScrollView(
|
||||
child: HighlightView(
|
||||
content ?? "",
|
||||
language: getLanguageType(widget.title),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 15,
|
||||
),
|
||||
theme: ref.watch(themeProvider).themeColor.codeEditorTheme(),
|
||||
tabSize: 14,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> loadData() async {
|
||||
HttpResponse<String> response = await Api.scriptDetail(
|
||||
widget.title,
|
||||
widget.path,
|
||||
);
|
||||
|
||||
if (response.success) {
|
||||
content = response.bean;
|
||||
setState(() {});
|
||||
} else {
|
||||
response.message?.toast();
|
||||
}
|
||||
}
|
||||
|
||||
getLanguageType(String title) {
|
||||
if (title.endsWith(".js")) {
|
||||
return "js";
|
||||
}
|
||||
|
||||
if (title.endsWith(".sh")) {
|
||||
return "sh";
|
||||
}
|
||||
|
||||
if (title.endsWith(".py")) {
|
||||
return "py";
|
||||
}
|
||||
if (title.endsWith(".json")) {
|
||||
return "json";
|
||||
}
|
||||
if (title.endsWith(".yaml")) {
|
||||
return "yaml";
|
||||
}
|
||||
return "html";
|
||||
}
|
||||
|
||||
@override
|
||||
void onLazyLoad() {
|
||||
loadData();
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,30 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:qinglong_app/base/http/api.dart';
|
||||
import 'package:qinglong_app/base/http/http.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/module/others/scripts/script_bean.dart';
|
||||
import 'package:qinglong_app/utils/extension.dart';
|
||||
|
||||
/// @author NewTab
|
||||
class ScriptPage extends StatefulWidget {
|
||||
class ScriptPage extends ConsumerStatefulWidget {
|
||||
const ScriptPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
_ScriptPageState createState() => _ScriptPageState();
|
||||
}
|
||||
|
||||
class _ScriptPageState extends State<ScriptPage> {
|
||||
class _ScriptPageState extends ConsumerState<ScriptPage> {
|
||||
List<ScriptBean> list = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
loadData();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
@@ -20,7 +35,94 @@ class _ScriptPageState extends State<ScriptPage> {
|
||||
},
|
||||
title: "脚本管理",
|
||||
),
|
||||
body: Container(),
|
||||
body: ListView.builder(
|
||||
itemBuilder: (context, index) {
|
||||
ScriptBean item = list[index];
|
||||
|
||||
return ColoredBox(
|
||||
color: ref.watch(themeProvider).themeColor.settingBgColor(),
|
||||
child: (item.children != null && item.children!.isNotEmpty)
|
||||
? ExpansionTile(
|
||||
title: Text(
|
||||
item.title ?? "",
|
||||
style: TextStyle(
|
||||
color: (item.disabled ?? false)
|
||||
? ref.watch(themeProvider).themeColor.descColor()
|
||||
: ref
|
||||
.watch(themeProvider)
|
||||
.themeColor
|
||||
.taskTitleColor(),
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
children: item.children!
|
||||
.map((e) => ListTile(
|
||||
onTap: () {
|
||||
Navigator.of(context).pushNamed(
|
||||
Routes.routeScriptDetail,
|
||||
arguments: {
|
||||
"title": e.title,
|
||||
"path": e.parent,
|
||||
},
|
||||
);
|
||||
},
|
||||
title: Text(
|
||||
e.title ?? "",
|
||||
style: TextStyle(
|
||||
color: (item.disabled ?? false)
|
||||
? ref
|
||||
.watch(themeProvider)
|
||||
.themeColor
|
||||
.descColor()
|
||||
: ref
|
||||
.watch(themeProvider)
|
||||
.themeColor
|
||||
.taskTitleColor(),
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
)
|
||||
: ListTile(
|
||||
onTap: () {
|
||||
Navigator.of(context).pushNamed(
|
||||
Routes.routeScriptDetail,
|
||||
arguments: {
|
||||
"title": item.title,
|
||||
"path": "",
|
||||
},
|
||||
);
|
||||
},
|
||||
title: Text(
|
||||
item.title ?? "",
|
||||
style: TextStyle(
|
||||
color: (item.disabled ?? false)
|
||||
? ref.watch(themeProvider).themeColor.descColor()
|
||||
: ref
|
||||
.watch(themeProvider)
|
||||
.themeColor
|
||||
.taskTitleColor(),
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
itemCount: list.length,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> loadData() async {
|
||||
HttpResponse<List<ScriptBean>> response = await Api.scripts();
|
||||
|
||||
if (response.success) {
|
||||
list.clear();
|
||||
list.addAll(response.bean ?? []);
|
||||
setState(() {});
|
||||
} else {
|
||||
response.message?.toast();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ class _TaskLogDetailPageState extends ConsumerState<TaskLogDetailPage> {
|
||||
horizontal: 15,
|
||||
),
|
||||
child: SelectableText(
|
||||
(content == null || content!.isEmpty)?"暂无数据":content!,
|
||||
(content == null || content!.isEmpty) ? "暂无数据" : content!,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
@@ -46,19 +46,27 @@ class _TaskLogPageState extends ConsumerState<TaskLogPage> {
|
||||
title: Text(
|
||||
item.name ?? "",
|
||||
style: TextStyle(
|
||||
color: ref.watch(themeProvider).themeColor.taskTitleColor(),
|
||||
color: ref
|
||||
.watch(themeProvider)
|
||||
.themeColor
|
||||
.taskTitleColor(),
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
children: item.files!
|
||||
.map((e) => ListTile(
|
||||
onTap: () {
|
||||
Navigator.of(context).pushNamed(Routes.routeTaskLogDetail, arguments: e);
|
||||
Navigator.of(context).pushNamed(
|
||||
Routes.routeTaskLogDetail,
|
||||
arguments: e);
|
||||
},
|
||||
title: Text(
|
||||
e ?? "",
|
||||
e,
|
||||
style: TextStyle(
|
||||
color: ref.watch(themeProvider).themeColor.taskTitleColor(),
|
||||
color: ref
|
||||
.watch(themeProvider)
|
||||
.themeColor
|
||||
.taskTitleColor(),
|
||||
fontSize: 14,
|
||||
),
|
||||
),
|
||||
@@ -67,12 +75,16 @@ class _TaskLogPageState extends ConsumerState<TaskLogPage> {
|
||||
)
|
||||
: ListTile(
|
||||
onTap: () {
|
||||
Navigator.of(context).pushNamed(Routes.routeTaskLogDetail, arguments: item.name);
|
||||
Navigator.of(context).pushNamed(Routes.routeTaskLogDetail,
|
||||
arguments: item.name);
|
||||
},
|
||||
title: Text(
|
||||
item.name ?? "",
|
||||
style: TextStyle(
|
||||
color: ref.watch(themeProvider).themeColor.taskTitleColor(),
|
||||
color: ref
|
||||
.watch(themeProvider)
|
||||
.themeColor
|
||||
.taskTitleColor(),
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -104,7 +104,8 @@ class _TaskPageState extends State<TaskPage> {
|
||||
if (_searchController.text.isEmpty ||
|
||||
(item.name?.contains(_searchController.text) ?? false) ||
|
||||
(item.command?.contains(_searchController.text) ?? false) ||
|
||||
(item.schedule?.contains(_searchController.text) ?? false)) {
|
||||
(item.schedule?.contains(_searchController.text) ??
|
||||
false)) {
|
||||
return TaskItemCell(item, ref);
|
||||
} else {
|
||||
return const SizedBox.shrink();
|
||||
@@ -174,7 +175,9 @@ class TaskItemCell extends StatelessWidget {
|
||||
child: Text(
|
||||
bean.status! == 1 ? "运行" : "停止运行",
|
||||
),
|
||||
trailingIcon: bean.status! == 1 ? CupertinoIcons.memories : CupertinoIcons.stop_circle,
|
||||
trailingIcon: bean.status! == 1
|
||||
? CupertinoIcons.memories
|
||||
: CupertinoIcons.stop_circle,
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
startCron(context, ref);
|
||||
@@ -192,7 +195,8 @@ class TaskItemCell extends StatelessWidget {
|
||||
child: const Text("编辑"),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
Navigator.of(context).pushNamed(Routes.routeAddTask, arguments: bean);
|
||||
Navigator.of(context)
|
||||
.pushNamed(Routes.routeAddTask, arguments: bean);
|
||||
},
|
||||
trailingIcon: CupertinoIcons.pencil_outline,
|
||||
),
|
||||
@@ -202,7 +206,9 @@ class TaskItemCell extends StatelessWidget {
|
||||
Navigator.of(context).pop();
|
||||
pinTask();
|
||||
},
|
||||
trailingIcon: bean.isPinned! == 0 ? CupertinoIcons.pin : CupertinoIcons.pin_slash,
|
||||
trailingIcon: bean.isPinned! == 0
|
||||
? CupertinoIcons.pin
|
||||
: CupertinoIcons.pin_slash,
|
||||
),
|
||||
QLCupertinoContextMenuAction(
|
||||
child: Text(bean.isDisabled! == 0 ? "禁用" : "启用"),
|
||||
@@ -211,7 +217,9 @@ class TaskItemCell extends StatelessWidget {
|
||||
enableTask();
|
||||
},
|
||||
isDestructiveAction: true,
|
||||
trailingIcon: bean.isDisabled! == 0 ? Icons.dnd_forwardslash : Icons.check_circle_outline_sharp,
|
||||
trailingIcon: bean.isDisabled! == 0
|
||||
? Icons.dnd_forwardslash
|
||||
: Icons.check_circle_outline_sharp,
|
||||
),
|
||||
QLCupertinoContextMenuAction(
|
||||
child: const Text("删除"),
|
||||
@@ -235,7 +243,8 @@ class TaskItemCell extends StatelessWidget {
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
color: ref.watch(themeProvider).themeColor.taskTitleColor(),
|
||||
color:
|
||||
ref.watch(themeProvider).themeColor.taskTitleColor(),
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
@@ -245,10 +254,10 @@ class TaskItemCell extends StatelessWidget {
|
||||
),
|
||||
bean.isDisabled == 1
|
||||
? const Icon(
|
||||
Icons.dnd_forwardslash,
|
||||
size: 16,
|
||||
color: Colors.red,
|
||||
)
|
||||
Icons.dnd_forwardslash,
|
||||
size: 16,
|
||||
color: Colors.red,
|
||||
)
|
||||
: const SizedBox.shrink(),
|
||||
],
|
||||
),
|
||||
@@ -259,7 +268,9 @@ class TaskItemCell extends StatelessWidget {
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Container(
|
||||
color: bean.isPinned == 1 ? ref.watch(themeProvider).themeColor.pinColor() : Colors.transparent,
|
||||
color: bean.isPinned == 1
|
||||
? ref.watch(themeProvider).themeColor.pinColor()
|
||||
: Colors.transparent,
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 15,
|
||||
vertical: 8,
|
||||
@@ -279,7 +290,10 @@ class TaskItemCell extends StatelessWidget {
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
color: ref.watch(themeProvider).themeColor.taskTitleColor(),
|
||||
color: ref
|
||||
.watch(themeProvider)
|
||||
.themeColor
|
||||
.taskTitleColor(),
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
@@ -300,11 +314,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,
|
||||
),
|
||||
),
|
||||
@@ -323,7 +342,8 @@ class TaskItemCell extends StatelessWidget {
|
||||
maxLines: 1,
|
||||
style: TextStyle(
|
||||
overflow: TextOverflow.ellipsis,
|
||||
color: ref.watch(themeProvider).themeColor.descColor(),
|
||||
color:
|
||||
ref.watch(themeProvider).themeColor.descColor(),
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user