133 lines
2.5 KiB
JavaScript
133 lines
2.5 KiB
JavaScript
|
import {
|
||
|
getToken,
|
||
|
setToken
|
||
|
} from '../../utils/auth'
|
||
|
import {
|
||
|
login,
|
||
|
getCodeImg,
|
||
|
refreshUser,
|
||
|
} from '../../api/login'
|
||
|
|
||
|
const app = getApp();
|
||
|
Page({
|
||
|
|
||
|
/**
|
||
|
* 页面的初始数据
|
||
|
*/
|
||
|
data: {
|
||
|
username: '',
|
||
|
password: '',
|
||
|
code: '',
|
||
|
uuid: '',
|
||
|
codeUrl: '',
|
||
|
show: false,
|
||
|
checked: true
|
||
|
},
|
||
|
|
||
|
//获取填写的账号信息
|
||
|
name: function (even) {
|
||
|
this.setData({
|
||
|
username: even.detail.value
|
||
|
})
|
||
|
},
|
||
|
//获取填写的密码信息
|
||
|
psw: function (even) {
|
||
|
this.setData({
|
||
|
password: even.detail.value
|
||
|
})
|
||
|
},
|
||
|
//获取填写的密码信息
|
||
|
code: function (even) {
|
||
|
this.setData({
|
||
|
code: even.detail.value
|
||
|
})
|
||
|
},
|
||
|
|
||
|
onClickShow() {
|
||
|
this.setData({
|
||
|
show: true
|
||
|
});
|
||
|
},
|
||
|
|
||
|
onClickHide() {
|
||
|
this.setData({
|
||
|
show: false
|
||
|
});
|
||
|
},
|
||
|
|
||
|
onLoad: function (option) {
|
||
|
if (getToken()) {
|
||
|
console.log("Authorization...{}", getToken());
|
||
|
//刷新权限信息
|
||
|
refreshUser().then(res => {
|
||
|
if (res.code == '200') {
|
||
|
wx.redirectTo({
|
||
|
url: '../index/index',
|
||
|
})
|
||
|
} else {
|
||
|
that.loadCodeImage();
|
||
|
}
|
||
|
});
|
||
|
} else {
|
||
|
console.log("未查询到Token...{}...准备重新登录")
|
||
|
this.loadCodeImage();
|
||
|
}
|
||
|
},
|
||
|
|
||
|
loadCodeImage: function () {
|
||
|
getCodeImg().then(res => {
|
||
|
let captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
|
||
|
if (captchaEnabled) {
|
||
|
this.setData({
|
||
|
codeUrl: 'data:image/gif;base64,' + res.img,
|
||
|
uuid: res.uuid
|
||
|
})
|
||
|
}
|
||
|
});
|
||
|
},
|
||
|
|
||
|
//登录
|
||
|
userLogin: function () {
|
||
|
var username = this.data.username;
|
||
|
var password = this.data.password;
|
||
|
var code = this.data.code;
|
||
|
if (username == "") {
|
||
|
app.toast("登录账号不能为空");
|
||
|
return;
|
||
|
}
|
||
|
if (password == "") {
|
||
|
app.toast("登录密码不能为空");
|
||
|
return;
|
||
|
}
|
||
|
if (code == "") {
|
||
|
app.toast("验证码不能为空");
|
||
|
return;
|
||
|
}
|
||
|
//启动蒙版
|
||
|
//this.onClickShow();
|
||
|
let that = this;
|
||
|
//发送请求
|
||
|
login({
|
||
|
"username": username,
|
||
|
"password": password,
|
||
|
"code": code,
|
||
|
"uuid": that.data.uuid,
|
||
|
}).then(res => {
|
||
|
if (res.code == '200') {
|
||
|
setToken(res.token)
|
||
|
//跳转页面
|
||
|
wx.redirectTo({
|
||
|
url: '../index/index',
|
||
|
})
|
||
|
} else {
|
||
|
that.loadCodeImage();
|
||
|
}
|
||
|
});
|
||
|
},
|
||
|
|
||
|
getPhoneNumber(e) {
|
||
|
var_this = this
|
||
|
console.log("getPhoneNumber", e)
|
||
|
},
|
||
|
|
||
|
})
|