mirror of
https://github.com/qinglong-app/qinglong_app.git
synced 2025-10-09 16:48:19 +08:00
适配新版本api
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import 'package:qinglong_app/base/http/http.dart';
|
import 'package:qinglong_app/base/http/http.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/login/login_bean.dart';
|
import 'package:qinglong_app/module/login/login_bean.dart';
|
||||||
import 'package:qinglong_app/module/login/user_bean.dart';
|
import 'package:qinglong_app/module/login/user_bean.dart';
|
||||||
import 'package:qinglong_app/module/others/dependencies/dependency_bean.dart';
|
import 'package:qinglong_app/module/others/dependencies/dependency_bean.dart';
|
||||||
@@ -9,9 +10,17 @@ 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 '../../utils/utils.dart';
|
||||||
import 'url.dart';
|
import 'url.dart';
|
||||||
|
|
||||||
class Api {
|
class Api {
|
||||||
|
static Future<HttpResponse<SystemBean>> system() async {
|
||||||
|
return await Http.get<SystemBean>(
|
||||||
|
Url.system,
|
||||||
|
{},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static Future<HttpResponse<LoginBean>> login(
|
static Future<HttpResponse<LoginBean>> login(
|
||||||
String userName,
|
String userName,
|
||||||
String passWord,
|
String passWord,
|
||||||
@@ -24,6 +33,7 @@ class Api {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<HttpResponse<LoginBean>> loginOld(
|
static Future<HttpResponse<LoginBean>> loginOld(
|
||||||
String userName,
|
String userName,
|
||||||
String passWord,
|
String passWord,
|
||||||
@@ -36,6 +46,7 @@ class Api {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<HttpResponse<LoginBean>> loginTwo(
|
static Future<HttpResponse<LoginBean>> loginTwo(
|
||||||
String userName,
|
String userName,
|
||||||
String passWord,
|
String passWord,
|
||||||
@@ -78,21 +89,24 @@ class Api {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<HttpResponse<NullResponse>> startTasks(List<String> crons) async {
|
static Future<HttpResponse<NullResponse>> startTasks(
|
||||||
|
List<String> crons) async {
|
||||||
return await Http.put<NullResponse>(
|
return await Http.put<NullResponse>(
|
||||||
Url.runTasks,
|
Url.runTasks,
|
||||||
crons,
|
crons,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<HttpResponse<NullResponse>> stopTasks(List<String> crons) async {
|
static Future<HttpResponse<NullResponse>> stopTasks(
|
||||||
|
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(String name, String password) async {
|
static Future<HttpResponse<NullResponse>> updatePassword(
|
||||||
|
String name, String password) async {
|
||||||
return await Http.put<NullResponse>(
|
return await Http.put<NullResponse>(
|
||||||
Url.updatePassword,
|
Url.updatePassword,
|
||||||
{
|
{
|
||||||
@@ -109,11 +123,17 @@ class Api {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<HttpResponse<NullResponse>> addTask(String name, String command, String cron, {String? id}) async {
|
static Future<HttpResponse<NullResponse>> addTask(
|
||||||
|
String name, String command, String cron,
|
||||||
|
{String? id}) async {
|
||||||
var data = {"name": name, "command": command, "schedule": cron};
|
var data = {"name": name, "command": command, "schedule": cron};
|
||||||
|
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
|
if (Utils.isUpperVersion()) {
|
||||||
data["id"] = id;
|
data["id"] = id;
|
||||||
|
} else {
|
||||||
|
data["_id"] = id;
|
||||||
|
}
|
||||||
return await Http.put<NullResponse>(
|
return await Http.put<NullResponse>(
|
||||||
Url.addTask,
|
Url.addTask,
|
||||||
data,
|
data,
|
||||||
@@ -174,7 +194,8 @@ class Api {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<HttpResponse<NullResponse>> saveFile(String name, String content) async {
|
static Future<HttpResponse<NullResponse>> saveFile(
|
||||||
|
String name, String content) async {
|
||||||
return await Http.post<NullResponse>(
|
return await Http.post<NullResponse>(
|
||||||
Url.saveFile,
|
Url.saveFile,
|
||||||
{"content": content, "name": name},
|
{"content": content, "name": name},
|
||||||
@@ -209,7 +230,9 @@ class Api {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<HttpResponse<NullResponse>> addEnv(String name, String value, String remarks, {String? id}) async {
|
static Future<HttpResponse<NullResponse>> addEnv(
|
||||||
|
String name, String value, String remarks,
|
||||||
|
{String? id}) async {
|
||||||
var data = {
|
var data = {
|
||||||
"value": value,
|
"value": value,
|
||||||
"remarks": remarks,
|
"remarks": remarks,
|
||||||
@@ -217,7 +240,12 @@ class Api {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
|
if (Utils.isUpperVersion()) {
|
||||||
data["id"] = id;
|
data["id"] = id;
|
||||||
|
} else {
|
||||||
|
data["_id"] = id;
|
||||||
|
}
|
||||||
|
|
||||||
return await Http.put<NullResponse>(
|
return await Http.put<NullResponse>(
|
||||||
Url.addEnv,
|
Url.addEnv,
|
||||||
data,
|
data,
|
||||||
@@ -229,7 +257,8 @@ class Api {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<HttpResponse<NullResponse>> moveEnv(String id, int fromIndex, int toIndex) async {
|
static Future<HttpResponse<NullResponse>> moveEnv(
|
||||||
|
String id, int fromIndex, int toIndex) async {
|
||||||
return await Http.put<NullResponse>(
|
return await Http.put<NullResponse>(
|
||||||
Url.envMove(id),
|
Url.envMove(id),
|
||||||
{"fromIndex": fromIndex, "toIndex": toIndex},
|
{"fromIndex": fromIndex, "toIndex": toIndex},
|
||||||
@@ -244,7 +273,8 @@ 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, serializationName: "dirs");
|
return await Http.get<List<TaskLogBean>>(Url.taskLog, null,
|
||||||
|
serializationName: "dirs");
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<HttpResponse<String>> taskLogDetail(String name) async {
|
static Future<HttpResponse<String>> taskLogDetail(String name) async {
|
||||||
@@ -261,7 +291,8 @@ class Api {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<HttpResponse<NullResponse>> updateScript(String name, String path, String content) async {
|
static Future<HttpResponse<NullResponse>> updateScript(
|
||||||
|
String name, String path, String content) async {
|
||||||
return await Http.put<NullResponse>(
|
return await Http.put<NullResponse>(
|
||||||
Url.scriptDetail,
|
Url.scriptDetail,
|
||||||
{
|
{
|
||||||
@@ -272,7 +303,8 @@ class Api {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<HttpResponse<NullResponse>> delScript(String name, String path) async {
|
static Future<HttpResponse<NullResponse>> delScript(
|
||||||
|
String name, String path) async {
|
||||||
return await Http.delete<NullResponse>(
|
return await Http.delete<NullResponse>(
|
||||||
Url.scriptDetail,
|
Url.scriptDetail,
|
||||||
{
|
{
|
||||||
@@ -282,7 +314,8 @@ class Api {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<HttpResponse<String>> scriptDetail(String name, String? path) async {
|
static Future<HttpResponse<String>> scriptDetail(
|
||||||
|
String name, String? path) async {
|
||||||
return await Http.get<String>(
|
return await Http.get<String>(
|
||||||
Url.scriptDetail + name,
|
Url.scriptDetail + name,
|
||||||
{
|
{
|
||||||
@@ -291,7 +324,8 @@ class Api {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<HttpResponse<List<DependencyBean>>> dependencies(String type) async {
|
static Future<HttpResponse<List<DependencyBean>>> dependencies(
|
||||||
|
String type) async {
|
||||||
return await Http.get<List<DependencyBean>>(
|
return await Http.get<List<DependencyBean>>(
|
||||||
Url.dependencies,
|
Url.dependencies,
|
||||||
{
|
{
|
||||||
@@ -300,7 +334,8 @@ class Api {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<HttpResponse<NullResponse>> dependencyReinstall(String id) async {
|
static Future<HttpResponse<NullResponse>> dependencyReinstall(
|
||||||
|
String id) async {
|
||||||
return await Http.put<NullResponse>(
|
return await Http.put<NullResponse>(
|
||||||
Url.dependencies,
|
Url.dependencies,
|
||||||
[id],
|
[id],
|
||||||
@@ -314,7 +349,8 @@ class Api {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future<HttpResponse<NullResponse>> addDependency(String name, int type) async {
|
static Future<HttpResponse<NullResponse>> addDependency(
|
||||||
|
String name, int type) async {
|
||||||
return await Http.post<NullResponse>(
|
return await Http.post<NullResponse>(
|
||||||
Url.dependencies,
|
Url.dependencies,
|
||||||
[
|
[
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import '../../main.dart';
|
|||||||
import '../userinfo_viewmodel.dart';
|
import '../userinfo_viewmodel.dart';
|
||||||
|
|
||||||
class Url {
|
class Url {
|
||||||
|
static get system => "/api/system";
|
||||||
|
|
||||||
static get login => "/api/user/login";
|
static get login => "/api/user/login";
|
||||||
|
|
||||||
static get loginOld => "/api/login";
|
static get loginOld => "/api/login";
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
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/login/login_bean.dart';
|
import 'package:qinglong_app/module/login/login_bean.dart';
|
||||||
import 'package:qinglong_app/module/login/user_bean.dart';
|
import 'package:qinglong_app/module/login/user_bean.dart';
|
||||||
import 'package:qinglong_app/module/others/dependencies/dependency_bean.dart';
|
import 'package:qinglong_app/module/others/dependencies/dependency_bean.dart';
|
||||||
@@ -33,6 +34,10 @@ class JsonConversion$Json {
|
|||||||
return EnvBean.jsonConversion(json) as M;
|
return EnvBean.jsonConversion(json) as M;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(type == (SystemBean).toString()){
|
||||||
|
return SystemBean.jsonConversion(json) as M;
|
||||||
|
}
|
||||||
|
|
||||||
if(type == (LoginBean).toString()){
|
if(type == (LoginBean).toString()){
|
||||||
return LoginBean.jsonConversion(json) as M;
|
return LoginBean.jsonConversion(json) as M;
|
||||||
}
|
}
|
||||||
@@ -73,6 +78,10 @@ class JsonConversion$Json {
|
|||||||
return data.map<EnvBean>((e) => EnvBean.jsonConversion(e)).toList() as M;
|
return data.map<EnvBean>((e) => EnvBean.jsonConversion(e)).toList() as M;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(<SystemBean>[] is M){
|
||||||
|
return data.map<SystemBean>((e) => SystemBean.jsonConversion(e)).toList() as M;
|
||||||
|
}
|
||||||
|
|
||||||
if(<LoginBean>[] is M){
|
if(<LoginBean>[] is M){
|
||||||
return data.map<LoginBean>((e) => LoginBean.jsonConversion(e)).toList() as M;
|
return data.map<LoginBean>((e) => LoginBean.jsonConversion(e)).toList() as M;
|
||||||
}
|
}
|
||||||
|
|||||||
2
lib/module/env/env_page.dart
vendored
2
lib/module/env/env_page.dart
vendored
@@ -152,7 +152,7 @@ class EnvItemCell extends StatelessWidget {
|
|||||||
Navigator.of(context).pushNamed(Routes.routeAddEnv, arguments: bean);
|
Navigator.of(context).pushNamed(Routes.routeAddEnv, arguments: bean);
|
||||||
},
|
},
|
||||||
foregroundColor: Colors.white,
|
foregroundColor: Colors.white,
|
||||||
icon: CupertinoIcons.pencil,
|
icon: CupertinoIcons.pencil_outline,
|
||||||
),
|
),
|
||||||
SlidableAction(
|
SlidableAction(
|
||||||
backgroundColor: Colors.orange,
|
backgroundColor: Colors.orange,
|
||||||
|
|||||||
@@ -1,16 +1,22 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||||
|
import 'package:qinglong_app/base/http/api.dart';
|
||||||
import 'package:qinglong_app/base/ql_app_bar.dart';
|
import 'package:qinglong_app/base/ql_app_bar.dart';
|
||||||
import 'package:qinglong_app/base/routes.dart';
|
import 'package:qinglong_app/base/routes.dart';
|
||||||
import 'package:qinglong_app/module/config/config_page.dart';
|
import 'package:qinglong_app/module/config/config_page.dart';
|
||||||
import 'package:qinglong_app/module/env/env_page.dart';
|
import 'package:qinglong_app/module/env/env_page.dart';
|
||||||
|
import 'package:qinglong_app/module/home/system_bean.dart';
|
||||||
import 'package:qinglong_app/module/others/other_page.dart';
|
import 'package:qinglong_app/module/others/other_page.dart';
|
||||||
import 'package:qinglong_app/module/task/task_page.dart';
|
import 'package:qinglong_app/module/task/task_page.dart';
|
||||||
import 'package:move_to_background/move_to_background.dart';
|
import 'package:move_to_background/move_to_background.dart';
|
||||||
import 'package:qinglong_app/utils/update_utils.dart';
|
import 'package:qinglong_app/utils/update_utils.dart';
|
||||||
import 'dart:math' as math;
|
import 'dart:math' as math;
|
||||||
|
|
||||||
|
import '../../utils/utils.dart';
|
||||||
|
|
||||||
class HomePage extends ConsumerStatefulWidget {
|
class HomePage extends ConsumerStatefulWidget {
|
||||||
const HomePage({Key? key}) : super(key: key);
|
const HomePage({Key? key}) : super(key: key);
|
||||||
|
|
||||||
@@ -18,7 +24,8 @@ class HomePage extends ConsumerStatefulWidget {
|
|||||||
_HomePageState createState() => _HomePageState();
|
_HomePageState createState() => _HomePageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _HomePageState extends ConsumerState<HomePage> with TickerProviderStateMixin {
|
class _HomePageState extends ConsumerState<HomePage>
|
||||||
|
with TickerProviderStateMixin {
|
||||||
int _index = 0;
|
int _index = 0;
|
||||||
String _title = "";
|
String _title = "";
|
||||||
bool isNewYear = false;
|
bool isNewYear = false;
|
||||||
@@ -41,6 +48,7 @@ class _HomePageState extends ConsumerState<HomePage> with TickerProviderStateMix
|
|||||||
super.initState();
|
super.initState();
|
||||||
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
|
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
|
||||||
update();
|
update();
|
||||||
|
getSystemBean();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,7 +246,8 @@ class _HomePageState extends ConsumerState<HomePage> with TickerProviderStateMix
|
|||||||
void update() async {
|
void update() async {
|
||||||
String? result = await UpdateUtils().checkUpdate();
|
String? result = await UpdateUtils().checkUpdate();
|
||||||
if (result != null && result.isNotEmpty) {
|
if (result != null && result.isNotEmpty) {
|
||||||
UpdateDialog updateDialog = UpdateDialog(context, title: "发现新版本", updateContent: "版本号:v$result", onUpdate: () {
|
UpdateDialog updateDialog = UpdateDialog(context,
|
||||||
|
title: "发现新版本", updateContent: "版本号:v$result", onUpdate: () {
|
||||||
UpdateUtils.launchURL(result);
|
UpdateUtils.launchURL(result);
|
||||||
});
|
});
|
||||||
updateDialog.show();
|
updateDialog.show();
|
||||||
@@ -256,6 +265,13 @@ class _HomePageState extends ConsumerState<HomePage> with TickerProviderStateMix
|
|||||||
isNewYear = false;
|
isNewYear = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void getSystemBean() async {
|
||||||
|
var bean = await Api.system();
|
||||||
|
if (bean.success) {
|
||||||
|
Utils.systemBean.version = bean.bean?.version ?? "2.10.13";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class IndexBean {
|
class IndexBean {
|
||||||
|
|||||||
23
lib/module/home/system_bean.dart
Normal file
23
lib/module/home/system_bean.dart
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
import 'package:json_conversion_annotation/json_conversion_annotation.dart';
|
||||||
|
|
||||||
|
@JsonConversion()
|
||||||
|
class SystemBean {
|
||||||
|
String? version;
|
||||||
|
|
||||||
|
SystemBean({this.version});
|
||||||
|
|
||||||
|
SystemBean.fromJson(Map<String, dynamic> json) {
|
||||||
|
version = json['version'];
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() {
|
||||||
|
final Map<String, dynamic> data = new Map<String, dynamic>();
|
||||||
|
data['version'] = this.version;
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SystemBean jsonConversion(Map<String, dynamic> json) {
|
||||||
|
return SystemBean.fromJson(json);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,40 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
import '../module/home/system_bean.dart';
|
||||||
|
|
||||||
class Utils {
|
class Utils {
|
||||||
|
static final SystemBean systemBean = SystemBean();
|
||||||
|
|
||||||
|
static bool isUpperVersion() {
|
||||||
|
try {
|
||||||
|
List<String>? version = Utils.systemBean.version?.split("\.");
|
||||||
|
|
||||||
|
String f = version?[0] ?? "2";
|
||||||
|
String s = version?[1] ?? "10";
|
||||||
|
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) {
|
||||||
FocusScope.of(context).requestFocus(FocusNode());
|
FocusScope.of(context).requestFocus(FocusNode());
|
||||||
}
|
}
|
||||||
@@ -71,7 +104,7 @@ class Utils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static String formatMessageTime(int time) {
|
static String formatMessageTime(int time) {
|
||||||
if(time == 0){
|
if (time == 0) {
|
||||||
return "-";
|
return "-";
|
||||||
}
|
}
|
||||||
DateTime current = DateTime.now();
|
DateTime current = DateTime.now();
|
||||||
|
|||||||
Reference in New Issue
Block a user