// pages/login/logn.js import { loginRequest } from '../../utils/network.js' // md5 password加密 const app = getApp() Page({ /** * 页面的初始数据 */ data: { // userName: 'admin', // psw: 'admin123', userName: 'wumei-t1', psw: '123456', codeNum: '', loginImg: '/images/login.png', uuid: '', imgSrc: '' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // if (wx.getStorageSync('user')) { // app.setUser(wx.getStorageSync('user')) // wx.switchTab({ // url: '/pages/home/home', // }) // } // this.getImg() }, // 绑定用户名 bindUserName(e) { this.setData({ userName: e.detail.value }) }, // 绑定密码 bindPSW(e) { console.log(e); this.setData({ psw: e.detail.value }) }, // 验证码 bindCodeNum(e) { console.log(e); this.setData({ codeNum: e.detail.value }) console.log(this.data.codeNum); }, getProfile() { wx.request({ url: 'https://puyue.yhupai.com/prod-api/system/user/profile', method: "GET", header: { "Access-Control-Allow-Headers": 'token', Authorization: `Bearer ${wx.getStorageSync('token')}` }, success: (res, header) => { if (res.data.code != 200) { wx.showToast({ title: res.data.msg, icon: 'none' }); } else { wx.setStorageSync('userInfo', res.data.data) } } }) }, getInfo() { wx.request({ url: 'https://puyue.yhupai.com/prod-api/getInfo', method: "GET", header: { "Access-Control-Allow-Headers": 'token', Authorization: `Bearer ${wx.getStorageSync('token')}` }, success: (res, header) => { if (res.data.code != 200) { wx.showToast({ title: res.data.msg, icon: 'none' }); } else { // let data = JSON.parse(JSON.stringify(res.data)) // let erectoId = data.user.userId console.log(res.data.user.userId); wx.setStorageSync('userInfo', res.data) wx.setStorageSync('roleKey', res.data.user.roles[0].roleKey) wx.setStorageSync('deptId', res.data.user.dept.deptId) wx.setStorageSync('erectoId', res.data.user.userId) // console.log(wx.getStorageInfoSync('erectoId')); } } }) }, // 登录 login() { console.log(this.data); wx.showLoading({ title: '登录中', }) loginRequest(this.data.userName, this.data.psw, this.data.codeNum, this.data.uuid).then(res => { console.log(res); if (res.data.code != 200) { wx.showToast({ title: res.data.msg, icon: "none" }) this.getImg() } else { wx.setStorageSync('token', res.data.token) wx.showToast({ title: '登录成功!', icon: 'none' }); this.getInfo() app.setUser(res.data) wx.hideLoading({ success: (res) => { wx.switchTab({ url: '/pages/home/home', }) }, }) } }).catch(() => { }) }, //忘记密码 goForgot() { wx.navigateTo({ url: '/pages/forgot/forgot' }) }, //忘记密码 goReg() { wx.navigateTo({ url: '/pages/reg/reg' }) }, // 验证码 getImg() { this.setData({ imgSrc: "", uuid: "", codeNum: '' }) wx.request({ url: `https://puyue.yhupai.com/prod-api/captchaImage`, method: 'GET', // header: { // "Access-Control-Allow-Headers": 'token' // }, dataType: 'json', success: (res, header) => { // console.log(res); if (res.data.code != 200) { wx.showToast({ title: res.data.msg, icon: 'none' }); } else { this.setData({ imgSrc: "data:image/gif;base64," + res.data.img, uuid: res.data.uuid }) console.log(this.data.imgSrc) // this.imgSrc = "data:image/gif;base64," + res.data.img // this.login.uuid = res.data.uuid // console.log(this.imgSrc); } }, }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { this.getImg() }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })