123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- // 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)
- // }
- })
|