codeLogin_frm.html
6.38 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
<title>验证码登录</title>
<link rel="stylesheet" type="text/css" href="../../css/api.css"/>
<link rel="stylesheet" type="text/css" href="../../css/aui.css"/>
<link rel="stylesheet" type="text/css" href="../../css/style.css"/>
<link rel="stylesheet" type="text/css" href="../../css/login/codeLogin.css"/>
<style>
html,
body{
background-color: #F4F6F9;
}
</style>
</head>
<body>
<div class="form-panel">
<div class="aui-list" style="border-radius:16px;">
<div class="aui-list-item" style="border-bottom: none;background-size: 100% 0px;margin-top:-0.5rem;">
<div class="aui-list-item-left">
<img src="../../image/login_icon_pohone.png" style="height:24px;width:24px;margin-top:-0.1rem;"/>
</div>
<div class="aui-list-item-center">
<input id="login_phone" class="aui-input input-style-normal" type="tel" placeholder="+86 | 请输入手机号" style="height:3.3rem;border-bottom:1px solid #F0F5FF;margin-right:15px;">
</div>
</div>
<div class="aui-list-item" style="margin-top:-1rem;margin-bottom:-1rem;">
<div class="aui-list-item-left">
<img src="../../image/login_icon_captcha.png" style="height:24px;width:24px;margin-top:-0.1rem;"/>
</div>
<div class="aui-list-item-center">
<input id="login_code" class="aui-input input-style-normal" type="text" placeholder="手机验证码" style="height:3.3rem;border-bottom:1px solid #F0F5FF;">
</div>
<div class="aui-list-item-right">
<div class="aui-btn send-code-btn code-btn-disable" tapmode onclick="sendCode();"><span id='sms-text'>获取验证码</span></div>
</div>
</div>
</div>
</div>
<div style="margin-left:15px;margin-right:15px;margin-top:15px;" ontouchstart="">
<span onclick="login();" id="loginBtn" class="login-btn">登录</span>
</div>
<div style="margin-left:15px;margin-right:15px;margin-top:20px;text-align:center;">
<span style="font-size:14px;color:#37394E;font-family:PingFang SC;font-weight:500;">使用其它登录方式</span>
</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">
var cooldown = 0;
var cid;
apiready = function(){
api.parseTapmode();
};
function sendCode() {
var login_phone_dom = $api.byId("login_phone");
login_phone_dom.blur();
var login_phone = $api.trim($api.val($api.byId("login_phone")));
if (!checkPhone(login_phone)) {
api.toast({
msg: "请输入正确的手机号"
});
return;
}
//发送验证码
api.ajax({
url: HOST+'/iot_api/v1/app/send_sms_need_phone_exist',
method: 'post',
headers: {
'Content-Type': 'application/json;charset=utf-8',
'imei': api.deviceId
},
data: {
body: {
phone: login_phone
}
}
}, function(ret, err) {
if (ret) {
if (ret.code == 0) {
api.toast({
msg: '验证码发送成功!',
duration: 2000,
location: 'bottom'
});
cid = ret.data.cid;
cooldown = 60;
Cooldown();
} else {
api.toast({
msg: "发送失败," + ajaxCodeCheck(ret.code, ret.msg,"")
});
}
} else {
api.toast({
msg: "发送失败,请稍候再试"
});
}
});
}
function Cooldown() {
var obj = $api.byId("sms-text");
$api.html(obj, cooldown+'s后重发');
if (cooldown <=0) {
$api.html(obj, '发送验证码');
}else {
cooldown = cooldown-1;
window.setTimeout('Cooldown()',1000);
}
}
function login() {
var phone_input = $api.byId('login_phone');
var code_input = $api.byId('login_code');
phone_input.blur();
code_input.blur();
var login_phone = $api.trim($api.val($api.byId("login_phone")));
var login_code = $api.trim($api.val($api.byId("login_code")));
if (!checkPhone(login_phone)) {
api.toast({
msg: "请输入正确的手机号"
});
return;
}
api.showProgress({
style: 'default',
animationType: 'zoom',
modal: true
});
api.ajax({
url: HOST+'/iot_api/v1/app/sms_login',
method: 'post',
headers: {
'Content-Type': 'application/json;charset=utf-8',
'imei': api.deviceId
},
data: {
body: {
phone: login_phone,
cid: cid,
code: login_code
}
}
}, function(ret, err) {
api.hideProgress();
if (ret.code == 0) {
$api.clearStorage();
api.toast({
msg: '登陆成功',
duration: 2000,
location: 'bottom'
});
var now = new Date();
$api.setStorage('login_time', now.getTime());
$api.setStorage('userToken', ret.data.token);
api.ajax({
url: HOST + '/iot_api/v1/app/user',
method: 'get',
headers: {
'Content-Type': 'application/json;charset=utf-8',
'token': ret.data.token
},
}, function(rett, err) {
if (rett) {
if (rett.code == 0 && rett.data.user) {
var user = rett.data.user;
$api.setStorage('userName', user.name);
$api.setStorage('userPhone', user.user);
$api.setStorage('userID', user.id);
api.sendEvent({
name: 'cleanLoginPage',
});
}
}
});
}else {
api.toast({
msg: "登陆失败," + ajaxCodeCheck(ret.code, ret.msg, '请稍后再试')
});
}
});
}
</script>
</html>