bind-mobile.vue 2.2 KB
Newer Older
1
<template>
DCloud_JSON's avatar
DCloud_JSON 已提交
2
	<view class="box">
3
		<!-- 登录框 (选择手机号所属国家和地区需要另行实现) -->
DCloud_JSON's avatar
DCloud_JSON 已提交
4
		<uni-easyinput clearable focus type="number" class="input-box" :inputBorder="false" v-model="formData.phone"
5
			maxlength="11" placeholder="请输入手机号"></uni-easyinput>
DCloud_JSON's avatar
DCloud_JSON 已提交
6
		<uni-easyinput clearable type="number" class="input-box" :inputBorder="false" v-model="formData.code" maxlength="6"
7 8
			placeholder="请输入验证码">
			<template slot="right">
9
				<uni-send-sms-code ref="shortCode" code-type="bind" :phone="formData.phone"></uni-send-sms-code>
10 11 12 13 14
			</template>
		</uni-easyinput>
		<button class="send-btn-box" type="primary" @click="submit">提交</button>
	</view>
</template>
DCloud_JSON's avatar
DCloud_JSON 已提交
15 16 17 18
<script>
	import {
		mapMutations,
		mapGetters
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
	} from 'vuex';
	export default {
		data() {
			return {
				currenPhoneArea: '',
				formData: {
					phone:"",
					code:""
				}
			}
		},
		computed: {
			tipText() {
				return `验证码已通过短信发送至${this.currenPhoneArea} ${this.formData.phone}。密码为6 - 20位`
			},
			canSubmit() {
				return this.isPhone && this.isPwd && this.isCode;
			}
		},
		onLoad(event) {
		},
		onReady() {
		},
DCloud_JSON's avatar
DCloud_JSON 已提交
42 43 44
		methods: {
			...mapMutations({
				setUserInfo: 'user/login'
45 46 47 48
			}),
			/**
			 * 完成并提交
			 */
DCloud_JSON's avatar
DCloud_JSON 已提交
49 50
			submit() {
				console.log(this.formData);
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
				uniCloud.callFunction({
					name:'uni-id-cf',
					data:{
						action:'bindMobileBySms',
						params:{
							"mobile": this.formData.phone,
							"code": this.formData.code
						},
					},
					success: ({result}) => {
						console.log(result);
						this.setUserInfo({"mobile":result.mobile})
						uni.showToast({
							title: result.msg,
							icon: 'none'
						});
						if (result.code === 0) {
							uni.navigateBack()
						}
					}
71 72 73 74 75 76 77 78 79 80
				})
			}
		}
	}
</script>

<style>
	.box {
		align-items: center;
		justify-content: center;
DCloud_JSON's avatar
DCloud_JSON 已提交
81
		padding: 50rpx;
82 83 84 85
		padding-top: 10px;
	}

	.box /deep/ .uni-easyinput__content {
DCloud_JSON's avatar
DCloud_JSON 已提交
86
		height: 50px;
87 88
	}

89
	.input-box {
90
		width: 100%;
91 92 93 94 95 96 97 98 99 100 101
		margin-top: 16px;
		background-color: #f9f9f9;
		border-radius: 6rpx;
		flex-direction: row;
		flex-wrap: nowrap;
	}

	.send-btn-box {
		width: 650rpx;
		margin-top: 15px;
	}
DCloud_JSON's avatar
DCloud_JSON 已提交
102
</style>