myCenter.js 4.3 KB

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