// pages/staff/login/index.js let myPro = require("../../../utils/wxRequest.js"); let util = require("../../../utils/util.js"); var app = getApp(); Page({ /** * 页面的初始数据 */ data: { phoneNum:'', password:'', showPS:false, latitude:0, longitude:0, }, onPhoneChange(e){ this.setData({ phoneNum:e.detail }) }, onPasswordChange(e){ this.setData({ password:e.detail }) }, onClickShowPassword() { this.setData({ showPS:!this.data.showPS }) }, loginAction() { if (this.data.phoneNum === undefined || this.data.phoneNum === null || this.data.phoneNum === '') { Toast('请输入手机号') return } if (this.data.password === undefined || this.data.password === null || this.data.password === '') { Toast('请输入密码') return } wx.showLoading({ mask:true }) var that = this; var params = { phone: this.data.phoneNum, password: this.data.password } myPro.wxRequest("staff/login","POST",params).then(res=>{ wx.hideLoading() var res = res.data; console.log(res) if (res.code === 200) { app.globalData.token = res.result.token app.globalData.xxInfo = res.result.user app.globalData.showedWaterDialog = false wx.setStorage({ key:"xxInfo", data:res.result.user }) wx.setStorage({ key:"token", data:res.result.token }) wx.setStorage({ key:'staffphone', data:this.data.phoneNum }); wx.switchTab({ url: '../index/index' }) } else { Toast(res.msg); } // wx.reLaunch({ // url: '/pages/index/index' // }); }).catch(err=>{ console.log('报错信息',err); wx.showToast({ title: err, icon: "none" }) }) // wx.redirectTo({ // url: '../../index/index' // }); }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { // wx.hideHomeButton() }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { console.log(wx.getStorageSync('staffphone')) var that = this; var staffphone = wx.getStorageSync('staffphone'); if ( staffphone != undefined && staffphone != null ) { this.setData({ phoneNum:staffphone }) } wx.getLocation({ type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02' success: function (res) { that.setData({ latitude:res.latitude, longitude:res.longitude }) } }) }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })