Mine.ets 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import { BasicType, copyText, IBestToast, UserInfo, YTAvoid, YTLog, YTRouter } from 'basic'
  2. import { common, Want } from '@kit.AbilityKit'
  3. import { BusinessError } from '@kit.BasicServicesKit'
  4. import { BUNDLE_NAME } from 'BuildProfile'
  5. @Component
  6. export struct Mine {
  7. @StorageProp(YTAvoid.SAFE_TOP_KEY) safeTop: number = 0
  8. @StorageProp(UserInfo.KEY) userInfo: UserInfo = UserInfo.getInstance()
  9. setArr: Array<BasicType<undefined>> = [
  10. {
  11. text: '意见反馈',
  12. click: () => {
  13. if (this.userInfo.checkLogin()) {
  14. YTRouter.router2SuggestionPage()
  15. } else {
  16. YTRouter.router2LoginPage()
  17. }
  18. },
  19. src: $r('app.media.right_arrow')
  20. },
  21. {
  22. text: '给个好评',
  23. click: () => {
  24. const want: Want = {
  25. uri: "store://appgallery.huawei.com/app/detail?id=" + BUNDLE_NAME
  26. };
  27. const context = this.getUIContext().getHostContext() as common.UIAbilityContext;
  28. context.startAbility(want).then(() => {
  29. //拉起成功
  30. YTLog.info('跳转成功')
  31. }).catch((err: BusinessError) => {
  32. // 拉起失败
  33. YTLog.error(err)
  34. IBestToast.show('出现未知错误,请稍后再试')
  35. });
  36. },
  37. src: $r('app.media.right_arrow')
  38. },
  39. {
  40. text: '关于我们',
  41. click: () => {
  42. YTRouter.router2AboutUS()
  43. },
  44. src: $r('app.media.right_arrow')
  45. }
  46. ]
  47. aboutToAppear(): void {
  48. }
  49. build() {
  50. Column() {
  51. Row() {
  52. Row() {
  53. Image(this.userInfo.getHeadImg() ?? $r('app.media.app_icon'))
  54. .aspectRatio(1)
  55. .height(40)
  56. .borderRadius(20)
  57. .margin({ right: 9 })
  58. Column({ space: 7 }) {
  59. Text(this.userInfo.getName() ?? this.userInfo.getPhoneNumber() ?? this.userInfo.getId()?.toString() ??
  60. '未登录')
  61. .fontSize($r('[basic].float.page_text_font_size_16'))
  62. .fontColor('Color.Black')
  63. Text() {
  64. Span('ID:' + (this.userInfo.getId()?.toString().padStart(8, '0') ?? '00000000'))
  65. ImageSpan($r('app.media.copy'))
  66. .width(7)
  67. .height(8)
  68. .margin({ left: 4 })
  69. .onClick(() => {
  70. copyText((this.userInfo.getId()?.toString().padStart(8, '0') ?? '00000000'))
  71. })
  72. .offset({ bottom: 4 })
  73. }
  74. .fontColor('#80000000')
  75. .fontSize($r('[basic].float.page_text_font_size_10'))
  76. }
  77. .alignItems(HorizontalAlign.Start)
  78. }
  79. .onClick(() => {
  80. if (this.userInfo.checkLogin()) {
  81. YTRouter.router2SettingPage()
  82. return
  83. }
  84. YTRouter.router2LoginPage()
  85. })
  86. }
  87. .width('100%')
  88. .margin({ bottom: 30 })
  89. // ShowBannerAd()
  90. Column() {
  91. List() {
  92. ForEach(this.setArr, (item: BasicType<undefined>, index) => {
  93. ListItem() {
  94. Row() {
  95. Text(item.text)
  96. .fontColor('#80000000')
  97. .fontSize(12)
  98. if (!index) {
  99. Row() {
  100. Text(this.userInfo.getAiNum()?.toString() ?? '')
  101. .fontWeight(600)
  102. .fontSize($r('[basic].float.page_text_font_size_14'))
  103. Image($r('app.media.right_arrow'))
  104. .width(24)
  105. .aspectRatio(1)
  106. }
  107. } else {
  108. Image($r('app.media.right_arrow'))
  109. .width(24)
  110. .aspectRatio(1)
  111. }
  112. }
  113. .width('100%')
  114. .height(36)
  115. .justifyContent(FlexAlign.SpaceBetween)
  116. .onClick(() => {
  117. item.click?.()
  118. })
  119. }
  120. })
  121. }
  122. .padding({ left: 12, right: 4 })
  123. .divider({ strokeWidth: 1, color: '#0A000000', endMargin: 8 })
  124. .margin({ top: 30 })
  125. .width('100%')
  126. .height('100%')
  127. }
  128. .layoutWeight(1)
  129. .width('100%')
  130. }
  131. .padding({ top: this.safeTop + 22, left: 16, right: 16 })
  132. .height('100%')
  133. }
  134. }