login.vue 5.0 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
		<view>
			<text class="rgst" @click="goBack(1,'/pages/login/register')">注册账号</text>
			<text class="fbpw" @click="goBack(2,'/pages/login/find')">找回密码</text>
		</view>
Y
..  
yyt 已提交
24 25 26 27 28 29 30 31 32
	</view>
</template>

<script>
	export default {
		name: 'login',
		components: {},
		data() {
			return {
33
				sceenHeight: getApp().globalData.sceenHeight,
Y
yyt 已提交
34
				formData: {
Y
..  
yyt 已提交
35 36 37
					phone: '',
					password: ''
				},
Y
yyt 已提交
38 39 40 41 42 43 44
				loginRules: {
					phone: {
						rules: [{
							required: true,
							errorMessage: '请输入手机号'
						}, {
							validateFunction: function(rule, value, data, callback) {
45 46 47
								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 已提交
48
								} else {
49
									callback('请输入正确的手机号')
Y
yyt 已提交
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
								}
							}
						}]
					},
					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 已提交
68 69 70 71
				}
			}
		},
		methods: {
Y
yyt 已提交
72
			login(validateForm) {
73 74 75
				this.$refs[validateForm].validate(valid => {
					if (!valid) {
						uniCloud.callFunction({
Y
yyt 已提交
76 77 78 79 80 81 82 83 84
							name: 'fe-login',
							data: {
								phone: this.formData.phone,
								password: this.formData.password
							}
						}).then(res => {
							if (res.result.code === 200) {
								uniCloud.callFunction({
									name: 'uni-cloud-push',
Y
yyt 已提交
85
									data: {
Y
yyt 已提交
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
										uid: res.result.data.userId,
										cid: getApp().globalData.push_clientid
									}
								})
								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
								getApp().globalData.school = res.result.data.school
								getApp().globalData.moblie = res.result.data.phone_num
								getApp().globalData.gender = res.result.data.gender
								getApp().globalData.teamNameStorageCount = 1
								getApp().globalData.runningRecordStorageCount = 1
								getApp().globalData.walkingRecordStorageCount = 1
								uni.setStorageSync('token', '用户登录状态')
								uni.setStorageSync('userId', res.result.data.userId)
								uni.setStorageSync('name', res.result.data.name)
								uni.setStorageSync('type', res.result.data.type)
								uni.setStorageSync('icon', res.result.data.icon)
								uni.setStorageSync('school', res.result.data.school)
								uni.setStorageSync('moblie', res.result.data.phone_num)
								uni.setStorageSync('gender', res.result.data.gender)
								uni.setStorageSync('teamNameStorageCount', 1)
								uni.setStorageSync('runningRecordStorageCount', 1)
								uni.setStorageSync('walkingRecordStorageCount', 1)
								console.log(res)
								uni.showToast({
									title: '登录成功',
									icon: 'success'
								})
								uni.reLaunch({
									url: '/pages/sport/main',
									animationType: 'pop-in',
									animationDuration: 300
								})
							} else {
								uni.showToast({
									title: '账号或密码错误',
									icon: 'error'
								})
							}
						});
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
					}
				})
			},
			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 已提交
146
			}
147
		}
Y
..  
yyt 已提交
148 149 150 151 152
	}
</script>

<style>
	.content {
153
		background-color: #edeef0;
Y
..  
yyt 已提交
154 155
		display: flex;
		align-items: center;
156
		flex-direction: column;
Y
..  
yyt 已提交
157
		justify-content: center;
158 159 160
		position: absolute;
		width: 100%;
		height: 100%;
Y
..  
yyt 已提交
161 162 163 164 165 166 167
	}

	.logo {
		height: 480rpx;
		width: 500rpx;
		margin-left: auto;
		margin-right: auto;
168
		margin-bottom: 70rpx;
Y
..  
yyt 已提交
169 170 171 172 173 174
	}

	.text-area {
		display: flex;
		justify-content: center;
	}
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196

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