登录页面样式
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 'package:cashier_reserve/login/login_view.dart';
|
||||||
|
|
||||||
import '../base/ui.dart';
|
import '../base/ui.dart';
|
||||||
@@ -38,13 +39,15 @@ class AppManager {
|
|||||||
Navigator.of(globalContext!).pop();
|
Navigator.of(globalContext!).pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
showDialog(
|
YJPush.presentWidget(globalContext!, const LoginView());
|
||||||
context: globalContext!,
|
|
||||||
barrierDismissible: false,
|
// showDialog(
|
||||||
builder: (BuildContext context) {
|
// context: globalContext!,
|
||||||
return WillPopScope(
|
// barrierDismissible: false,
|
||||||
onWillPop: () => Future.value(false), child: const LoginView());
|
// builder: (BuildContext context) {
|
||||||
});
|
// return WillPopScope(
|
||||||
|
// onWillPop: () => Future.value(false), child: const LoginView());
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
static void disposeLoginWidget() {
|
static void disposeLoginWidget() {
|
||||||
@@ -54,4 +57,8 @@ class AppManager {
|
|||||||
static bool isShowLoginView() {
|
static bool isShowLoginView() {
|
||||||
return _isAlertLogin;
|
return _isAlertLogin;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String getUserToken() {
|
||||||
|
return HiveManager.getUserToken();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
|
const bool inProduction = !kDebugMode;
|
||||||
|
|
||||||
void yjPrint(Object? object) {
|
void yjPrint(Object? object) {
|
||||||
if (kDebugMode) {
|
if (kDebugMode) {
|
||||||
print(object);
|
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();
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -48,12 +48,14 @@ class HomeView extends BaseUI {
|
|||||||
return Container(
|
return Container(
|
||||||
color: const Color(0xff1D2227),
|
color: const Color(0xff1D2227),
|
||||||
width: leftBarWidth,
|
width: leftBarWidth,
|
||||||
child: Column(
|
child: SingleChildScrollView(
|
||||||
children: _buildDestinations(
|
child: Column(
|
||||||
context,
|
children: _buildDestinations(
|
||||||
provider,
|
context,
|
||||||
leftBarWidth,
|
provider,
|
||||||
itemHeight,
|
leftBarWidth,
|
||||||
|
itemHeight,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,4 +1,8 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:cashier_reserve/common/print/print.dart';
|
import 'package:cashier_reserve/common/print/print.dart';
|
||||||
|
import 'package:cashier_reserve/model/login_model.dart';
|
||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
@@ -20,6 +24,35 @@ class _LoginViewState extends State<LoginView> {
|
|||||||
TextEditingController passwordText = TextEditingController();
|
TextEditingController passwordText = TextEditingController();
|
||||||
TextEditingController codeText = TextEditingController();
|
TextEditingController codeText = TextEditingController();
|
||||||
|
|
||||||
|
String authCodeUuid = "";
|
||||||
|
String authCodeImg = "";
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
_loadAuthCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _loadAuthCode() async {
|
||||||
|
var res = await LoginModel.getLoginAuthCode();
|
||||||
|
|
||||||
|
if (res is Map) {
|
||||||
|
Map<String, dynamic> result = res as Map<String, dynamic>;
|
||||||
|
setState(() {
|
||||||
|
authCodeUuid = result["uuid"] ?? "";
|
||||||
|
String img = result["img"] ?? "";
|
||||||
|
if (img.startsWith("data:image/png;base64,")) {
|
||||||
|
authCodeImg = img.substring("data:image/png;base64,".length);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
yjPrint("获取验证码失败");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _goLogin() async {}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
merchantText.dispose();
|
merchantText.dispose();
|
||||||
@@ -31,89 +64,211 @@ class _LoginViewState extends State<LoginView> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container(
|
return Scaffold(
|
||||||
width: MediaQuery.of(context).size.width,
|
backgroundColor: Colors.black.withOpacity(0.2),
|
||||||
height: MediaQuery.of(context).size.height,
|
body: GestureDetector(
|
||||||
color: const Color(0x55000000),
|
onTap: () {
|
||||||
child: Center(
|
FocusScope.of(context).requestFocus(FocusNode());
|
||||||
|
},
|
||||||
child: Container(
|
child: Container(
|
||||||
padding: const EdgeInsets.fromLTRB(30, 30, 30, 30),
|
width: MediaQuery.of(context).size.width,
|
||||||
decoration: BoxDecoration(
|
height: MediaQuery.of(context).size.height,
|
||||||
color: Colors.white,
|
color: const Color(0x55000000),
|
||||||
borderRadius: BorderRadius.circular(10),
|
child: Center(
|
||||||
),
|
child: Container(
|
||||||
width: 400,
|
padding: const EdgeInsets.fromLTRB(30, 30, 30, 30),
|
||||||
height: 400,
|
decoration: BoxDecoration(
|
||||||
child: Column(
|
color: Colors.white,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
borderRadius: BorderRadius.circular(10),
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
|
||||||
children: [
|
|
||||||
const Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
"银收客订餐系统",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 25,
|
|
||||||
color: Color(0xff333333),
|
|
||||||
decoration: TextDecoration.none),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
const SizedBox(
|
width: 400,
|
||||||
height: 30,
|
// height: 400,
|
||||||
),
|
child: SingleChildScrollView(
|
||||||
CupertinoSegmentedControl(
|
child: Column(
|
||||||
//子标签
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: {
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
0: Container(
|
children: [
|
||||||
width: 60,
|
_buildTitle(context),
|
||||||
height: 30,
|
const SizedBox(
|
||||||
alignment: Alignment.center,
|
height: 30,
|
||||||
child: const Text(
|
|
||||||
"商户",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
// color: Color(0xff333333),
|
|
||||||
decoration: TextDecoration.none),
|
|
||||||
),
|
),
|
||||||
),
|
_buildSegment(context),
|
||||||
1: Container(
|
const SizedBox(
|
||||||
width: 60,
|
height: 5,
|
||||||
height: 30,
|
|
||||||
alignment: Alignment.center,
|
|
||||||
child: const Text(
|
|
||||||
"员工",
|
|
||||||
style: TextStyle(
|
|
||||||
fontSize: 14,
|
|
||||||
// color: Color(0xff333333),
|
|
||||||
decoration: TextDecoration.none),
|
|
||||||
),
|
),
|
||||||
),
|
_buildInputTextField(context, merchantText,
|
||||||
},
|
hintText: "请输入商户号",
|
||||||
//当前选中的索引
|
icon: Icons.store_sharp,
|
||||||
groupValue: segmentIndex,
|
isHidden: loginType == "merchant"),
|
||||||
//点击回调
|
_buildInputTextField(context, accountText,
|
||||||
onValueChanged: (int index) {
|
hintText: "请输入账号", icon: Icons.people),
|
||||||
setState(() {
|
_buildInputTextField(context, passwordText,
|
||||||
segmentIndex = index;
|
hintText: "请输入密码", icon: Icons.lock, isPassword: true),
|
||||||
loginType = index == 0 ? "merchant" : "staff";
|
_buildInputTextField(context, codeText,
|
||||||
});
|
hintText: "请输入验证码",
|
||||||
},
|
icon: Icons.admin_panel_settings_sharp,
|
||||||
selectedColor: Colors.blue,
|
isCode: true),
|
||||||
borderColor: Colors.blue,
|
_buildLoginBtn(context),
|
||||||
unselectedColor: Colors.white,
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
const SizedBox(
|
),
|
||||||
height: 5,
|
|
||||||
),
|
|
||||||
// TextField(
|
|
||||||
// controller: merchantText,
|
|
||||||
// )
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildLoginBtn(BuildContext context) {
|
||||||
|
return InkWell(
|
||||||
|
onTap: () {
|
||||||
|
_goLogin();
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
margin: const EdgeInsets.only(top: 25),
|
||||||
|
height: 35,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: Colors.blue,
|
||||||
|
borderRadius: BorderRadius.circular(5),
|
||||||
|
),
|
||||||
|
child: const Center(
|
||||||
|
child: Text(
|
||||||
|
"登录",
|
||||||
|
style: TextStyle(fontSize: 15, color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildTitle(BuildContext context) {
|
||||||
|
return const Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
"银收客订餐系统",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 25,
|
||||||
|
color: Color(0xff333333),
|
||||||
|
decoration: TextDecoration.none),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildSegment(BuildContext context) {
|
||||||
|
return CupertinoSegmentedControl(
|
||||||
|
//子标签
|
||||||
|
children: {
|
||||||
|
0: Container(
|
||||||
|
width: 60,
|
||||||
|
height: 30,
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: const Text(
|
||||||
|
"商户",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
// color: Color(0xff333333),
|
||||||
|
decoration: TextDecoration.none),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
1: Container(
|
||||||
|
width: 60,
|
||||||
|
height: 30,
|
||||||
|
alignment: Alignment.center,
|
||||||
|
child: const Text(
|
||||||
|
"员工",
|
||||||
|
style: TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
// color: Color(0xff333333),
|
||||||
|
decoration: TextDecoration.none),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
//当前选中的索引
|
||||||
|
groupValue: segmentIndex,
|
||||||
|
//点击回调
|
||||||
|
onValueChanged: (int index) {
|
||||||
|
setState(() {
|
||||||
|
segmentIndex = index;
|
||||||
|
loginType = index == 0 ? "merchant" : "staff";
|
||||||
|
});
|
||||||
|
},
|
||||||
|
selectedColor: Colors.blue,
|
||||||
|
borderColor: Colors.blue,
|
||||||
|
unselectedColor: Colors.white,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildInputTextField(
|
||||||
|
BuildContext context,
|
||||||
|
TextEditingController controller, {
|
||||||
|
String hintText = "",
|
||||||
|
IconData icon = Icons.people,
|
||||||
|
bool isPassword = false,
|
||||||
|
bool isHidden = false,
|
||||||
|
bool isCode = false,
|
||||||
|
}) {
|
||||||
|
if (isHidden) {
|
||||||
|
return Container();
|
||||||
|
}
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
const SizedBox(
|
||||||
|
height: 10,
|
||||||
|
),
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
Expanded(
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
border: Border.all(color: const Color(0xffefefef), width: 1),
|
||||||
|
borderRadius: BorderRadius.circular(5),
|
||||||
|
),
|
||||||
|
padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
|
||||||
|
height: 35,
|
||||||
|
child: TextField(
|
||||||
|
controller: controller,
|
||||||
|
obscureText: isPassword,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
icon: Icon(
|
||||||
|
icon,
|
||||||
|
color: const Color(0xffa6a6a6),
|
||||||
|
),
|
||||||
|
hintText: hintText,
|
||||||
|
hintStyle: const TextStyle(
|
||||||
|
fontSize: 14,
|
||||||
|
color: Color(0xff999999),
|
||||||
|
),
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
border: OutlineInputBorder(
|
||||||
|
borderSide: BorderSide.none,
|
||||||
|
borderRadius: BorderRadius.circular(5),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (isCode)
|
||||||
|
InkWell(
|
||||||
|
onTap: () {
|
||||||
|
_loadAuthCode();
|
||||||
|
},
|
||||||
|
child: Container(
|
||||||
|
margin: const EdgeInsets.only(left: 15),
|
||||||
|
width: 100,
|
||||||
|
height: 35,
|
||||||
|
child: Image.memory(base64ToUint8List(authCodeImg)),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Uint8List base64ToUint8List(String base64String) {
|
||||||
|
const decoder = Base64Decoder();
|
||||||
|
return decoder.convert(base64String);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
lib/model/login_model.dart
Normal file
11
lib/model/login_model.dart
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import 'package:cashier_reserve/common/print/print.dart';
|
||||||
|
import 'package:cashier_reserve/common/request/request_manager.dart';
|
||||||
|
|
||||||
|
class LoginModel {
|
||||||
|
|
||||||
|
/// 获取 登录验证码
|
||||||
|
static Future<dynamic> getLoginAuthCode() async {
|
||||||
|
final r = await RequestManager.get("/auth/code");
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
13
pubspec.lock
13
pubspec.lock
@@ -221,6 +221,19 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
version: "0.0.0"
|
||||||
|
flutter_web_plugins:
|
||||||
|
dependency: transitive
|
||||||
|
description: flutter
|
||||||
|
source: sdk
|
||||||
|
version: "0.0.0"
|
||||||
|
fluttertoast:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: fluttertoast
|
||||||
|
sha256: "95f349437aeebe524ef7d6c9bde3e6b4772717cf46a0eb6a3ceaddc740b297cc"
|
||||||
|
url: "https://pub.flutter-io.cn"
|
||||||
|
source: hosted
|
||||||
|
version: "8.2.8"
|
||||||
glob:
|
glob:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ dependencies:
|
|||||||
hive: ^4.0.0-dev.2
|
hive: ^4.0.0-dev.2
|
||||||
isar_flutter_libs: ^4.0.0-dev.13
|
isar_flutter_libs: ^4.0.0-dev.13
|
||||||
path_provider: ^2.1.0
|
path_provider: ^2.1.0
|
||||||
|
fluttertoast: ^8.2.8
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
Reference in New Issue
Block a user