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:
@@ -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,
|
||||
),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user