register.vue 2.4 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 36
				rules,
				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 52
			submit() {
				if(!this.agree){
					return uni.showToast({
						title: '你未同意隐私政策协议',
						icon: 'none'
					});
				}
芊里 已提交
53 54 55
				uni.showLoading({
					mask: true
				})
DCloud_JSON's avatar
DCloud_JSON 已提交
56
				this.$refs.form.submit().then((res) => {
芊里 已提交
57 58 59 60 61 62 63 64 65
						this.submitForm(res)
					}).catch((errors) => {
						console.log(errors);
					})
					.finally(() => {
						uni.hideLoading()
					})
			},
			submitForm(value) {
DCloud_JSON's avatar
DCloud_JSON 已提交
66 67 68 69 70
				this.request('user-center/register',value,result=>{
					console.log(result);
					if(result.code === 0){
						this.loginSuccess(result)
					}
71
				})
芊里 已提交
72 73 74 75 76
			}
		}
	}
</script>

DCloud_JSON's avatar
DCloud_JSON 已提交
77
<style>
DCloud_JSON's avatar
DCloud_JSON 已提交
78
	@import url("../common/login-page.css");
芊里 已提交
79 80 81
	.uni-container {
		padding: 15px;
	}
DCloud_JSON's avatar
DCloud_JSON 已提交
82 83 84 85
	.send-btn{
		margin-top: 5px;
	}
</style>