- 评价详情展示
- 功能:展示课程的评价详情,包括评价者头像、姓名、评分、时间和内容。
- 代码段:
Column() {
Text(`评价详情(${this.totalNum}个评价)`)
.width(TrainConstants.FULL_WIDTH)
.margin({
top: 10,
bottom: 8
})
List() {
ForEach(CourseEvaluateList, (item: CourseEvaluateInfo) => {
ListItem() {
Row() {
Image(item.img)
.width(32)
.height(32)
.margin({
right: 10
})
Column() {
Row() {
Text(item.name)
Rating({ rating: item.starCount, indicator: false })
.stars(5)
.stepSize(0.5)
.width(120)
.onChange((value: number) => {
item.starCount = value
})
.padding({
right: 50
})
}
.width(TrainConstants.FULL_WIDTH)
.justifyContent(FlexAlign.SpaceBetween)
Text(item.time)
.fontColor($r('app.color.gray_color'))
.margin({
top: 6,
bottom: 15
})
Text(item.content)
.width(TrainConstants.FULL_WIDTH)
.wordBreak(WordBreak.BREAK_ALL)
.padding({
right: 50
})
}
.alignItems(HorizontalAlign.Start)
}
.width(TrainConstants.FULL_WIDTH)
.alignItems(VerticalAlign.Top)
.margin({
top: 10,
bottom: 10
})
}
}, (item: CourseEvaluateInfo) => JSON.stringify(item))
}
.divider({ strokeWidth: 2, color: '#eeeeee' })
}
.width(TrainConstants.FULL_WIDTH)
.layoutWeight(1)
.backgroundColor(Color.White)
.padding(10)
.margin({
top: 10
})
总结
通过以上代码的实现,我们在 HarmonyOS Next 中成功构建了一个课程评价页面。利用 HarmonyOS 提供的状态管理、组件化开发和列表渲染机制,我们可以方便地展示课程评价详情,提升用户对课程的反馈和交流体验。该页面结构清晰,易于维护和扩展,有助于开发者在 HarmonyOS Next 平台上快速开发出高质量的教育应用。