diff --git a/lib/const/api.dart b/lib/const/api.dart index 5bf79f0..499863b 100644 --- a/lib/const/api.dart +++ b/lib/const/api.dart @@ -3,7 +3,7 @@ class API { static const String host = 'http://test.akuhotel.com:8804'; ///接口基础地址 - static const String baseURL = '$host/IntelligentCommunity/manage'; + static const String baseURL = '$host/IntelligentCommunity/butlerApp'; ///静态资源路径 static String get resource => '$host/static'; @@ -11,10 +11,13 @@ class API { static String image(String path) => '$resource$path'; static const int networkTimeOut = 10000; - static _Login login = _Login(); + static _Auth auth = _Auth(); } -class _Login { +class _Auth { ///登录/退出:发送短信验证码 String get sendSMS => '/login/sendMMSLogin'; + + ///登录/退出:管家app用户短信登录 + String get login => '/login/loginSMSUser'; } diff --git a/lib/main.dart b/lib/main.dart index 785b9e5..8539d68 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,7 +4,6 @@ import 'package:aku_community_manager/provider/fix_provider.dart'; import 'package:aku_community_manager/provider/manage_provider.dart'; import 'package:aku_community_manager/provider/outdoor_provider.dart'; import 'package:aku_community_manager/provider/user_provider.dart'; -import 'package:aku_community_manager/ui/home/home_page.dart'; import 'package:aku_community_manager/ui/splash/splash_page.dart'; import 'package:amap_map_fluttify/amap_map_fluttify.dart'; import 'package:bot_toast/bot_toast.dart'; diff --git a/lib/provider/user_provider.dart b/lib/provider/user_provider.dart index 09d0cb4..52dfd4b 100644 --- a/lib/provider/user_provider.dart +++ b/lib/provider/user_provider.dart @@ -1,10 +1,29 @@ import 'dart:io'; import 'package:aku_community_manager/mock_models/users/user_info_model.dart'; +import 'package:aku_community_manager/utils/hive_store.dart'; +import 'package:aku_community_manager/utils/network/net_util.dart'; import 'package:flutter/material.dart'; //登录状态管理 class UserProvider extends ChangeNotifier { + bool _isLogin = false; + + bool get isLogin => _isLogin; + + Future setLogin(int token) async { + _isLogin = true; + NetUtil().dio.options.headers.putIfAbsent('App-Admin-Token', () => token); + HiveStore.appBox.put('token', token); + HiveStore.appBox.put('login', true); + // await updateProfile(); + // await updateUserDetail(); + // await setCurrentHouse((_userDetailModel?.estateNames?.isEmpty ?? true) + // ? '' + // : _userDetailModel?.estateNames?.first); + notifyListeners(); + } + bool _isSigned = false; ///用户是否登陆 diff --git a/lib/ui/login/login_page.dart b/lib/ui/login/login_page.dart index 70705cf..e7e2884 100644 --- a/lib/ui/login/login_page.dart +++ b/lib/ui/login/login_page.dart @@ -1,5 +1,6 @@ import 'dart:ui'; +import 'package:aku_community_manager/const/api.dart'; import 'package:aku_community_manager/style/app_style.dart'; import 'package:aku_community_manager/tools/widget_tool.dart'; import 'package:aku_community_manager/ui/agreements/agreement_page.dart'; @@ -7,6 +8,7 @@ import 'package:aku_community_manager/ui/agreements/privacy_page.dart'; import 'package:aku_community_manager/ui/login/login_sms_page.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_back_button.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart'; +import 'package:aku_community_manager/utils/network/net_util.dart'; import 'package:aku_ui/common_widgets/aku_material_button.dart'; import 'package:common_utils/common_utils.dart'; import 'package:extended_text/extended_text.dart'; diff --git a/lib/ui/login/login_sms_page.dart b/lib/ui/login/login_sms_page.dart index 9aaee9e..a79279f 100644 --- a/lib/ui/login/login_sms_page.dart +++ b/lib/ui/login/login_sms_page.dart @@ -1,5 +1,6 @@ import 'dart:async'; +import 'package:aku_community_manager/const/api.dart'; import 'package:aku_community_manager/mock_models/users/user_info_model.dart'; import 'package:aku_community_manager/provider/user_provider.dart'; import 'package:aku_community_manager/style/app_style.dart'; @@ -7,8 +8,11 @@ import 'package:aku_community_manager/tools/widget_tool.dart'; import 'package:aku_community_manager/ui/home/home_page.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_back_button.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart'; +import 'package:aku_community_manager/utils/network/login_model.dart'; +import 'package:aku_community_manager/utils/network/net_util.dart'; import 'package:aku_ui/common_widgets/aku_material_button.dart'; import 'package:bot_toast/bot_toast.dart'; +import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:aku_community_manager/tools/screen_tool.dart'; import 'package:get/get.dart'; @@ -47,9 +51,18 @@ class _LoginSMSPageState extends State { }); } + sendSMS() { + NetUtil().post( + API.auth.sendSMS, + params: {'tel': widget.phone}, + showMessage: true, + ); + } + @override void initState() { super.initState(); + sendSMS(); startTick(); } @@ -62,6 +75,7 @@ class _LoginSMSPageState extends State { @override Widget build(BuildContext context) { + final userProvider = Provider.of(context); return AkuScaffold( backgroundColor: Colors.white, leading: AkuBackButton(), @@ -95,31 +109,51 @@ class _LoginSMSPageState extends State { lineHeight: 1.w, colorBuilder: FixedColorBuilder(Color(0xFFE8E8E8)), ), - onChanged: (text) { - final userProvider = - Provider.of(context, listen: false); - if (text == '000000') { - userProvider.setUserInfo(UserInfoModel.manager()); - Get.offAll(HomePage()); - } else if (text == '000001') { - userProvider.setUserInfo(UserInfoModel.fixer()); - Get.offAll(HomePage()); - } else if (text == '000002') { - userProvider.setUserInfo(UserInfoModel.security()); - Get.offAll(HomePage()); - } else if (text == '000003') { - userProvider.setUserInfo(UserInfoModel.property()); - Get.offAll(HomePage()); - } else { - if (text.length == 6) BotToast.showText(text: '验证码错误'); + onChanged: (text) async { + if (text.length == 6) { + Function cancel = BotToast.showLoading(); + Response response = await NetUtil().dio.post( + API.auth.login, + data: {'tel': widget.phone, 'code': text}, + ); + if (response.data['status'] == true) { + userProvider.setLogin(response.data['token']); + } else { + _textEditingController.clear(); + BotToast.showText(text: '登陆失败'); + } + cancel(); } + + // final userProvider = + // Provider.of(context, listen: false); + // if (text == '000000') { + // userProvider.setUserInfo(UserInfoModel.manager()); + // Get.offAll(HomePage()); + // } else if (text == '000001') { + // userProvider.setUserInfo(UserInfoModel.fixer()); + // Get.offAll(HomePage()); + // } else if (text == '000002') { + // userProvider.setUserInfo(UserInfoModel.security()); + // Get.offAll(HomePage()); + // } else if (text == '000003') { + // userProvider.setUserInfo(UserInfoModel.property()); + // Get.offAll(HomePage()); + // } else { + // if (text.length == 6) BotToast.showText(text: '验证码错误'); + // } }, ), AkuBox.h(40), Row( children: [ AkuMaterialButton( - onPressed: canResend ? () => startTick() : null, + onPressed: canResend + ? () { + sendSMS(); + startTick(); + } + : null, child: Text( '重新发送 $countString', style: TextStyle( diff --git a/lib/ui/splash/splash_page.dart b/lib/ui/splash/splash_page.dart index fc38cd4..c56d7e5 100644 --- a/lib/ui/splash/splash_page.dart +++ b/lib/ui/splash/splash_page.dart @@ -1,7 +1,10 @@ import 'package:aku_community_manager/ui/home/home_page.dart'; -import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart'; +import 'package:aku_community_manager/utils/hive_store.dart'; +import 'package:amap_map_fluttify/amap_map_fluttify.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:hive/hive.dart'; +import 'package:hive_flutter/hive_flutter.dart'; import 'package:power_logger/power_logger.dart'; class SplashPage extends StatefulWidget { @@ -12,13 +15,23 @@ class SplashPage extends StatefulWidget { } class _SplashPageState extends State { + Future _originOp() async { + //初始化HiveStore + await Hive.initFlutter(); + await HiveStore.init(); + + //初始化AMap + await AmapLocation.instance.init(iosKey: 'ios key'); + } + @override void initState() { super.initState(); Future.delayed(Duration(milliseconds: 300), () { if (mounted) PowerLogger.init(context); }); - Future.delayed(Duration(milliseconds: 3000), () { + Future.delayed(Duration(milliseconds: 2000), () async { + await _originOp(); Get.to(HomePage()); }); } diff --git a/lib/utils/hive_store.dart b/lib/utils/hive_store.dart new file mode 100644 index 0000000..11b013a --- /dev/null +++ b/lib/utils/hive_store.dart @@ -0,0 +1,10 @@ +// Package imports: +import 'package:hive/hive.dart'; + +class HiveStore { + static Box _appBox; + static Box get appBox => _appBox; + static init() async { + _appBox = await Hive.openBox('app'); + } +} diff --git a/pubspec.lock b/pubspec.lock index e6c0a0c..7741b48 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -171,6 +171,20 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.2.0-nullsafety.1" + ffi: + dependency: transitive + description: + name: ffi + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.3" + file: + dependency: transitive + description: + name: file + url: "https://pub.flutter-io.cn" + source: hosted + version: "5.2.1" flutter: dependency: "direct main" description: flutter @@ -247,6 +261,20 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "0.6.0" + hive: + dependency: "direct main" + description: + name: hive + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.4.4+1" + hive_flutter: + dependency: "direct main" + description: + name: hive_flutter + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.3.1" http: dependency: transitive description: @@ -317,6 +345,41 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.8.0-nullsafety.1" + path_provider: + dependency: transitive + description: + name: path_provider + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.6.27" + path_provider_linux: + dependency: transitive + description: + name: path_provider_linux + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.1+2" + path_provider_macos: + dependency: transitive + description: + name: path_provider_macos + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.4+8" + path_provider_platform_interface: + dependency: transitive + description: + name: path_provider_platform_interface + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.0.4" + path_provider_windows: + dependency: transitive + description: + name: path_provider_windows + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.0.4+3" pedantic: dependency: transitive description: @@ -345,6 +408,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "3.1.1" + platform: + dependency: transitive + description: + name: platform + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.2.1" plugin_platform_interface: dependency: transitive description: @@ -357,10 +427,10 @@ packages: description: path: "." ref: HEAD - resolved-ref: "1469b68b32bb5a7d02e6c89c5a9933ef77f738ad" + resolved-ref: "5a6be230ed03e9da941b2c67018e4a6bc3e81759" url: "http://192.168.2.201:8099/aku_fe/power_logger.git" source: git - version: "0.0.1" + version: "0.1.0" pretty_json: dependency: transitive description: @@ -368,6 +438,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.1.0" + process: + dependency: transitive + description: + name: process + url: "https://pub.flutter-io.cn" + source: hosted + version: "3.0.13" provider: dependency: "direct main" description: @@ -492,6 +569,20 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "2.1.0-nullsafety.3" + win32: + dependency: transitive + description: + name: win32 + url: "https://pub.flutter-io.cn" + source: hosted + version: "1.7.4+1" + xdg_directories: + dependency: transitive + description: + name: xdg_directories + url: "https://pub.flutter-io.cn" + source: hosted + version: "0.1.2" sdks: dart: ">=2.10.0 <2.11.0" flutter: ">=1.22.0 <2.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 3302ca3..fecc8e3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -57,6 +57,9 @@ dependencies: git: url: http://test.akuhotel.com:8099/aku_fe/aku_ui.git + hive: ^1.4.4+1 + hive_flutter: ^0.3.1 + dev_dependencies: flutter_test: sdk: flutter