add others

This commit is contained in:
jyuesong
2022-01-17 16:42:46 +08:00
parent 105d6172b6
commit ad141e4bd1
18 changed files with 291 additions and 128 deletions

View File

@@ -37,9 +37,9 @@ class _BaseStateWidgetState<T extends BaseViewModel> extends ConsumerState<BaseS
@override
Widget build(BuildContext context) {
var viewModel = ref.watch<T>(widget.model);
if (viewModel.failReason != null) {
if (viewModel.failedToast != null) {
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
failDialog(context, viewModel.failReason!);
failDialog(context, viewModel.failedToast!);
viewModel.clearToast();
});
}

View File

@@ -5,9 +5,11 @@ class ViewModel extends ChangeNotifier {}
class BaseViewModel extends ViewModel {
PageState currentState = PageState.START;
String? failReason;
String? failedToast;
void loading({bool notify = false}) {
failReason = null;
failedToast = null;
currentState = PageState.LOADING;
if (notify) {
notifyListeners();
@@ -16,6 +18,7 @@ class BaseViewModel extends ViewModel {
void success({bool notify = true}) {
failReason = null;
failedToast = null;
currentState = PageState.CONTENT;
if (notify) {
notifyListeners();
@@ -25,24 +28,28 @@ class BaseViewModel extends ViewModel {
void failed(String? reason, {bool notify = false}) {
currentState = PageState.FAILED;
failReason = reason;
failedToast = null;
if (notify) {
notifyListeners();
}
}
void failToast(String? reason, {bool notify = false}) {
currentState = PageState.CONTENT;
failedToast = reason;
failReason = reason;
if (notify) {
notifyListeners();
}
}
void clearToast(){
failReason = null;
void clearToast() {
failedToast = null;
}
void empty({bool notify = false}) {
failReason = null;
failedToast = null;
currentState = PageState.EMPTY;
if (notify) {
notifyListeners();

View File

@@ -6,9 +6,11 @@ import 'package:dio_log/dio_log.dart';
import 'package:flutter/foundation.dart';
import 'package:qinglong_app/base/http/token_interceptor.dart';
import 'package:qinglong_app/base/userinfo_viewmodel.dart';
import 'package:qinglong_app/utils/QlNavigatorObserver.dart';
import '../../json.jc.dart';
import '../../main.dart';
import '../routes.dart';
class Http {
static const int NOT_LOGIN = 1000;
@@ -43,6 +45,9 @@ class Http {
return decodeResponse<T>(response, compute);
} on DioError catch (e) {
if (e.response?.statusCode == 401) {
exitLogin();
}
return HttpResponse(success: false, message: e.message, code: 0);
}
}
@@ -54,6 +59,9 @@ class Http {
return decodeResponse<T>(response, compute);
} on DioError catch (e) {
if (e.response?.statusCode == 401) {
exitLogin();
}
return HttpResponse(success: false, message: e.message, code: 0);
}
}
@@ -65,6 +73,9 @@ class Http {
return decodeResponse<T>(response, compute);
} on DioError catch (e) {
if (e.response?.statusCode == 401) {
exitLogin();
}
return HttpResponse(success: false, message: e.message, code: 0);
}
}
@@ -75,16 +86,27 @@ class Http {
var response = await _dio!.put(uri, data: json);
return decodeResponse<T>(response, compute);
} on DioError catch (e) {
if (e.response?.statusCode == 401) {
exitLogin();
}
return HttpResponse(success: false, message: e.message, code: 0);
}
}
static bool pushedLoginPage = false;
static void exitLogin() {
if (!pushedLoginPage) {
pushedLoginPage = true;
navigatorState.currentState?.pushReplacementNamed(Routes.route_LOGIN);
}
}
static HttpResponse<T> decodeResponse<T>(
Response<dynamic> response,
bool compute,
) {
int code = 0;
if (response.statusCode == 200) {
try {
if (response.data["code"] == 200) {
@@ -191,3 +213,5 @@ void decode<T>() async {
}
class NullResponse {}
class NotLoginException implements Exception {}

View File

@@ -6,7 +6,7 @@ import '../userinfo_viewmodel.dart';
class TokenInterceptor extends Interceptor {
@override
void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
if (getIt<UserInfoViewModel>().token != null) {
if (getIt<UserInfoViewModel>().token != null && getIt<UserInfoViewModel>().token!.isNotEmpty) {
options.headers["Authorization"] = "Bearer " + getIt<UserInfoViewModel>().token!;
}
options.queryParameters["t"] = (DateTime.now().millisecondsSinceEpoch~/1000).toString();

View File

@@ -15,8 +15,8 @@ class Url {
static const ENVS = "/api/envs";
static const ADD_ENV = "/api/envs";
static const DEL_ENV = "/api/envs";
static const DISABLE_ENVS = "/api/disable";
static const ENABLE_ENVS = "/api/enable";
static const DISABLE_ENVS = "/api/envs/disable";
static const ENABLE_ENVS = "/api/envs/enable";
static INTIME_LOG(String cronId) {
return "/api/crons/$cronId/log";

View File

@@ -2,11 +2,13 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:qinglong_app/module/config/config_edit_page.dart';
import 'package:qinglong_app/module/home/home_page.dart';
import 'package:qinglong_app/module/login/login_page.dart';
import 'package:qinglong_app/module/task/add_task_page.dart';
import 'package:qinglong_app/module/task/task_bean.dart';
class Routes {
static const String route_HomePage = "/home/homepage";
static const String route_LOGIN = "/login";
static const String route_AddTask = "/task/add";
static const String route_ConfigEdit = "/config/edit";
@@ -14,6 +16,8 @@ class Routes {
switch (settings.name) {
case route_HomePage:
return MaterialPageRoute(builder: (context) => const HomePage());
case route_LOGIN:
return MaterialPageRoute(builder: (context) => const LoginPage());
case route_AddTask:
if (settings.arguments != null) {
return CupertinoPageRoute(

View File

@@ -25,6 +25,9 @@ class ThemeViewModel extends ChangeNotifier {
ThemeData darkTheme = ThemeData.dark().copyWith(
primaryColor: const Color(0xffffffff),
appBarTheme: const AppBarTheme(
backgroundColor: Colors.black,
),
inputDecorationTheme: const InputDecorationTheme(
labelStyle: TextStyle(color: _primaryColor),
focusedBorder: UnderlineInputBorder(
@@ -41,12 +44,14 @@ ThemeData darkTheme = ThemeData.dark().copyWith(
fontSize: 14,
),
labelColor: Color(0xffffffff),
unselectedLabelColor: Color(0xff999999),
unselectedLabelColor: Color(0xff999999),
),
colorScheme: const ColorScheme.light(secondary: _primaryColor,primary: _primaryColor,),
);
ThemeData lightTheme = ThemeData.light().copyWith(
primaryColor: _primaryColor,
colorScheme: const ColorScheme.light(secondary: _primaryColor,primary: _primaryColor,),
scaffoldBackgroundColor: Colors.white,
inputDecorationTheme: const InputDecorationTheme(
labelStyle: TextStyle(color: _primaryColor),
@@ -76,7 +81,7 @@ ThemeData lightTheme = ThemeData.light().copyWith(
fontSize: 14,
),
labelColor: _primaryColor,
unselectedLabelColor: Color(0xff999999),
unselectedLabelColor: Color(0xff999999),
indicator: UnderlineTabIndicator(
borderSide: BorderSide(color: _primaryColor),
),
@@ -85,6 +90,7 @@ ThemeData lightTheme = ThemeData.light().copyWith(
abstract class ThemeColors {
Color taskTitleColor();
Color descColor();
Color searchBarBg();