陈剑华

兴趣卡篇交互

@@ -15,8 +15,14 @@ const TAG = 'Zh_Single_Column-09' @@ -15,8 +15,14 @@ const TAG = 'Zh_Single_Column-09'
15 @Component 15 @Component
16 export struct ZhSingleColumn09 { 16 export struct ZhSingleColumn09 {
17 @State compDTO: CompDTO = {} as CompDTO 17 @State compDTO: CompDTO = {} as CompDTO
18 - @State list: Array<string> = ['社会', '三个字', '是四个字', '时事', '社会', '三个字', '是四个字', '时事']  
19 @State activeIndexs: Array<number> = [] 18 @State activeIndexs: Array<number> = []
  19 + @State operDataList: ContentDTO[] = this.compDTO?.operDataList || []
  20 + @State selfClosed: Boolean = false;
  21 +
  22 + aboutToAppear(): void {
  23 + this.operDataList = this.shuffleArray(this.compDTO?.operDataList)
  24 + }
  25 +
20 26
21 getItemWidth(index: number) { 27 getItemWidth(index: number) {
22 if (index % 4 === 0 || index % 4 === 3) { 28 if (index % 4 === 0 || index % 4 === 3) {
@@ -26,12 +32,56 @@ export struct ZhSingleColumn09 { @@ -26,12 +32,56 @@ export struct ZhSingleColumn09 {
26 } 32 }
27 } 33 }
28 34
  35 + shuffleArray(array: ContentDTO[]) {
  36 + for(let i = array.length - 1; i > 0; i--) {
  37 + const j = Math.floor(Math.random() * (i + 1));
  38 + const tempArray = array[i];
  39 + array[i] = array[j];
  40 + array[j] = tempArray
  41 + }
  42 + return array
  43 + }
  44 +
29 build() { 45 build() {
30 Column() { 46 Column() {
31 //顶部 47 //顶部
32 - this.CompHeader(this.compDTO) 48 + Row() {
  49 + Column() {
  50 + Text('以下是否有您感兴趣?')
  51 + .fontSize(18)
  52 + .fontColor(0x000000)
  53 + .fontWeight(600)
  54 + .width('70%')
  55 + .margin({bottom: 4})
  56 +
  57 + Text('选中标签,为您推荐更多您感兴趣的内容')
  58 + .fontSize(12)
  59 + .fontColor(0xB0B0B0)
  60 + .margin({bottom: 10})
  61 + .width('70%')
  62 + }
  63 +
  64 + Button('选好了', { type: ButtonType.Normal, stateEffect: false })
  65 + .fontColor(this.activeIndexs.length > 0 ? 0xed2800 : 0xB0B0B0)
  66 + .fontSize(14)
  67 + .width(62)
  68 + .height(26)
  69 + .backgroundColor(this.activeIndexs.length > 0 ? 0xfdf0ed : 0xf5f5f5)
  70 + // .lineHeight(26)
  71 + .borderRadius(4)
  72 + .margin({top: -10})
  73 + .padding({top: 0, bottom: 0, left: 0, right: 0})
  74 + .onClick(() => {
  75 + if (this.activeIndexs.length > 0) {
  76 + this.selfClosed = true;
  77 + }
  78 + })
  79 + }
  80 + .justifyContent(FlexAlign.SpaceBetween)
  81 + .width('100%')
  82 +
33 Grid() { 83 Grid() {
34 - ForEach(this.compDTO.operDataList, (item: ContentDTO, index: number) => { 84 + ForEach(this.operDataList, (item: ContentDTO, index: number) => {
35 GridItem() { 85 GridItem() {
36 Stack({alignContent: Alignment.TopEnd}) { 86 Stack({alignContent: Alignment.TopEnd}) {
37 Image(item.coverUrl) 87 Image(item.coverUrl)
@@ -73,17 +123,24 @@ export struct ZhSingleColumn09 { @@ -73,17 +123,24 @@ export struct ZhSingleColumn09 {
73 Row() { 123 Row() {
74 Text('换一换') 124 Text('换一换')
75 .fontSize(14) 125 .fontSize(14)
76 - .fontColor(0xed2800) 126 + .fontColor(this.compDTO?.operDataList.length > 8 ? 0xed2800 : 0xB0B0B0)
77 .margin({right: 4}) 127 .margin({right: 4})
78 - Image($r('app.media.icon_refresh')) 128 + Image(this.compDTO?.operDataList.length > 8 ? $r('app.media.icon_refresh') : $r('app.media.ic_refresh'))
79 .width(14) 129 .width(14)
80 .height(14) 130 .height(14)
81 } 131 }
  132 + .onClick(() => {
  133 + if (this.compDTO?.operDataList.length > 8) {
  134 + this.operDataList = this.shuffleArray(this.operDataList)
  135 + this.activeIndexs = [];
  136 + }
  137 + })
82 138
83 Image($r("app.media.close_button")) 139 Image($r("app.media.close_button"))
84 .width(14) 140 .width(14)
85 .height(14) 141 .height(14)
86 .onClick(() => { 142 .onClick(() => {
  143 + this.selfClosed = true;
87 }) 144 })
88 } 145 }
89 .height(40) 146 .height(40)
@@ -98,42 +155,7 @@ export struct ZhSingleColumn09 { @@ -98,42 +155,7 @@ export struct ZhSingleColumn09 {
98 bottom: $r('app.float.card_comp_pagePadding_tb') 155 bottom: $r('app.float.card_comp_pagePadding_tb')
99 }) 156 })
100 .backgroundColor($r('app.color.white')) 157 .backgroundColor($r('app.color.white'))
101 - .margin({ bottom: 8 })  
102 -  
103 - }  
104 -  
105 - @Builder  
106 - CompHeader(item: CompDTO) {  
107 - Row() {  
108 - Column() {  
109 - Text('以下是否有您感兴趣?')  
110 - .fontSize(18)  
111 - .fontColor(0x000000)  
112 - .fontWeight(600)  
113 - .width('70%')  
114 - .margin({bottom: 4})  
115 -  
116 - Text('选中标签,为您推荐更多您感兴趣的内容')  
117 - .fontSize(12)  
118 - .fontColor(0xB0B0B0)  
119 - .margin({bottom: 10})  
120 - .width('70%')  
121 - }  
122 -  
123 - Text('选好了')  
124 - .fontColor(0xed2800)  
125 - .fontSize(14)  
126 - .width(62)  
127 - .height(26)  
128 - .backgroundColor(0xfdf0ed)  
129 - .textAlign(TextAlign.Center)  
130 - // .lineHeight(26)  
131 - .borderRadius(4)  
132 - .margin({top: -10})  
133 -  
134 - }  
135 - .justifyContent(FlexAlign.SpaceBetween)  
136 - .width('100%') 158 + .visibility(this.selfClosed ? Visibility.None : Visibility.Visible)
137 } 159 }
138 } 160 }
139 161