login.vue 3.9 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
				loginRules: {
					phone: {
						rules: [{
							required: true,
							errorMessage: '请输入手机号'
						}, {
							validateFunction: function(rule, value, data, callback) {
46 47 48
								const reg = /^(13[0-9]|14[0-9]|15[0-9]|166|17[0-9]|18[0-9]|19[8|9])\d{8}$/
								if (reg.test(value)) {
									callback()
Y
yyt 已提交
49
								} else {
50
									callback('请输入正确的手机号')
Y
yyt 已提交
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
								}
							}
						}]
					},
					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 已提交
69 70 71 72
				}
			}
		},
		methods: {
Y
yyt 已提交
73
			login(validateForm) {
74 75 76
				this.$refs[validateForm].validate(valid => {
					if (!valid) {
						uniCloud.callFunction({
77
								name: 'fe-login',
78 79 80 81 82 83
								data: {
									phone: this.formData.phone,
									password: this.formData.password
								}
							})
							.then(res => {
84
								if(res.result.code===200){
R
Renic1 已提交
85 86 87 88 89 90
									getApp().globalData.userId=res.result.data.userId
									getApp().globalData.name=res.result.data.name
									getApp().globalData.type=res.result.data.type
									getApp().globalData.icon=res.result.data.icon
									console.log(res)
									console.log(getApp().globalData.type)
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
									uni.showToast({
										title: '登录成功',
										icon: 'success'
									})
									uni.reLaunch({
										url: '/pages/sport/main',
										animationType: 'pop-in',
										animationDuration: 300
									})
								}else{
									uni.showToast({
										title: '账号或密码错误',
										icon: 'error'
									})
								}
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
							});

					}
				})
			},
			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 已提交
126
			}
127
		}
Y
..  
yyt 已提交
128 129 130 131 132
	}
</script>

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

	.logo {
		height: 480rpx;
		width: 500rpx;
		margin-left: auto;
		margin-right: auto;
148
		margin-bottom: 70rpx;
Y
..  
yyt 已提交
149 150 151 152 153 154
	}

	.text-area {
		display: flex;
		justify-content: center;
	}
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178

	.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 已提交
179
</style>