From de1d559a88477c828d87f2f582cc6f1cb04ff2eb Mon Sep 17 00:00:00 2001 From: laiiihz Date: Mon, 18 Jan 2021 10:36:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E7=99=BB=E9=99=86=E6=B3=A8?= =?UTF-8?q?=E5=86=8C=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/constants/api.dart | 9 ++ lib/model/user/user_info_model.dart | 28 +----- .../certification_page.dart | 1 - lib/pages/personal/personal_page.dart | 4 +- lib/pages/sign/sign_func.dart | 28 ++++++ lib/pages/sign/sign_in_page.dart | 5 +- .../sign/sign_up/sign_up_pick_role_page.dart | 2 - .../sign_up/sign_up_set_nickname_page.dart | 42 +++++++-- .../sign/sign_up/sign_up_verify_page.dart | 94 +++++++++++++++++++ lib/provider/sign_up_provider.dart | 34 ++++++- lib/provider/user_provider.dart | 14 ++- lib/utils/logger/logger_card.dart | 9 +- lib/utils/logger/logger_dio_err.dart | 1 - lib/utils/logger/logger_dio_success.dart | 40 ++++++++ 14 files changed, 257 insertions(+), 54 deletions(-) create mode 100644 lib/pages/sign/sign_up/sign_up_verify_page.dart create mode 100644 lib/utils/logger/logger_dio_success.dart diff --git a/lib/constants/api.dart b/lib/constants/api.dart index 14c422ed..f7cb1efc 100644 --- a/lib/constants/api.dart +++ b/lib/constants/api.dart @@ -3,6 +3,7 @@ class API { static String get resource => '$host/static'; static const int networkTimeOut = 10000; static _Login login = _Login(); + static _User user = _User(); } class _Login { @@ -17,4 +18,12 @@ class _Login { ///查询单元ID String get unitInfo => '/login/findEstateIANByBuilding'; + + /// app用户注册 + String get signUp => '/login/register'; +} + +class _User { + ///用户资料 + String get userProfile => '/user/personalData/findPersonalData'; } diff --git a/lib/model/user/user_info_model.dart b/lib/model/user/user_info_model.dart index 14d53268..6cd1c756 100644 --- a/lib/model/user/user_info_model.dart +++ b/lib/model/user/user_info_model.dart @@ -1,28 +1,4 @@ class UserInfoModel { - Data data; - String message; - bool status; - - UserInfoModel({this.data, this.message, this.status}); - - UserInfoModel.fromJson(Map json) { - data = json['data'] != null ? new Data.fromJson(json['data']) : null; - message = json['message']; - status = json['status']; - } - - Map toJson() { - final Map data = new Map(); - if (this.data != null) { - data['data'] = this.data.toJson(); - } - data['message'] = this.message; - data['status'] = this.status; - return data; - } -} - -class Data { int id; List imgUrls; String name; @@ -31,7 +7,7 @@ class Data { int sex; String birthday; - Data( + UserInfoModel( {this.id, this.imgUrls, this.name, @@ -40,7 +16,7 @@ class Data { this.sex, this.birthday}); - Data.fromJson(Map json) { + UserInfoModel.fromJson(Map json) { id = json['id']; imgUrls = json['imgUrls'].cast(); name = json['name']; diff --git a/lib/pages/certification_page/certification_page.dart b/lib/pages/certification_page/certification_page.dart index 7a786fd9..879a09f7 100644 --- a/lib/pages/certification_page/certification_page.dart +++ b/lib/pages/certification_page/certification_page.dart @@ -4,7 +4,6 @@ import 'package:flutter/cupertino.dart'; import 'package:akuCommunity/base/assets_image.dart'; import 'package:akuCommunity/utils/headers.dart'; import 'package:akuCommunity/widget/common_input.dart'; -import 'package:akuCommunity/widget/common_app_bar.dart'; import 'package:akuCommunity/widget/single_image_up.dart'; class CertificationPage extends StatefulWidget { diff --git a/lib/pages/personal/personal_page.dart b/lib/pages/personal/personal_page.dart index 125395f3..f63f1ef7 100644 --- a/lib/pages/personal/personal_page.dart +++ b/lib/pages/personal/personal_page.dart @@ -136,13 +136,13 @@ class _PersonalIndexState extends State ), InkWell( onTap: () { - if (!userProvider.isSigned) SignInPage().to(); + if (!userProvider.isLogin) SignInPage().to(); }, child: Container( margin: EdgeInsets.only(left: 16.w), child: userProvider.isLogin ? Text( - 'Cheailune', + userProvider.userInfoModel.nickName, style: TextStyle( fontSize: 32.sp, color: Color(0xffad8940), diff --git a/lib/pages/sign/sign_func.dart b/lib/pages/sign/sign_func.dart index 4962ba91..b2ff6c04 100644 --- a/lib/pages/sign/sign_func.dart +++ b/lib/pages/sign/sign_func.dart @@ -1,8 +1,14 @@ import 'package:akuCommunity/constants/api.dart'; import 'package:akuCommunity/model/user/pick_building_model.dart'; +import 'package:akuCommunity/model/user/user_info_model.dart'; +import 'package:akuCommunity/provider/sign_up_provider.dart'; +import 'package:akuCommunity/provider/user_provider.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'; +import 'package:get/get.dart' hide Response; +import 'package:provider/provider.dart'; class SignFunc { static Future sendMessageCode(String phone) async { @@ -38,4 +44,26 @@ class SignFunc { .map((e) => PickBuildingModel.fromJson(e)) .toList(); } + + ///注册 + static Future signUp() async { + final signUpProvider = + Provider.of(Get.context, listen: false); + final userProvider = Provider.of(Get.context, listen: false); + Response response = await NetUtil().dio.post( + API.login.signUp, + data: signUpProvider.toMap, + ); + BotToast.showText(text: response.data['message']); + if (response.data['status']) { + userProvider.setLogin(response.data['token']); + return true; + } else + return false; + } + + static Future getUserInfo() async { + BaseModel baseModel = await NetUtil().get(API.user.userProfile); + return UserInfoModel.fromJson(baseModel.data); + } } diff --git a/lib/pages/sign/sign_in_page.dart b/lib/pages/sign/sign_in_page.dart index 05b60ea0..d4d3b52e 100644 --- a/lib/pages/sign/sign_in_page.dart +++ b/lib/pages/sign/sign_in_page.dart @@ -35,7 +35,6 @@ class SignInPage extends StatefulWidget { class _SignInPageState extends State { TextEditingController _phone = new TextEditingController(); TextEditingController _code = new TextEditingController(); - AppBar get _appBar => AppBar(elevation: 0, backgroundColor: Colors.white); Timer _timer; bool get validPhone => RegexUtil.isMobileSimple(_phone.text); @@ -90,8 +89,7 @@ class _SignInPageState extends State { if (response.data['status']) { if (response.data['choose'] == 1) { - userProvider.setLogin(response.data['token'] as String); - + userProvider.setLogin(response.data['token']); Get.offAll(TabNavigator()); } else { cancel(); @@ -195,7 +193,6 @@ class _SignInPageState extends State { Widget build(BuildContext context) { return Scaffold( backgroundColor: Colors.white, - appBar: _appBar, body: GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { 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 index 6723861f..3fc9660d 100644 --- a/lib/pages/sign/sign_up/sign_up_pick_role_page.dart +++ b/lib/pages/sign/sign_up/sign_up_pick_role_page.dart @@ -28,8 +28,6 @@ class _SignUpPickRolePageState extends State { @override Widget build(BuildContext context) { - final signUpProvider = Provider.of(context); - return Scaffold( body: ListView( padding: EdgeInsets.symmetric(horizontal: 32.w), 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 index 1fe4ae1d..79397ee4 100644 --- a/lib/pages/sign/sign_up/sign_up_set_nickname_page.dart +++ b/lib/pages/sign/sign_up/sign_up_set_nickname_page.dart @@ -1,7 +1,12 @@ 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_verify_page.dart'; +import 'package:akuCommunity/provider/sign_up_provider.dart'; import 'package:akuCommunity/utils/headers.dart'; +import 'package:flustars/flustars.dart'; import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:provider/provider.dart'; import 'package:velocity_x/velocity_x.dart'; class SignUpSetNicknamePage extends StatefulWidget { @@ -12,6 +17,14 @@ class SignUpSetNicknamePage extends StatefulWidget { } class _SignUpSetNicknamePageState extends State { + GlobalKey _globalKey = GlobalKey(); + TextEditingController _textEditingController = TextEditingController(); + @override + void dispose() { + _textEditingController?.dispose(); + super.dispose(); + } + @override Widget build(BuildContext context) { return Scaffold( @@ -22,12 +35,22 @@ class _SignUpSetNicknamePageState extends State { signUpTitle('设置昵称'), 190.hb, '请输入您的昵称'.text.size(32.sp).color(ktextPrimary).make(), - TextField( - decoration: InputDecoration( - border: UnderlineInputBorder( - borderSide: BorderSide(color: Color(0xFFD8D8D8)), + Form( + key: _globalKey, + child: TextFormField( + controller: _textEditingController, + validator: (value) { + if (TextUtil.isEmpty(value)) + return '昵称不能为空'; + else + return null; + }, + decoration: InputDecoration( + border: UnderlineInputBorder( + borderSide: BorderSide(color: Color(0xFFD8D8D8)), + ), + hintText: '为保护个人隐私,在与邻居交流时将显示昵称', ), - hintText: '为保护个人隐私,在与邻居交流时将显示昵称', ), ), ], @@ -42,7 +65,14 @@ class _SignUpSetNicknamePageState extends State { height: 89.w, child: '保存'.text.make(), shape: StadiumBorder(), - onPressed: () {}, + onPressed: () { + if (_globalKey.currentState.validate()) { + final signUpProvider = + Provider.of(context, listen: false); + signUpProvider.setNickName(_textEditingController.text); + Get.to(SignUpVerifyPage()); + } + }, ), MaterialButton( elevation: 0, diff --git a/lib/pages/sign/sign_up/sign_up_verify_page.dart b/lib/pages/sign/sign_up/sign_up_verify_page.dart new file mode 100644 index 00000000..fb51d799 --- /dev/null +++ b/lib/pages/sign/sign_up/sign_up_verify_page.dart @@ -0,0 +1,94 @@ +import 'package:akuCommunity/base/base_style.dart'; +import 'package:akuCommunity/pages/sign/sign_func.dart'; +import 'package:akuCommunity/pages/sign/sign_up/sign_up_common_widget.dart'; +import 'package:akuCommunity/pages/tab_navigator.dart'; +import 'package:akuCommunity/provider/sign_up_provider.dart'; +import 'package:akuCommunity/utils/headers.dart'; +import 'package:common_utils/common_utils.dart'; +import 'package:flutter/material.dart'; +import 'package:get/get.dart'; +import 'package:provider/provider.dart'; +import 'package:velocity_x/velocity_x.dart'; + +class SignUpVerifyPage extends StatefulWidget { + SignUpVerifyPage({Key key}) : super(key: key); + + @override + _SignUpVerifyPageState createState() => _SignUpVerifyPageState(); +} + +class _SignUpVerifyPageState extends State { + TextEditingController _nameController = TextEditingController(); + TextEditingController _idNumberController = TextEditingController(); + + GlobalKey _formKey = GlobalKey(); + @override + Widget build(BuildContext context) { + return Scaffold( + body: Form( + key: _formKey, + child: ListView( + padding: EdgeInsets.symmetric(horizontal: 32.w), + children: [ + 148.hb, + signUpTitle('设置昵称'), + 190.hb, + '请输入您的姓名'.text.size(32.sp).color(ktextPrimary).make(), + TextFormField( + controller: _nameController, + validator: (value) { + if (TextUtil.isEmpty(value)) + return '姓名不能为空'; + else + return null; + }, + decoration: InputDecoration( + border: UnderlineInputBorder( + borderSide: BorderSide(color: Color(0xFFD8D8D8)), + ), + // hintText: '', + ), + ), + 40.hb, + '请输入您的身份证号'.text.size(32.sp).color(ktextPrimary).make(), + TextFormField( + controller: _idNumberController, + validator: (value) { + if (TextUtil.isEmpty(value)) return '身份证号不能为空'; + if (!RegexUtil.isIDCard(value)) + return '身份证格式错误'; + else + return null; + }, + decoration: InputDecoration( + border: UnderlineInputBorder( + borderSide: BorderSide(color: Color(0xFFD8D8D8)), + ), + // hintText: '', + ), + ), + ], + ), + ), + bottomNavigationBar: MaterialButton( + height: 89.w, + color: kPrimaryColor, + shape: StadiumBorder(), + disabledColor: kPrimaryColor.withOpacity(0.3), + child: '登录'.text.bold.make(), + onPressed: () async { + final signUpProvider = + Provider.of(context, listen: false); + + if (_formKey.currentState.validate()) { + signUpProvider.setName(_nameController.text); + signUpProvider.setIdNumber(_idNumberController.text); + bool result = await SignFunc.signUp(); + if (result) Get.offAll(TabNavigator()); + } + }, + elevation: 0, + ).pLTRB(82.w, 0, 82.w, 155.w), + ); + } +} diff --git a/lib/provider/sign_up_provider.dart b/lib/provider/sign_up_provider.dart index 865308b2..bb7c5ac1 100644 --- a/lib/provider/sign_up_provider.dart +++ b/lib/provider/sign_up_provider.dart @@ -11,11 +11,36 @@ class SignUpProvider extends ChangeNotifier { String get name => _name; String _tel; String get tel => _tel; - int _idType; + + ///default is 1 + /// + ///证件类型 + ///1. 身份证 + ///2. 营业执照 + ///3. 军人证 + int _idType = 1; + + ///default is 1 + /// + ///证件类型 + ///1. 身份证 + ///2. 营业执照 + ///3. 军人证 int get idType => _idType; String _idNumber; + String get idNumber => _idNumber; + Map get toMap => { + 'estateId': _estateId, + 'type': _type, + 'nickName': _nickName, + 'name': _name, + 'tel': _tel, + 'idType': _idType, + 'idNumber': _idNumber, + }; + setEstateId(int id) { _estateId = id; notifyListeners(); @@ -26,6 +51,11 @@ class SignUpProvider extends ChangeNotifier { notifyListeners(); } + setNickName(String name) { + _nickName = name; + notifyListeners(); + } + setName(String name) { _name = name; notifyListeners(); @@ -36,7 +66,7 @@ class SignUpProvider extends ChangeNotifier { notifyListeners(); } - setidType(int idType) { + setIdType(int idType) { _idType = idType; notifyListeners(); } diff --git a/lib/provider/user_provider.dart b/lib/provider/user_provider.dart index 5e588930..7a42c583 100644 --- a/lib/provider/user_provider.dart +++ b/lib/provider/user_provider.dart @@ -1,3 +1,5 @@ +import 'package:akuCommunity/model/user/user_info_model.dart'; +import 'package:akuCommunity/pages/sign/sign_func.dart'; import 'package:akuCommunity/utils/hive_store.dart'; import 'package:akuCommunity/utils/network/net_util.dart'; import 'package:flutter/material.dart'; @@ -13,25 +15,31 @@ class UserProvider extends ChangeNotifier { bool _isLogin = false; bool get isLogin => _isLogin; - setLogin(String token) { + Future setLogin(int token) async { _isLogin = true; NetUtil().dio.options.headers.putIfAbsent('App-Admin-Token', () => token); HiveStore.appBox.put('token', token); + await updateProfile(); notifyListeners(); } logout() { _isLogin = false; _token = null; + _userInfoModel = null; NetUtil().dio.options.headers.remove('App-Admin-Token'); HiveStore.appBox.delete('token'); notifyListeners(); } - updateProfile() async { - // await + Future updateProfile() async { + _userInfoModel = await SignFunc.getUserInfo(); + notifyListeners(); } String _token; String get token => _token ?? ''; + + UserInfoModel _userInfoModel; + UserInfoModel get userInfoModel => _userInfoModel; } diff --git a/lib/utils/logger/logger_card.dart b/lib/utils/logger/logger_card.dart index 2bcbcb7e..a54ad9f8 100644 --- a/lib/utils/logger/logger_card.dart +++ b/lib/utils/logger/logger_card.dart @@ -1,4 +1,5 @@ import 'package:akuCommunity/utils/logger/logger_dio_err.dart'; +import 'package:akuCommunity/utils/logger/logger_dio_success.dart'; import 'package:dio/dio.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; @@ -13,13 +14,7 @@ class LoggerCard extends StatelessWidget { Widget _buildResponse() { Response response = data; - return Card( - child: Column( - children: [ - Text(response.statusCode.toString()), - ], - ), - ); + return LoggerDioSuccess(response: response); } Widget _getLoggerView() { diff --git a/lib/utils/logger/logger_dio_err.dart b/lib/utils/logger/logger_dio_err.dart index 2385e987..f885f68d 100644 --- a/lib/utils/logger/logger_dio_err.dart +++ b/lib/utils/logger/logger_dio_err.dart @@ -1,5 +1,4 @@ import 'package:akuCommunity/extensions/num_ext.dart'; -import 'package:common_utils/common_utils.dart'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:velocity_x/velocity_x.dart'; diff --git a/lib/utils/logger/logger_dio_success.dart b/lib/utils/logger/logger_dio_success.dart new file mode 100644 index 00000000..33dfec88 --- /dev/null +++ b/lib/utils/logger/logger_dio_success.dart @@ -0,0 +1,40 @@ +import 'package:akuCommunity/extensions/num_ext.dart'; +import 'package:dio/dio.dart'; +import 'package:flutter/material.dart'; +import 'package:velocity_x/velocity_x.dart'; + +class LoggerDioSuccess extends StatelessWidget { + final Response response; + const LoggerDioSuccess({Key key, this.response}) : super(key: key); + + @override + Widget build(BuildContext context) { + return MaterialButton( + elevation: 10, + highlightElevation: 1, + color: Colors.white, + onPressed: () {}, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + children: [ + 5.wb, + response.request.path.text.bold.make().expand(), + Chip( + backgroundColor: Colors.redAccent, + label: Text(response?.statusCode?.toString() ?? 'UNKNOW'), + ), + 5.wb, + Chip( + backgroundColor: Colors.greenAccent, + label: Text(response.request.method), + ), + ], + ), + response.headers['date'].first.toString().text.make(), + ], + ), + ); + } +}