From 8aa41e577b6cee95ab72dfc57d7297aff823fa89 Mon Sep 17 00:00:00 2001 From: jyuesong <425698907@qq.com> Date: Tue, 18 Jan 2022 13:09:29 +0800 Subject: [PATCH] add scripts --- lib/base/http/api.dart | 38 ++++-- lib/base/http/http.dart | 25 +++- lib/base/routes.dart | 22 +++- lib/base/ui/lazy_load_state.dart | 29 +++++ lib/json.jc.dart | 123 ++++++++++-------- lib/module/login/login_page.dart | 39 ++++-- .../others/dependencies/dependency_bean.dart | 15 ++- .../others/login_log/login_log_bean.dart | 3 +- lib/module/others/other_page.dart | 76 +++++++---- lib/module/others/scripts/script_bean.dart | 12 +- .../others/scripts/script_detail_page.dart | 94 +++++++++++++ lib/module/others/scripts/script_page.dart | 108 ++++++++++++++- .../others/task_log/task_log_detail_page.dart | 2 +- lib/module/others/task_log/task_log_page.dart | 24 +++- lib/module/task/task_page.dart | 50 ++++--- 15 files changed, 506 insertions(+), 154 deletions(-) create mode 100644 lib/base/ui/lazy_load_state.dart create mode 100644 lib/module/others/scripts/script_detail_page.dart diff --git a/lib/base/http/api.dart b/lib/base/http/api.dart index 73bf62e..a36587a 100644 --- a/lib/base/http/api.dart +++ b/lib/base/http/api.dart @@ -12,7 +12,8 @@ import 'package:qinglong_app/module/task/task_detail/task_detail_bean.dart'; import 'url.dart'; class Api { - static Future> login(String userName, String passWord) async { + static Future> login( + String userName, String passWord) async { return await Http.post( Url.login, { @@ -29,14 +30,16 @@ class Api { ); } - static Future> startTasks(List crons) async { + static Future> startTasks( + List crons) async { return await Http.put( Url.runTasks, crons, ); } - static Future> stopTasks(List crons) async { + static Future> stopTasks( + List crons) async { return await Http.put( Url.runTasks, crons, @@ -57,7 +60,9 @@ class Api { ); } - static Future> addTask(String name, String command, String cron, {String? id}) async { + static Future> 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> saveFile(String name, String content) async { + static Future> saveFile( + String name, String content) async { return await Http.post( Url.saveFile, {"content": content, "name": name}, @@ -157,7 +163,9 @@ class Api { ); } - static Future> addEnv(String name, String value, String remarks, {String? id}) async { + static Future> addEnv( + String name, String value, String remarks, + {String? id}) async { var data = { "value": value, "remarks": remarks, @@ -177,7 +185,8 @@ class Api { ); } - static Future> moveEnv(String id, int fromIndex, int toIndex) async { + static Future> moveEnv( + String id, int fromIndex, int toIndex) async { return await Http.put( Url.envMove(id), {"fromIndex": fromIndex, "toIndex": toIndex}, @@ -192,7 +201,8 @@ class Api { } static Future>> taskLog() async { - return await Http.get>(Url.taskLog, null, serializationName: "dirs"); + return await Http.get>(Url.taskLog, null, + serializationName: "dirs"); } static Future> taskLogDetail(String name) async { @@ -209,7 +219,8 @@ class Api { ); } - static Future> scriptDetail(String name, String path) async { + static Future> scriptDetail( + String name, String? path) async { return await Http.get( Url.scriptDetail + name, { @@ -218,7 +229,8 @@ class Api { ); } - static Future>> dependencies(String type) async { + static Future>> dependencies( + String type) async { return await Http.get>( Url.dependencies, { @@ -227,7 +239,8 @@ class Api { ); } - static Future> dependencyReinstall(String id) async { + static Future> dependencyReinstall( + String id) async { return await Http.put( Url.dependencies, [id], @@ -241,7 +254,8 @@ class Api { ); } - static Future> addDependency(String name, int type) async { + static Future> addDependency( + String name, int type) async { return await Http.post( Url.dependencies, [ diff --git a/lib/base/http/http.dart b/lib/base/http/http.dart index 05a1d71..180ca2b 100644 --- a/lib/base/http/http.dart +++ b/lib/base/http/http.dart @@ -40,7 +40,7 @@ class Http { static Future> get( String uri, - Map? json, { + Map? 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 { 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 { diff --git a/lib/base/routes.dart b/lib/base/routes.dart index e39e796..66df6ca 100644 --- a/lib/base/routes.dart +++ b/lib/base/routes.dart @@ -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? 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; diff --git a/lib/base/ui/lazy_load_state.dart b/lib/base/ui/lazy_load_state.dart new file mode 100644 index 0000000..8f168f5 --- /dev/null +++ b/lib/base/ui/lazy_load_state.dart @@ -0,0 +1,29 @@ +import 'package:flutter/material.dart'; + +/// @author NewTab + +mixin LazyLoadState on State { + @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(); +} diff --git a/lib/json.jc.dart b/lib/json.jc.dart index 949ace9..3a9bb76 100644 --- a/lib/json.jc.dart +++ b/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(dynamic json) { + static M fromJson(dynamic json) { if (json is List) { return _getListChildType(json); } else { @@ -22,85 +20,96 @@ class JsonConversion$Json { } static M _fromJsonSingle(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(List data) { - if([] is M){ - return data.map((e) => ConfigBean.jsonConversion(e)).toList() as M; + if ([] is M) { + return data.map((e) => ConfigBean.jsonConversion(e)).toList() + as M; } - - if([] is M){ + + if ([] is M) { return data.map((e) => EnvBean.jsonConversion(e)).toList() as M; } - - if([] is M){ - return data.map((e) => LoginBean.jsonConversion(e)).toList() as M; + + if ([] is M) { + return data.map((e) => LoginBean.jsonConversion(e)).toList() + as M; } - - if([] is M){ - return data.map((e) => DependencyBean.jsonConversion(e)).toList() as M; + + if ([] is M) { + return data + .map((e) => DependencyBean.jsonConversion(e)) + .toList() as M; } - - if([] is M){ - return data.map((e) => LoginLogBean.jsonConversion(e)).toList() as M; + + if ([] is M) { + return data + .map((e) => LoginLogBean.jsonConversion(e)) + .toList() as M; } - - if([] is M){ - return data.map((e) => ScriptBean.jsonConversion(e)).toList() as M; + + if ([] is M) { + return data.map((e) => ScriptBean.jsonConversion(e)).toList() + as M; } - - if([] is M){ - return data.map((e) => TaskLogBean.jsonConversion(e)).toList() as M; + + if ([] is M) { + return data + .map((e) => TaskLogBean.jsonConversion(e)) + .toList() as M; } - - if([] is M){ - return data.map((e) => TaskBean.jsonConversion(e)).toList() as M; + + if ([] is M) { + return data.map((e) => TaskBean.jsonConversion(e)).toList() + as M; } - - if([] is M){ - return data.map((e) => TaskDetailBean.jsonConversion(e)).toList() as M; + + if ([] is M) { + return data + .map((e) => TaskDetailBean.jsonConversion(e)) + .toList() as M; } - + throw Exception("not found"); } } diff --git a/lib/module/login/login_page.dart b/lib/module/login/login_page.dart index 93cf72b..99c7042 100644 --- a/lib/module/login/login_page.dart +++ b/lib/module/login/login_page.dart @@ -20,7 +20,8 @@ class LoginPage extends ConsumerStatefulWidget { } class _LoginPageState extends ConsumerState { - final TextEditingController _hostController = TextEditingController(text: getIt().host); + final TextEditingController _hostController = + TextEditingController(text: getIt().host); final TextEditingController _userNameController = TextEditingController(); final TextEditingController _passwordController = TextEditingController(); @@ -30,13 +31,15 @@ class _LoginPageState extends ConsumerState { void initState() { super.initState(); - if (getIt().userName != null && getIt().userName!.isNotEmpty) { + if (getIt().userName != null && + getIt().userName!.isNotEmpty) { _userNameController.text = getIt().userName!; rememberPassword = true; } else { rememberPassword = false; } - if (getIt().passWord != null && getIt().passWord!.isNotEmpty) { + if (getIt().passWord != null && + getIt().passWord!.isNotEmpty) { _passwordController.text = getIt().passWord!; } getIt().updateToken(""); @@ -196,15 +199,25 @@ class _LoginPageState extends ConsumerState { 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 { ), onPressed: () { if (rememberPassword) { - getIt().updateUserName(_userNameController.text, _passwordController.text); + getIt().updateUserName( + _userNameController.text, + _passwordController.text); } Http.pushedLoginPage = false; Utils.hideKeyBoard(context); - getIt().updateHost(_hostController.text); - login(_userNameController.text, _passwordController.text); + getIt() + .updateHost(_hostController.text); + login(_userNameController.text, + _passwordController.text); }), ), ), diff --git a/lib/module/others/dependencies/dependency_bean.dart b/lib/module/others/dependencies/dependency_bean.dart index c493abc..88ca001 100644 --- a/lib/module/others/dependencies/dependency_bean.dart +++ b/lib/module/others/dependencies/dependency_bean.dart @@ -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 json) { sId = json['_id']; @@ -45,6 +45,7 @@ class DependencyBean { data['remark'] = this.remark; return data; } + static DependencyBean jsonConversion(Map json) { return DependencyBean.fromJson(json); } diff --git a/lib/module/others/login_log/login_log_bean.dart b/lib/module/others/login_log/login_log_bean.dart index 32b75a4..95ea622 100644 --- a/lib/module/others/login_log/login_log_bean.dart +++ b/lib/module/others/login_log/login_log_bean.dart @@ -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 json) { timestamp = json['timestamp']; diff --git a/lib/module/others/other_page.dart b/lib/module/others/other_page.dart index bd43ef6..454eb95 100644 --- a/lib/module/others/other_page.dart +++ b/lib/module/others/other_page.dart @@ -38,28 +38,39 @@ class _OtherPageState extends ConsumerState { 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 { 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 { 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 { 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 { 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 { ), onPressed: () { getIt().updateToken(""); - Navigator.of(context).pushReplacementNamed(Routes.routeLogin); + Navigator.of(context) + .pushReplacementNamed(Routes.routeLogin); }), ), ), diff --git a/lib/module/others/scripts/script_bean.dart b/lib/module/others/scripts/script_bean.dart index 485c09d..4370716 100644 --- a/lib/module/others/scripts/script_bean.dart +++ b/lib/module/others/scripts/script_bean.dart @@ -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 json) { title = json['title']; @@ -44,10 +44,10 @@ class ScriptBean { } return data; } + static ScriptBean jsonConversion(Map json) { return ScriptBean.fromJson(json); } - } class ScriptChildren { diff --git a/lib/module/others/scripts/script_detail_page.dart b/lib/module/others/scripts/script_detail_page.dart new file mode 100644 index 0000000..0c6e8f4 --- /dev/null +++ b/lib/module/others/scripts/script_detail_page.dart @@ -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 + with LazyLoadState { + 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 loadData() async { + HttpResponse 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(); + } +} diff --git a/lib/module/others/scripts/script_page.dart b/lib/module/others/scripts/script_page.dart index f2bc331..da78035 100644 --- a/lib/module/others/scripts/script_page.dart +++ b/lib/module/others/scripts/script_page.dart @@ -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 { +class _ScriptPageState extends ConsumerState { + List list = []; + + @override + void initState() { + super.initState(); + loadData(); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -20,7 +35,94 @@ class _ScriptPageState extends State { }, 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 loadData() async { + HttpResponse> response = await Api.scripts(); + + if (response.success) { + list.clear(); + list.addAll(response.bean ?? []); + setState(() {}); + } else { + response.message?.toast(); + } + } } diff --git a/lib/module/others/task_log/task_log_detail_page.dart b/lib/module/others/task_log/task_log_detail_page.dart index 583ab16..6e074dd 100644 --- a/lib/module/others/task_log/task_log_detail_page.dart +++ b/lib/module/others/task_log/task_log_detail_page.dart @@ -44,7 +44,7 @@ class _TaskLogDetailPageState extends ConsumerState { horizontal: 15, ), child: SelectableText( - (content == null || content!.isEmpty)?"暂无数据":content!, + (content == null || content!.isEmpty) ? "暂无数据" : content!, ), ), ); diff --git a/lib/module/others/task_log/task_log_page.dart b/lib/module/others/task_log/task_log_page.dart index b14b826..fd10e2f 100644 --- a/lib/module/others/task_log/task_log_page.dart +++ b/lib/module/others/task_log/task_log_page.dart @@ -46,19 +46,27 @@ class _TaskLogPageState extends ConsumerState { 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 { ) : 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, ), ), diff --git a/lib/module/task/task_page.dart b/lib/module/task/task_page.dart index 0611c32..bfbb022 100644 --- a/lib/module/task/task_page.dart +++ b/lib/module/task/task_page.dart @@ -104,7 +104,8 @@ class _TaskPageState extends State { 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, ), ),