me.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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: `./../home/home`
  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. let num = this.data.rightId === 1 ? 2 : 1
  84. if (typeof this.getTabBar === 'function' &&
  85. this.getTabBar()) {
  86. this.getTabBar().setData({
  87. selected: num
  88. })
  89. }
  90. app.eventBus.on('rightChange', data =>{
  91. if(data !== this.data.rightId){
  92. this.setData({
  93. rightId: data
  94. })
  95. num = this.data.rightId === 1 ? 2 : 1
  96. if (typeof this.getTabBar === 'function' &&
  97. this.getTabBar()) {
  98. this.getTabBar().setData({
  99. selected: num
  100. })
  101. }
  102. }
  103. })
  104. this.onLoad();
  105. },
  106. /**
  107. * 生命周期函数--监听页面隐藏
  108. */
  109. onHide() {
  110. },
  111. /**
  112. * 生命周期函数--监听页面卸载
  113. */
  114. onUnload() {
  115. },
  116. /**
  117. * 页面相关事件处理函数--监听用户下拉动作
  118. */
  119. onPullDownRefresh() {
  120. },
  121. /**
  122. * 页面上拉触底事件的处理函数
  123. */
  124. onReachBottom() {
  125. },
  126. /**
  127. * 用户点击右上角分享
  128. */
  129. onShareAppMessage() {
  130. },
  131. goDownload() {
  132. wx.navigateTo({
  133. url: './../download/download',
  134. })
  135. }
  136. })