register.vue 3.2 KB
Newer Older
DCloud_JSON's avatar
DCloud_JSON 已提交
1 2 3 4 5 6 7
<template>
	<view class="uni-container">
		<uni-forms ref="form" :value="formData" :rules="rules" validate-trigger="submit" err-show-type="undertext">
			<uni-forms-item name="username" required>
				<uni-easyinput :inputBorder="false" class="easyinput" :placeholder="$t('register.usernamePlaceholder')" v-model="formData.username" trim="both" />
			</uni-forms-item>
			<uni-forms-item name="nickname">
8
				<uni-easyinput :inputBorder="false" class="easyinput" :placeholder="$t('register.nicknamePlaceholder')" v-model="formData.nickname" trim="both"  />
DCloud_JSON's avatar
DCloud_JSON 已提交
9 10 11 12 13 14
			</uni-forms-item>
			<uni-forms-item name="password" v-model="formData.password" required>
				<uni-easyinput :inputBorder="false" class="easyinput" :placeholder="$t('register.passwordDigitsPlaceholder')" type="password" v-model="formData.password" trim="both" />
			</uni-forms-item>
			<uni-forms-item name="pwd2" v-model="formData.pwd2" required>
				<uni-easyinput :inputBorder="false" class="easyinput" :placeholder="$t('register.passwordAgain')" type="password" v-model="formData.pwd2" trim="both" />
15 16 17 18
			</uni-forms-item>
			<uni-forms-item name="captcha" required>
				<uni-captcha scene="register" v-model="formData.captcha"></uni-captcha>
			</uni-forms-item>
DCloud_JSON's avatar
DCloud_JSON 已提交
19
			<uni-agreements @setAgree="agree = $event"></uni-agreements>
20
			<button class="send-btn" :disabled="!canSubmit" :type="canSubmit?'primary':'default'" @click="submit">{{$t('register.registerAndLogin')}}</button>
DCloud_JSON's avatar
DCloud_JSON 已提交
21 22 23 24 25 26 27 28 29 30 31 32
		</uni-forms>
	</view>
</template>

<script>
import rules from './validator.js';
import mixin from '../common/login-page.mixin.js';
	export default {
		mixins:[mixin],
		data() {
			return {
				formData: {
DCloud_JSON's avatar
DCloud_JSON 已提交
33 34 35 36
					"username": "",
					"nickname": "",
					"password":"",
					"pwd2":"",
37
					"captcha":""
DCloud_JSON's avatar
DCloud_JSON 已提交
38 39
				},
				rules,
40
				agree:false,
DCloud_JSON's avatar
DCloud_JSON 已提交
41
			}
42 43 44 45 46 47
		},
		computed:{
			canSubmit(){
				return this.formData.username.length && this.formData.password.length && this.formData.captcha.length == 4 && this.agree
			}
		},
DCloud_JSON's avatar
DCloud_JSON 已提交
48 49 50 51 52 53 54
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: this.$t('register.navigationBarTitle')
			})
雪洛's avatar
雪洛 已提交
55
		},
DCloud_JSON's avatar
DCloud_JSON 已提交
56 57 58 59 60 61 62
		methods: {
			/**
			 * 触发表单提交
			 */
			submit() {
				if(!this.agree){
					return uni.showToast({
63
						title: this.$t('common.noAgree'),
DCloud_JSON's avatar
DCloud_JSON 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
						icon: 'none'
					});
				}
				uni.showLoading({
					mask: true
				})
				this.$refs.form.validate().then((res) => {
						this.submitForm(res)
					}).catch((errors) => {
						console.log(errors);
					})
					.finally(() => {
						uni.hideLoading()
					})
			},
			submitForm(params) {
雪洛's avatar
雪洛 已提交
80 81 82 83 84 85 86 87 88 89
				uniCloud.callFunction({
					name:'uni-id-cf',
					data:{
						action:'register',
						params,
					},
					success: ({result}) => {
						console.log(result);
						if(result.code === 0){
							this.loginSuccess(result)
DCloud_JSON's avatar
DCloud_JSON 已提交
90 91 92 93 94
						}else{
							uni.showModal({
								content: result.msg,
								showCancel: false
							});
雪洛's avatar
雪洛 已提交
95 96
						}
					}
DCloud_JSON's avatar
DCloud_JSON 已提交
97 98 99 100 101 102
				})
			}
		}
	}
</script>

103
<style lang="scss" scoped>
DCloud_JSON's avatar
DCloud_JSON 已提交
104 105 106
	@import url("../common/login-page.css");
	.uni-container {
		padding: 15px;
107
	}
DCloud_JSON's avatar
DCloud_JSON 已提交
108
	.send-btn{
109
		margin-top: 15px;
雪洛's avatar
雪洛 已提交
110 111 112
	}
	.uni-container ::v-deep .uni-forms-item__label{
		width: 15px !important;
DCloud_JSON's avatar
DCloud_JSON 已提交
113 114
	}
</style>