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

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

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

@ -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:
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/tel_change_page.dart';
import 'package:flutter/material.dart';
// Package imports:
@ -52,7 +53,12 @@ class _UserInfoPageState extends State<UserInfoPage> {
suffix: Text(userProvider.infoModel.nickName),
),
AkuTile(
onTap: () {},
onTap: () async{
await TelChangePage().to();
setState(() {
});
},
title: Text('手机'),
suffix: Text(TextUtil.hideNumber(userProvider.infoModel.tel)),
),

Loading…
Cancel
Save