login.ts
3.78 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
// pages/login/login.ts
import { API_CONST } from "./../../api/smartElectric";
import { HTTPService as HTTP } from "./../../services/HTTPService";
Page({
/**
* 页面的初始数据
*/
data: {
logoUrl: "./../../img/qixiao.png",
checkFlag: true,
username: "15556367216",// 用户名
password: "efault",//密码
hideFlag: true,//是否隐藏
keyStr: "",// key值
imgUrl: "",//显示验证码的图片地址
codeKey: ""//验证码
},
/**
* 生命周期函数--监听页面加载
*/
onLoad() {
this.__getLoginSecurityImg()
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
},
getPhoneNumber(e: any) {
console.log(e, 'eeee---------eeeeee')
wx.switchTab({ url: "/pages/monitor/monitor" })
// console.log(e.detail.code) // 动态令牌
// console.log(e.detail.errMsg) // 回调信息(成功失败都会返回)
// console.log(e.detail.errno) // 错误码(失败时返回)
},
loginEvent(): any {
if (!this.data.username || !this.data.password) {
wx.showToast({
title: "请将信息填写完整",
icon: 'none',
duration: 2000
});
return false;
}
HTTP.POST({
...API_CONST.login.wxLogin,
payload: this.getLoginParams()
}).then((data: any) => {
console.log(data, '登录参数')
if (data.success) {
//登录请求回来之后,读取res的header的cookie
//cookie是个唯一标识
wx.setStorageSync("cookie", data.data)
wx.switchTab({
url: "/pages/monitor/monitor"
})
} else {
this.__getUserSecurityImg()
wx.showToast({
title: data.msg || '请求失败',
icon: 'error',
duration: 2000
});
}
})
},
userEvent(e: any) {
this.setData({
username: e.detail
})
},
passEvent(e: any) {
this.setData({
password: e.detail
})
},
getLoginParams() {
// 组织ID登录
return {
LOGIN_TYPE: 'CORP',
code: this.data.codeKey.replace(/(^\s*)|(\s*$)/g, ''), // 图片验证码
corpCode: "default",
username: this.data.username,
password: this.data.password,
key: this.data.keyStr,
autoLogin: false,
}
},
imgKeyEvent(e: any) {
this.setData({
codeKey: e.detail
})
},
changeIconEvent() {
this.setData({
checkFlag: !this.data.checkFlag
})
},
//登录时获取key值
__getLoginSecurityImg() {
HTTP.GET({
...API_CONST.login.loginSecurity,
payload: {
corpCode: "default"
}
}).then((res: any) => {
if (res.success) {
this.setData({
hideFlag: res.data.hide,//是否隐藏
keyStr: res.data.key,// key值
})
if (res.data.hide === false) {
this.__getUserSecurityImg()
}
}
})
},
//用户获取codekey
__getUserSecurityImg() {
HTTP.GET({
...API_CONST.login.userSecurity,
payload: {
corpCode: "default",
key: this.data.keyStr
}
}).then((res: any) => {
console.log(res, 'res------')
if (res.success) {
this.setData({
hideFlag: res.data.hide,//是否隐藏
keyStr: res.data.key,// key值
imgUrl: res.data.img
})
}
})
}
})