bind-mobile.vue 3.4 KB
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
<!-- 绑定手机号码页 -->
<template>
	<view class="uni-content">
		<match-media :min-width="690">
			<view class="login-logo">
				<image :src="logo"></image>
			</view>
			<!-- 顶部文字 -->
			<text class="title title-box">绑定手机号</text>
		</match-media>
		<!-- 登录框 (选择手机号所属国家和地区需要另行实现) -->
		<uni-easyinput clearable :focus="focusMobile" @blur="focusMobile = false" type="number" class="input-box" :inputBorder="false" v-model="formData.mobile"
			maxlength="11" placeholder="请输入手机号"></uni-easyinput>
		<uni-id-pages-sms-form ref="smsForm" type="bind-mobile-by-sms" v-model="formData.code" :phone="formData.mobile">
		</uni-id-pages-sms-form>
		<button class="uni-btn send-btn-box" type="primary" @click="submit">提交</button>
		<uni-popup-captcha @confirm="submit" v-model="formData.captcha" scene="bind-mobile-by-sms" ref="popup">
		</uni-popup-captcha>
	</view>
</template>
<script>
	import {
		store,
		mutations
	} from '@/uni_modules/uni-id-pages/common/store.js'
	export default {
		data() {
			return {
				formData: {
					mobile: "",
					code: "",
					captcha: ""
				},
				focusMobile:true,
				logo: "/static/logo.png"
			}
		},
		computed: {
			tipText() {
				return `验证码已通过短信发送至 ${this.formData.mobile}。密码为6 - 20位`
			}
		},
		onLoad(event) {},
		onReady() {},

		methods: {
			/**
			 * 完成并提交
			 */
study夏羽's avatar
study夏羽 已提交
50
			async submit() {
DCloud_JSON's avatar
DCloud_JSON 已提交
51 52 53 54
				if(! /^1\d{10}$/.test(this.formData.mobile)){
					this.focusMobile = true 
					return uni.showToast({
						title: '手机号码格式不正确',
55 56
						icon: 'none',
						duration: 3000
DCloud_JSON's avatar
DCloud_JSON 已提交
57 58
					});
				}
study夏羽's avatar
study夏羽 已提交
59
				console.log("this.formData.code: ",this.formData.code);
DCloud_JSON's avatar
DCloud_JSON 已提交
60 61 62 63
				if(! /^\d{6}$/.test(this.formData.code)){
					this.$refs.smsForm.focusSmsCodeInput = true 
					return uni.showToast({
						title: '验证码格式不正确',
64 65
						icon: 'none',
						duration: 3000
DCloud_JSON's avatar
DCloud_JSON 已提交
66 67 68
					});
				}
				
69 70 71 72 73 74 75 76 77
				// console.log(this.formData);
				const uniIdCo = uniCloud.importObject("uni-id-co")
				uniIdCo.bindMobileBySms(this.formData).then(e => {
					// console.log(e);
					uni.showToast({
						title: e.errMsg,
						icon: 'none',
						duration: 3000
					});
DCloud_JSON's avatar
DCloud_JSON 已提交
78 79 80 81 82 83 84 85
					// #ifdef APP-NVUE
					const eventChannel = this.$scope.eventChannel; // 兼容APP-NVUE
					// #endif
					// #ifndef APP-NVUE
					const eventChannel = this.getOpenerEventChannel();
					// #endif
					mutations.setUserInfo(this.formData)
					uni.navigateBack()
study夏羽's avatar
study夏羽 已提交
86
					return e
DCloud_JSON's avatar
DCloud_JSON 已提交
87 88 89 90 91
				}).catch(e => {
					console.log(e);
					if (e.errCode == 'uni-id-captcha-required') {
						this.$refs.popup.open()
					}
study夏羽's avatar
study夏羽 已提交
92
					return e
DCloud_JSON's avatar
DCloud_JSON 已提交
93 94
				}).finally(e => {
					this.formData.captcha = ""
study夏羽's avatar
study夏羽 已提交
95
					return e
DCloud_JSON's avatar
DCloud_JSON 已提交
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
				})
			}
		}
	}
</script>

<style lang="scss">
	@import "@/uni_modules/uni-id-pages/common/login-page.scss";

	.uni-content {
		padding: 0;
		align-items: center;
		justify-content: center;
		padding: 50rpx;
		padding-top: 10px;
	}
	
	
	@media screen and (min-width: 690px) {
		.uni-content{
			padding: 30px 40px 40px;
		}
	}

	/* #ifndef APP-NVUE  || VUE3 */
	.uni-content ::v-deep .uni-easyinput__content {}

	/* #endif */
	.input-box {
		width: 100%;
		margin-top: 16px;
		background-color: #f9f9f9;
		border-radius: 6rpx;
		flex-direction: row;
		flex-wrap: nowrap;
		margin-bottom: 10px;
	}

	.send-btn-box {
		margin-top: 15px;
	}
</style>