register.vue 3.3 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 5 6
			<uni-forms-item name="username" label="用户名" required>
				<uni-easyinput placeholder="请输入用户名" v-model="formData.username" trim="both" />
			</uni-forms-item>
7
			<uni-forms-item name="gender" label="性别">
芊里 已提交
8 9
				<uni-data-checkbox v-model="formData.gender" :localdata="formOptions.gender_localdata" />
			</uni-forms-item>
10
			<uni-forms-item name="nickname" label="昵称">
芊里 已提交
11 12
				<uni-easyinput placeholder="请输入用户昵称" v-model="formData.nickname" trim="both" />
			</uni-forms-item>
13 14
			<uni-forms-item name="password" label="密码" v-model="formData.password" required>
				<uni-easyinput placeholder="请输入6-20位密码" type="password" v-model="formData.password" trim="both" />
芊里 已提交
15 16 17 18
			</uni-forms-item>
			<uni-forms-item name="pwd2" label="确认密码" v-model="formData.pwd2" required>
				<uni-easyinput placeholder="再次输入密码" type="password" v-model="formData.pwd2" trim="both" />
			</uni-forms-item>
芊里 已提交
19 20 21 22 23 24 25
			<view class="uni-button-group">
				<button type="primary" class="uni-button" @click="submit">注册</button>
			</view>
		</uni-forms>
	</view>
</template>

26 27 28 29 30
<script>
import rules from './validator.js';
import mixin from '../../common/loginPage.mixin.js';
	export default {
		mixins:[mixin],
芊里 已提交
31 32 33 34 35
		data() {
			return {
				formData: {
					"username": "",
					"gender": 0,
芊里 已提交
36
					"nickname": "",
37 38
					'password':'123456',
					'pwd2':'123456'
芊里 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
				},
				formOptions: {
					"gender_localdata": [{
							"text": "未知",
							"value": 0
						}, {
							"text": "",
							"value": 1
						},
						{
							"text": "",
							"value": 2
						}
					]
				},
54
				rules
芊里 已提交
55 56 57 58 59 60 61 62 63
			}
		},
		onReady() {
			this.$refs.form.setRules(this.rules)
		},
		methods: {
			/**
			 * 触发表单提交
			 */
芊里 已提交
64
			submit() {
芊里 已提交
65 66 67
				uni.showLoading({
					mask: true
				})
68
				this.$refs.form.submit().then((res) => {
芊里 已提交
69 70 71 72 73 74 75 76 77
						this.submitForm(res)
					}).catch((errors) => {
						console.log(errors);
					})
					.finally(() => {
						uni.hideLoading()
					})
			},
			submitForm(value) {
78 79 80 81 82 83
				this.request('user-center/register',value,(data,result)=>{
					console.log(result);
					if(result.code === 0){
						this.loginSuccess(result)
					}
				})
芊里 已提交
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
			}
		}
	}
</script>

<style>
	.uni-container {
		padding: 15px;
	}

	.uni-input-border,
	.uni-textarea-border {
		width: 100%;
		font-size: 14px;
		color: #666;
		border: 1px #e5e5e5 solid;
		border-radius: 5px;
		box-sizing: border-box;
	}

	.uni-input-border {
		padding: 0 10px;
		height: 35px;

	}

	.uni-textarea-border {
		padding: 10px;
		height: 80px;
	}

	.uni-button-group {
		margin-top: 50px;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.uni-button {
		width: 184px;
		padding: 12px 20px;
		font-size: 14px;
		border-radius: 4px;
		line-height: 1;
		margin: 0;
	}

	.avatar-box {
		width: 700rpx;
		height: 200rpx;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		justify-content: center;
		align-items: center;
	}

	.avatar-img {
		width: 150rpx;
		height: 150rpx;
		border-radius: 75rpx;
		border: #F8F8F8 solid 3px;
	}
</style>