login.vue 3.7 KB
Newer Older
Y
..  
yyt 已提交
1 2 3 4
<template>
	<view class="content">
		<image class="logo" src="/static/login/login.png"></image>
		<view class="text-area">
5 6
			<uni-forms :modelValue="formData" :rules="loginRules" ref="form" validate-trigger="bind"
				err-show-type="undertext">
Y
yyt 已提交
7 8 9 10 11
				<uni-forms-item name="phone" required label="手机号">
					<uni-easyinput type="text" :inputBorder="true" v-model="formData.phone"
						placeholder="请输入手机号"></uni-easyinput>
				</uni-forms-item>
				<uni-forms-item name="password" required label="密码">
12 13
					<uni-easyinput type="password" :inputBorder="true" v-model="formData.password"
						placeholder="请输入密码"></uni-easyinput>
Y
yyt 已提交
14 15
				</uni-forms-item>
				<uni-forms-item>
16
					<button class="loginButton" @click="login('form')">登录</button>
Y
yyt 已提交
17 18
				</uni-forms-item>
			</uni-forms>
Y
..  
yyt 已提交
19
		</view>
20 21 22 23 24
		<view>
			<text class="rgst" @click="goBack(1,'/pages/login/register')">注册账号</text>
			<text class="fbpw" @click="goBack(2,'/pages/login/find')">找回密码</text>
		</view>

Y
..  
yyt 已提交
25 26 27 28 29 30 31 32 33
	</view>
</template>

<script>
	export default {
		name: 'login',
		components: {},
		data() {
			return {
34
				sceenHeight: getApp().globalData.sceenHeight,
Y
yyt 已提交
35
				formData: {
Y
..  
yyt 已提交
36 37 38
					phone: '',
					password: ''
				},
Y
yyt 已提交
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
				loginRules: {
					phone: {
						rules: [{
							required: true,
							errorMessage: '请输入手机号'
						}, {
							validateFunction: function(rule, value, data, callback) {
								if (value === '') {
									callback(new Error('手机号不能为空'))
								} else {
									const reg = /^1[3|4|5|7|8][0-9]\d{8}$/
									const reg2 = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/
									if ((reg.test(value) || reg2.test(value))) {
										this.yzmshow = true
										callback()
									} else {
										callback(new Error('请输入正确的手机号'))
									}
								}
							}
						}]
					},
					password: {
						rules: [{
							required: true,
							errorMessage: '请输入密码'
						}, {
							validateFunction: function(rule, value, data, callback) {
								if (value.length > 20 || value.length < 8) {
									callback('密码长度在8-20位!')
								} else {
									callback();
								}
							}
						}]
					},
Y
..  
yyt 已提交
75 76 77 78
				}
			}
		},
		methods: {
Y
yyt 已提交
79
			login(validateForm) {
80 81 82 83 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
				this.$refs[validateForm].validate(valid => {
					if (!valid) {
						uniCloud.callFunction({
								name: 'auth',
								data: {
									phone: this.formData.phone,
									password: this.formData.password
								}
							})
							.then(res => {
								console.log(res);
							});

					}
				})
			},
			goBack(index, url) {
				if (index == 1) {
					// 关闭所有页面,打开到应用内的某个页面。
					uni.reLaunch({
						url: url,
						animationType: 'pop-in',
						animationDuration: 300
					})
				}
				if (index == 2) {
					// 关闭所有页面,打开到应用内的某个页面。
					uni.reLaunch({
						url: url,
						animationType: 'pop-in',
						animationDuration: 300
					})
				}
Y
..  
yyt 已提交
113
			}
Y
yyt 已提交
114
		},
115 116 117 118 119 120 121 122
		change(e) {
			console.log('e:', e);
		},
		onLoad() {
			this.sceenHeight = uni.getSystemInfoSync().windowHeight
			console.log(this.sceenHeight)
		},

Y
..  
yyt 已提交
123 124 125 126 127
	}
</script>

<style>
	.content {
128
		background-color: #edeef0;
Y
..  
yyt 已提交
129 130
		display: flex;
		align-items: center;
131
		flex-direction: column;
Y
..  
yyt 已提交
132
		justify-content: center;
133 134 135
		position: absolute;
		width: 100%;
		height: 100%;
Y
..  
yyt 已提交
136 137 138 139 140 141 142
	}

	.logo {
		height: 480rpx;
		width: 500rpx;
		margin-left: auto;
		margin-right: auto;
143
		margin-bottom: 70rpx;
Y
..  
yyt 已提交
144 145 146 147 148 149
	}

	.text-area {
		display: flex;
		justify-content: center;
	}
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173

	.loginButton {
		background-color: #f1992d;
		color: #fff;
		border: 0;
		border-radius: 20px;
	}

	.loginButton::after {
		border: 0;
	}



	.rgst {
		color: #f1992d;
		display: inline-block;
	}

	.fbpw {
		color: #f1992d;
		display: inline-block;
		margin-left: 90px;
	}
Y
..  
yyt 已提交
174
</style>