163 lines
3.6 KiB
JavaScript
Raw Normal View History

2021-11-01 15:45:38 +08:00
//index.js
const app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
no: '',
pwd: '',
code: '',
img: '',
uuid: '',
},
formSubmit: function(e) {
wx.showLoading({
title: '登录中...',
})
//获取token
wx.request({
url: 'https://api.mpecloud.cn/auth/oauth/token?username='+e.detail.value.no+'&password='+e.detail.value.pwd+'&code=' + e.detail.value.yzm + '&uuid=' + this.data.uuid + '&client_id=wxx&client_secret=hsgz@1q2w&grant_type=password&scope=server',
// url: 'https://api.mpecloud.cn/auth/oauth/token?username=Jason&password=13579246&code=' + e.detail.value.yzm + '&uuid=' + this.data.uuid + '&client_id=wxx&client_secret=hsgz@1q2w&grant_type=password&scope=server',
header: {
'content-type': 'application/json'
},
success: res => {
app.globalData.token = res.data.access_token; //修改全局变量-token
app.globalData.userid = e.detail.value.no; //修改全局变量-用户id
app.globalData.password=e.detail.value.pwd;//修改全局变量-用户密码
console.log('userid是'+app.globalData.userid)
console.log('pwd是'+app.globalData.password)
console.log('token是'+app.globalData.token)
if(res.data.code==500)
{
wx.showToast({
title: '账号密码或者验证码错误,请重新输入!',
icon: 'none',
duration: 2000
})
}
else{
//跳转到设备页面
wx.switchTab({
url: '../homefree/homefree'
})
}
},
fail: function() {
wx.showToast({
title: '无法获取Token',
icon: 'none',
duration: 2000
})
}
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {
wx.request({
url: 'https://api.mpecloud.cn/code',
header: {
'content-type': 'application/json'
},
success: res => {
console.log(res.data)
this.setData({
img: res.data.img,
uuid: res.data.uuid,
})
},
fail: function() {
wx.showToast({
title: '无法获取验证码!',
icon: 'none',
duration: 2000
})
}
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function() {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function() {
},
REFreshClick:function (){
wx.request({
url: 'https://api.mpecloud.cn/code',
header: {
'content-type': 'application/json'
},
success: res => {
console.log(res.data)
this.setData({
img: res.data.img,
uuid: res.data.uuid,
})
},
fail: function() {
wx.showToast({
title: '无法获取验证码!',
icon: 'none',
duration: 2000
})
}
})
},
registerClick:function(e){
var that = this;
//跳转到注册页面
wx.redirectTo({
url: '../Register/Register',
})
},
})