// pages/login/login.js var app = getApp(); let host = app.globalData.servsers; // 请求的url Page({ /** * 页面的初始数据 */ data: { account:null, pwd:null, url:null, type:0, //默认nav 为1表示switch back:1, onUnload:true,//默认为true,表示头部返回操作 }, /** * 生命周期函数--监听页面加载 */ onLoad: function (options) { console.log(options) this.setData({ url:options.url, type: options.type ? options.type : 0, back: options.back ? options.back : 1 }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function (e) { if (this.data.back == 2 && this.data.onUnload){ //表示需要返回2级,给首页 console.log(e, "监听页面卸载") wx.reLaunch({ url: '/pages/index/index' }) } }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { }, account(e){ console.log(e.detail.value) this.setData({ account: e.detail.value }) }, pwd(e){ this.setData({ pwd: e.detail.value }) console.log(this.data.pwd) }, login(){ let that = this; wx.request({ url: host +'/channelLogin', method:'post', header: { 'content-type': 'application/x-www-form-urlencoded' }, data:{ loginName:that.data.account, loginPwd:that.data.pwd }, success(res){ console.log(res,"dddd") if (res.data.status == "fail"){ wx.showToast({ title: res.data.msg, icon:"none" }) } else { wx.setStorageSync('channelIdObj', res.data) console.log(that.data.type, "that.data.type") that.setData({ onUnload: false, //表示离开,不是返回操作 }) wx.request({ url: host + '/getMyChannelInfo', method: 'get', data: { channelAccountId: wx.getStorageSync('channelIdObj').channelAccountId }, success(res) { wx.setStorageSync('channelName', res.data.channel.channelName) if(that.data.type ==1){ console.log(that.data.url,"that.data.url") wx.switchTab({ url: that.data.url, }) } else { wx.redirectTo({ url:that.data.url, }) } } }) } } }) } })