me.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. },
  46. gologin() {
  47. //
  48. const _this = this;
  49. if (this.data.islogin) {
  50. // 退出登录
  51. wx.removeStorage({
  52. key: 'userInfo',
  53. success(res) {
  54. _this.setData({
  55. islogin: false,
  56. userName: "未登录",
  57. userPic: "./../../img/head_pic.png",
  58. });
  59. wx.switchTab({
  60. url: `./../index/index`
  61. });
  62. }
  63. });
  64. wx.removeStorage({
  65. key: 'token',
  66. })
  67. } else {
  68. // 登录
  69. wx.navigateTo({
  70. url: './../login/login',
  71. });
  72. }
  73. },
  74. /**
  75. * 生命周期函数--监听页面初次渲染完成
  76. */
  77. onReady() {
  78. },
  79. /**
  80. * 生命周期函数--监听页面显示
  81. */
  82. onShow() {
  83. // 当前的index
  84. let num = this.data.rightId === 1 ? 2 : 1
  85. if (typeof this.getTabBar === 'function' &&
  86. this.getTabBar()) {
  87. this.getTabBar().setData({
  88. selected: num
  89. })
  90. }
  91. app.eventBus.on('rightChange', data =>{
  92. if(data !== this.data.rightId){
  93. this.setData({
  94. rightId: data
  95. })
  96. num = this.data.rightId === 1 ? 2 : 1
  97. if (typeof this.getTabBar === 'function' &&
  98. this.getTabBar()) {
  99. this.getTabBar().setData({
  100. selected: num
  101. })
  102. }
  103. }
  104. })
  105. this.onLoad();
  106. },
  107. /**
  108. * 生命周期函数--监听页面隐藏
  109. */
  110. onHide() {
  111. },
  112. /**
  113. * 生命周期函数--监听页面卸载
  114. */
  115. onUnload() {
  116. },
  117. /**
  118. * 页面相关事件处理函数--监听用户下拉动作
  119. */
  120. onPullDownRefresh() {
  121. },
  122. /**
  123. * 页面上拉触底事件的处理函数
  124. */
  125. onReachBottom() {
  126. },
  127. /**
  128. * 用户点击右上角分享
  129. */
  130. onShareAppMessage() {
  131. },
  132. goDownload() {
  133. wx.navigateTo({
  134. url: './../download/download',
  135. })
  136. }
  137. })