ChatList.ets 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import { BasicType, MessageType, Role } from '../models'
  2. import { BreakPointType, yTBreakPoint } from '../utils/YTBreakPoint'
  3. @Component
  4. export struct ChatList {
  5. @Prop chatList: MessageType[] = [
  6. {
  7. header: $r('app.media.ibest_icon_star'),
  8. text: '喜欢不是一件浪漫的事',
  9. role: Role.USER,
  10. },
  11. {
  12. header: $r('app.media.ibest_icon_star_o'),
  13. text: '那是什么?',
  14. role: Role.OTHER,
  15. },
  16. {
  17. header: $r('app.media.ibest_icon_star'),
  18. text: '喜欢你才是',
  19. role: Role.USER,
  20. },
  21. ]
  22. @Prop haveMoreHistory: boolean = true
  23. @Prop promptArr: BasicType<undefined>[] = [
  24. {
  25. text: '每日读书打卡'
  26. },
  27. {
  28. text: '励志正能量'
  29. },
  30. {
  31. text: '公司团建'
  32. }
  33. ]
  34. @StorageProp(yTBreakPoint.KEY) bp: string = 'sm'
  35. @State isLoading: boolean = false
  36. build() {
  37. List({ space: 24 }) {
  38. ForEach(this.chatList, (item: MessageType, index) => {
  39. ListItem() {
  40. if (item.role == Role.USER) {
  41. Row({ space: 16 }) {
  42. Text(item.text)
  43. .padding(12)
  44. .backgroundColor('#FFF0FBFF')
  45. .constraintSize({ maxWidth: '70%' })
  46. .borderRadius(8)
  47. Image(item.header)
  48. .width(40)
  49. .aspectRatio(1)
  50. }
  51. .width('100%')
  52. .margin({ top: index == 0 ? 20 : 0, bottom: index == this.chatList.length - 1 ? 20 : 0 })
  53. .alignItems(VerticalAlign.Bottom)
  54. .justifyContent(FlexAlign.End)
  55. } else if (item.role == Role.OTHER) {
  56. Row({ space: 16 }) {
  57. Image(item.header)
  58. .width(40)
  59. .aspectRatio(1)
  60. Text(item.text)
  61. .padding(12)
  62. .constraintSize({ maxWidth: '70%' })
  63. .borderRadius(8)
  64. .backgroundColor('#FFF0FBFF')
  65. }
  66. .width('100%')
  67. .margin({ top: index == 0 ? 20 : 0, bottom: index == this.chatList.length - 1 ? 20 : 0 })
  68. .alignItems(VerticalAlign.Bottom)
  69. .justifyContent(FlexAlign.Start)
  70. } else {
  71. }
  72. }
  73. })
  74. }
  75. .width('100%')
  76. .height('100%')
  77. .scrollBar(BarState.Off)
  78. }
  79. @Builder
  80. card() {
  81. ListItem() {
  82. Column() {
  83. if (this.haveMoreHistory) {
  84. Row() {
  85. Text('下拉查看历史消息')
  86. .fontWeight(500)
  87. .fontSize(10)
  88. .fontColor('#80595959')
  89. }
  90. .height(38)
  91. .width('100%')
  92. .justifyContent(FlexAlign.Center)
  93. }
  94. Column() {
  95. Text('输入你想生成的文案主题,一键生成所需文案,轻松高效不费脑,例如:')
  96. .fontColor('#E6595959')
  97. .fontWeight(500)
  98. .fontSize(14)
  99. .margin({ bottom: 10 })
  100. ForEach(this.promptArr, (item: BasicType<undefined>, index) => {
  101. Text(item.text)
  102. .fontColor('#E6595959')
  103. .fontSize(10)
  104. .fontWeight(600)
  105. .backgroundColor('#FFF7F9FA')
  106. .height(30)
  107. .borderRadius(4)
  108. .width('100%')
  109. .padding({ left: 8 })
  110. .textAlign(new BreakPointType<TextAlign>({
  111. sm: TextAlign.Start,
  112. md: TextAlign.Center,
  113. }
  114. ).getValue(this.bp))
  115. .margin({ bottom: this.promptArr.length - 1 == index ? 0 : 8 })
  116. .onClick(() => {
  117. })
  118. })
  119. }
  120. .width('100%')
  121. .backgroundColor(Color.White)
  122. .borderRadius(8)
  123. .padding(12)
  124. .alignItems(HorizontalAlign.Start)
  125. .margin({ bottom: 10 })
  126. }
  127. }
  128. }
  129. }