login.vue
3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
75
76
77
78
79
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
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
148
149
150
151
152
<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: ''
}
},
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: '登录成功'
})
uni.setStorageSync('userInfo', res.data)
uni.setStorageSync('Authorization', res.data.token)
let authURL = 'http://ranqi-admin.t.brotop.cn/api/index/auth?token=' + uni
.getStorageSync('Authorization') + '&url=/#/pages/index/index'
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>