index.js
6.67 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
193
194
195
import React, { Component } from 'react'
import { connect } from 'dva'
import styles from './Login.css'
import $ from 'jquery';
import { Toast } from 'antd-mobile';
import shareHide from "../../utils/shareHide";
class Login extends Component {
constructor(props){
super(props)
this.state={
authenticationFailure:false,
num :1,
verificationCode:'',
mobile:'',
send:false,
second:60,
message:'' ,
submit:{},
userOpenId:'',
publicOpenId:''
}
}
history = ()=>{
let that = this;
let mobile = this.state.mobile;
let verificationCode = this.state.verificationCode;
if(!mobile){
this.showToast('请输入正确的手机号!')
return false;
}
if(!verificationCode){
this.showToast('请输入正确的验证码!')
return false;
}
$.ajax({
//几个参数需要注意一下
type: "POST",//方法类型
url: "https://zmt.ihxlife.com/o2o/authentication/mobile" ,//url
contentType: "application/x-www-form-urlencoded",
headers: {
'deviceId':this.state.userOpenId, //微信号 userOpenId
'gzhId':this.state.publicOpenId, //公众号 publicOpenId
Authorization:"Basic ZWR3aW5DbGllbnQ6ZWR3aW5TZWNyZXQ="
},
data: {"mobile":mobile ,"smsCode":verificationCode},
success: function (result) {
let userInfo = result.userInfo
let storage = window.localStorage;
storage.setItem("id",userInfo.id) //id
storage.setItem("roleId",userInfo.roleId) //角色
storage.setItem("number",userInfo.number) //手机号
storage.setItem("name",userInfo.name) //名字
storage.setItem("public_id",userInfo.public_id) //公众号
storage.setItem("weixin_id",userInfo.weixin_id) //微信号
storage.setItem("superiorid",userInfo.superiorid) //角色
storage.setItem("orgId", userInfo.orgId ? userInfo.orgId : '') //机构id
storage.setItem("project", userInfo.project ? userInfo.project:'') //项目id
storage.setItem("website", userInfo.website ? userInfo.website:'') //网点id
that.props.history.push('/welcome');
},
error : function(result) {
// console.log(result.responseJSON.content);
that.showToast('您所填写验证码错误,请重新验证')
}
});
}
showToast=(val)=>{
Toast.info(val);
}
componentWillUnmount() {
$('body,#root').removeClass('loginRelease');
}
componentDidMount() {
shareHide();
$(document).on('blur', 'input,textarea', function () {
document.activeElement.scrollIntoView();
})
$('body,#root').addClass('loginRelease');
let storage = window.localStorage;
storage.setItem("id",'') //id
storage.setItem("roleId",'') //角色
storage.setItem("number",'') //手机号
storage.setItem("name",'') //名字
storage.setItem("public_id",'') //公众号
storage.setItem("weixin_id",'') //微信号
storage.setItem("superiorid",'') //角色
let url = window.location.href;
const matchs = decodeURI(url).match(/userOpenId=(.*)&publicOpenId=(.*)/i);
if(matchs){
let userOpenId = matchs[1];
let publicOpenId = matchs[2];
this.setState({
userOpenId,
publicOpenId
})
}
}
render() {
return (
<div className={styles.box}>
<div className={styles.logo}>
<img src={require('../../assets/image/home-logo.png')} alt=""/>
</div>
<div className={styles.phone}>
<img src={require('../../assets/image/home-shadow.png')} alt=""/>
<input type="number" placeholder="输入手机号码"
value={this.state.mobile}
onChange={
(e)=>{
this.setState({
mobile:e.target.value.substr(0,11)
})
let storage = window.localStorage;
storage.setItem("mobile",e.target.value)
}
}/>
{
!this.state.send && <span onClick={()=>{
let mobile = this.state.mobile;
let that = this;
if(mobile.length !== 11){
this.showToast('请填写正确的手机号!')
return false
}
that.props.dispatch({
type:'login/checkUser',
payload:{
"number": mobile
},
callback(){
$.ajax({url:"https://zmt.ihxlife.com/o2o/code/sms?mobile="+ mobile,
type : "get",
headers:{"deviceId": that.state.userOpenId},
success:function(result){
that.showToast('验证码已发送,请注意查收!')
that.setState({
send:true,
})
let t1 = window.setInterval(function () {
that.setState({
second:that.state.second-1
})
if(that.state.second ===0 ){
window.clearInterval(t1);
that.setState({
send:false,
second:60
})
}
},1000)
}});
},
error(date){
that.showToast(date.message)
}
})
}}>获取验证码</span>
}
{
this.state.send &&<span >{this.state.second}秒</span>
}
</div>
<div className={styles.verification}>
<img src={require('../../assets/image/home-shadow.png')} alt="">
</img>
<input type="text" placeholder="输入验证码" onChange={(e)=>{
this.setState({
verificationCode:e.target.value,
})
}}/>
</div>
<div className={styles.approve} onClick={this.history}>
<img src={require('../../assets/image/home-approve.png')} alt=""/>
</div>
<div className={styles.bottom}><p>该平台仅供内部员工注册使用</p></div>
{this.state.authenticationFailure &&<div className={styles.pop}>
<div className={styles.up}>
<p>认证失败</p>
<p>该平台仅供内部员工注册使用!</p>
<div className={styles.button}>
<span>取消</span>
<span>确定</span>
</div>
</div>
</div>}
</div>
)
}
}
export default connect(({ login }) => ({ login }))(Login);