myCenter.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // pages/nais/nais.js
  2. import {
  3. imgUrl
  4. } from "../api/request"
  5. import {
  6. cacheGet
  7. } from "../../utils/cacheUtil"
  8. let app = getApp();
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. canIUseGetUserProfile: true,
  15. nickName: "",
  16. avatarUrl: "",
  17. hasUserInfo: false,
  18. imgUrl: imgUrl,
  19. show: false
  20. },
  21. // 自定义函数
  22. toCanteen: function (e) {
  23. wx.navigateTo({
  24. url: '/pages/ourCanteen/ourCanteen'
  25. })
  26. },
  27. handleAction() {
  28. var that = this
  29. wx.showActionSheet({
  30. itemList: ['退出登录'],
  31. success(res) {
  32. console.log(res.tapIndex)
  33. wx.clearStorageSync();
  34. that.setData({
  35. show: false,
  36. canIUseGetUserProfile: true,
  37. hasUserInfo: false
  38. })
  39. },
  40. fail(res) {
  41. console.log(res.errMsg)
  42. }
  43. })
  44. },
  45. /**
  46. * 生命周期函数--监听页面初次渲染完成
  47. */
  48. onReady() {
  49. if (typeof this.getTabBar === 'function' &&
  50. this.getTabBar()) {
  51. this.getTabBar().setData({
  52. selected: 4
  53. })
  54. }
  55. },
  56. /**
  57. * 生命周期函数--监听页面显示
  58. */
  59. onShow() {
  60. // let token = wx.getStorageSync('token');
  61. let token = cacheGet('token');
  62. if (token != null && token != '') {
  63. this.setData({
  64. canIUseGetUserProfile: false,
  65. nickName: wx.getStorageSync('nickName'),
  66. avatarUrl: wx.getStorageSync('imgUrl'),
  67. hasUserInfo: true
  68. })
  69. } else {
  70. this.setData({
  71. hasUserInfo: false,
  72. canIUseGetUserProfile: true
  73. })
  74. }
  75. if (typeof this.getTabBar === 'function' &&
  76. this.getTabBar()) {
  77. this.getTabBar().setData({
  78. selected: 4
  79. })
  80. }
  81. },
  82. onHide() {
  83. if (typeof this.getTabBar === 'function' &&
  84. this.getTabBar()) {
  85. this.getTabBar().setData({
  86. selected: -1
  87. })
  88. }
  89. },
  90. onLoad() {
  91. // let token = wx.getStorageSync('token');
  92. let token = cacheGet('token');
  93. if (token != null && token != '') {
  94. this.setData({
  95. nickName: wx.getStorageSync('nickName'),
  96. avatarUrl: wx.getStorageSync('imgUrl'),
  97. hasUserInfo: true
  98. })
  99. }
  100. },
  101. /**
  102. * 生命周期函数--监听页面卸载
  103. */
  104. onUnload() {
  105. },
  106. /**
  107. * 页面相关事件处理函数--监听用户下拉动作
  108. */
  109. onPullDownRefresh() {
  110. },
  111. /**
  112. * 页面上拉触底事件的处理函数
  113. */
  114. onReachBottom() {
  115. },
  116. /**
  117. * 用户点击右上角分享
  118. */
  119. onShareAppMessage() {
  120. return {
  121. title: '个人中心'
  122. }
  123. },
  124. toLike() {
  125. wx.navigateTo({
  126. url: '/pagesPublic/pages/like/like',
  127. })
  128. },
  129. navto() {
  130. wx.navigateTo({
  131. url: '/pagesPublic/pages/menu/menu',
  132. })
  133. },
  134. // toPersonalData() {
  135. // wx.navigateTo({
  136. // url: '/pagesPublic/pages/personalData/index/personalData',
  137. // })
  138. // },
  139. gotoMyCollection() {
  140. wx.navigateTo({
  141. url: '/pagesPublic/pages/myCollection/myCollection',
  142. })
  143. },
  144. toMyComment() {
  145. wx.navigateTo({
  146. url: '/pagesPublic/pages/myComment/myComment',
  147. })
  148. },
  149. tologin() {
  150. wx.navigateTo({
  151. url: '/pages/login/login',
  152. })
  153. },
  154. getUserInfo() {
  155. // this.setData({
  156. // nickName: wx.getStorageSync('nickName'),
  157. // avatarUrl: wx.getStorageSync('imgUrl'),
  158. // hasUserInfo: true
  159. // })
  160. },
  161. // logout(){
  162. // this.setData({
  163. // hasUserInfo: false,
  164. // nickName:"",
  165. // avatarUrl:""
  166. // })
  167. // wx.removeStorage({
  168. // key: 'nickName',
  169. // })(option)
  170. // wx.removeStorage({
  171. // key: 'imgUrl',
  172. // })(option)
  173. // }
  174. })