// pages/login/login.js const app=getApp(); Page({ /** * 页面的初始数据 */ data: { showEyes: false, form: { phone: "", password: '' }, phone: '' }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { const token = wx.getStorageSync('token') console.log(token); if (!token || token == '') { wx.setNavigationBarTitle({ title: '物流管家', }) }else{ wx.navigateTo({ url: '/pages/home/index', }) } }, onReady(){ }, close() { this.data.form.phone = '' this.setData({ phone: '' }) console.log(this.data.phone); }, inputValue1(e) { let { value } = e.detail this.data.form.phone = value this.setData({ phone: value }) console.log(this.data.phone); }, inputValue2(e) { let { value } = e.detail this.data.form.password = value }, changeEyes() { this.setData({ showEyes: !this.data.showEyes }) }, login() { var that=this; var phone=this.data.form.phone var password=this.data.form.password if(!phone){ wx.showLoading({ title: '手机号必填', }) setTimeout(function () { wx.hideLoading(); }, 1000); return false; } if(!password){ wx.showLoading({ title: '密码必填', }) setTimeout(function () { wx.hideLoading(); }, 1000); return false; } console.log(wx.getAccountInfoSync()); app.api.useApi(app.globalData.baseAppUrl + "api/admin/login", { phone:this.data.form.phone, password: this.data.form.password, appid: wx.getAccountInfoSync().miniProgram.appId }, "post").then(function (res) { wx.showLoading({ title: '登录中....', }) console.log(res); if (res.code != 200) { wx.showLoading({ title: res.message.msg, }) setTimeout(function () { wx.hideLoading(); }, 2000); } else { wx.hideLoading(); wx.setStorageSync('token', res.message.data.access_token); wx.navigateTo({ url: '/pages/home/index', }) } }).catch(function (err) { console.log(222); }) } })