登录页面样式
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'package:cashier_reserve/common/push/push.dart';
|
||||
import 'package:cashier_reserve/login/login_view.dart';
|
||||
|
||||
import '../base/ui.dart';
|
||||
@@ -38,13 +39,15 @@ class AppManager {
|
||||
Navigator.of(globalContext!).pop();
|
||||
}
|
||||
|
||||
showDialog(
|
||||
context: globalContext!,
|
||||
barrierDismissible: false,
|
||||
builder: (BuildContext context) {
|
||||
return WillPopScope(
|
||||
onWillPop: () => Future.value(false), child: const LoginView());
|
||||
});
|
||||
YJPush.presentWidget(globalContext!, const LoginView());
|
||||
|
||||
// showDialog(
|
||||
// context: globalContext!,
|
||||
// barrierDismissible: false,
|
||||
// builder: (BuildContext context) {
|
||||
// return WillPopScope(
|
||||
// onWillPop: () => Future.value(false), child: const LoginView());
|
||||
// });
|
||||
}
|
||||
|
||||
static void disposeLoginWidget() {
|
||||
@@ -54,4 +57,8 @@ class AppManager {
|
||||
static bool isShowLoginView() {
|
||||
return _isAlertLogin;
|
||||
}
|
||||
|
||||
static String getUserToken() {
|
||||
return HiveManager.getUserToken();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
const bool inProduction = !kDebugMode;
|
||||
|
||||
void yjPrint(Object? object) {
|
||||
if (kDebugMode) {
|
||||
print(object);
|
||||
|
||||
75
lib/common/request/request_manager.dart
Normal file
75
lib/common/request/request_manager.dart
Normal file
@@ -0,0 +1,75 @@
|
||||
import 'package:cashier_reserve/common/manager/app_manager.dart';
|
||||
import 'package:cashier_reserve/common/print/print.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
|
||||
import '../utils/utils.dart';
|
||||
|
||||
const String kBaseUrl = 'https://admintestpapi.sxczgkj.cn';
|
||||
|
||||
const kSuccessCode = 200;
|
||||
const kNeedLoginCode = 401;
|
||||
|
||||
class RequestManager {
|
||||
|
||||
/// HttpClient
|
||||
static final Dio _c = Dio(BaseOptions(
|
||||
baseUrl: kBaseUrl,
|
||||
connectTimeout: const Duration(milliseconds: 5000),
|
||||
receiveTimeout: const Duration(milliseconds: 5000)
|
||||
));
|
||||
|
||||
/// GET
|
||||
static Future<dynamic> get(String url, {bool catchError = true}) {
|
||||
return _doRequest("GET", url, catchError: catchError);
|
||||
}
|
||||
|
||||
/// DELETE
|
||||
static Future<dynamic> delete(String url, {bool catchError = true}) {
|
||||
return _doRequest("DELETE", url, catchError: catchError);
|
||||
}
|
||||
|
||||
/// POST
|
||||
static Future<dynamic> post(String url, Map<String, dynamic>? body,
|
||||
{bool catchError = true}) {
|
||||
return _doRequest("POST", url, body: body, catchError: catchError);
|
||||
}
|
||||
|
||||
/// PUT
|
||||
static Future<dynamic> put(String url, Map<String, dynamic>? body,
|
||||
{bool catchError = true}) {
|
||||
return _doRequest("PUT", url, body: body, catchError: catchError);
|
||||
}
|
||||
|
||||
static Future<dynamic> _doRequest(String method, String url,
|
||||
{Map<String, dynamic>? body, required bool catchError}) async {
|
||||
yjPrint("[RequestManager req]: $method 【$url】body === $body");
|
||||
|
||||
try {
|
||||
final resp = await _c.request(url,
|
||||
data: body,
|
||||
options: Options(
|
||||
method: method,
|
||||
headers: {"authorization": "Bearer ${AppManager.getUserToken()}"}));
|
||||
yjPrint("[RequestManager resp]: $method 【$url】body === $resp");
|
||||
if (catchError) {
|
||||
if (resp.statusCode == kNeedLoginCode) {
|
||||
AppManager.gotoLogin();
|
||||
return null;
|
||||
}
|
||||
if (resp.statusCode != kSuccessCode) {
|
||||
_alertError("提示", resp.data ?? "未知错误");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return resp.data;
|
||||
} catch (e) {
|
||||
yjPrint("[RequestManager error]: $method 【$url】error === $e");
|
||||
// _alertError("网络错误", "请检查您的网络连接!");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
static _alertError(String title, String errorText) {
|
||||
Utils.alert(AppManager.globalContext!, errorText, title: title);
|
||||
}
|
||||
}
|
||||
47
lib/common/utils/utils.dart
Normal file
47
lib/common/utils/utils.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
|
||||
import 'func_tools.dart';
|
||||
|
||||
class Utils {
|
||||
///大陆手机号码11位数,匹配格式:前三位固定格式+后8位任意数
|
||||
static bool isPhone(String phone) {
|
||||
return RegExp('^1\\d{10}\$').hasMatch(phone);
|
||||
}
|
||||
|
||||
static void toast(String? text, BuildContext? context) {
|
||||
if (isEmptyString(text)) {
|
||||
return;
|
||||
}
|
||||
Fluttertoast.showToast(
|
||||
msg: "$text",
|
||||
toastLength: Toast.LENGTH_SHORT,
|
||||
gravity: ToastGravity.CENTER,
|
||||
timeInSecForIosWeb: 1,
|
||||
// backgroundColor: Colors.red,
|
||||
// textColor: Colors.white,
|
||||
fontSize: 16.0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static Future alert(BuildContext context, String? content, {String? title}) {
|
||||
return showCupertinoDialog(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return CupertinoAlertDialog(
|
||||
title: Text(title ?? '提示'),
|
||||
content: Text(content!),
|
||||
actions: <Widget>[
|
||||
TextButton(
|
||||
child: const Text('确定'),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user