result-login.vue 3.6 KB
<template>
	<view class="content">
		
		<image src="../../static/ic_5@2x.png" style="width: 100%;height: 100vh;" mode=""></image>
		<view class="title">
			<view class="inputC">
				<input type="text" value="" placeholder="请输入身份证号" @input="HaveCard" @blur="cardBlur" />
			</view>
			<view class="inputC">
				<input type="text" value="" placeholder="请输入密码(默认身份证后8位)" @input="HavePass" password="true" />
			</view>
			<view class="okBox" @click="login">
				<text class="ok">确认</text>
			</view>
		</view>
	</view>
</template>

<script>
	import request from '../../utils/request.js'
	export default {
		data() {
			return {
				ajaxTrue: false, //校验身份证
				card: '',	
				password: ''
			}
		},
		onLoad() {
			uni.removeStorageSync('Authorization')
		},
		methods: {
			//密码
			HavePass(e) {
				this.card = e.detail.value
			},
			//身份信息
			HaveCard(e) {
				this.password = e.detail.value
			},
			//校验身份证
			cardBlur() {
				this.ajaxTrue = this.checkIDCard(this.password)
				if (!this.ajaxTrue) {
					uni.showToast({
						title: '请输入正确的身份证号码',
						icon: 'none'
					})
				}
			},
			//校验身份证号
			checkIDCard(idcode) {
				var weight_factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
				var check_code = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
				var code = idcode + "";
				var last = idcode[17]; //最后一位
				var seventeen = code.substring(0, 17);
				var arr = seventeen.split("");
				var len = arr.length;
				var num = 0;
				for (var i = 0; i < len; i++) {
					num = num + arr[i] * weight_factor[i];
				}
				// 获取余数
				var resisue = num % 11;
				var last_no = check_code[resisue];
				var idcard_patter =
					/^[1-9][0-9]{5}([1][9][0-9]{2}|[2][0][0|1][0-9])([0][1-9]|[1][0|1|2])([0][1-9]|[1|2][0-9]|[3][0|1])[0-9]{3}([0-9]|[X])$/;
				// 判断格式是否正确
				var format = idcard_patter.test(idcode);
				// 返回验证结果,校验码和格式同时正确才算是合法的身份证号码
				return last === last_no && format ? true : false;
			},
			//登录
			login() {
				if (!this.ajaxTrue) {
					uni.showToast({
						title: '请输入正确的身份证号码',
						icon: 'none'
					})
				} else {
					request.post('/api/index/login', {
						card: this.password,
						password: this.card
					}).then(res => {
						if (res.code == 1) {
							wx.showToast({
								title: '登录成功'
							})
							console.log(res.data,'data')
							uni.setStorageSync('userInfo', res.data)
							uni.setStorageSync('Authorization', res.data.token)
							let authURL = 'http://ranqi-admin.t.brotop.cn/api/index/auth?token=' + res.data.token + '&url=/pages/index/userJoin'
							console.log(uni.getStorageSync('token'),'token')
							window.location.href = authURL;

						}else{
							wx.showToast({
								title: '用户名或密码错误',
								icon: 'none'
							})
						}
					}).catch(err => {
					
					})
				}


			}
		}
	}
</script>

<style>
	.inputC {
		background: #ffffff;
		border: 1px solid #646566;
		border-radius: 9px;
		height: 52px;
		margin: 0 47px 26px 47px;
		display: flex;
		align-items: center;
		padding: 0 16px;
	}

	input {
		width: 500rpx;
	}

	.okBox {
		background: #1d4582;
		border-radius: 16rpx;
		height: 104rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 0 47px;

	}

	.ok {
		color: #FFFFFF;
		font-size: 36rpx;
	}

	.title {
		position: absolute;
		width: 100%;
		top: 250px;
	}

	.content {
		position: relative;
		height: 100%;
		overflow: hidden;
	}
</style>