register.vue 2.2 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" />
15
			</uni-forms-item>
DCloud_JSON's avatar
DCloud_JSON 已提交
16 17
			<uni-agreements></uni-agreements>
			<button class="send-btn" type="primary" @click="submit">注册并登陆</button>
芊里 已提交
18 19 20 21
		</uni-forms>
	</view>
</template>

22 23
<script>
import rules from './validator.js';
DCloud_JSON's avatar
DCloud_JSON 已提交
24
import mixin from '../common/login-page.mixin.js';
25 26
	export default {
		mixins:[mixin],
芊里 已提交
27 28 29 30
		data() {
			return {
				formData: {
					"username": "",
芊里 已提交
31
					"nickname": "",
DCloud_JSON's avatar
DCloud_JSON 已提交
32 33
					'password':'',
					'pwd2':''
芊里 已提交
34
				},
35
				rules
芊里 已提交
36 37 38 39 40 41 42 43 44
			}
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		methods: {
			/**
			 * 触发表单提交
			 */
芊里 已提交
45
			submit() {
芊里 已提交
46 47 48
				uni.showLoading({
					mask: true
				})
49
				this.$refs.form.submit().then((res) => {
芊里 已提交
50 51 52 53 54 55 56 57 58
						this.submitForm(res)
					}).catch((errors) => {
						console.log(errors);
					})
					.finally(() => {
						uni.hideLoading()
					})
			},
			submitForm(value) {
DCloud_JSON's avatar
DCloud_JSON 已提交
59
				this.request('user-center/register',value,result=>{
60 61 62 63 64
					console.log(result);
					if(result.code === 0){
						this.loginSuccess(result)
					}
				})
芊里 已提交
65 66 67 68 69
			}
		}
	}
</script>

70
<style>
DCloud_JSON's avatar
DCloud_JSON 已提交
71
	@import url("../common/login-page.css");
芊里 已提交
72 73
	.uni-container {
		padding: 15px;
DCloud_JSON's avatar
DCloud_JSON 已提交
74 75 76
	}
	.send-btn{
		margin-top: 5px;
芊里 已提交
77 78
	}
</style>