// pages/nais/nais.js import { imgUrl } from "../api/request" import { cacheGet } from "../../utils/cacheUtil" let app = getApp(); Page({ /** * 页面的初始数据 */ data: { canIUseGetUserProfile: true, nickName: "", avatarUrl: "", hasUserInfo: false, imgUrl: imgUrl, show: false }, // 自定义函数 toCanteen: function (e) { wx.navigateTo({ url: '/pages/ourCanteen/ourCanteen' }) }, handleAction() { var that = this wx.showActionSheet({ itemList: ['退出登录'], success(res) { console.log(res.tapIndex) wx.clearStorageSync(); that.setData({ show: false, canIUseGetUserProfile: true, hasUserInfo: false }) }, fail(res) { console.log(res.errMsg) } }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady() { if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: 4 }) } }, /** * 生命周期函数--监听页面显示 */ onShow() { // let token = wx.getStorageSync('token'); let token = cacheGet('token'); if (token != null && token != '') { this.setData({ canIUseGetUserProfile: false, nickName: wx.getStorageSync('nickName'), avatarUrl: wx.getStorageSync('imgUrl'), hasUserInfo: true }) } else { this.setData({ hasUserInfo: false, canIUseGetUserProfile: true }) } if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: 4 }) } }, onHide() { if (typeof this.getTabBar === 'function' && this.getTabBar()) { this.getTabBar().setData({ selected: -1 }) } }, onLoad() { // let token = wx.getStorageSync('token'); let token = cacheGet('token'); if (token != null && token != '') { this.setData({ nickName: wx.getStorageSync('nickName'), avatarUrl: wx.getStorageSync('imgUrl'), hasUserInfo: true }) } }, /** * 生命周期函数--监听页面卸载 */ onUnload() { }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh() { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom() { }, /** * 用户点击右上角分享 */ onShareAppMessage() { return { title: '个人中心' } }, toLike() { wx.navigateTo({ url: '/pagesPublic/pages/like/like', }) }, navto() { wx.navigateTo({ url: '/pagesPublic/pages/menu/menu', }) }, // toPersonalData() { // wx.navigateTo({ // url: '/pagesPublic/pages/personalData/index/personalData', // }) // }, gotoMyCollection() { wx.navigateTo({ url: '/pagesPublic/pages/myCollection/myCollection', }) }, toMyComment() { wx.navigateTo({ url: '/pagesPublic/pages/myComment/myComment', }) }, tologin() { wx.navigateTo({ url: '/pages/login/login', }) }, getUserInfo() { // this.setData({ // nickName: wx.getStorageSync('nickName'), // avatarUrl: wx.getStorageSync('imgUrl'), // hasUserInfo: true // }) }, // logout(){ // this.setData({ // hasUserInfo: false, // nickName:"", // avatarUrl:"" // }) // wx.removeStorage({ // key: 'nickName', // })(option) // wx.removeStorage({ // key: 'imgUrl', // })(option) // } })