// pages/login/logn.js import { loginRequest } from '../../utils/network.js' // md5 password加密 import { hexMD5 } from "../../utils/md5.js" const app = getApp() Page({ /** * 页面的初始数据 */ data: { userName: 'sdlys', 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); }, // 登录 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" }) } else { wx.setStorageSync('token', res.data.token) wx.showToast({ title: '登录成功!', icon: 'none' }); // // console.log(res); // this.$store.dispatch('setUserData', { // 'token': res.data.token // }); // uni.setStorageSync('token', res.data.token) // uni.setStorageSync('userName', this.login.phoneNumber) // this.$Router.pushTab({ // path: '/pages/home/index', // }); app.setUser(res.data) wx.hideLoading({ success: (res) => { wx.switchTab({ url: '/pages/home/home', }) }, }) // if (res.statusCode == 200) { // app.setUser(res.data.Data) // wx.hideLoading({ // success: (res) => { // wx.switchTab({ // url: '/pages/home/home', // }) // }, // }) // } else { // wx.showToast({ // title: '请检查您的网络设置', // icon: "none" // }) // } } }).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 }) // this.imgSrc = "data:image/gif;base64," + res.data.img // this.login.uuid = res.data.uuid // console.log(this.imgSrc); } }, }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })