增加若干基础页面
This commit is contained in:
10
lib/pages/layout/home/home_binding.dart
Normal file
10
lib/pages/layout/home/home_binding.dart
Normal file
@@ -0,0 +1,10 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'home_logic.dart';
|
||||
|
||||
class HomeBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut(() => HomeLogic());
|
||||
}
|
||||
}
|
||||
19
lib/pages/layout/home/home_logic.dart
Normal file
19
lib/pages/layout/home/home_logic.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'home_state.dart';
|
||||
|
||||
class HomeLogic extends GetxController {
|
||||
final HomeState state = HomeState();
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
// TODO: implement onReady
|
||||
super.onReady();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
// TODO: implement onClose
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
5
lib/pages/layout/home/home_state.dart
Normal file
5
lib/pages/layout/home/home_state.dart
Normal file
@@ -0,0 +1,5 @@
|
||||
class HomeState {
|
||||
HomeState() {
|
||||
///Initialize variables
|
||||
}
|
||||
}
|
||||
92
lib/pages/layout/home/home_view.dart
Normal file
92
lib/pages/layout/home/home_view.dart
Normal file
@@ -0,0 +1,92 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
||||
|
||||
import '../../../utils/utils.dart';
|
||||
import 'home_logic.dart';
|
||||
|
||||
class HomePage extends StatelessWidget {
|
||||
const HomePage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final logic = Get.find<HomeLogic>();
|
||||
final state = Get.find<HomeLogic>().state;
|
||||
|
||||
double statusBarHeight = MediaQuery.of(context).padding.top;
|
||||
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvoked: (_) {
|
||||
ToolFn().isExit();
|
||||
},
|
||||
child: Scaffold(
|
||||
body: Stack(
|
||||
fit: StackFit.expand,
|
||||
children: [
|
||||
Image.asset(
|
||||
'assets/images/home-tab-normal-bg.png',
|
||||
fit: BoxFit.fitWidth,
|
||||
),
|
||||
Padding(
|
||||
padding:
|
||||
EdgeInsets.only(top: statusBarHeight, left: 10, right: 10),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
ClipRRect(
|
||||
borderRadius: BorderRadius.circular(50),
|
||||
child: Image.network(
|
||||
"https://pic.ziyuan.wang/user/guest/2023/12/微信图片_20231109211458_c1a41ab0fd7dd.jpg",
|
||||
width: 50.0,
|
||||
)),
|
||||
const SizedBox(
|
||||
width: 5,
|
||||
),
|
||||
const Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
"商家: GAGA酒吧",
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w500),
|
||||
),
|
||||
Text(
|
||||
"Huakk,欢迎回来!!!",
|
||||
style: TextStyle(
|
||||
fontSize: 16,
|
||||
fontWeight: FontWeight.w400),
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
const Row(
|
||||
children: [
|
||||
Icon(
|
||||
TDIcons.search,
|
||||
size: 35,
|
||||
),
|
||||
Icon(
|
||||
TDIcons.scan,
|
||||
size: 35,
|
||||
),
|
||||
Icon(
|
||||
TDIcons.sound,
|
||||
size: 35,
|
||||
),
|
||||
],
|
||||
)
|
||||
],
|
||||
)
|
||||
],
|
||||
))
|
||||
],
|
||||
)));
|
||||
}
|
||||
}
|
||||
6
lib/pages/layout/home/index.dart
Normal file
6
lib/pages/layout/home/index.dart
Normal file
@@ -0,0 +1,6 @@
|
||||
library home;
|
||||
|
||||
export './home_binding.dart';
|
||||
export './home_logic.dart';
|
||||
export './home_state.dart';
|
||||
export './home_view.dart';
|
||||
4
lib/pages/layout/index.dart
Normal file
4
lib/pages/layout/index.dart
Normal file
@@ -0,0 +1,4 @@
|
||||
library tabbar;
|
||||
|
||||
export './home/index.dart';
|
||||
export './user/index.dart';
|
||||
6
lib/pages/layout/user/index.dart
Normal file
6
lib/pages/layout/user/index.dart
Normal file
@@ -0,0 +1,6 @@
|
||||
library user;
|
||||
|
||||
export './user_binding.dart';
|
||||
export './user_logic.dart';
|
||||
export './user_state.dart';
|
||||
export './user_view.dart';
|
||||
10
lib/pages/layout/user/user_binding.dart
Normal file
10
lib/pages/layout/user/user_binding.dart
Normal file
@@ -0,0 +1,10 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'user_logic.dart';
|
||||
|
||||
class UserBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut(() => UserLogic());
|
||||
}
|
||||
}
|
||||
19
lib/pages/layout/user/user_logic.dart
Normal file
19
lib/pages/layout/user/user_logic.dart
Normal file
@@ -0,0 +1,19 @@
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'user_state.dart';
|
||||
|
||||
class UserLogic extends GetxController {
|
||||
final UserState state = UserState();
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
// TODO: implement onReady
|
||||
super.onReady();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
// TODO: implement onClose
|
||||
super.onClose();
|
||||
}
|
||||
}
|
||||
5
lib/pages/layout/user/user_state.dart
Normal file
5
lib/pages/layout/user/user_state.dart
Normal file
@@ -0,0 +1,5 @@
|
||||
class UserState {
|
||||
UserState() {
|
||||
///Initialize variables
|
||||
}
|
||||
}
|
||||
30
lib/pages/layout/user/user_view.dart
Normal file
30
lib/pages/layout/user/user_view.dart
Normal file
@@ -0,0 +1,30 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../../utils/utils.dart';
|
||||
import 'user_logic.dart';
|
||||
|
||||
class UserPage extends StatelessWidget {
|
||||
const UserPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final logic = Get.find<UserLogic>();
|
||||
final state = Get.find<UserLogic>().state;
|
||||
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvoked: (_) {
|
||||
ToolFn().isExit();
|
||||
},
|
||||
child: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("商家中心"),
|
||||
),
|
||||
body: const Center(
|
||||
child: Text("商家中心!!!"),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,64 @@
|
||||
import 'dart:io';
|
||||
import 'package:bot_toast/bot_toast.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
||||
import 'state.dart';
|
||||
import '../../utils/utils.dart';
|
||||
import '../../api/index.dart';
|
||||
|
||||
class LoginLogic extends GetxController {
|
||||
final LoginState state = LoginState();
|
||||
|
||||
void isExit(context) {
|
||||
if (state.lastPressedAt == null ||
|
||||
DateTime.now().difference(state.lastPressedAt!) >
|
||||
const Duration(seconds: 1)) {
|
||||
//两次点击间隔超过1秒则重新计时
|
||||
state.lastPressedAt = DateTime.now();
|
||||
BotToast.showText(text:"再按一次退出程序");
|
||||
return;
|
||||
void setPhone(String value) => state.phone = value;
|
||||
|
||||
void setSmsCode(String value) => state.code = value;
|
||||
|
||||
// 验证码倒计时
|
||||
void startCountdownTimer() {
|
||||
if (state.countTime > 0) {
|
||||
state.countTime--;
|
||||
update();
|
||||
Future.delayed(const Duration(seconds: 1), startCountdownTimer);
|
||||
} else {
|
||||
state.countTime = 0;
|
||||
update();
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
// 获取验证码
|
||||
Future<void> getCode(context) async {
|
||||
if (ToolFn.isBlank(state.phone) || ToolFn.checkMobile(state.phone)) {
|
||||
return ToolFn.tips("请输入正确的手机号");
|
||||
}
|
||||
if (state.countTime == 0) {
|
||||
final res =
|
||||
await Request.post<Map<String, dynamic>>(LoginApi.getCode, data: {
|
||||
"phone": state.phone,
|
||||
});
|
||||
TDToast.showText(res["msg"].toString(), context: context);
|
||||
state.countTime = 60;
|
||||
startCountdownTimer();
|
||||
}
|
||||
}
|
||||
|
||||
// 登录
|
||||
Future<void> loginFn(context) async {
|
||||
if (ToolFn.isBlank(state.phone) || ToolFn.checkMobile(state.phone)) {
|
||||
return ToolFn.tips("请输入正确的手机号");
|
||||
}
|
||||
if (ToolFn.isBlank(state.code)) {
|
||||
return ToolFn.tips("请输入正确的验证码");
|
||||
}
|
||||
FocusScope.of(context).unfocus();
|
||||
final res =
|
||||
await Request.post<Map<String, dynamic>>(LoginApi.phoneLogin, data: {
|
||||
"Phone": state.phone,
|
||||
"Code": state.code,
|
||||
});
|
||||
// 保存token
|
||||
StorageUtil().putString("token", res["data"]["token"]);
|
||||
// 保存用户信息
|
||||
StorageUtil().putJSON("userInfo", res["data"]["data"]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,22 @@
|
||||
class LoginState {
|
||||
DateTime? lastPressedAt; //上次点击时间
|
||||
// 表单
|
||||
late String phone;
|
||||
|
||||
late String code;
|
||||
|
||||
// 验证码倒计时
|
||||
late int countTime;
|
||||
|
||||
// 登录按钮状态
|
||||
late bool loginBtnStatus;
|
||||
|
||||
LoginState() {
|
||||
///Initialize variables
|
||||
phone = '';
|
||||
|
||||
code = '';
|
||||
|
||||
countTime = 0;
|
||||
|
||||
loginBtnStatus = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
||||
|
||||
import '../../utils/utils.dart';
|
||||
import 'logic.dart';
|
||||
|
||||
class LoginPage extends StatelessWidget {
|
||||
@@ -9,18 +11,123 @@ class LoginPage extends StatelessWidget {
|
||||
final logic = Get.find<LoginLogic>();
|
||||
final state = Get.find<LoginLogic>().state;
|
||||
|
||||
DateTime? _lastPressedAt;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvoked: (_) {
|
||||
logic.isExit(context);
|
||||
ToolFn().isExit();
|
||||
},
|
||||
child: const Scaffold(
|
||||
body: Center(
|
||||
child: Text("login"),
|
||||
child: Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
body: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Image.asset(
|
||||
"assets/images/login/icon-no-shop-head.png",
|
||||
width: double.maxFinite,
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(left: 10, right: 10, top: 50),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(left: 15),
|
||||
child: Text("手机登录",
|
||||
style: TextStyle(
|
||||
fontSize: 30,
|
||||
color: Colors.black,
|
||||
fontWeight: FontWeight.w400))),
|
||||
const SizedBox(height: 16.0),
|
||||
Form(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
TDInput(
|
||||
maxNum: 11,
|
||||
leftLabel: '+86',
|
||||
hintText: '请输入手机号码',
|
||||
onChanged: (text) {
|
||||
logic.setPhone(text);
|
||||
},
|
||||
onClearTap: () {
|
||||
state.phone = "";
|
||||
},
|
||||
),
|
||||
TDInput(
|
||||
maxNum: 6,
|
||||
hintText: '请输入验证码',
|
||||
rightBtn: SizedBox(
|
||||
width: 100,
|
||||
child: Row(
|
||||
mainAxisAlignment:
|
||||
MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 16),
|
||||
child: Container(
|
||||
width: 0.5,
|
||||
height: 24,
|
||||
color: TDTheme.of(context).grayColor3,
|
||||
),
|
||||
),
|
||||
GetBuilder<LoginLogic>(
|
||||
builder: (_) {
|
||||
return state.countTime != 0
|
||||
? TDText(
|
||||
'重发(${state.countTime}秒)',
|
||||
textColor: TDTheme.of(context)
|
||||
.fontGyColor4,
|
||||
)
|
||||
: TDText("发送验证码",
|
||||
textColor: TDTheme.of(context)
|
||||
.brandNormalColor);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
needClear: false,
|
||||
onBtnTap: () {
|
||||
logic.getCode(context);
|
||||
},
|
||||
onChanged: (text) {
|
||||
logic.setSmsCode(text);
|
||||
},
|
||||
onClearTap: () {
|
||||
state.phone = "";
|
||||
},
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(15),
|
||||
child: TDText(
|
||||
"未注册的手机号登录成功后将自动注册",
|
||||
textColor: TDTheme.of(context).grayColor6,
|
||||
textAlign: TextAlign.start,
|
||||
style: const TextStyle(fontSize: 13),
|
||||
)),
|
||||
GetBuilder<LoginLogic>(
|
||||
builder: (_) {
|
||||
return TDButton(
|
||||
isBlock: true,
|
||||
size: TDButtonSize.large,
|
||||
theme: TDButtonTheme.primary,
|
||||
width: double.maxFinite,
|
||||
text: "立即登录",
|
||||
disabled: false,
|
||||
onTap: () {
|
||||
logic.loginFn(context);
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
)
|
||||
]),
|
||||
)
|
||||
],
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
@@ -54,10 +54,9 @@ class SplashLogic extends GetxController with GetTickerProviderStateMixin {
|
||||
await Future.delayed(const Duration(seconds: 3), () {
|
||||
final token = StorageUtil().getString("token");
|
||||
if (!ToolFn.isBlank(token)) {
|
||||
Get.offAllNamed('/home');
|
||||
Get.offAllNamed('/tab');
|
||||
} else {
|
||||
Get.offAllNamed('/login');
|
||||
// Get.toNamed('/login');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
6
lib/pages/tab/index.dart
Normal file
6
lib/pages/tab/index.dart
Normal file
@@ -0,0 +1,6 @@
|
||||
library tab;
|
||||
|
||||
export './tab_logic.dart';
|
||||
export './tab_state.dart';
|
||||
export './tab_view.dart';
|
||||
export './tab_binding.dart';
|
||||
14
lib/pages/tab/tab_binding.dart
Normal file
14
lib/pages/tab/tab_binding.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
import 'package:flutter_jdt_store/pages/layout/home/index.dart';
|
||||
import 'package:flutter_jdt_store/pages/layout/user/index.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import 'tab_logic.dart';
|
||||
|
||||
class TabBinding extends Bindings {
|
||||
@override
|
||||
void dependencies() {
|
||||
Get.lazyPut(() => TabLogic());
|
||||
Get.lazyPut(() => HomeLogic());
|
||||
Get.lazyPut(() => UserLogic());
|
||||
}
|
||||
}
|
||||
48
lib/pages/tab/tab_logic.dart
Normal file
48
lib/pages/tab/tab_logic.dart
Normal file
@@ -0,0 +1,48 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
import '../../global.dart';
|
||||
import 'tab_state.dart';
|
||||
|
||||
class TabLogic extends GetxController {
|
||||
final TabState state = TabState();
|
||||
|
||||
@override
|
||||
void onInit() {
|
||||
super.onInit();
|
||||
state.pageController = PageController(initialPage: state.currentPage);
|
||||
}
|
||||
|
||||
@override
|
||||
void onReady() {
|
||||
// TODO: implement onReady
|
||||
super.onReady();
|
||||
}
|
||||
|
||||
@override
|
||||
void onClose() {
|
||||
// TODO: implement onClose
|
||||
super.onClose();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
state.pageController!.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
handlePageChanged(int page) {
|
||||
state.currentPage = page;
|
||||
update();
|
||||
}
|
||||
|
||||
handleNavBarTap(int index) {
|
||||
if (index == state.currentPage) return;
|
||||
if (Global.isOfflineLogin && index != 0) {
|
||||
Get.toNamed('/tab');
|
||||
return;
|
||||
}
|
||||
state.pageController!.jumpToPage(index);
|
||||
}
|
||||
}
|
||||
10
lib/pages/tab/tab_state.dart
Normal file
10
lib/pages/tab/tab_state.dart
Normal file
@@ -0,0 +1,10 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
|
||||
class TabState {
|
||||
late int currentPage;
|
||||
PageController? pageController;
|
||||
TabState() {
|
||||
///Initialize variables
|
||||
currentPage = 0;
|
||||
}
|
||||
}
|
||||
89
lib/pages/tab/tab_view.dart
Normal file
89
lib/pages/tab/tab_view.dart
Normal file
@@ -0,0 +1,89 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:tdesign_flutter/tdesign_flutter.dart';
|
||||
import '../../utils/utils.dart';
|
||||
import '../layout/home/index.dart';
|
||||
import '../layout/user/index.dart';
|
||||
import 'tab_logic.dart';
|
||||
|
||||
class TabPage extends StatelessWidget {
|
||||
const TabPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final logic = Get.find<TabLogic>();
|
||||
final state = Get.find<TabLogic>().state;
|
||||
|
||||
/// 内容页
|
||||
Widget buildPageView() {
|
||||
return GetBuilder<TabLogic>(builder: (_) {
|
||||
return PageView(
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
controller: state.pageController,
|
||||
onPageChanged: logic.handlePageChanged,
|
||||
children: const <Widget>[
|
||||
HomePage(),
|
||||
UserPage(),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
List<BottomNavigationBarItem> createBottomItems() {
|
||||
return <BottomNavigationBarItem>[
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(
|
||||
TDIcons.dashboard,
|
||||
color: Colors.grey,
|
||||
),
|
||||
activeIcon: Icon(
|
||||
TDIcons.dashboard,
|
||||
color: Color.fromRGBO(0, 82, 217, 1),
|
||||
),
|
||||
label: "工作台",
|
||||
),
|
||||
const BottomNavigationBarItem(
|
||||
icon: Icon(
|
||||
TDIcons.desktop,
|
||||
color: Colors.grey,
|
||||
),
|
||||
activeIcon: Icon(
|
||||
TDIcons.desktop,
|
||||
color: Color.fromRGBO(0, 82, 217, 1),
|
||||
),
|
||||
label: "商家中心",
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
/// 底部导航
|
||||
Widget buildBottomNavigationBar() {
|
||||
List<BottomNavigationBarItem> bottomItems = createBottomItems();
|
||||
return GetBuilder<TabLogic>(builder: (_) {
|
||||
return BottomNavigationBar(
|
||||
items: bottomItems,
|
||||
currentIndex: state.currentPage,
|
||||
backgroundColor: Colors.white,
|
||||
unselectedItemColor: Colors.grey,
|
||||
selectedItemColor: const Color.fromRGBO(0, 82, 217, 1),
|
||||
type: BottomNavigationBarType.fixed,
|
||||
onTap: logic.handleNavBarTap,
|
||||
selectedFontSize: 10.sp,
|
||||
unselectedFontSize: 10.sp,
|
||||
iconSize: 32.w,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
return PopScope(
|
||||
canPop: false,
|
||||
onPopInvoked: (_) {
|
||||
ToolFn().isExit();
|
||||
},
|
||||
child: Scaffold(
|
||||
body: buildPageView(),
|
||||
bottomNavigationBar: buildBottomNavigationBar(),
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user