caohuahui

代码优化

@@ -7,14 +7,21 @@ import { CompUtils } from '../../utils/CompUtils'; @@ -7,14 +7,21 @@ import { CompUtils } from '../../utils/CompUtils';
7 @Component 7 @Component
8 export struct HeadPictureCardComponent { 8 export struct HeadPictureCardComponent {
9 @State compDTO: CompDTO = {} as CompDTO 9 @State compDTO: CompDTO = {} as CompDTO
  10 + private item: ContentDTO
  11 +
  12 + aboutToAppear() {
  13 +
  14 + // Data Initialization.
  15 + this.item = this.compDTO.operDataList[0];
  16 + }
10 17
11 build() { 18 build() {
12 Stack() { 19 Stack() {
13 - Image(this.compDTO.operDataList[0].coverUrl) 20 + Image(this.item.coverUrl)
14 .width(CommonConstants.FULL_WIDTH) 21 .width(CommonConstants.FULL_WIDTH)
15 .height(CommonConstants.FULL_HEIGHT) 22 .height(CommonConstants.FULL_HEIGHT)
16 23
17 - if (this.compDTO.operDataList[0].newsTitle != null) { 24 + if (this.item.newsTitle != null) {
18 Row() 25 Row()
19 .width(CommonConstants.FULL_WIDTH) 26 .width(CommonConstants.FULL_WIDTH)
20 .height(59) 27 .height(59)
@@ -24,7 +31,7 @@ export struct HeadPictureCardComponent { @@ -24,7 +31,7 @@ export struct HeadPictureCardComponent {
24 ] 31 ]
25 }) 32 })
26 Row() { 33 Row() {
27 - Text(this.compDTO.operDataList[0].newsTitle) 34 + Text(this.item.newsTitle)
28 .width(CommonConstants.FULL_WIDTH) 35 .width(CommonConstants.FULL_WIDTH)
29 .height(CommonConstants.FULL_HEIGHT) 36 .height(CommonConstants.FULL_HEIGHT)
30 .fontColor(Color.White) 37 .fontColor(Color.White)
@@ -39,7 +46,7 @@ export struct HeadPictureCardComponent { @@ -39,7 +46,7 @@ export struct HeadPictureCardComponent {
39 } 46 }
40 .alignContent(Alignment.Bottom) 47 .alignContent(Alignment.Bottom)
41 .width(CommonConstants.FULL_WIDTH) 48 .width(CommonConstants.FULL_WIDTH)
42 - .aspectRatio(imageSizeRatio(this.compDTO.operDataList[0].coverSize)) 49 + .aspectRatio(imageSizeRatio(this.item.coverSize))
43 .height(200) 50 .height(200)
44 } 51 }
45 } 52 }