// pages/me/me.ts const app = getApp(); Page({ /** * 页面的初始数据 */ data: { loginStatus: true, userName: "未登录", userPic: './../../img/head_pic.png', nvabarData: { showCapsule: 0, //是否显示左上角图标 1表示显示 0表示不显示 title: '', //导航栏 中间的标题 }, islogin: false, rightId:wx.getStorageSync('rightId') || 0 }, changeRole(){ app.changeUserRight() }, /** * 生命周期函数--监听页面加载 */ onLoad() { // wx.getStorage("userInfo") const _this = this; wx.getStorage({ key: "userInfo", success(res) { if (!res.data.phone) { return; }; _this.setData({ userName: res.data.nickname || "", userPic: res.data.headUrl || "", islogin: true, }) } }) }, goabout() { // wx.navigateTo({ // url: './../about/about', // }) wx.navigateTo({ url: './../detail/detail', }); }, gologin() { // const _this = this; if (this.data.islogin) { // 退出登录 wx.removeStorage({ key: 'userInfo', success(res) { _this.setData({ islogin: false, userName: "未登录", userPic: "./../../img/head_pic.png", }); wx.switchTab({ url: `./../index/index` }); } }); wx.removeStorage({ key: 'token', }) } else { // 登录 wx.navigateTo({ url: './../login/login', }); } }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { }, /** * 生命周期函数--监听页面显示 */ onShow() { // 当前的index let num = this.data.rightId === 1 ? 2 : 1 if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: num }) } app.eventBus.on('rightChange', data =>{ if(data !== this.data.rightId){ this.setData({ rightId: data }) num = this.data.rightId === 1 ? 2 : 1 if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: num }) } } }) this.onLoad(); }, /** * 生命周期函数--监听页面隐藏 */ onHide() { }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { }, goDownload() { wx.navigateTo({ url: './../download/download', }) } })