user.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // pages/user/user.js
  2. import { navigateTo, getStorageSync, clearStorageSync, showModal } from '../../utils/util'
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. userInfo: null,
  9. hasUserInfo: false
  10. },
  11. /**
  12. * 生命周期函数--监听页面加载
  13. */
  14. onLoad: function (options) {
  15. },
  16. onShow: function () {
  17. const userInfo = getStorageSync('USERINFO')
  18. if (userInfo) {
  19. this.setData({
  20. userInfo,
  21. hasUserInfo: true
  22. })
  23. } else {
  24. this.setData({
  25. userInfo: null,
  26. hasUserInfo: false
  27. })
  28. }
  29. },
  30. onAboutTap: function () {
  31. navigateTo('/pages/about/about')
  32. },
  33. login: function () {
  34. navigateTo('/pages/login/login')
  35. },
  36. logout: function() {
  37. showModal({
  38. content: '确定退出登录',
  39. showCancel: true,
  40. cancelText: '取消',
  41. cancelColor: '#000000',
  42. confirmText: '确定',
  43. confirmColor: '#3CC51F',
  44. success: (result) => {
  45. if(result.confirm){
  46. clearStorageSync('USERINFO')
  47. this.setData({
  48. userInfo: null,
  49. hasUserInfo: false
  50. })
  51. }
  52. }
  53. })
  54. }
  55. })