Преглед изворни кода

1.增加commonutil.js
2.验证码判断
3.绑定手机号请求

zhangmengjie пре 5 година
родитељ
комит
a79aec87bd
3 измењених фајлова са 24 додато и 19 уклоњено
  1. 2 13
      pages/PhoneBind.js
  2. 9 6
      pages/components/PersonalInfo.js
  3. 13 0
      pages/utils/commonutil.js

+ 2 - 13
pages/PhoneBind.js

@@ -25,6 +25,7 @@ import ShopBox from './components/ShopBox';
 import TopicTitle from './components/TopicTitle';
 import TopicTitle from './components/TopicTitle';
 import ScrollRow from './components/ScrollRow';
 import ScrollRow from './components/ScrollRow';
 import http_user from './services/user';
 import http_user from './services/user';
+import commonutil from './utils/commonutil';
 
 
 export default class PhoneBind extends BasePage {
 export default class PhoneBind extends BasePage {
 	state = {
 	state = {
@@ -105,7 +106,7 @@ export default class PhoneBind extends BasePage {
 
 
 	getVerification() {
 	getVerification() {
 		if (this.state.verification_text === '获取验证码') {
 		if (this.state.verification_text === '获取验证码') {
-			if (this.isPoneAvailable(this.state.phone_num)) {
+			if (commonutil.isPoneAvailable(this.state.phone_num)) {
 				http_user.getVerificationCode(this.state.phone_num).then((result) => {
 				http_user.getVerificationCode(this.state.phone_num).then((result) => {
 					if (result.code != 200) {
 					if (result.code != 200) {
 						ToastAndroid.show(result.message, ToastAndroid.SHORT);
 						ToastAndroid.show(result.message, ToastAndroid.SHORT);
@@ -144,18 +145,6 @@ export default class PhoneBind extends BasePage {
 		}
 		}
 	}
 	}
 
 
-	//验证手机号
-	isPoneAvailable(str) {
-		let myreg = /^[1][3,4,5,7,8][0-9]{9}$/;
-		if (str.length == 0 || str == null) {
-			return false;
-		} else if (!myreg.test(str)) {
-			return false;
-		} else {
-			return true;
-		}
-	}
-
 	//绑定手机号
 	//绑定手机号
 	clickOK() {
 	clickOK() {
 		if (this.state.http_verification_code == this.state.verification_code) {
 		if (this.state.http_verification_code == this.state.verification_code) {

+ 9 - 6
pages/components/PersonalInfo.js

@@ -15,6 +15,7 @@ import {
 	Image,
 	Image,
 	TouchableOpacity,
 	TouchableOpacity,
 	ImageBackground,
 	ImageBackground,
+	ToastAndroid,
 	Button,
 	Button,
 	StatusBar,
 	StatusBar,
 	Modal,
 	Modal,
@@ -822,13 +823,15 @@ export default class PersonalInfo extends BasePage {
 							nickName: result['nickname']
 							nickName: result['nickname']
 						}
 						}
 					};
 					};
-					//接口不通
 					user.bind_wechat(opts).then((res) => {
 					user.bind_wechat(opts).then((res) => {
-						console.log(res);
-						this.setState({
-							wechat_nickName: result['nickname'],
-							wechat_bind_color: 'rgba(113, 113, 113, 1)'
-						});
+						if (res.code == 200) {
+							this.setState({
+								wechat_nickName: res['nickname'],
+								wechat_bind_color: 'rgba(113, 113, 113, 1)'
+							});
+						} else {
+							ToastAndroid.show(res.message, ToastAndroid.SHORT);
+						}
 					});
 					});
 				});
 				});
 				break;
 				break;

+ 13 - 0
pages/utils/commonutil.js

@@ -0,0 +1,13 @@
+export default class commonutil {
+	//验证手机号
+	static isPoneAvailable(str) {
+		let myreg = /^[1][0-9]{10}$/;
+		if (str.length == 0 || str == null) {
+			return false;
+		} else if (!myreg.test(str)) {
+			return false;
+		} else {
+			return true;
+		}
+	}
+}