me.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. },
  17. /**
  18. * 生命周期函数--监听页面加载
  19. */
  20. onLoad() {
  21. // wx.getStorage("userInfo")
  22. const _this = this;
  23. wx.getStorage({
  24. key: "userInfo",
  25. success(res) {
  26. if (!res.data.phone) {
  27. return;
  28. };
  29. _this.setData({
  30. userName: res.data.nickname || "",
  31. userPic: res.data.headUrl || "",
  32. islogin: true,
  33. })
  34. }
  35. })
  36. },
  37. goabout() {
  38. wx.navigateTo({
  39. url: './../about/about',
  40. })
  41. },
  42. gologin() {
  43. //
  44. const _this = this;
  45. if (this.data.islogin) {
  46. // 退出登录
  47. wx.removeStorage({
  48. key: 'userInfo',
  49. success(res) {
  50. _this.setData({
  51. islogin: false,
  52. userName: "未登录",
  53. userPic: "./../../img/head_pic.png",
  54. });
  55. wx.switchTab({
  56. url: `./../index/index`
  57. });
  58. }
  59. });
  60. wx.removeStorage({
  61. key: 'token',
  62. })
  63. } else {
  64. // 登录
  65. wx.navigateTo({
  66. url: './../login/login',
  67. });
  68. }
  69. },
  70. /**
  71. * 生命周期函数--监听页面显示
  72. */
  73. onShow() {
  74. this.onLoad();
  75. },
  76. goDownload() {
  77. wx.navigateTo({
  78. url: './../download/download',
  79. })
  80. }
  81. })