index.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { getNavBarLayout } from '../../utils/nav-bar'
  2. Component({
  3. properties: {
  4. nickname: {
  5. type: String,
  6. value: '未登录',
  7. },
  8. avatar: {
  9. type: String,
  10. value: '',
  11. },
  12. loggedIn: {
  13. type: Boolean,
  14. value: false,
  15. },
  16. loggingIn: {
  17. type: Boolean,
  18. value: false,
  19. },
  20. },
  21. data: {
  22. headerPaddingTop: 64,
  23. avatarFailed: false,
  24. },
  25. observers: {
  26. avatar() {
  27. this.setData({ avatarFailed: false })
  28. },
  29. },
  30. lifetimes: {
  31. attached() {
  32. const { statusBarHeight, navHeight } = getNavBarLayout()
  33. this.setData({
  34. headerPaddingTop: statusBarHeight + navHeight,
  35. })
  36. },
  37. },
  38. methods: {
  39. onLoginTap() {
  40. if (!this.data.loggingIn) {
  41. this.triggerEvent(this.data.loggedIn ? 'editprofile' : 'login')
  42. }
  43. },
  44. onNicknameTap() {
  45. if (this.data.loggedIn && !this.data.loggingIn) {
  46. this.triggerEvent('editprofile')
  47. }
  48. },
  49. onAvatarError() {
  50. this.setData({ avatarFailed: true })
  51. },
  52. },
  53. })