phone-code.vue 2.8 KB
Newer Older
芊里 已提交
1 2 3 4 5 6 7
<template>
	<view class="wrap">
		<view class="wrap-content">
			<view class="content">
				<!-- 顶部文字 -->
				<text class="content-top-title">请输入验证码</text>
				<login-ikonw class="login-iknow" :text="tipText"></login-ikonw>
DCloud_JSON's avatar
DCloud_JSON 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
				<!-- 登录框 (选择手机号所属国家和地区需要另行实现) -->
				<uni-forms ref="form" :value="formData" :rules="rules">
					<uni-forms-item name="phone">
						<!-- <uni-easyinput type="number" class="phone-input-box" :inputBorder="false"
							v-model="formData.phone" maxlength="11" placeholder="请输入手机号码">
						</uni-easyinput> -->
						<uni-easyinput type="number" class="phone-input-box" :inputBorder="false"
							v-model="formData.code" maxlength="6" placeholder="请输入验证码">
							<template slot="right">
								<send-sms-code :phone="formData.phone" ref="shortCode"></send-sms-code>
							</template>
						</uni-easyinput>
					</uni-forms-item>
					<button class="send-btn-box" :disabled="!canSubmit" :type="canSubmit?'primary':'default'"
						@click="submit">登录</button>
芊里 已提交
23 24
				</uni-forms>
			</view>
DCloud_JSON's avatar
DCloud_JSON 已提交
25
		</view>
L
123  
linju 已提交
26
		<uni-quick-login></uni-quick-login>
芊里 已提交
27 28 29
	</view>
</template>

DCloud_JSON's avatar
DCloud_JSON 已提交
30
<script>
31
	import mixin from '../common/loginPage.mixin.js';
DCloud_JSON's avatar
DCloud_JSON 已提交
32
	export default {
芊里 已提交
33
		mixins:[mixin],
芊里 已提交
34 35
		data() {
			return {
芊里 已提交
36
				currenPhoneArea: '',
芊里 已提交
37 38 39 40
			}
		},
		computed: {
			tipText() {
芊里 已提交
41
				return `验证码已通过短信发送至${this.currenPhoneArea} ${this.formData.phone}。`;
芊里 已提交
42 43
			},
			canSubmit() {
44
				return this.isPhone && this.isCode;
芊里 已提交
45 46
			}
		},
L
123  
linju 已提交
47
		onLoad({phoneNumber,phoneArea}) {
芊里 已提交
48
			this.formData.phone = phoneNumber;
L
123  
linju 已提交
49
			this.currenPhoneArea = '+' + Number(phoneArea);
芊里 已提交
50
		},
DCloud_JSON's avatar
DCloud_JSON 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
		onReady() {
			this.$refs.shortCode.start();
		},
		methods: {
			/**
			 * 完成并提交
			 */
			submit(){
				uniCloud.callFunction({//联网验证登陆
					"name": "user-center",
					"data": {
						"action": "loginBySms",
						"params":{
							"mobile":this.formData.phone,
							"code":this.formData.code
						}
					},
					success:async (e) => {
						uni.hideLoading()
						console.log(e.result);
						if(e.result.code === 0){
							this.loginSuccess(e.result)
						}else{
							uni.showModal({
								title: '错误',
								content: e.result.msg,
								showCancel: false,
								confirmText: '知道了',
							});
						}
					},
					fail: (err) => {
						console.log(err);
						uni.showModal({
							title: '错误',
							content: JSON.stringify(err),
							showCancel: false,
							confirmText: '知道了',
						});
						if(err.errCode===30002){
							
						}
					},
					complete: () => {
						uni.hideLoading()
					}
				})
芊里 已提交
98 99 100 101 102
			}
		}
	}
</script>

DCloud_JSON's avatar
DCloud_JSON 已提交
103 104 105 106 107 108
<style>
	@import url("../common/loginPage.css");
	.phone-input-box{
		margin-top: 10px;
	}
</style>