diff --git a/lib/constants/sars_api.dart b/lib/constants/sars_api.dart index 1fec263c..d5d9add6 100644 --- a/lib/constants/sars_api.dart +++ b/lib/constants/sars_api.dart @@ -37,6 +37,12 @@ class _User { ///app用户发送手机号验证码(忘记密码) String get sendForgotTelCode => '/app/user/sendTelCodeForgetPwd'; + + ///检测昵称是否重复 + String get checkNickRepeat => '/app/user/checkNickNameRepeat'; + + ///设置昵称 + String get setNickName => '/app/user/settingNickName'; } class _Login { diff --git a/lib/pages/sign/login/set_nick_name_page.dart b/lib/pages/sign/login/set_nick_name_page.dart new file mode 100644 index 00000000..a085b038 --- /dev/null +++ b/lib/pages/sign/login/set_nick_name_page.dart @@ -0,0 +1,141 @@ +import 'package:aku_new_community/pages/sign/sign_func.dart'; +import 'package:aku_new_community/pages/sign/widget/login_button_widget.dart'; +import 'package:aku_new_community/pages/tab_navigator.dart'; +import 'package:aku_new_community/widget/bee_scaffold.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_screenutil/flutter_screenutil.dart'; +import 'package:get/get.dart'; +import 'package:velocity_x/velocity_x.dart'; + +class SetNickNamePage extends StatefulWidget { + const SetNickNamePage({Key? key}) : super(key: key); + + @override + _SetNickNamePageState createState() => _SetNickNamePageState(); +} + +class _SetNickNamePageState extends State { + TextEditingController _nickController = TextEditingController(); + bool _nickIsRepeat = false; + + @override + void dispose() { + _nickController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return BeeScaffold( + title: '', + bodyColor: Colors.white, + body: Column( + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + 24.w.heightBox, + Row( + children: [ + 48.w.widthBox, + '请设置您的昵称' + .text + .size(36.sp) + .bold + .color(Colors.black.withOpacity(0.65)) + .make(), + Spacer(), + ], + ), + 16.w.heightBox, + Row( + children: [ + 48.w.widthBox, + '昵称不可设置侮辱性词汇、特殊符号、敏感字符' + .text + .size(28.sp) + .color(Colors.black.withOpacity(0.45)) + .make(), + Spacer(), + ], + ), + 95.w.heightBox, + Container( + width: 686.w, + height: 94.w, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(60.w), + color: Colors.black.withOpacity(0.06), + ), + child: TextField( + onChanged: (text) async { + _nickIsRepeat = !(await SignFunc.checkNickRepeat(text)); + setState(() {}); + }, + maxLength: 20, + controller: _nickController, + decoration: InputDecoration( + isDense: false, + contentPadding: + EdgeInsets.symmetric(horizontal: 24.w, vertical: 24.w), + border: InputBorder.none, + counterText: '', + hintText: '请输入您的昵称,不超过20个字符', + hintStyle: TextStyle( + color: Colors.black.withOpacity(0.25), fontSize: 28.sp)), + ), + ), + _nickIsRepeat ? _nickRepeat() : 100.w.heightBox, + LoginButtonWidget( + onTap: () async { + var result = await SignFunc.setNickName(_nickController.text); + if (result) { + Get.offAll(TabNavigator()); + } + }, + text: '确定'), + ], + ), + ); + } + + Widget _nickRepeat() { + return Padding( + padding: EdgeInsets.symmetric(horizontal: 48.w), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + 24.w.heightBox, + '该昵称已有人注册,请重新输入'.text.size(28.sp).color(Colors.red).make(), + 50.w.heightBox, + '试试以下昵称' + .text + .size(28.sp) + .color(Colors.black.withOpacity(0.65)) + .make(), + 24.w.heightBox, + otherNick('123'), + 24.w.heightBox, + otherNick('321'), + 24.w.heightBox, + otherNick('231'), + 100.w.heightBox, + ], + ), + ); + } + + Container otherNick(String extra) { + return Container( + height: 70.w, + padding: EdgeInsets.symmetric(horizontal: 24.w, vertical: 16.w), + alignment: Alignment.centerLeft, + decoration: BoxDecoration( + color: Colors.black.withOpacity(0.03), + borderRadius: BorderRadius.circular(42.sp)), + child: '${_nickController.text}$extra' + .text + .size(28.sp) + .color(Color(0xFF5096F1)) + .make(), + ); + } +} diff --git a/lib/pages/sign/sign_func.dart b/lib/pages/sign/sign_func.dart index 6e5cd943..13ed3276 100644 --- a/lib/pages/sign/sign_func.dart +++ b/lib/pages/sign/sign_func.dart @@ -3,8 +3,8 @@ import 'package:aku_new_community/constants/sars_api.dart'; import 'package:aku_new_community/model/user/pick_building_model.dart'; import 'package:aku_new_community/models/user/my_house_model.dart'; import 'package:aku_new_community/models/user/user_info_model.dart'; +import 'package:aku_new_community/pages/sign/login/set_nick_name_page.dart'; import 'package:aku_new_community/pages/sign/login/set_psd_page.dart'; -import 'package:aku_new_community/pages/sign/sign_up/sign_up_set_nickname_page.dart'; import 'package:aku_new_community/provider/sign_up_provider.dart'; import 'package:aku_new_community/provider/user_provider.dart'; import 'package:aku_new_community/utils/network/base_model.dart'; @@ -158,7 +158,7 @@ class SignFunc { BaseModel baseModel = await NetUtil().get( SARSAPI.profile.house.userHouse, ); - if (baseModel.data == null) return null; + if ((baseModel.data as List).isEmpty) return null; return MyHouseModel.fromJson(baseModel.data); } @@ -166,9 +166,31 @@ class SignFunc { if (!UserTool.userProvider.userInfoModel!.isExistPassword) { await Get.to(() => SetPsdPage()); } else if (UserTool.userProvider.userInfoModel!.nickName == null) { - await Get.to(() => SignUpSetNicknamePage()); + print('111'); + await Get.to(() => SetNickNamePage()); } else { + print('222'); Get.offAll(() => TabNavigator()); } } + + ///检测昵称是否重复 + static Future checkNickRepeat(String nick) async { + BaseModel baseModel = await NetUtil().get(SARSAPI.user.checkNickRepeat, + params: { + 'nickName': nick, + }, + showMessage: true); + return baseModel.success; + } + + ///设置昵称 + static Future setNickName(String nick) async { + BaseModel baseModel = await NetUtil().get(SARSAPI.user.setNickName, + params: { + 'nickName': nick, + }, + showMessage: true); + return baseModel.success; + } } diff --git a/lib/pages/sign/sign_up/sign_up_common_widget.dart b/lib/pages/sign/sign_up/sign_up_common_widget.dart deleted file mode 100644 index 9a7a96c1..00000000 --- a/lib/pages/sign/sign_up/sign_up_common_widget.dart +++ /dev/null @@ -1,17 +0,0 @@ -import 'package:aku_new_community/base/base_style.dart'; -import 'package:aku_new_community/utils/headers.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_screenutil/flutter_screenutil.dart'; -import 'package:velocity_x/velocity_x.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_set_nickname_page.dart b/lib/pages/sign/sign_up/sign_up_set_nickname_page.dart deleted file mode 100644 index 3ddcc943..00000000 --- a/lib/pages/sign/sign_up/sign_up_set_nickname_page.dart +++ /dev/null @@ -1,102 +0,0 @@ -import 'package:aku_new_community/base/base_style.dart'; -import 'package:aku_new_community/pages/sign/sign_func.dart'; -import 'package:aku_new_community/pages/sign/sign_up/sign_up_common_widget.dart'; -import 'package:aku_new_community/pages/tab_navigator.dart'; -import 'package:aku_new_community/provider/sign_up_provider.dart'; -import 'package:aku_new_community/utils/headers.dart'; -import 'package:bot_toast/bot_toast.dart'; -import 'package:flustars/flustars.dart'; -import 'package:flutter/material.dart'; -import 'package:get/get.dart'; -import 'package:provider/provider.dart'; -import 'package:random_character/chinese_character/random_chinese_charater.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 { - GlobalKey _globalKey = GlobalKey(); - TextEditingController _textEditingController = TextEditingController(); - - @override - void dispose() { - _textEditingController.dispose(); - super.dispose(); - } - - @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(), - 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: '为保护个人隐私,在与邻居交流时将显示昵称', - ), - ), - ), - ], - ), - bottomNavigationBar: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [ - MaterialButton( - color: kPrimaryColor, - elevation: 0, - height: 89.w, - child: '保存'.text.make(), - shape: StadiumBorder(), - onPressed: () async { - final cancel = BotToast.showLoading(); - if (_globalKey.currentState!.validate()) { - final signUpProvider = - Provider.of(context, listen: false); - signUpProvider.setNickName(_textEditingController.text); - cancel(); - bool result = await SignFunc.signUp(); - if (result) Get.offAll(() => TabNavigator()); - } - }, - ), - MaterialButton( - elevation: 0, - height: 89.w, - child: [ - Icon(Icons.cached_rounded), - 12.wb, - '换一换'.text.make(), - ].row(), - shape: StadiumBorder(), - onPressed: () { - _textEditingController.text = - RandomCharacter.getChinese(length: 3); - }, - ), - ], - ).pLTRB(82.w, 0, 82.w, 60.w), - ); - } -} diff --git a/lib/pages/sign/sign_up/sign_up_verify_page.dart b/lib/pages/sign/sign_up/sign_up_verify_page.dart deleted file mode 100644 index ab773072..00000000 --- a/lib/pages/sign/sign_up/sign_up_verify_page.dart +++ /dev/null @@ -1,87 +0,0 @@ -import 'package:aku_new_community/base/base_style.dart'; -import 'package:aku_new_community/pages/sign/sign_func.dart'; -import 'package:aku_new_community/pages/sign/sign_up/sign_up_common_widget.dart'; -import 'package:aku_new_community/pages/tab_navigator.dart'; -import 'package:aku_new_community/utils/headers.dart'; -import 'package:flustars/flustars.dart'; -import 'package:flutter/material.dart'; -import 'package:get/get.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 { - if (_formKey.currentState!.validate()) { - bool result = await SignFunc.signUp(); - if (result) Get.offAll(() => TabNavigator()); - } - }, - elevation: 0, - ).pLTRB(82.w, 0, 82.w, 155.w), - ); - } -} diff --git a/lib/pages/splash/splash_page.dart b/lib/pages/splash/splash_page.dart index ec17ca33..c3fe1342 100644 --- a/lib/pages/splash/splash_page.dart +++ b/lib/pages/splash/splash_page.dart @@ -4,7 +4,6 @@ import 'package:aku_new_community/const/resource.dart'; import 'package:aku_new_community/main_initialize.dart'; import 'package:aku_new_community/pages/setting_page/agreement_page/agreement_page.dart'; import 'package:aku_new_community/pages/setting_page/agreement_page/privacy_page.dart'; -import 'package:aku_new_community/pages/tab_navigator.dart'; import 'package:aku_new_community/provider/app_provider.dart'; import 'package:aku_new_community/provider/user_provider.dart'; import 'package:aku_new_community/utils/developer_util.dart'; @@ -139,7 +138,6 @@ class _SplashPageState extends State { MainInitialize.initTheme(); MainInitialize.initWechat(); MainInitialize.initWebSocket(); - Get.offAll(() => TabNavigator()); }); } diff --git a/lib/provider/data_provider.dart b/lib/provider/data_provider.dart index d5280edd..24463377 100644 --- a/lib/provider/data_provider.dart +++ b/lib/provider/data_provider.dart @@ -12,7 +12,10 @@ class DataProvider extends ChangeNotifier { ?.cast() .toList() ?? []; - if (_loginHistories.isEmpty) { + _cityModel = + HiveStore.dataBox!.get('cities')?.cast().toList() ?? + []; + if (_cityModel.isEmpty) { updateCityList(); } } diff --git a/lib/provider/user_provider.dart b/lib/provider/user_provider.dart index 4a862fa9..f83f10f1 100644 --- a/lib/provider/user_provider.dart +++ b/lib/provider/user_provider.dart @@ -33,7 +33,7 @@ class UserProvider extends ChangeNotifier { HiveStore.appBox!.put('token', token); HiveStore.appBox!.put('login', true); await updateUserInfo(); - await updateMyHouseInfo(); + // await updateMyHouseInfo(); ///初始化用户配置 _userConfig = await HiveStore.userBox!.get('${_userInfoModel!.id}') ?? @@ -71,14 +71,11 @@ class UserProvider extends ChangeNotifier { Future updateUserInfo() async { _userInfoModel = await SignFunc.getUserInfo(); - print('222'); - if (_userInfoModel == null) { BotToast.showText(text: '获取用户信息失败'); return false; } if (_userInfoModel != null && !kIsWeb && !Platform.isMacOS) { - print('111'); SignFunc.checkNameAndAccount(); }