me.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // pages/me/me.ts
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. loginStatus: true,
  9. userName: "未登录",
  10. userPic: './../../img/head_pic.png',
  11. nvabarData: {
  12. showCapsule: 0, //是否显示左上角图标 1表示显示 0表示不显示
  13. title: '', //导航栏 中间的标题
  14. },
  15. islogin: false,
  16. rightId:wx.getStorageSync('rightId') || 0
  17. },
  18. changeRole(){
  19. app.changeUserRight()
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad() {
  25. // wx.getStorage("userInfo")
  26. const _this = this;
  27. wx.getStorage({
  28. key: "userInfo",
  29. success(res) {
  30. if (!res.data.phone) {
  31. return;
  32. };
  33. _this.setData({
  34. userName: res.data.nickname || "",
  35. userPic: res.data.headUrl || "",
  36. islogin: true,
  37. })
  38. }
  39. })
  40. },
  41. goabout() {
  42. // wx.navigateTo({
  43. // url: './../about/about',
  44. // })
  45. wx.navigateTo({
  46. url: './../detail/detail',
  47. });
  48. },
  49. gologin() {
  50. //
  51. const _this = this;
  52. if (this.data.islogin) {
  53. // 退出登录
  54. wx.removeStorage({
  55. key: 'userInfo',
  56. success(res) {
  57. _this.setData({
  58. islogin: false,
  59. userName: "未登录",
  60. userPic: "./../../img/head_pic.png",
  61. });
  62. wx.switchTab({
  63. url: `./../index/index`
  64. });
  65. }
  66. });
  67. wx.removeStorage({
  68. key: 'token',
  69. })
  70. } else {
  71. // 登录
  72. wx.navigateTo({
  73. url: './../login/login',
  74. });
  75. }
  76. },
  77. /**
  78. * 生命周期函数--监听页面初次渲染完成
  79. */
  80. onReady() {
  81. },
  82. /**
  83. * 生命周期函数--监听页面显示
  84. */
  85. onShow() {
  86. // 当前的index
  87. let num = this.data.rightId === 1 ? 2 : 1
  88. if (typeof this.getTabBar === 'function' &&
  89. this.getTabBar()) {
  90. this.getTabBar().setData({
  91. selected: num
  92. })
  93. }
  94. app.eventBus.on('rightChange', data =>{
  95. if(data !== this.data.rightId){
  96. this.setData({
  97. rightId: data
  98. })
  99. num = this.data.rightId === 1 ? 2 : 1
  100. if (typeof this.getTabBar === 'function' &&
  101. this.getTabBar()) {
  102. this.getTabBar().setData({
  103. selected: num
  104. })
  105. }
  106. }
  107. })
  108. this.onLoad();
  109. },
  110. /**
  111. * 生命周期函数--监听页面隐藏
  112. */
  113. onHide() {
  114. },
  115. /**
  116. * 生命周期函数--监听页面卸载
  117. */
  118. onUnload() {
  119. },
  120. /**
  121. * 页面相关事件处理函数--监听用户下拉动作
  122. */
  123. onPullDownRefresh() {
  124. },
  125. /**
  126. * 页面上拉触底事件的处理函数
  127. */
  128. onReachBottom() {
  129. },
  130. /**
  131. * 用户点击右上角分享
  132. */
  133. onShareAppMessage() {
  134. },
  135. goDownload() {
  136. wx.navigateTo({
  137. url: './../download/download',
  138. })
  139. }
  140. })