register.vue 3.0 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 20 21 22 23 24 25 26 27 28 29 30 31 32
			<uni-agreements @setAgree="agree = $event"></uni-agreements>
			<button class="send-btn" type="primary" @click="submit">{{$t('register.registerAndLogin')}}</button>
		</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: {
33 34 35 36 37
					"username": "111111",
					"nickname": "111111",
					"password":"111111",
					"pwd2":"111111",
					"captcha":false
DCloud_JSON's avatar
DCloud_JSON 已提交
38 39 40 41 42 43 44 45 46 47 48 49
				},
				rules,
				agree:false
			}
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		onLoad() {
			uni.setNavigationBarTitle({
				title: this.$t('register.navigationBarTitle')
			})
雪洛's avatar
雪洛 已提交
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
		methods: {
			/**
			 * 触发表单提交
			 */
			submit() {
				if(!this.agree){
					return uni.showToast({
						title: this.$t('common').noAgree,
						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
雪洛 已提交
75 76 77 78 79 80 81 82 83 84
				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 已提交
85 86 87 88 89
						}else{
							uni.showModal({
								content: result.msg,
								showCancel: false
							});
雪洛's avatar
雪洛 已提交
90 91
						}
					}
DCloud_JSON's avatar
DCloud_JSON 已提交
92 93 94 95 96 97
				})
			}
		}
	}
</script>

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