diff --git a/lib/base/http/api.dart b/lib/base/http/api.dart index 12fcdcf..73bf62e 100644 --- a/lib/base/http/api.dart +++ b/lib/base/http/api.dart @@ -1,17 +1,18 @@ -import 'dart:ffi'; - import 'package:qinglong_app/base/http/http.dart'; import 'package:qinglong_app/module/config/config_bean.dart'; import 'package:qinglong_app/module/env/env_bean.dart'; import 'package:qinglong_app/module/login/login_bean.dart'; +import 'package:qinglong_app/module/others/dependencies/dependency_bean.dart'; +import 'package:qinglong_app/module/others/login_log/login_log_bean.dart'; +import 'package:qinglong_app/module/others/scripts/script_bean.dart'; +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'; 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, { @@ -22,104 +23,240 @@ class Api { } static Future>> crons() async { - return await Http.get>(Url.tasks, {"searchValue": ""}); + return await Http.get>( + Url.tasks, + {"searchValue": ""}, + ); } - static Future> startTasks( - List crons) async { - return await Http.put(Url.runTasks, crons); + static Future> startTasks(List crons) async { + return await Http.put( + Url.runTasks, + crons, + ); } - static Future> stopTasks( - List crons) async { - return await Http.put(Url.runTasks, crons); + static Future> stopTasks(List crons) async { + return await Http.put( + Url.runTasks, + crons, + ); } static Future> inTimeLog(String cron) async { - return await Http.get(Url.intimeLog(cron), null); + return await Http.get( + Url.intimeLog(cron), + null, + ); } static Future> taskDetail(String cron) async { - return await Http.get(Url.taskDetail + cron, null); + return await Http.get( + Url.taskDetail + cron, + null, + ); } - 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) { data["_id"] = id; - return await Http.put(Url.addTask, data); + return await Http.put( + Url.addTask, + data, + ); } - return await Http.post(Url.addTask, data); + return await Http.post( + Url.addTask, + data, + ); } static Future> delTask(String cron) async { - return await Http.delete(Url.addTask, [cron]); + return await Http.delete( + Url.addTask, + [cron], + ); } static Future> pinTask(String cron) async { - return await Http.put(Url.pinTask, [cron]); + return await Http.put( + Url.pinTask, + [cron], + ); } static Future> unpinTask(String cron) async { - return await Http.put(Url.unpinTask, [cron]); + return await Http.put( + Url.unpinTask, + [cron], + ); } static Future> enableTask(String cron) async { - return await Http.put(Url.enableTask, [cron]); + return await Http.put( + Url.enableTask, + [cron], + ); } static Future> disableTask(String cron) async { - return await Http.put(Url.disableTask, [cron]); + return await Http.put( + Url.disableTask, + [cron], + ); } static Future>> files() async { - return await Http.get>(Url.files, null); + return await Http.get>( + Url.files, + null, + ); } static Future> content(String name) async { - return await Http.get(Url.configContent + name, null); + return await Http.get( + Url.configContent + name, + null, + ); } - 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}); + Url.saveFile, + {"content": content, "name": name}, + ); } static Future>> envs(String search) async { - return await Http.get>(Url.envs, {"searchValue": search}); + return await Http.get>( + Url.envs, + {"searchValue": search}, + ); } static Future> enableEnv(String id) async { - return await Http.put(Url.enableEnvs, [id]); + return await Http.put( + Url.enableEnvs, + [id], + ); } static Future> disableEnv(String id) async { - return await Http.put(Url.disableEnvs, [id]); + return await Http.put( + Url.disableEnvs, + [id], + ); } static Future> delEnv(String id) async { - return await Http.delete(Url.delEnv, [id]); + return await Http.delete( + Url.delEnv, + [id], + ); } - static Future> addEnv( - String name, String value, String remarks, - {String? id}) async { - var data = {"value": value, "remarks": remarks, "name": name}; + static Future> addEnv(String name, String value, String remarks, {String? id}) async { + var data = { + "value": value, + "remarks": remarks, + "name": name, + }; if (id != null) { data["_id"] = id; - return await Http.put(Url.addEnv, data); + return await Http.put( + Url.addEnv, + data, + ); } - return await Http.post(Url.addEnv, [data]); + return await Http.post( + Url.addEnv, + [data], + ); } - 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}); + Url.envMove(id), + {"fromIndex": fromIndex, "toIndex": toIndex}, + ); + } + + static Future>> loginLog() async { + return await Http.get>( + Url.loginLog, + null, + ); + } + + static Future>> taskLog() async { + return await Http.get>(Url.taskLog, null, serializationName: "dirs"); + } + + static Future> taskLogDetail(String name) async { + return await Http.get( + Url.taskLogDetail + name, + null, + ); + } + + static Future>> scripts() async { + return await Http.get>( + Url.scripts, + null, + ); + } + + static Future> scriptDetail(String name, String path) async { + return await Http.get( + Url.scriptDetail + name, + { + "path": path, + }, + ); + } + + static Future>> dependencies(String type) async { + return await Http.get>( + Url.dependencies, + { + "type": type, + }, + ); + } + + static Future> dependencyReinstall(String id) async { + return await Http.put( + Url.dependencies, + [id], + ); + } + + static Future> dependencyLog(String id) async { + return await Http.get( + Url.dependencies + "/" + id, + null, + ); + } + + static Future> addDependency(String name, int type) async { + return await Http.post( + Url.dependencies, + [ + { + "name": name, + "type": type, + } + ], + ); + } + + static Future> delDependency(String id) async { + return await Http.delete( + Url.dependencies, + [id], + ); } } diff --git a/lib/base/http/http.dart b/lib/base/http/http.dart index 0af6ad0..05a1d71 100644 --- a/lib/base/http/http.dart +++ b/lib/base/http/http.dart @@ -38,74 +38,90 @@ class Http { } } - static Future> get(String uri, Map? json, - {bool compute = true}) async { + static Future> get( + String uri, + Map? json, { + bool compute = true, + String serializationName = "data", + }) async { try { _init(); var response = await _dio!.get(uri, queryParameters: json); - return decodeResponse(response, compute); + return decodeResponse(response, serializationName, compute); } on DioError catch (e) { 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); } } - static Future> post(String uri, dynamic json, - {bool compute = true}) async { + static Future> post( + String uri, + dynamic json, { + bool compute = true, + String serializationName = "data", + }) async { try { _init(); var response = await _dio!.post(uri, data: json); - return decodeResponse(response, compute); + return decodeResponse( + response, + serializationName, + compute, + ); } on DioError catch (e) { 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); } } - static Future> delete(String uri, dynamic json, - {bool compute = true}) async { + static Future> delete( + String uri, + dynamic json, { + bool compute = true, + String serializationName = "data", + }) async { try { _init(); var response = await _dio!.delete(uri, data: json); - return decodeResponse(response, compute); + return decodeResponse( + response, + serializationName, + compute, + ); } on DioError catch (e) { 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); } } - static Future> put(String uri, dynamic json, - {bool compute = true}) async { + static Future> put( + String uri, + dynamic json, { + bool compute = true, + String serializationName = "data", + }) async { try { _init(); var response = await _dio!.put(uri, data: json); - return decodeResponse(response, compute); + return decodeResponse( + response, + serializationName, + compute, + ); } on DioError catch (e) { 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); } } @@ -120,13 +136,14 @@ class Http { static HttpResponse decodeResponse( Response response, + String serializationName, bool compute, ) { int code = 0; if (response.statusCode == 200) { try { if (response.data["code"] == 200) { - if (response.data["data"] != null) { + if (response.data[serializationName] != null) { if (T == NullResponse) { return HttpResponse( success: true, @@ -134,7 +151,7 @@ class Http { ); } - dynamic data = response.data["data"]; + dynamic data = response.data[serializationName]; T t; if (T == String) { if (data is String) { @@ -198,8 +215,7 @@ 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/http/url.dart b/lib/base/http/url.dart index 448136b..661d2b8 100644 --- a/lib/base/http/url.dart +++ b/lib/base/http/url.dart @@ -17,6 +17,13 @@ class Url { static const delEnv = "/api/envs"; static const disableEnvs = "/api/envs/disable"; static const enableEnvs = "/api/envs/enable"; + static const loginLog = "/api/user/login-log"; + static const taskLog = "/api/logs"; + static const taskLogDetail = "/api/logs/code/"; + static const scripts = "/api/scripts/files"; + static const scriptDetail = "/api/scripts/"; + static const dependencies = "/api/dependencies"; + static const dependencyReinstall = "/api/dependencies/reinstall"; static intimeLog(String cronId) { return "/api/crons/$cronId/log"; diff --git a/lib/base/routes.dart b/lib/base/routes.dart index 474b8a5..3e8d5ab 100644 --- a/lib/base/routes.dart +++ b/lib/base/routes.dart @@ -5,6 +5,7 @@ import 'package:qinglong_app/module/env/add_env_page.dart'; 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/task/add_task_page.dart'; import 'package:qinglong_app/module/task/task_bean.dart'; @@ -14,6 +15,7 @@ class Routes { static const String routeAddTask = "/task/add"; static const String routeAddEnv = "/env/add"; static const String routeConfigEdit = "/config/edit"; + static const String routeLoginLog = "/log/login"; static Route? generateRoute(RouteSettings settings) { switch (settings.name) { @@ -46,6 +48,10 @@ class Routes { (settings.arguments as Map)["content"], ), ); + case routeLoginLog: + return CupertinoPageRoute( + builder: (context) => const LoginLogPage(), + ); } return null; diff --git a/lib/base/theme.dart b/lib/base/theme.dart index 5dce1c7..e314601 100644 --- a/lib/base/theme.dart +++ b/lib/base/theme.dart @@ -9,6 +9,8 @@ import 'package:qinglong_app/utils/sp_utils.dart'; var themeProvider = ChangeNotifierProvider((ref) => ThemeViewModel()); const Color _primaryColor = Color(0xFF299343); +get primaryColor => _primaryColor; + class ThemeViewModel extends ChangeNotifier { ThemeData currentTheme = lightTheme; @@ -221,7 +223,7 @@ class DartThemeColors extends ThemeColors { @override Color settingBgColor() { - return Colors.black; + return Colors.black12; } @override diff --git a/lib/json.jc.dart b/lib/json.jc.dart index 7204ff2..949ace9 100644 --- a/lib/json.jc.dart +++ b/lib/json.jc.dart @@ -3,11 +3,17 @@ import 'package:qinglong_app/module/config/config_bean.dart'; import 'package:qinglong_app/module/env/env_bean.dart'; import 'package:qinglong_app/module/login/login_bean.dart'; +import 'package:qinglong_app/module/others/dependencies/dependency_bean.dart'; +import 'package:qinglong_app/module/others/login_log/login_log_bean.dart'; +import 'package:qinglong_app/module/others/scripts/script_bean.dart'; +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 { @@ -16,57 +22,85 @@ 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 == (TaskBean).toString()) { - return TaskBean.jsonConversion(json) as M; + + if(type == (DependencyBean).toString()){ + return DependencyBean.jsonConversion(json) as M; } - - if (type == (TaskDetailBean).toString()) { - return TaskDetailBean.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 == (TaskLogBean).toString()){ + return TaskLogBean.jsonConversion(json) as M; + } + + if(type == (TaskBean).toString()){ + return TaskBean.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) => TaskBean.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) => TaskDetailBean.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) => 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) => TaskDetailBean.jsonConversion(e)).toList() as M; + } + throw Exception("not found"); } } diff --git a/lib/module/others/dependencies/dependency_bean.dart b/lib/module/others/dependencies/dependency_bean.dart new file mode 100644 index 0000000..c493abc --- /dev/null +++ b/lib/module/others/dependencies/dependency_bean.dart @@ -0,0 +1,51 @@ +import 'package:json_conversion_annotation/json_conversion_annotation.dart'; + +/// @author NewTab +@JsonConversion() +class DependencyBean { + String? sId; + int? created; + int? status; + int? type; + String? timestamp; + String? name; + List? log; + String? remark; + + DependencyBean( + {this.sId, + this.created, + this.status, + this.type, + this.timestamp, + this.name, + this.log, + this.remark}); + + DependencyBean.fromJson(Map json) { + sId = json['_id']; + created = json['created']; + status = json['status']; + type = json['type']; + timestamp = json['timestamp']; + name = json['name']; + log = json['log'].cast(); + remark = json['remark']; + } + + Map toJson() { + final Map data = new Map(); + data['_id'] = this.sId; + data['created'] = this.created; + data['status'] = this.status; + data['type'] = this.type; + data['timestamp'] = this.timestamp; + data['name'] = this.name; + data['log'] = this.log; + 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 new file mode 100644 index 0000000..32b75a4 --- /dev/null +++ b/lib/module/others/login_log/login_log_bean.dart @@ -0,0 +1,35 @@ +import 'package:json_conversion_annotation/json_conversion_annotation.dart'; + +/// @author NewTab +@JsonConversion() +class LoginLogBean { + int? timestamp; + String? address; + String? ip; + String? platform; + int? status; //0代表成功,1代表失败 + + LoginLogBean({this.timestamp, this.address, this.ip, this.platform, this.status}); + + LoginLogBean.fromJson(Map json) { + timestamp = json['timestamp']; + address = json['address']; + ip = json['ip']; + platform = json['platform']; + status = json['status']; + } + + Map toJson() { + final Map data = new Map(); + data['timestamp'] = this.timestamp; + data['address'] = this.address; + data['ip'] = this.ip; + data['platform'] = this.platform; + data['status'] = this.status; + return data; + } + + static LoginLogBean jsonConversion(Map json) { + return LoginLogBean.fromJson(json); + } +} diff --git a/lib/module/others/login_log/login_log_page.dart b/lib/module/others/login_log/login_log_page.dart new file mode 100644 index 0000000..ade2b66 --- /dev/null +++ b/lib/module/others/login_log/login_log_page.dart @@ -0,0 +1,112 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/widgets.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/utils/extension.dart'; +import 'package:qinglong_app/utils/utils.dart'; + +import 'login_log_bean.dart'; + +/// @author NewTab +class LoginLogPage extends ConsumerStatefulWidget { + const LoginLogPage({Key? key}) : super(key: key); + + @override + _LoginLogPageState createState() => _LoginLogPageState(); +} + +class _LoginLogPageState extends ConsumerState { + List list = []; + + @override + void initState() { + super.initState(); + loadData(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: QlAppBar( + canBack: true, + backCall: () { + Navigator.of(context).pop(); + }, + title: "任务日志", + ), + body: ListView.builder( + itemBuilder: (context, index) { + LoginLogBean item = list[index]; + + return ColoredBox( + color: ref.watch(themeProvider).themeColor.settingBgColor(), + child: ListTile( + isThreeLine: true, + title: Text( + Utils.formatMessageTime(item.timestamp ?? 0), + style: TextStyle( + fontSize: 16, + color: ref.watch(themeProvider).themeColor.taskTitleColor(), + ), + ), + subtitle: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox( + height: 5, + ), + Text( + "${item.address}", + style: TextStyle( + color: ref.watch(themeProvider).themeColor.descColor(), + fontSize: 14, + ), + ), + const SizedBox( + height: 5, + ), + Text( + "${item.ip}", + style: TextStyle( + color: ref.watch(themeProvider).themeColor.descColor(), + fontSize: 14, + ), + ), + ], + ), + trailing: item.status == 0 + ? Icon( + CupertinoIcons.checkmark_circle, + color: primaryColor, + size: 16, + ) + : const Icon( + CupertinoIcons.clear_circled, + color: Colors.red, + size: 16, + ), + ), + ); + }, + itemCount: list.length, + ), + ); + } + + Future loadData() async { + HttpResponse> response = await Api.loginLog(); + + if (response.success) { + list.clear(); + list.addAll(response.bean ?? []); + setState(() {}); + } else { + response.message?.toast(); + } + } +} diff --git a/lib/module/others/other_page.dart b/lib/module/others/other_page.dart index f9f9352..4fd5168 100644 --- a/lib/module/others/other_page.dart +++ b/lib/module/others/other_page.dart @@ -50,10 +50,7 @@ class _OtherPageState extends ConsumerState { Text( "脚本管理", style: TextStyle( - color: ref - .watch(themeProvider) - .themeColor - .taskTitleColor(), + color: ref.watch(themeProvider).themeColor.taskTitleColor(), fontSize: 16, ), ), @@ -78,10 +75,7 @@ class _OtherPageState extends ConsumerState { Text( "依赖管理", style: TextStyle( - color: ref - .watch(themeProvider) - .themeColor - .taskTitleColor(), + color: ref.watch(themeProvider).themeColor.taskTitleColor(), fontSize: 16, ), ), @@ -106,10 +100,7 @@ class _OtherPageState extends ConsumerState { Text( "任务日志", style: TextStyle( - color: ref - .watch(themeProvider) - .themeColor - .taskTitleColor(), + color: ref.watch(themeProvider).themeColor.taskTitleColor(), fontSize: 16, ), ), @@ -124,29 +115,35 @@ class _OtherPageState extends ConsumerState { const Divider( indent: 15, ), - Padding( - padding: const EdgeInsets.symmetric( - vertical: 10, - horizontal: 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.routeLoginLog, + ); + }, + child: Padding( + padding: const EdgeInsets.symmetric( + vertical: 10, + horizontal: 15, + ), + child: Row( + mainAxisSize: MainAxisSize.max, + 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, + ), + ], + ), ), ), ], @@ -181,10 +178,7 @@ class _OtherPageState extends ConsumerState { Text( "夜间模式", style: TextStyle( - color: ref - .watch(themeProvider) - .themeColor - .taskTitleColor(), + color: ref.watch(themeProvider).themeColor.taskTitleColor(), fontSize: 16, ), ), @@ -204,7 +198,9 @@ class _OtherPageState extends ConsumerState { child: SizedBox( width: MediaQuery.of(context).size.width - 40, child: CupertinoButton( - padding: const EdgeInsets.symmetric(vertical: 5,), + padding: const EdgeInsets.symmetric( + vertical: 5, + ), color: ref.watch(themeProvider).themeColor.buttonBgColor(), child: const Text( "退出登录", @@ -214,8 +210,7 @@ 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 new file mode 100644 index 0000000..485c09d --- /dev/null +++ b/lib/module/others/scripts/script_bean.dart @@ -0,0 +1,79 @@ +import 'package:json_conversion_annotation/json_conversion_annotation.dart'; + +/// @author NewTab +@JsonConversion() +class ScriptBean { + String? title; + String? value; + String? key; + double? mtime; + bool? disabled; + List? children; + + ScriptBean( + {this.title, + this.value, + this.key, + this.mtime, + this.disabled, + this.children}); + + ScriptBean.fromJson(Map json) { + title = json['title']; + value = json['value']; + key = json['key']; + mtime = json['mtime']; + disabled = json['disabled']; + if (json['children'] != null) { + children = []; + json['children'].forEach((v) { + children!.add(new ScriptChildren.fromJson(v)); + }); + } + } + + Map toJson() { + final Map data = new Map(); + data['title'] = this.title; + data['value'] = this.value; + data['key'] = this.key; + data['mtime'] = this.mtime; + data['disabled'] = this.disabled; + if (this.children != null) { + data['children'] = this.children!.map((v) => v.toJson()).toList(); + } + return data; + } + static ScriptBean jsonConversion(Map json) { + return ScriptBean.fromJson(json); + } + +} + +class ScriptChildren { + String? title; + String? value; + String? key; + double? mtime; + String? parent; + + ScriptChildren({this.title, this.value, this.key, this.mtime, this.parent}); + + ScriptChildren.fromJson(Map json) { + title = json['title']; + value = json['value']; + key = json['key']; + mtime = json['mtime']; + parent = json['parent']; + } + + Map toJson() { + final Map data = new Map(); + data['title'] = this.title; + data['value'] = this.value; + data['key'] = this.key; + data['mtime'] = this.mtime; + data['parent'] = this.parent; + return data; + } +} diff --git a/lib/module/others/scripts/script_page.dart b/lib/module/others/scripts/script_page.dart new file mode 100644 index 0000000..f2bc331 --- /dev/null +++ b/lib/module/others/scripts/script_page.dart @@ -0,0 +1,26 @@ +import 'package:flutter/material.dart'; +import 'package:qinglong_app/base/ql_app_bar.dart'; + +/// @author NewTab +class ScriptPage extends StatefulWidget { + const ScriptPage({Key? key}) : super(key: key); + + @override + _ScriptPageState createState() => _ScriptPageState(); +} + +class _ScriptPageState extends State { + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: QlAppBar( + canBack: true, + backCall: () { + Navigator.of(context).pop(); + }, + title: "脚本管理", + ), + body: Container(), + ); + } +} diff --git a/lib/module/others/task_log/task_log_bean.dart b/lib/module/others/task_log/task_log_bean.dart new file mode 100644 index 0000000..175e200 --- /dev/null +++ b/lib/module/others/task_log/task_log_bean.dart @@ -0,0 +1,29 @@ +import 'package:json_conversion_annotation/json_conversion_annotation.dart'; + +/// @author NewTab +@JsonConversion() +class TaskLogBean { + String? name; + bool? isDir; + List? files; + + TaskLogBean({this.name, this.isDir, this.files}); + + TaskLogBean.fromJson(Map json) { + name = json['name']; + isDir = json['isDir']; + files = json['files'].cast(); + } + + Map toJson() { + final Map data = new Map(); + data['name'] = this.name; + data['isDir'] = this.isDir; + data['files'] = this.files; + return data; + } + + static TaskLogBean jsonConversion(Map json) { + return TaskLogBean.fromJson(json); + } +} diff --git a/lib/module/others/task_log/task_log_page.dart b/lib/module/others/task_log/task_log_page.dart new file mode 100644 index 0000000..d6a87a5 --- /dev/null +++ b/lib/module/others/task_log/task_log_page.dart @@ -0,0 +1,39 @@ +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/module/others/login_log/login_log_bean.dart'; +import 'package:qinglong_app/utils/extension.dart'; +import 'package:qinglong_app/utils/utils.dart'; + +/// @author NewTab +class TaskLogPage extends ConsumerStatefulWidget { + const TaskLogPage({Key? key}) : super(key: key); + + @override + _TaskLogPageState createState() => _TaskLogPageState(); +} + +class _TaskLogPageState extends ConsumerState { + + + @override + void initState() { + super.initState(); + } + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: QlAppBar( + canBack: true, + backCall: () { + Navigator.of(context).pop(); + }, + title: "任务日志", + ), + ); + } + +} diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index bb41dfe..4ec766a 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -8,7 +8,13 @@ class Utils { static String formatMessageTime(int time) { DateTime current = DateTime.now(); - DateTime chatTime = DateTime.fromMillisecondsSinceEpoch(time * 1000); + DateTime chatTime; + if (time.toString().length == 10) { + chatTime = DateTime.fromMillisecondsSinceEpoch(time * 1000); + } else { + chatTime = DateTime.fromMillisecondsSinceEpoch(time); + } + if (current.year == chatTime.year) { if (current.day == chatTime.day) { if (chatTime.hour <= 12) {