优化任务列表,环境变量

This commit is contained in:
jyuesong
2022-05-30 13:04:33 +08:00
parent 2c64038fda
commit 578bb926fa
5 changed files with 383 additions and 327 deletions

View File

@@ -1,4 +1,6 @@
import 'package:qinglong_app/base/http/http.dart'; import 'package:qinglong_app/base/http/http.dart';
import 'package:qinglong_app/base/http/url.dart';
import 'package:qinglong_app/main.dart';
import 'package:qinglong_app/module/config/config_bean.dart'; import 'package:qinglong_app/module/config/config_bean.dart';
import 'package:qinglong_app/module/env/env_bean.dart'; import 'package:qinglong_app/module/env/env_bean.dart';
import 'package:qinglong_app/module/home/system_bean.dart'; import 'package:qinglong_app/module/home/system_bean.dart';
@@ -9,9 +11,7 @@ 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/scripts/script_bean.dart';
import 'package:qinglong_app/module/others/task_log/task_log_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_bean.dart';
import 'package:qinglong_app/utils/utils.dart';
import '../../utils/utils.dart';
import 'url.dart';
class Api { class Api {
static Future<HttpResponse<SystemBean>> system() async { static Future<HttpResponse<SystemBean>> system() async {
@@ -89,24 +89,21 @@ class Api {
); );
} }
static Future<HttpResponse<NullResponse>> startTasks( static Future<HttpResponse<NullResponse>> startTasks(List<String> crons) async {
List<String> crons) async {
return await Http.put<NullResponse>( return await Http.put<NullResponse>(
Url.runTasks, Url.runTasks,
crons, crons,
); );
} }
static Future<HttpResponse<NullResponse>> stopTasks( static Future<HttpResponse<NullResponse>> stopTasks(List<String> crons) async {
List<String> crons) async {
return await Http.put<NullResponse>( return await Http.put<NullResponse>(
Url.stopTasks, Url.stopTasks,
crons, crons,
); );
} }
static Future<HttpResponse<NullResponse>> updatePassword( static Future<HttpResponse<NullResponse>> updatePassword(String name, String password) async {
String name, String password) async {
return await Http.put<NullResponse>( return await Http.put<NullResponse>(
Url.updatePassword, Url.updatePassword,
{ {
@@ -124,15 +121,19 @@ class Api {
} }
static Future<HttpResponse<NullResponse>> addTask( static Future<HttpResponse<NullResponse>> addTask(
String name, String command, String cron, String name,
{String? id}) async { String command,
var data = {"name": name, "command": command, "schedule": cron}; String cron, {
int? id,
String? nId,
}) async {
var data = <String, dynamic>{"name": name, "command": command, "schedule": cron};
if (id != null) { if (id != null || nId != null) {
if (Utils.isUpperVersion()) { if (id != null) {
data["id"] = id; data["id"] = id;
} else { } else if (nId != null) {
data["_id"] = id; data["_id"] = nId;
} }
return await Http.put<NullResponse>( return await Http.put<NullResponse>(
Url.addTask, Url.addTask,
@@ -194,8 +195,7 @@ class Api {
); );
} }
static Future<HttpResponse<NullResponse>> saveFile( static Future<HttpResponse<NullResponse>> saveFile(String name, String content) async {
String name, String content) async {
return await Http.post<NullResponse>( return await Http.post<NullResponse>(
Url.saveFile, Url.saveFile,
{"content": content, "name": name}, {"content": content, "name": name},
@@ -231,21 +231,24 @@ class Api {
} }
static Future<HttpResponse<NullResponse>> addEnv( static Future<HttpResponse<NullResponse>> addEnv(
String name, String value, String remarks, String name,
{String? id}) async { String value,
var data = { String remarks, {
int? id,
String? nId,
}) async {
var data = <String, dynamic>{
"value": value, "value": value,
"remarks": remarks, "remarks": remarks,
"name": name, "name": name,
}; };
if (id != null) { if (id != null || nId != null) {
if (Utils.isUpperVersion()) { if (id != null) {
data["id"] = id; data["id"] = id;
} else { } else if (nId != null) {
data["_id"] = id; data["_id"] = nId;
} }
return await Http.put<NullResponse>( return await Http.put<NullResponse>(
Url.addEnv, Url.addEnv,
data, data,
@@ -257,8 +260,7 @@ class Api {
); );
} }
static Future<HttpResponse<NullResponse>> moveEnv( static Future<HttpResponse<NullResponse>> moveEnv(String id, int fromIndex, int toIndex) async {
String id, int fromIndex, int toIndex) async {
return await Http.put<NullResponse>( return await Http.put<NullResponse>(
Url.envMove(id), Url.envMove(id),
{"fromIndex": fromIndex, "toIndex": toIndex}, {"fromIndex": fromIndex, "toIndex": toIndex},
@@ -273,26 +275,32 @@ class Api {
} }
static Future<HttpResponse<List<TaskLogBean>>> taskLog() async { static Future<HttpResponse<List<TaskLogBean>>> taskLog() async {
return await Http.get<List<TaskLogBean>>(Url.taskLog, null, return await Http.get<List<TaskLogBean>>(Url.taskLog, null, serializationName: Utils.isUpperVersion2_12_2() ? "data" : "dirs");
serializationName: "dirs");
} }
static Future<HttpResponse<String>> taskLogDetail(String name) async { static Future<HttpResponse<String>> taskLogDetail(String name, String path) async {
return await Http.get<String>( if (Utils.isUpperVersion2_13_0()) {
Url.taskLogDetail + name, return await Http.get<String>(
null, Url.taskLogDetail + name + "?path=" + path,
); null,
);
} else {
return await Http.get<String>(
Url.taskLogDetail + path + "/" + name,
null,
);
}
} }
static Future<HttpResponse<List<ScriptBean>>> scripts() async { static Future<HttpResponse<List<ScriptBean>>> scripts() async {
//2.12.2以及以上版本,脚本路径url做了修改
return await Http.get<List<ScriptBean>>( return await Http.get<List<ScriptBean>>(
Url.scripts, Utils.isUpperVersion2_13_0() ? Url.scripts2 : Url.scripts,
null, null,
); );
} }
static Future<HttpResponse<NullResponse>> updateScript( static Future<HttpResponse<NullResponse>> updateScript(String name, String path, String content) async {
String name, String path, String content) async {
return await Http.put<NullResponse>( return await Http.put<NullResponse>(
Url.scriptDetail, Url.scriptDetail,
{ {
@@ -303,8 +311,7 @@ class Api {
); );
} }
static Future<HttpResponse<NullResponse>> delScript( static Future<HttpResponse<NullResponse>> delScript(String name, String path) async {
String name, String path) async {
return await Http.delete<NullResponse>( return await Http.delete<NullResponse>(
Url.scriptDetail, Url.scriptDetail,
{ {
@@ -314,8 +321,7 @@ class Api {
); );
} }
static Future<HttpResponse<String>> scriptDetail( static Future<HttpResponse<String>> scriptDetail(String name, String? path) async {
String name, String? path) async {
return await Http.get<String>( return await Http.get<String>(
Url.scriptDetail + name, Url.scriptDetail + name,
{ {
@@ -324,8 +330,7 @@ class Api {
); );
} }
static Future<HttpResponse<List<DependencyBean>>> dependencies( static Future<HttpResponse<List<DependencyBean>>> dependencies(String type) async {
String type) async {
return await Http.get<List<DependencyBean>>( return await Http.get<List<DependencyBean>>(
Url.dependencies, Url.dependencies,
{ {
@@ -334,8 +339,7 @@ class Api {
); );
} }
static Future<HttpResponse<NullResponse>> dependencyReinstall( static Future<HttpResponse<NullResponse>> dependencyReinstall(String id) async {
String id) async {
return await Http.put<NullResponse>( return await Http.put<NullResponse>(
Url.dependencies, Url.dependencies,
[id], [id],
@@ -349,8 +353,7 @@ class Api {
); );
} }
static Future<HttpResponse<NullResponse>> addDependency( static Future<HttpResponse<NullResponse>> addDependency(String name, int type) async {
String name, int type) async {
return await Http.post<NullResponse>( return await Http.post<NullResponse>(
Url.dependencies, Url.dependencies,
[ [
@@ -362,6 +365,17 @@ class Api {
); );
} }
static Future<HttpResponse<NullResponse>> addScript(String name, String path, String content) async {
return await Http.post<NullResponse>(
Url.addScript,
{
"filename": name,
"path": path,
"content": content,
},
);
}
static Future<HttpResponse<NullResponse>> delDependency(String id) async { static Future<HttpResponse<NullResponse>> delDependency(String id) async {
return await Http.delete<NullResponse>( return await Http.delete<NullResponse>(
Url.dependencies, Url.dependencies,

View File

@@ -1,11 +1,11 @@
import '../../main.dart'; import 'package:qinglong_app/base/userinfo_viewmodel.dart';
import '../userinfo_viewmodel.dart'; import 'package:qinglong_app/main.dart';
class Url { class Url {
static get system => "/api/system";
static get login => "/api/user/login"; static get login => "/api/user/login";
static get system => "/api/system";
static get loginOld => "/api/login"; static get loginOld => "/api/login";
static get loginTwo => "/api/user/two-factor/login"; static get loginTwo => "/api/user/two-factor/login";
@@ -14,119 +14,70 @@ class Url {
static const updatePassword = "/api/user"; static const updatePassword = "/api/user";
static get tasks => getIt<UserInfoViewModel>().useSecretLogined static get tasks => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons" : "/api/crons";
? "/open/crons"
: "/api/crons";
static get runTasks => getIt<UserInfoViewModel>().useSecretLogined static get runTasks => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/run" : "/api/crons/run";
? "/open/crons/run"
: "/api/crons/run";
static get stopTasks => getIt<UserInfoViewModel>().useSecretLogined static get stopTasks => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/stop" : "/api/crons/stop";
? "/open/crons/stop"
: "/api/crons/stop";
static get taskDetail => getIt<UserInfoViewModel>().useSecretLogined static get taskDetail => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/" : "/api/crons/";
? "/open/crons/"
: "/api/crons/";
static get addTask => getIt<UserInfoViewModel>().useSecretLogined static get addTask => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons" : "/api/crons";
? "/open/crons"
: "/api/crons";
static get pinTask => getIt<UserInfoViewModel>().useSecretLogined static get pinTask => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/pin" : "/api/crons/pin";
? "/open/crons/pin"
: "/api/crons/pin";
static get unpinTask => getIt<UserInfoViewModel>().useSecretLogined static get unpinTask => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/unpin" : "/api/crons/unpin";
? "/open/crons/unpin"
: "/api/crons/unpin";
static get enableTask => getIt<UserInfoViewModel>().useSecretLogined static get enableTask => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/enable" : "/api/crons/enable";
? "/open/crons/enable"
: "/api/crons/enable";
static get disableTask => getIt<UserInfoViewModel>().useSecretLogined static get disableTask => getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/disable" : "/api/crons/disable";
? "/open/crons/disable"
: "/api/crons/disable";
static get files => getIt<UserInfoViewModel>().useSecretLogined static get files => getIt<UserInfoViewModel>().useSecretLogined ? "/open/configs/files" : "/api/configs/files";
? "/open/configs/files"
: "/api/configs/files";
static get configContent => getIt<UserInfoViewModel>().useSecretLogined static get configContent => getIt<UserInfoViewModel>().useSecretLogined ? "/open/configs/" : "/api/configs/";
? "/open/configs/"
: "/api/configs/";
static get saveFile => getIt<UserInfoViewModel>().useSecretLogined static get saveFile => getIt<UserInfoViewModel>().useSecretLogined ? "/open/configs/save" : "/api/configs/save";
? "/open/configs/save"
: "/api/configs/save";
static get envs => static get envs => getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs" : "/api/envs";
getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs" : "/api/envs";
static get addEnv => static get addEnv => getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs" : "/api/envs";
getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs" : "/api/envs";
static get delEnv => static get delEnv => getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs" : "/api/envs";
getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs" : "/api/envs";
static get disableEnvs => getIt<UserInfoViewModel>().useSecretLogined static get disableEnvs => getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs/disable" : "/api/envs/disable";
? "/open/envs/disable"
: "/api/envs/disable";
static get enableEnvs => getIt<UserInfoViewModel>().useSecretLogined static get enableEnvs => getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs/enable" : "/api/envs/enable";
? "/open/envs/enable"
: "/api/envs/enable";
static get loginLog => getIt<UserInfoViewModel>().useSecretLogined static get loginLog => getIt<UserInfoViewModel>().useSecretLogined ? "/open/user/login-log" : "/api/user/login-log";
? "/open/user/login-log"
: "/api/user/login-log";
static get taskLog => static get taskLog => getIt<UserInfoViewModel>().useSecretLogined ? "/open/logs" : "/api/logs";
getIt<UserInfoViewModel>().useSecretLogined ? "/open/logs" : "/api/logs";
static get taskLogDetail => getIt<UserInfoViewModel>().useSecretLogined static get taskLogDetail => getIt<UserInfoViewModel>().useSecretLogined ? "/open/logs/" : "/api/logs/";
? "/open/logs/"
: "/api/logs/";
static get scripts => getIt<UserInfoViewModel>().useSecretLogined static get scripts => getIt<UserInfoViewModel>().useSecretLogined ? "/open/scripts/files" : "/api/scripts/files";
? "/open/scripts/files"
: "/api/scripts/files";
static get scriptUpdate => getIt<UserInfoViewModel>().useSecretLogined static get scripts2 => getIt<UserInfoViewModel>().useSecretLogined ? "/open/scripts" : "/api/scripts";
? "/open/scripts"
: "/api/scripts";
static get scriptDetail => getIt<UserInfoViewModel>().useSecretLogined static get scriptUpdate => getIt<UserInfoViewModel>().useSecretLogined ? "/open/scripts" : "/api/scripts";
? "/open/scripts/"
: "/api/scripts/";
static get dependencies => getIt<UserInfoViewModel>().useSecretLogined static get scriptDetail => getIt<UserInfoViewModel>().useSecretLogined ? "/open/scripts/" : "/api/scripts/";
? "/open/dependencies"
: "/api/dependencies";
static get dependencyReinstall => getIt<UserInfoViewModel>().useSecretLogined static get dependencies => getIt<UserInfoViewModel>().useSecretLogined ? "/open/dependencies" : "/api/dependencies";
? "/open/dependencies/reinstall"
: "/api/dependencies/reinstall"; static get addScript => getIt<UserInfoViewModel>().useSecretLogined ? "/open/scripts" : "/api/scripts";
static get dependencyReinstall => getIt<UserInfoViewModel>().useSecretLogined ? "/open/dependencies/reinstall" : "/api/dependencies/reinstall";
static intimeLog(String cronId) { static intimeLog(String cronId) {
return getIt<UserInfoViewModel>().useSecretLogined return getIt<UserInfoViewModel>().useSecretLogined ? "/open/crons/$cronId/log" : "/api/crons/$cronId/log";
? "/open/crons/$cronId/log"
: "/api/crons/$cronId/log";
} }
static envMove(String envId) { static envMove(String envId) {
return getIt<UserInfoViewModel>().useSecretLogined return getIt<UserInfoViewModel>().useSecretLogined ? "/open/envs/$envId/move" : "/api/envs/$envId/move";
? "/open/envs/$envId/move"
: "/api/envs/$envId/move";
} }
static bool inWhiteList(String path) { static bool inWhiteList(String path) {
if (path == login || if (path == login || path == loginByClientId || path == loginTwo || path == loginOld) {
path == loginByClientId ||
path == loginTwo ||
path == loginOld) {
return true; return true;
} }
return false; return false;
@@ -138,7 +89,4 @@ class Url {
} }
return false; return false;
} }
static String checkUpdateUrl =
"https://raw.githubusercontent.com/qinglong-app/qinglong_app/main/version";
} }

View File

@@ -23,6 +23,14 @@ class EnvPage extends StatefulWidget {
class _EnvPageState extends State<EnvPage> { class _EnvPageState extends State<EnvPage> {
final TextEditingController _searchController = TextEditingController(); final TextEditingController _searchController = TextEditingController();
@override
void initState() {
super.initState();
_searchController.addListener(() {
setState(() {});
});
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return BaseStateWidget<EnvViewModel>( return BaseStateWidget<EnvViewModel>(
@@ -37,7 +45,7 @@ class _EnvPageState extends State<EnvPage> {
(value.remarks?.contains(_searchController.text) ?? false)) { (value.remarks?.contains(_searchController.text) ?? false)) {
list.add(EnvItemCell( list.add(EnvItemCell(
value, value,
i + 1, i,
ref, ref,
key: ValueKey(value.sId), key: ValueKey(value.sId),
)); ));
@@ -51,32 +59,34 @@ class _EnvPageState extends State<EnvPage> {
onRefresh: () async { onRefresh: () async {
return model.loadData(false); return model.loadData(false);
}, },
child: ReorderableListView( child: SlidableAutoCloseBehavior(
keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag, child: ReorderableListView(
header: searchCell(ref), keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
onReorder: (int oldIndex, int newIndex) { header: searchCell(ref),
if (list.length != model.list.length) { onReorder: (int oldIndex, int newIndex) {
"请先清空搜索关键词".toast(); if (list.length != model.list.length) {
return; "请先清空搜索关键词".toast();
} return;
setState(() {
//交换数据
if (newIndex > oldIndex) {
newIndex -= 1;
} }
final EnvBean item = model.list.removeAt(oldIndex);
model.list.insert(newIndex, item); setState(() {
model.update(item.sId ?? "", newIndex, oldIndex); //交换数据
}); if (newIndex > oldIndex) {
}, newIndex -= 1;
children: list, }
final EnvBean item = model.list.removeAt(oldIndex);
model.list.insert(newIndex, item);
model.update(item.sId ?? "", newIndex, oldIndex);
});
},
children: list,
),
), ),
); );
}, },
model: envProvider, model: envProvider,
onReady: (viewModel) { onReady: (viewModel) {
viewModel.loadData(); viewModel.loadData(context);
}, },
); );
} }
@@ -133,185 +143,181 @@ class EnvItemCell extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GestureDetector( return ColoredBox(
onTap: () { color: ref.watch(themeProvider).themeColor.settingBgColor(),
Navigator.of(context).pushNamed(Routes.routeEnvDetail, arguments: bean); child: Slidable(
}, key: ValueKey(bean.sId),
child: ColoredBox( endActionPane: ActionPane(
color: ref.watch(themeProvider).themeColor.settingBgColor(), motion: const StretchMotion(),
child: Slidable( extentRatio: 0.5,
key: ValueKey(bean.sId), children: [
endActionPane: ActionPane( SlidableAction(
motion: const ScrollMotion(), backgroundColor: const Color(0xff5D5E70),
extentRatio: 0.45, onPressed: (_) {
Navigator.of(context).pushNamed(Routes.routeAddEnv, arguments: bean);
},
foregroundColor: Colors.white,
icon: CupertinoIcons.pencil_outline,
),
SlidableAction(
backgroundColor: const Color(0xffA356D6),
onPressed: (_) {
enableEnv(context);
},
foregroundColor: Colors.white,
icon: bean.status == 0 ? Icons.dnd_forwardslash : Icons.check_circle_outline_sharp,
),
SlidableAction(
backgroundColor: const Color(0xffEA4D3E),
onPressed: (_) {
delEnv(context, ref);
},
foregroundColor: Colors.white,
icon: CupertinoIcons.delete,
),
],
),
child: SizedBox(
width: MediaQuery.of(context).size.width,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
SlidableAction( Material(
backgroundColor: Colors.grey, color: ref.watch(themeProvider).themeColor.settingBgColor(),
flex: 1, child: InkWell(
onPressed: (_) { onTap: () {
Navigator.of(context).pushNamed(Routes.routeAddEnv, arguments: bean); Navigator.of(context).pushNamed(Routes.routeEnvDetail, arguments: bean);
}, },
foregroundColor: Colors.white, child: Container(
icon: CupertinoIcons.pencil_outline, padding: const EdgeInsets.symmetric(
), horizontal: 15,
SlidableAction( vertical: 8,
backgroundColor: Colors.orange, ),
flex: 1, child: Column(
onPressed: (_) { mainAxisSize: MainAxisSize.min,
enableEnv(); mainAxisAlignment: MainAxisAlignment.start,
}, crossAxisAlignment: CrossAxisAlignment.start,
foregroundColor: Colors.white, children: [
icon: bean.status == 0 ? Icons.dnd_forwardslash : Icons.check_circle_outline_sharp, Row(
), mainAxisAlignment: MainAxisAlignment.start,
SlidableAction( children: [
backgroundColor: Colors.red, Expanded(
flex: 1, child: Row(
onPressed: (_) { children: [
delEnv(context, ref); bean.status == 1
}, ? const Icon(
foregroundColor: Colors.white, Icons.dnd_forwardslash,
icon: CupertinoIcons.delete, size: 18,
), color: Color(0xffEA4D3E),
], )
), : Container(
child: SizedBox( padding: const EdgeInsets.symmetric(
width: MediaQuery.of(context).size.width, horizontal: 5,
child: Column( ),
mainAxisSize: MainAxisSize.min, decoration: BoxDecoration(
crossAxisAlignment: CrossAxisAlignment.start, borderRadius: BorderRadius.circular(5),
children: [ border: Border.all(color: ref.watch(themeProvider).primaryColor, width: 1),
Container( ),
padding: const EdgeInsets.symmetric( child: Text(
horizontal: 15, "${getIndexByIndex(context, index)}",
vertical: 8, style: TextStyle(color: ref.watch(themeProvider).primaryColor, fontSize: 12),
), ),
child: Column( ),
mainAxisSize: MainAxisSize.min, const SizedBox(
mainAxisAlignment: MainAxisAlignment.start, width: 5,
crossAxisAlignment: CrossAxisAlignment.start, ),
children: [ Material(
Row( color: Colors.transparent,
mainAxisAlignment: MainAxisAlignment.start, child: Text(
children: [ bean.name ?? "",
Expanded( maxLines: 1,
child: Row( style: TextStyle(
children: [ overflow: TextOverflow.ellipsis,
Material( color: ref.watch(themeProvider).themeColor.titleColor(),
color: Colors.transparent, fontSize: 16,
child: Text( ),
bean.name ?? "",
maxLines: 1,
style: TextStyle(
overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.titleColor(),
fontSize: 18,
), ),
), ),
), const SizedBox(
], width: 5,
), ),
), Expanded(
const SizedBox( child: Visibility(
width: 5, visible: bean.remarks != null && bean.remarks!.isNotEmpty,
), child: Material(
Material( color: Colors.transparent,
color: Colors.transparent, child: Text(
child: Text( "(${bean.remarks})",
Utils.formatGMTTime(bean.timestamp ?? ""), maxLines: 1,
maxLines: 1, style: TextStyle(
style: TextStyle( height: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.descColor(), color: ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12, fontSize: 12,
), ),
), ),
), ),
], ),
), ),
Padding( ],
padding: const EdgeInsets.only(top: 8.0),
child: Row(
children: [
Container(
padding: const EdgeInsets.symmetric(
horizontal: 5,
),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
border: Border.all(color: ref.watch(themeProvider).primaryColor, width: 1),
),
child: Text(
"$index",
style: TextStyle(color: ref.watch(themeProvider).primaryColor, fontSize: 12),
), ),
), ),
const SizedBox( const SizedBox(
width: 5, width: 15,
),
bean.status == 1
? const Icon(
Icons.dnd_forwardslash,
size: 12,
color: Colors.red,
)
: const SizedBox.shrink(),
const SizedBox(
width: 5,
), ),
Material( Material(
color: Colors.transparent, color: Colors.transparent,
child: Text( child: Text(
bean.remarks ?? "-", Utils.formatGMTTime(bean.timestamp ?? ""),
maxLines: 1, maxLines: 1,
style: TextStyle( style: TextStyle(
height: 1,
overflow: TextOverflow.ellipsis, overflow: TextOverflow.ellipsis,
color: ref.watch(themeProvider).themeColor.descColor(), color: ref.watch(themeProvider).themeColor.descColor(),
fontSize: 12, fontSize: 12,
), ),
), ),
), ),
const Spacer(),
], ],
), ),
), const SizedBox(
const SizedBox( height: 15,
height: 8, ),
), Material(
Material( color: Colors.transparent,
color: Colors.transparent, child: Text(
child: Text( bean.value ?? "",
bean.value ?? "", maxLines: 1,
maxLines: 1, style: TextStyle(
style: TextStyle( overflow: TextOverflow.ellipsis,
overflow: TextOverflow.ellipsis, color: ref.watch(themeProvider).themeColor.descColor(),
color: ref.watch(themeProvider).themeColor.descColor(), fontSize: 12,
fontSize: 12, ),
), ),
), ),
), ],
], ),
), ),
), ),
const Divider( ),
height: 1, const Divider(
indent: 15, height: 1,
), indent: 15,
], ),
), ],
), ),
), ),
), ),
); );
} }
void enableEnv() { void enableEnv(BuildContext context) {
ref.read(envProvider).enableEnv(bean.sId!, bean.status!); ref.read(envProvider).enableEnv(bean.sId!, bean.status!);
} }
void delEnv(BuildContext context, WidgetRef ref) { void delEnv(BuildContext context, WidgetRef ref) {
showCupertinoDialog( showCupertinoDialog(
useRootNavigator: false,
context: context, context: context,
builder: (context) => CupertinoAlertDialog( builder: (context) => CupertinoAlertDialog(
title: const Text("确认删除"), title: const Text("确认删除"),
@@ -344,4 +350,17 @@ class EnvItemCell extends StatelessWidget {
), ),
); );
} }
int getIndexByIndex(BuildContext context, int index) {
var list = ref.watch(envProvider.notifier).list;
int result = 0;
for (int i = 0; i <= index; i++) {
if (list.length > index && list[i].status == 0) {
result++;
}
}
return result;
}
} }

View File

@@ -1,3 +1,4 @@
/// @author NewTab
import 'package:json_conversion_annotation/json_conversion_annotation.dart'; import 'package:json_conversion_annotation/json_conversion_annotation.dart';
@@ -11,6 +12,98 @@ class SystemBean {
version = json['version']; version = json['version'];
} }
//2.12.2 以及以上版本,日志从dirs换成了data
bool isUpperVersion2_12_2() {
try {
List<String>? version1 = version?.split("\.");
String f = version1?[0] ?? "2";
String s = version1?[1] ?? "10";
String t = version1?[2] ?? "0";
if (f.length == 1) {
f = "0$f";
}
if (s.length == 1) {
s = "0$s";
}
if (t.length == 1) {
t = "0$t";
}
String tempSum = "$f$s$t";
if ((int.tryParse(tempSum) ?? 1) >= 021202) {
return true;
}
return false;
} catch (e) {
return false;
}
}
//2.13.0 以及以上版本日志详情接口参数有变化
bool isUpperVersion2_13_0() {
try {
List<String>? version1 = version?.split("\.");
String f = version1?[0] ?? "2";
String s = version1?[1] ?? "10";
String t = version1?[2] ?? "0";
if (f.length == 1) {
f = "0$f";
}
if (s.length == 1) {
s = "0$s";
}
if (t.length == 1) {
t = "0$t";
}
String tempSum = "$f$s$t";
if ((int.tryParse(tempSum) ?? 1) >= 021300) {
return true;
}
return false;
} catch (e) {
return false;
}
}
// 2.10.13以上版本,针对任务,环境变量编辑做了修改
bool isUpperVersion() {
try {
List<String>? version1 = version?.split("\.");
String f = version1?[0] ?? "2";
String s = version1?[1] ?? "10";
String t = version1?[2] ?? "0";
if (f.length == 1) {
f = "0$f";
}
if (s.length == 1) {
s = "0$s";
}
if (t.length == 1) {
t = "0$t";
}
String tempSum = "$f$s$t";
if ((int.tryParse(tempSum) ?? 1) > 021013) {
return true;
}
return false;
} catch (e) {
return false;
}
}
Map<String, dynamic> toJson() { Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>(); final Map<String, dynamic> data = new Map<String, dynamic>();
data['version'] = this.version; data['version'] = this.version;

View File

@@ -7,32 +7,14 @@ class Utils {
static final SystemBean systemBean = SystemBean(); static final SystemBean systemBean = SystemBean();
static bool isUpperVersion() { static bool isUpperVersion() {
try { return systemBean.isUpperVersion();
List<String>? version = Utils.systemBean.version?.split("\."); }
static bool isUpperVersion2_12_2() {
return systemBean.isUpperVersion2_12_2();
}
String f = version?[0] ?? "2"; static bool isUpperVersion2_13_0() {
String s = version?[1] ?? "10"; return systemBean.isUpperVersion2_13_0();
String t = version?[2] ?? "0";
int first = int.parse(f);
int second = int.parse(s);
int third = int.parse(t);
/// 2.10.13 及以下版本
if (first > 2) {
return true;
}
if (second > 10) {
return true;
}
if (third > 13) {
return true;
}
return false;
} catch (e) {
return false;
}
} }
static void hideKeyBoard(BuildContext context) { static void hideKeyBoard(BuildContext context) {