diff --git a/lib/constants/api.dart b/lib/constants/api.dart index 6ebee7bc..14c422ed 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -11,4 +11,10 @@ class _Login { /// 通过验证码短信登陆 String get loginBySMS => '/login/loginSMSUser'; + + /// 查询楼栋ID + String get buildingInfo => '/login/findAllBuildingIAN'; + + ///查询单元ID + String get unitInfo => '/login/findEstateIANByBuilding'; } diff --git a/lib/main.dart b/lib/main.dart index a93ec6d3..d511e40c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,4 +1,5 @@ import 'package:akuCommunity/pages/splash/splash_page.dart'; +import 'package:akuCommunity/provider/sign_up_provider.dart'; import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/utils/developer_util.dart'; import 'package:akuCommunity/utils/hive_store.dart'; @@ -47,6 +48,7 @@ class _MyAppState extends State { providers: [ ChangeNotifierProvider(create: (context) => CartProvidde()), ChangeNotifierProvider(create: (context) => UserProvider()), + ChangeNotifierProvider(create: (context) => SignUpProvider()), ], child: GetMaterialApp( title: '智慧社区', diff --git a/lib/model/user/pick_building_model.dart b/lib/model/user/pick_building_model.dart new file mode 100644 index 00000000..6a5f0517 --- /dev/null +++ b/lib/model/user/pick_building_model.dart @@ -0,0 +1,18 @@ +class PickBuildingModel { + int value; + String label; + + PickBuildingModel({this.value, this.label}); + + PickBuildingModel.fromJson(Map json) { + value = json['value']; + label = json['label']; + } + + Map toJson() { + final Map data = new Map(); + data['value'] = this.value; + data['label'] = this.label; + return data; + } +} diff --git a/lib/pages/personal/personal_page.dart b/lib/pages/personal/personal_page.dart index b7676305..125395f3 100644 --- a/lib/pages/personal/personal_page.dart +++ b/lib/pages/personal/personal_page.dart @@ -13,7 +13,6 @@ import 'package:akuCommunity/painters/user_bottom_bar_painter.dart'; import 'package:akuCommunity/provider/user_provider.dart'; import 'package:akuCommunity/utils/network/net_util.dart'; import 'package:akuCommunity/widget/grid_buttons.dart'; -import 'package:ani_route/ani_route.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_icons/flutter_icons.dart'; @@ -141,7 +140,7 @@ class _PersonalIndexState extends State }, child: Container( margin: EdgeInsets.only(left: 16.w), - child: userProvider.isSigned + child: userProvider.isLogin ? Text( 'Cheailune', style: TextStyle( diff --git a/lib/pages/sign/sign_func.dart b/lib/pages/sign/sign_func.dart index 2aafac3f..4962ba91 100644 --- a/lib/pages/sign/sign_func.dart +++ b/lib/pages/sign/sign_func.dart @@ -1,7 +1,7 @@ import 'package:akuCommunity/constants/api.dart'; +import 'package:akuCommunity/model/user/pick_building_model.dart'; import 'package:akuCommunity/utils/network/base_model.dart'; import 'package:akuCommunity/utils/network/net_util.dart'; -import 'package:bot_toast/bot_toast.dart'; import 'package:dio/dio.dart'; class SignFunc { @@ -21,4 +21,21 @@ class SignFunc { ); return response; } + + static Future> getBuildingInfo() async { + BaseModel model = await NetUtil().get(API.login.buildingInfo); + return (model.data as List) + .map((e) => PickBuildingModel.fromJson(e)) + .toList(); + } + + static Future> getUnitInfo(int id) async { + BaseModel model = await NetUtil().get( + API.login.unitInfo, + params: {"buildingId": id}, + ); + return (model.data as List) + .map((e) => PickBuildingModel.fromJson(e)) + .toList(); + } } diff --git a/lib/pages/sign/sign_in_page.dart b/lib/pages/sign/sign_in_page.dart index d15a266d..05b60ea0 100644 --- a/lib/pages/sign/sign_in_page.dart +++ b/lib/pages/sign/sign_in_page.dart @@ -6,6 +6,10 @@ import 'package:akuCommunity/pages/setting_page/agreement_page/privacy_page.dart import 'package:akuCommunity/pages/sign/sign_func.dart'; import 'package:akuCommunity/extensions/num_ext.dart'; import 'package:akuCommunity/const/resource.dart'; +import 'package:akuCommunity/pages/sign/sign_up/sign_up_pick_plot_page.dart'; +import 'package:akuCommunity/pages/tab_navigator.dart'; +import 'package:akuCommunity/provider/sign_up_provider.dart'; +import 'package:akuCommunity/provider/user_provider.dart'; import 'package:ani_route/ani_route.dart'; import 'package:bot_toast/bot_toast.dart'; import 'package:common_utils/common_utils.dart'; @@ -18,6 +22,7 @@ import 'package:akuCommunity/base/base_style.dart'; import 'package:akuCommunity/base/assets_image.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart' hide Response; +import 'package:provider/provider.dart'; import 'package:velocity_x/velocity_x.dart'; class SignInPage extends StatefulWidget { @@ -76,14 +81,27 @@ class _SignInPageState extends State { } _parseLogin(bool result) async { + final userProvider = Provider.of(Get.context, listen: false); + final signUpProvider = + Provider.of(Get.context, listen: false); if (!result) return; - BotToast.showLoading(); + CancelFunc cancel = BotToast.showLoading(); Response response = await SignFunc.login(_phone.text, _code.text); - BotToast.cleanAll(); if (response.data['status']) { + if (response.data['choose'] == 1) { + userProvider.setLogin(response.data['token'] as String); + + Get.offAll(TabNavigator()); + } else { + cancel(); + signUpProvider.setTel(_phone.text); + await Get.to(SignUpPickPlotPage()); + signUpProvider.clearAll(); + } } else { BotToast.showText(text: response.data['message']); + cancel(); } } @@ -92,6 +110,7 @@ class _SignInPageState extends State { padding: EdgeInsets.symmetric(horizontal: 80.w), child: MaterialButton( onPressed: () async { + FocusScope.of(context).unfocus(); if (TextUtil.isEmpty(_phone.text)) BotToast.showText(text: '手机号不能为空'); else if (TextUtil.isEmpty(_code.text)) diff --git a/lib/pages/sign/sign_up/sign_up_common_widget.dart b/lib/pages/sign/sign_up/sign_up_common_widget.dart new file mode 100644 index 00000000..75c598fa --- /dev/null +++ b/lib/pages/sign/sign_up/sign_up_common_widget.dart @@ -0,0 +1,17 @@ +import 'package:akuCommunity/base/base_style.dart'; +import 'package:flutter/material.dart'; +import 'package:velocity_x/velocity_x.dart'; +import 'package:akuCommunity/utils/headers.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; + +signUpTitle(String subTitle) { + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + '欢迎登录小蜜蜂'.text.bold.size(38.sp).color(ktextPrimary).make(), + 8.hb, + subTitle.text.size(28.sp).color(ktextSubColor).make(), + ], + ); +} diff --git a/lib/pages/sign/sign_up/sign_up_pick_building_page.dart b/lib/pages/sign/sign_up/sign_up_pick_building_page.dart new file mode 100644 index 00000000..4ccff583 --- /dev/null +++ b/lib/pages/sign/sign_up/sign_up_pick_building_page.dart @@ -0,0 +1,48 @@ +import 'package:akuCommunity/model/user/pick_building_model.dart'; +import 'package:akuCommunity/pages/sign/sign_func.dart'; +import 'package:akuCommunity/pages/sign/sign_up/sign_up_pick_unit_page.dart'; +import 'package:akuCommunity/widget/bee_scaffold.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; +import 'package:get/get.dart'; +import 'package:velocity_x/velocity_x.dart'; + +class SignUpPickBuildingPage extends StatefulWidget { + SignUpPickBuildingPage({Key key}) : super(key: key); + + @override + _SignUpPickBuildingPageState createState() => _SignUpPickBuildingPageState(); +} + +class _SignUpPickBuildingPageState extends State { + List _buildingModels = []; + _buildItem(PickBuildingModel model) { + return ListTile( + title: model.label.text.make(), + onTap: () { + Get.off(SignUpPickUnitPage(buildingId: model.value)); + }, + ).material(color: Colors.white); + } + + @override + Widget build(BuildContext context) { + return BeeScaffold( + title: '选择楼栋', + body: EasyRefresh( + header: MaterialHeader(), + firstRefresh: true, + onRefresh: () async { + _buildingModels = await SignFunc.getBuildingInfo(); + setState(() {}); + }, + child: ListView.builder( + itemBuilder: (context, index) { + return _buildItem(_buildingModels[index]); + }, + itemCount: _buildingModels.length, + ), + ), + ); + } +} diff --git a/lib/pages/sign/sign_up/sign_up_pick_plot_page.dart b/lib/pages/sign/sign_up/sign_up_pick_plot_page.dart new file mode 100644 index 00000000..af806978 --- /dev/null +++ b/lib/pages/sign/sign_up/sign_up_pick_plot_page.dart @@ -0,0 +1,29 @@ +import 'package:akuCommunity/pages/sign/sign_up/sign_up_pick_building_page.dart'; +import 'package:akuCommunity/widget/bee_scaffold.dart'; +import 'package:akuCommunity/extensions/page_router.dart'; +import 'package:flutter/material.dart'; +import 'package:velocity_x/velocity_x.dart'; + +class SignUpPickPlotPage extends StatefulWidget { + SignUpPickPlotPage({Key key}) : super(key: key); + + @override + _SignUpPickPlotPageState createState() => _SignUpPickPlotPageState(); +} + +class _SignUpPickPlotPageState extends State { + @override + Widget build(BuildContext context) { + return BeeScaffold( + title: '选择小区', + body: ListView( + children: [ + ListTile( + title: 'PLACEHOLDER PLOT'.text.make(), + onTap: SignUpPickBuildingPage().to, + ).material(color: Colors.white), + ], + ), + ); + } +} diff --git a/lib/pages/sign/sign_up/sign_up_pick_role_page.dart b/lib/pages/sign/sign_up/sign_up_pick_role_page.dart new file mode 100644 index 00000000..6723861f --- /dev/null +++ b/lib/pages/sign/sign_up/sign_up_pick_role_page.dart @@ -0,0 +1,63 @@ +import 'package:akuCommunity/base/base_style.dart'; +import 'package:akuCommunity/pages/sign/sign_up/sign_up_common_widget.dart'; +import 'package:akuCommunity/pages/sign/sign_up/sign_up_set_nickname_page.dart'; +import 'package:akuCommunity/provider/sign_up_provider.dart'; +import 'package:akuCommunity/utils/headers.dart'; +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:provider/provider.dart'; +import 'package:velocity_x/velocity_x.dart'; + +class SignUpPickRolePage extends StatefulWidget { + SignUpPickRolePage({Key key}) : super(key: key); + + @override + _SignUpPickRolePageState createState() => _SignUpPickRolePageState(); +} + +class _SignUpPickRolePageState extends State { + Widget _buildTile(int type, String title) { + final signUpProvider = Provider.of(context); + return RadioListTile( + groupValue: signUpProvider.type, + onChanged: (int value) => signUpProvider.setType(value), + value: type, + title: title.text.make(), + ); + } + + @override + Widget build(BuildContext context) { + final signUpProvider = Provider.of(context); + + return Scaffold( + body: ListView( + padding: EdgeInsets.symmetric(horizontal: 32.w), + children: [ + 148.hb, + signUpTitle('身份选择'), + 190.hb, + ...[ + _buildTile(1, '租客'), + _buildTile(2, '业主'), + _buildTile(3, '亲属'), + ].sepWidget( + separate: Divider( + height: 1.w, + thickness: 1.w, + color: Color(0xFFD8D8D8), + )), + ], + ), + bottomNavigationBar: MaterialButton( + height: 89.w, + color: kPrimaryColor, + shape: StadiumBorder(), + disabledColor: kPrimaryColor.withOpacity(0.3), + child: '提交'.text.make(), + onPressed: () => Get.to(SignUpSetNicknamePage()), + elevation: 0, + ).pLTRB(82.w, 0, 82.w, 155.w), + ); + } +} diff --git a/lib/pages/sign/sign_up/sign_up_pick_unit_page.dart b/lib/pages/sign/sign_up/sign_up_pick_unit_page.dart new file mode 100644 index 00000000..b0ca4638 --- /dev/null +++ b/lib/pages/sign/sign_up/sign_up_pick_unit_page.dart @@ -0,0 +1,54 @@ +import 'package:akuCommunity/model/user/pick_building_model.dart'; +import 'package:akuCommunity/pages/sign/sign_func.dart'; +import 'package:akuCommunity/pages/sign/sign_up/sign_up_pick_role_page.dart'; +import 'package:akuCommunity/provider/sign_up_provider.dart'; +import 'package:akuCommunity/widget/bee_scaffold.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_easyrefresh/easy_refresh.dart'; +import 'package:get/get.dart'; +import 'package:provider/provider.dart'; +import 'package:velocity_x/velocity_x.dart'; + +class SignUpPickUnitPage extends StatefulWidget { + final int buildingId; + SignUpPickUnitPage({Key key, this.buildingId}) : super(key: key); + + @override + _SignUpPickUnitPageState createState() => _SignUpPickUnitPageState(); +} + +class _SignUpPickUnitPageState extends State { + List _buildingModels = []; + _buildItem(PickBuildingModel model) { + return ListTile( + title: model.label.text.make(), + onTap: () { + final signUpProvider = + Provider.of(context, listen: false); + signUpProvider.setEstateId(model.value); + Get.off(SignUpPickRolePage()); + }, + ).material(color: Colors.white); + } + + @override + Widget build(BuildContext context) { + return BeeScaffold( + title: '选择单元', + body: EasyRefresh( + header: MaterialHeader(), + firstRefresh: true, + onRefresh: () async { + _buildingModels = await SignFunc.getUnitInfo(widget.buildingId); + setState(() {}); + }, + child: ListView.builder( + itemBuilder: (context, index) { + return _buildItem(_buildingModels[index]); + }, + itemCount: _buildingModels.length, + ), + ), + ); + } +} diff --git a/lib/pages/sign/sign_up/sign_up_set_nickname_page.dart b/lib/pages/sign/sign_up/sign_up_set_nickname_page.dart new file mode 100644 index 00000000..1fe4ae1d --- /dev/null +++ b/lib/pages/sign/sign_up/sign_up_set_nickname_page.dart @@ -0,0 +1,62 @@ +import 'package:akuCommunity/base/base_style.dart'; +import 'package:akuCommunity/pages/sign/sign_up/sign_up_common_widget.dart'; +import 'package:akuCommunity/utils/headers.dart'; +import 'package:flutter/material.dart'; +import 'package:velocity_x/velocity_x.dart'; + +class SignUpSetNicknamePage extends StatefulWidget { + SignUpSetNicknamePage({Key key}) : super(key: key); + + @override + _SignUpSetNicknamePageState createState() => _SignUpSetNicknamePageState(); +} + +class _SignUpSetNicknamePageState extends State { + @override + Widget build(BuildContext context) { + return Scaffold( + body: ListView( + padding: EdgeInsets.symmetric(horizontal: 32.w), + children: [ + 148.hb, + signUpTitle('设置昵称'), + 190.hb, + '请输入您的昵称'.text.size(32.sp).color(ktextPrimary).make(), + TextField( + decoration: InputDecoration( + border: UnderlineInputBorder( + borderSide: BorderSide(color: Color(0xFFD8D8D8)), + ), + hintText: '为保护个人隐私,在与邻居交流时将显示昵称', + ), + ), + ], + ), + bottomNavigationBar: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + MaterialButton( + color: kPrimaryColor, + elevation: 0, + height: 89.w, + child: '保存'.text.make(), + shape: StadiumBorder(), + onPressed: () {}, + ), + MaterialButton( + elevation: 0, + height: 89.w, + child: [ + Icon(Icons.cached_rounded), + 12.wb, + '换一换'.text.make(), + ].row(), + shape: StadiumBorder(), + onPressed: () {}, + ), + ], + ).pLTRB(82.w, 0, 82.w, 60.w), + ); + } +} diff --git a/lib/pages/splash/splash_page.dart b/lib/pages/splash/splash_page.dart index 115f3156..9bcad8e2 100644 --- a/lib/pages/splash/splash_page.dart +++ b/lib/pages/splash/splash_page.dart @@ -1,4 +1,6 @@ import 'package:akuCommunity/pages/tab_navigator.dart'; +import 'package:akuCommunity/utils/hive_store.dart'; +import 'package:akuCommunity/utils/logger/logger_view.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:velocity_x/velocity_x.dart'; @@ -14,11 +16,15 @@ class SplashPage extends StatefulWidget { class _SplashPageState extends State { Future _initOp() async { await Future.delayed(Duration(seconds: 2)); + print(HiveStore.appBox.get('token')); } @override void initState() { super.initState(); + Future.delayed(Duration(milliseconds: 300), () { + if (mounted) LoggerFAB.openLogger(context); + }); _initOp().then((value) => Get.offAll(TabNavigator())); } diff --git a/lib/pages/tab_navigator.dart b/lib/pages/tab_navigator.dart index 68c7b7ef..3e520d21 100644 --- a/lib/pages/tab_navigator.dart +++ b/lib/pages/tab_navigator.dart @@ -1,4 +1,3 @@ -import 'package:akuCommunity/utils/logger/logger_view.dart'; import 'package:flutter/material.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; @@ -28,9 +27,7 @@ class _TabNavigatorState extends State { @override void initState() { super.initState(); - Future.delayed(Duration(milliseconds: 300), () { - if (mounted) LoggerFAB.openLogger(context); - }); + _pages = [ HomePage(), // MarketPage(), diff --git a/lib/provider/sign_up_provider.dart b/lib/provider/sign_up_provider.dart new file mode 100644 index 00000000..865308b2 --- /dev/null +++ b/lib/provider/sign_up_provider.dart @@ -0,0 +1,59 @@ +import 'package:flutter/material.dart'; + +class SignUpProvider extends ChangeNotifier { + int _estateId; + int get estateId => _estateId; + int _type = 1; + int get type => _type; + String _nickName; + String get nickName => _nickName; + String _name; + String get name => _name; + String _tel; + String get tel => _tel; + int _idType; + int get idType => _idType; + String _idNumber; + String get idNumber => _idNumber; + + setEstateId(int id) { + _estateId = id; + notifyListeners(); + } + + setType(int type) { + _type = type; + notifyListeners(); + } + + setName(String name) { + _name = name; + notifyListeners(); + } + + setTel(String tel) { + _tel = tel; + notifyListeners(); + } + + setidType(int idType) { + _idType = idType; + notifyListeners(); + } + + setIdNumber(String idNumber) { + _idNumber = idNumber; + notifyListeners(); + } + + clearAll() { + _estateId = null; + _type = 1; + _nickName = null; + _name = null; + _tel = null; + _idType = null; + _idNumber = null; + notifyListeners(); + } +} diff --git a/lib/provider/user_provider.dart b/lib/provider/user_provider.dart index fbcf4580..5e588930 100644 --- a/lib/provider/user_provider.dart +++ b/lib/provider/user_provider.dart @@ -1,4 +1,5 @@ import 'package:akuCommunity/utils/hive_store.dart'; +import 'package:akuCommunity/utils/network/net_util.dart'; import 'package:flutter/material.dart'; class UserProvider extends ChangeNotifier { @@ -12,8 +13,9 @@ class UserProvider extends ChangeNotifier { bool _isLogin = false; bool get isLogin => _isLogin; - setLogin(bool state, String token) { - _isLogin = state; + setLogin(String token) { + _isLogin = true; + NetUtil().dio.options.headers.putIfAbsent('App-Admin-Token', () => token); HiveStore.appBox.put('token', token); notifyListeners(); } @@ -21,10 +23,15 @@ class UserProvider extends ChangeNotifier { logout() { _isLogin = false; _token = null; + NetUtil().dio.options.headers.remove('App-Admin-Token'); HiveStore.appBox.delete('token'); notifyListeners(); } + updateProfile() async { + // await + } + String _token; String get token => _token ?? ''; } diff --git a/lib/utils/headers.dart b/lib/utils/headers.dart index 1464443b..5a9390fb 100644 --- a/lib/utils/headers.dart +++ b/lib/utils/headers.dart @@ -1,5 +1,7 @@ export 'package:flutter_screenutil/flutter_screenutil.dart'; export 'package:akuCommunity/extensions/page_router.dart'; +export 'package:akuCommunity/extensions/num_ext.dart'; +export 'package:akuCommunity/extensions/widget_list_ext.dart'; // class Screenutil { // static double length(double lengthNum) => ScreenUtil().setWidth(lengthNum); diff --git a/pubspec.lock b/pubspec.lock index 876fd48b..66f3f077 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -377,6 +377,13 @@ packages: url: "https://pub.flutter-io.cn" source: hosted version: "1.4.0" + flutter_easyrefresh: + dependency: "direct main" + description: + name: flutter_easyrefresh + url: "https://pub.flutter-io.cn" + source: hosted + version: "2.1.8" flutter_html: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 2aac273c..9481fd55 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -100,6 +100,7 @@ dependencies: hive: hive_flutter: logger: ^0.9.4 + flutter_easyrefresh: ^2.1.8 dev_dependencies: flutter_test: