对接:发送手机号修改验证码

对接:个人资料修改手机号
hmxc
张萌 4 years ago
parent 0c617d83ed
commit 010817038b

@ -35,4 +35,11 @@ class _User {
/// ///
String get updateNickName => '/user/personalData/updateNickName'; String get updateNickName => '/user/personalData/updateNickName';
///
String get sendTelUpdateCode => '/user/personalData/sendTelUpdateCode';
///
String get updateTel =>'/user/personalData/updateTel';
} }

@ -1,7 +1,9 @@
import 'dart:async'; import 'dart:async';
import 'package:aku_community_manager/provider/user_provider.dart'; import 'package:aku_community_manager/provider/user_provider.dart';
import 'package:aku_community_manager/ui/settings/update_userinfo_func.dart';
import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart'; import 'package:aku_community_manager/ui/widgets/common/aku_scaffold.dart';
import 'package:aku_community_manager/utils/network/base_model.dart';
import 'package:bot_toast/bot_toast.dart'; import 'package:bot_toast/bot_toast.dart';
import 'package:common_utils/common_utils.dart'; import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -28,6 +30,7 @@ class _TelChangePageState extends State<TelChangePage> {
bool timeActive = _timer?.isActive ?? false; bool timeActive = _timer?.isActive ?? false;
return (!timeActive) && validPhone; return (!timeActive) && validPhone;
} }
startTick() { startTick() {
_timer = Timer.periodic(Duration(seconds: 1), (_timer) { _timer = Timer.periodic(Duration(seconds: 1), (_timer) {
if (_timer.tick >= 60) { if (_timer.tick >= 60) {
@ -37,13 +40,15 @@ class _TelChangePageState extends State<TelChangePage> {
setState(() {}); setState(() {});
}); });
} }
@override @override
void initState() { void initState() {
super.initState(); super.initState();
_codeController=TextEditingController(); _codeController = TextEditingController();
_newTelController=TextEditingController(); _newTelController = TextEditingController();
_oldTelController=TextEditingController(); _oldTelController = TextEditingController();
} }
@override @override
void dispose() { void dispose() {
_codeController?.dispose(); _codeController?.dispose();
@ -51,9 +56,9 @@ class _TelChangePageState extends State<TelChangePage> {
_oldTelController?.dispose(); _oldTelController?.dispose();
super.dispose(); super.dispose();
} }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
UserProvider userProvider = Provider.of<UserProvider>(context); UserProvider userProvider = Provider.of<UserProvider>(context);
return AkuScaffold( return AkuScaffold(
title: '修改手机', title: '修改手机',
@ -97,8 +102,13 @@ class _TelChangePageState extends State<TelChangePage> {
BoxConstraints(minHeight: 0.w, minWidth: 0.w), BoxConstraints(minHeight: 0.w, minWidth: 0.w),
suffixIcon: MaterialButton( suffixIcon: MaterialButton(
onPressed: _canGetCode onPressed: _canGetCode
? () { ? () async {
BaseModel baseModel =
await UpdateUserInfoFunc.sendTelUpdateCode(
_newTelController.text);
if (baseModel.status) {
startTick(); startTick();
} else {}
} }
: () {}, : () {},
child: _timer?.isActive ?? false child: _timer?.isActive ?? false
@ -107,7 +117,11 @@ class _TelChangePageState extends State<TelChangePage> {
.color(Color(0xFFFFC40C)) .color(Color(0xFFFFC40C))
.size(28.sp) .size(28.sp)
.make() .make()
: '获取验证码'.text.color(Color(0xFFFFC40C)).size(28.sp).make(), : '获取验证码'
.text
.color(Color(0xFFFFC40C))
.size(28.sp)
.make(),
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
minWidth: 177.w, minWidth: 177.w,
height: 62.w, height: 62.w,
@ -155,7 +169,7 @@ class _TelChangePageState extends State<TelChangePage> {
), ),
64.w.heightBox, 64.w.heightBox,
MaterialButton( MaterialButton(
onPressed: () { onPressed: () async {
if (TextUtil.isEmpty(_oldTelController.text)) { if (TextUtil.isEmpty(_oldTelController.text)) {
BotToast.showText(text: '旧手机号不能为空'); BotToast.showText(text: '旧手机号不能为空');
} else if (TextUtil.isEmpty(_newTelController.text)) { } else if (TextUtil.isEmpty(_newTelController.text)) {
@ -163,9 +177,16 @@ class _TelChangePageState extends State<TelChangePage> {
} else if (TextUtil.isEmpty(_codeController.text)) { } else if (TextUtil.isEmpty(_codeController.text)) {
BotToast.showText(text: '验证码不能为空'); BotToast.showText(text: '验证码不能为空');
} else { } else {
// userProvider.setTel(_oldTelController.text, BaseModel baseModel = await UpdateUserInfoFunc.updateTel(
// _newTelController.text, _codeController.text); _oldTelController.text,
_newTelController.text,
_codeController.text);
if (baseModel.status) {
userProvider.setTel(_newTelController.text);
Get.back(); Get.back();
} else {
BotToast.showText(text: baseModel.message);
}
} }
}, },
child: '保存'.text.black.size(32.sp).make(), child: '保存'.text.black.size(32.sp).make(),

@ -0,0 +1,23 @@
import 'package:aku_community_manager/const/api.dart';
import 'package:aku_community_manager/utils/network/base_model.dart';
import 'package:aku_community_manager/utils/network/net_util.dart';
class UpdateUserInfoFunc {
static Future<BaseModel> sendTelUpdateCode(String tel) async {
BaseModel baseModel =
await NetUtil().post(API.user.sendTelUpdateCode, params: {
'newTel': tel,
});
return baseModel;
}
static Future<BaseModel> updateTel(
String oldTel, String newTel, String code) async {
BaseModel baseModel = await NetUtil().post(API.user.updateTel, params: {
'oldTel': oldTel,
'newTel': newTel,
'code': code,
});
return baseModel;
}
}

@ -1,6 +1,7 @@
// Flutter imports: // Flutter imports:
import 'package:aku_community_manager/tools/aku_divider.dart'; import 'package:aku_community_manager/tools/aku_divider.dart';
import 'package:aku_community_manager/ui/settings/nick_name_change_page.dart'; import 'package:aku_community_manager/ui/settings/nick_name_change_page.dart';
import 'package:aku_community_manager/ui/settings/tel_change_page.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
// Package imports: // Package imports:
@ -52,7 +53,12 @@ class _UserInfoPageState extends State<UserInfoPage> {
suffix: Text(userProvider.infoModel.nickName), suffix: Text(userProvider.infoModel.nickName),
), ),
AkuTile( AkuTile(
onTap: () {}, onTap: () async{
await TelChangePage().to();
setState(() {
});
},
title: Text('手机'), title: Text('手机'),
suffix: Text(TextUtil.hideNumber(userProvider.infoModel.tel)), suffix: Text(TextUtil.hideNumber(userProvider.infoModel.tel)),
), ),

Loading…
Cancel
Save