Mine.ets 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. import { BasicType, IBestToast, userInfo, 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. import { systemShare } from '@kit.ShareKit'
  6. import { uniformTypeDescriptor } from '@kit.ArkData'
  7. @Component
  8. export struct Mine {
  9. @StorageProp(YTAvoid.SAFE_TOP_KEY) safeTop: number = 0
  10. @StorageProp(UserInfo.KEY) userInfo: UserInfo = userInfo
  11. setArr: Array<BasicType> = [
  12. {
  13. text: '分享给好友',
  14. message: '去分享',
  15. click: () => {
  16. this.shareData()
  17. },
  18. src: $r('app.media.mine_right_arrow')
  19. },
  20. {
  21. text: '意见反馈',
  22. click: () => {
  23. if (this.userInfo.checkLogin()) {
  24. yTRouter.router2SuggestionPage()
  25. } else {
  26. yTRouter.router2LoginPage()
  27. }
  28. },
  29. src: $r('app.media.mine_right_arrow')
  30. },
  31. {
  32. text: '给个好评',
  33. click: () => {
  34. const want: Want = {
  35. uri: "store://appgallery.huawei.com/app/detail?id=" + BUNDLE_NAME
  36. };
  37. const context = this.getUIContext().getHostContext() as common.UIAbilityContext;
  38. context.startAbility(want).then(() => {
  39. //拉起成功
  40. YTLog.info('跳转成功')
  41. }).catch((err: BusinessError) => {
  42. // 拉起失败
  43. YTLog.error(err)
  44. IBestToast.show('出现未知错误,请稍后再试')
  45. });
  46. },
  47. src: $r('app.media.mine_right_arrow')
  48. },
  49. {
  50. text: '关于我们',
  51. click: () => {
  52. yTRouter.router2AboutUS()
  53. },
  54. src: $r('app.media.mine_right_arrow')
  55. }
  56. ]
  57. aboutToAppear(): void {
  58. }
  59. build() {
  60. RelativeContainer() {
  61. Image(this.userInfo.getHeadImg())
  62. .aspectRatio(1)
  63. .height(80)
  64. .borderRadius(999)
  65. .border({ width: 4, color: Color.White })
  66. .alignRules({
  67. top: { anchor: "__container__", align: VerticalAlign.Top },
  68. left: { anchor: "__container__", align: HorizontalAlign.Start },
  69. bottom: { anchor: "bottomColumn", align: VerticalAlign.Top },
  70. bias: { vertical: 176 / (176 - 40) }
  71. })
  72. .offset({ x: 28 })
  73. .zIndex(999)
  74. .id("headerImg")
  75. Text(this.userInfo.getName())
  76. .fontSize(18)
  77. .fontColor('#FF1C1C1C')
  78. .fontWeight(500)
  79. .alignRules({
  80. top: { anchor: "headerImg", align: VerticalAlign.Bottom },
  81. left: { anchor: "headerImg", align: HorizontalAlign.Start },
  82. })
  83. .offset({ x: 28, y: 20 })
  84. .zIndex(999)
  85. Text(this.userInfo.checkLogin() ? '编辑' : '登录')
  86. .textAlign(TextAlign.Center)
  87. .height(29)
  88. .width(57)
  89. .borderRadius(32)
  90. .fontColor(Color.White)
  91. .fontSize(14)
  92. .fontWeight(400)
  93. .alignRules({
  94. center: { anchor: "headerImg", align: VerticalAlign.Bottom },
  95. right: { anchor: "__container__", align: HorizontalAlign.End },
  96. })
  97. .zIndex(999)
  98. .linearGradient({ angle: 135, colors: [['#CAE2F9', -0.1571], ['#D4D1F4', 0.4709], ['#EDF5FD', 1.1235]] })
  99. .offset({ x: -32, y: -2 })
  100. .onClick(() => {
  101. if (!this.userInfo.checkLogin()) {
  102. yTRouter.router2LoginPage()
  103. } else {
  104. yTRouter.router2SettingPage()
  105. }
  106. })
  107. Column() {
  108. List() {
  109. ForEach(this.setArr, (item: BasicType, index) => {
  110. ListItem() {
  111. Row() {
  112. Text(item.text)
  113. .fontColor('#FF1C1C1C')
  114. .fontSize(14)
  115. if (!index) {
  116. Text('去分享')
  117. .fontColor('#801C1C1C')
  118. .fontSize(14)
  119. .fontWeight(400)
  120. } else {
  121. Image($r('app.media.right_arrow'))
  122. .width(24)
  123. .aspectRatio(1)
  124. }
  125. }
  126. .width('100%')
  127. .height(56)
  128. .justifyContent(FlexAlign.SpaceBetween)
  129. .onClick(() => {
  130. item.click?.()
  131. })
  132. }
  133. })
  134. }
  135. .divider({ strokeWidth: 1, color: '#1A1C1C1C', })
  136. .width('100%')
  137. .height('100%')
  138. }
  139. .backgroundColor(Color.White)
  140. .width('100%')
  141. .height(550)
  142. .borderRadius({ topRight: 32 })
  143. .alignRules({
  144. bottom: { anchor: "__container__", align: VerticalAlign.Bottom },
  145. left: { anchor: "__container__", align: HorizontalAlign.Start },
  146. })
  147. .id("bottomColumn")
  148. .padding({ top: 142, left: 24, right: 24 })
  149. }
  150. .height('100%')
  151. .backgroundImage($r('app.media.mine_bgc'))
  152. .backgroundImageSize({ width: '100%', height: 305 })
  153. .backgroundImagePosition(Alignment.Top)
  154. }
  155. async shareData() {
  156. try {
  157. // 构造ShareData,需配置一条有效数据信息
  158. const data = new systemShare.SharedData({
  159. // utd: uniformTypeDescriptor.UniformDataType.HYPERLINK,
  160. utd: uniformTypeDescriptor.UniformDataType.TEXT,
  161. title: '盒小仓',
  162. content: 'http://appgallery.huawei.com/app/detail?id=6917580461832049757',
  163. description: "http://appgallery.huawei.com/app/detail?id=6917580461832049757"
  164. })
  165. const controller = new systemShare.ShareController(data)
  166. const context = this.getUIContext().getHostContext()! as common.UIAbilityContext;
  167. // 进行分享面板显示
  168. controller.show(context, {
  169. previewMode: systemShare.SharePreviewMode.DEFAULT,
  170. selectionMode: systemShare.SelectionMode.SINGLE,
  171. // anchor: { windowOffset: { x: 0, y: 0 }, size: { width: this.breakWidth, height: 500 } }
  172. })
  173. } catch (error) {
  174. IBestToast.show({ message: '当前设备不支持', duration: 500 })
  175. }
  176. }
  177. }