登录接口调试
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:cashier_reserve/common/encrypt/pwd.dart';
|
||||
import 'package:cashier_reserve/common/manager/app_manager.dart';
|
||||
import 'package:cashier_reserve/common/print/print.dart';
|
||||
import 'package:cashier_reserve/common/utils/utils.dart';
|
||||
import 'package:cashier_reserve/model/login_model.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
class LoginView extends StatefulWidget {
|
||||
const LoginView({super.key});
|
||||
@@ -26,11 +30,15 @@ class _LoginViewState extends State<LoginView> {
|
||||
|
||||
String authCodeUuid = "";
|
||||
String authCodeImg = "";
|
||||
DateTime? lastPopTime;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
accountText.text = "13718478323";
|
||||
passwordText.text = "123456789";
|
||||
|
||||
_loadAuthCode();
|
||||
}
|
||||
|
||||
@@ -51,7 +59,52 @@ class _LoginViewState extends State<LoginView> {
|
||||
}
|
||||
}
|
||||
|
||||
void _goLogin() async {}
|
||||
void _goLogin() async {
|
||||
if (loginType == "staff") {
|
||||
if (merchantText.text.isEmpty) {
|
||||
Utils.toast("请输入商户号", context);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (accountText.text.isEmpty) {
|
||||
Utils.toast("请输入账号", context);
|
||||
return;
|
||||
}
|
||||
|
||||
if (passwordText.text.isEmpty) {
|
||||
Utils.toast("请输入密码", context);
|
||||
return;
|
||||
}
|
||||
|
||||
if (codeText.text.isEmpty) {
|
||||
Utils.toast("请输入验证码", context);
|
||||
return;
|
||||
}
|
||||
|
||||
String pwd = PwdEncrypt.encrypt(passwordText.text);
|
||||
yjPrint("pwd === $pwd");
|
||||
|
||||
var params = {
|
||||
"username": accountText.text,
|
||||
"password": pwd,
|
||||
"code": codeText.text,
|
||||
"uuid": authCodeUuid,
|
||||
"loginType": loginType,
|
||||
};
|
||||
|
||||
if (loginType == "staff") {
|
||||
params["loginType"] = "staff";
|
||||
params["merchantName"] = merchantText.text;
|
||||
}
|
||||
|
||||
final r = await LoginModel.login(params);
|
||||
if (r == null) {
|
||||
_loadAuthCode();
|
||||
return;
|
||||
}
|
||||
AppManager.loginSuccess(r);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
@@ -64,52 +117,69 @@ class _LoginViewState extends State<LoginView> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.black.withOpacity(0.2),
|
||||
body: GestureDetector(
|
||||
onTap: () {
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
},
|
||||
child: Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
height: MediaQuery.of(context).size.height,
|
||||
color: const Color(0x55000000),
|
||||
child: Center(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.fromLTRB(30, 30, 30, 30),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
width: 400,
|
||||
// height: 400,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildTitle(context),
|
||||
const SizedBox(
|
||||
height: 30,
|
||||
),
|
||||
_buildSegment(context),
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
_buildInputTextField(context, merchantText,
|
||||
hintText: "请输入商户号",
|
||||
icon: Icons.store_sharp,
|
||||
isHidden: loginType == "merchant"),
|
||||
_buildInputTextField(context, accountText,
|
||||
hintText: "请输入账号", icon: Icons.people),
|
||||
_buildInputTextField(context, passwordText,
|
||||
hintText: "请输入密码", icon: Icons.lock, isPassword: true),
|
||||
_buildInputTextField(context, codeText,
|
||||
hintText: "请输入验证码",
|
||||
icon: Icons.admin_panel_settings_sharp,
|
||||
isCode: true),
|
||||
_buildLoginBtn(context),
|
||||
],
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvokedWithResult: (didPop, result) async {
|
||||
// 点击返回键的操作
|
||||
if (lastPopTime == null ||
|
||||
DateTime.now().difference(lastPopTime!) > const Duration(seconds: 2)) {
|
||||
lastPopTime = DateTime.now();
|
||||
Utils.toast('再按一次退出', context);
|
||||
} else {
|
||||
lastPopTime = DateTime.now();
|
||||
// 退出app
|
||||
await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
|
||||
}
|
||||
},
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.black.withOpacity(0.2),
|
||||
body: GestureDetector(
|
||||
onTap: () {
|
||||
FocusScope.of(context).requestFocus(FocusNode());
|
||||
},
|
||||
child: Container(
|
||||
width: MediaQuery.of(context).size.width,
|
||||
height: MediaQuery.of(context).size.height,
|
||||
color: const Color(0x55000000),
|
||||
child: Center(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.fromLTRB(30, 30, 30, 30),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
width: 400,
|
||||
// height: 400,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
_buildTitle(context),
|
||||
const SizedBox(
|
||||
height: 30,
|
||||
),
|
||||
_buildSegment(context),
|
||||
const SizedBox(
|
||||
height: 5,
|
||||
),
|
||||
_buildInputTextField(context, merchantText,
|
||||
hintText: "请输入商户号",
|
||||
icon: Icons.store_sharp,
|
||||
isHidden: loginType == "merchant"),
|
||||
_buildInputTextField(context, accountText,
|
||||
hintText: "请输入账号", icon: Icons.people),
|
||||
_buildInputTextField(context, passwordText,
|
||||
hintText: "请输入密码",
|
||||
icon: Icons.lock,
|
||||
isPassword: true),
|
||||
_buildInputTextField(context, codeText,
|
||||
hintText: "请输入验证码",
|
||||
icon: Icons.admin_panel_settings_sharp,
|
||||
isCode: true),
|
||||
_buildLoginBtn(context),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -258,7 +328,9 @@ class _LoginViewState extends State<LoginView> {
|
||||
margin: const EdgeInsets.only(left: 15),
|
||||
width: 100,
|
||||
height: 35,
|
||||
child: Image.memory(base64ToUint8List(authCodeImg)),
|
||||
child: (authCodeImg.isNotEmpty)
|
||||
? Image.memory(base64ToUint8List(authCodeImg))
|
||||
: Container(),
|
||||
),
|
||||
)
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user