register.vue 2.6 KB
Newer Older
芊里 已提交
1 2
<template>
	<view class="uni-container">
3
		<uni-forms ref="form" :value="formData" :rules="rules" validate-trigger="submit" err-show-type="undertext">
4
			<uni-forms-item name="username" required>
DCloud_JSON's avatar
DCloud_JSON 已提交
5
				<uni-easyinput :inputBorder="false" class="easyinput" placeholder="请输入用户名" v-model="formData.username" trim="both" />
芊里 已提交
6
			</uni-forms-item>
7
			<uni-forms-item name="nickname">
DCloud_JSON's avatar
DCloud_JSON 已提交
8
				<uni-easyinput :inputBorder="false" class="easyinput" placeholder="请输入用户昵称" v-model="formData.nickname" trim="both" />
芊里 已提交
9
			</uni-forms-item>
10
			<uni-forms-item name="password" v-model="formData.password" required>
DCloud_JSON's avatar
DCloud_JSON 已提交
11
				<uni-easyinput :inputBorder="false" class="easyinput" placeholder="请输入6-20位密码" type="password" v-model="formData.password" trim="both" />
芊里 已提交
12
			</uni-forms-item>
13
			<uni-forms-item name="pwd2" v-model="formData.pwd2" required>
DCloud_JSON's avatar
DCloud_JSON 已提交
14
				<uni-easyinput :inputBorder="false" class="easyinput" placeholder="再次输入密码" type="password" v-model="formData.pwd2" trim="both" />
DCloud_JSON's avatar
DCloud_JSON 已提交
15
			</uni-forms-item>
16
			<uni-agreements @setAgree="agree = $event"></uni-agreements>
DCloud_JSON's avatar
DCloud_JSON 已提交
17
			<button class="send-btn" type="primary" @click="submit">注册并登录</button>
芊里 已提交
18 19 20 21
		</uni-forms>
	</view>
</template>

DCloud_JSON's avatar
DCloud_JSON 已提交
22 23
<script>
import rules from './validator.js';
DCloud_JSON's avatar
DCloud_JSON 已提交
24
import mixin from '../common/login-page.mixin.js';
DCloud_JSON's avatar
DCloud_JSON 已提交
25
	export default {
26
		mixins:[mixin],
芊里 已提交
27 28 29 30
		data() {
			return {
				formData: {
					"username": "",
DCloud_JSON's avatar
DCloud_JSON 已提交
31 32
					"nickname": "",
					'password':'',
DCloud_JSON's avatar
DCloud_JSON 已提交
33
					'pwd2':''
芊里 已提交
34
				},
35
				rules,
36
				agree:false
芊里 已提交
37 38 39 40 41 42 43 44 45
			}
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		methods: {
			/**
			 * 触发表单提交
			 */
46 47 48 49 50 51
			submit() {
				if(!this.agree){
					return uni.showToast({
						title: '你未同意隐私政策协议',
						icon: 'none'
					});
52
				}
芊里 已提交
53 54 55
				uni.showLoading({
					mask: true
				})
56
				this.$refs.form.validate().then((res) => {
芊里 已提交
57 58 59 60 61 62 63 64
						this.submitForm(res)
					}).catch((errors) => {
						console.log(errors);
					})
					.finally(() => {
						uni.hideLoading()
					})
			},
65 66 67 68 69 70 71 72 73 74 75
			submitForm(params) {
				uniCloud.callFunction({
					name:'uni-id-cf',
					data:{
						action:'register',
						params,
					},
					success: ({result}) => {
						console.log(result);
						if(result.code === 0){
							this.loginSuccess(result)
76 77 78 79 80
						}else{
							uni.showModal({
								content: result.msg,
								showCancel: false
							});
81 82
						}
					}
83
				})
芊里 已提交
84 85 86 87 88
			}
		}
	}
</script>

DCloud_JSON's avatar
DCloud_JSON 已提交
89
<style>
DCloud_JSON's avatar
DCloud_JSON 已提交
90
	@import url("../common/login-page.css");
芊里 已提交
91 92 93
	.uni-container {
		padding: 15px;
	}
DCloud_JSON's avatar
DCloud_JSON 已提交
94 95 96 97
	.send-btn{
		margin-top: 5px;
	}
</style>