phone-code.vue 2.1 KB
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1 2 3 4
<template>
	<view class="content">
		<!-- 顶部文字 -->
		<text class="tit">{{$t('common.verifyCodePlaceholder')}}</text>
雪洛's avatar
雪洛 已提交
5
		<text class="tip">{{tipText}}</text>
DCloud_JSON's avatar
DCloud_JSON 已提交
6 7 8 9 10 11 12 13 14 15
		<uni-forms>
		<!-- 登录框 (选择手机号所属国家和地区需要另行实现) -->
			<uni-easyinput type="number" class="easyinput" :inputBorder="false"
				v-model="code" maxlength="6" :placeholder="$t('common.verifyCodePlaceholder')">
				<template v-slot:right>
					<uni-send-sms-code :phone="phone" ref="sendSmsCode"></uni-send-sms-code>
				</template>
			</uni-easyinput>
			<button class="send-btn" :disabled="!canSubmit" :type="canSubmit?'primary':'default'"
				@click="submit">{{$t('common.login')}}</button>
16
		</uni-forms>
17 18
		<uni-quick-login agree></uni-quick-login>
		<uni-popup-captcha @confirm="submit" ref="popup-captcha" v-model="captcha" scene="loginBySms"></uni-popup-captcha>
DCloud_JSON's avatar
DCloud_JSON 已提交
19 20 21 22 23 24 25 26 27
	</view>
</template>
<script>
	import mixin from '../common/login-page.mixin.js';
	export default {
		mixins:[mixin],
		data() {
			return {
				code:'',
28 29
				phone:'',
				captcha:false
DCloud_JSON's avatar
DCloud_JSON 已提交
30 31 32 33 34 35 36 37
			}
		},
		computed: {
			tipText() {
				return this.$t('common.verifyCodeSend')+ `${this.phone}。`;
			},
			canSubmit(){
				return this.code.length==6;
雪洛's avatar
雪洛 已提交
38
			}
DCloud_JSON's avatar
DCloud_JSON 已提交
39 40 41 42
		},
		onLoad({phoneNumber,phoneArea}) {
			this.phone = phoneNumber;
		},
雪洛's avatar
雪洛 已提交
43
		onReady() {
DCloud_JSON's avatar
-...  
DCloud_JSON 已提交
44 45 46
			if(this.phone.length==11){
				this.$refs.sendSmsCode.start();
			}
DCloud_JSON's avatar
DCloud_JSON 已提交
47 48 49
		},
		methods: {
			submit(){ //完成并提交
雪洛's avatar
雪洛 已提交
50 51 52 53 54
				uniCloud.callFunction({
					name:'uni-id-cf',
					data:{
						action:'loginBySms',
						params:{
DCloud_JSON's avatar
DCloud_JSON 已提交
55
							"mobile":this.phone,
56 57
							"code":this.code,
							"captcha":this.captcha
雪洛's avatar
雪洛 已提交
58 59 60
						},
					},
					success: ({result}) => {
61 62 63 64 65 66 67
						uni.showToast({
							title: result.msg || result.errMsg,
							icon: 'none'
						});
						if(result.errCode == "CAPTCHA_REQUIRED"){
							return this.$refs['popup-captcha'].open()
						}
雪洛's avatar
雪洛 已提交
68 69 70
						if(result.code === 0){
							this.loginSuccess(result)
						}
71 72 73
					},
					complete: () => {
						this.captcha = false
雪洛's avatar
雪洛 已提交
74 75
					}
				})
DCloud_JSON's avatar
DCloud_JSON 已提交
76 77 78 79 80 81
			}
		}
	}
</script>
<style>
	@import url("../common/login-page.css");
82
</style>