Showing
2 changed files
with
203 additions
and
0 deletions
sight_harmony/features/wdComponent/src/main/ets/components/cardview/RecommendAttentionRmh.ets
0 → 100644
| 1 | +import { RmhInfoDTO, ContentDTO, Params } from 'wdBean'; | ||
| 2 | +import { WDRouterPage, WDRouterRule } from 'wdRouter/Index'; | ||
| 3 | +import { HttpUrlUtils } from 'wdNetwork/Index'; | ||
| 4 | +import { postInteractAccentionOperateParams } from 'wdBean'; | ||
| 5 | +import { PageRepository } from '../../repository/PageRepository'; | ||
| 6 | +import { CommonConstants } from 'wdConstant/Index'; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 人民号--推荐---没有关注的情况下,推荐的优质号主---ui称为:人民号冷启动卡 | ||
| 10 | + * RecommendAttentionRmh | ||
| 11 | + */ | ||
| 12 | +const TAG = 'RecommendAttentionRmh' | ||
| 13 | + | ||
| 14 | +interface RmhInfo extends RmhInfoDTO { | ||
| 15 | + isSelected: boolean; | ||
| 16 | + headPhotoUrl: string; | ||
| 17 | + introduction: string; | ||
| 18 | + userName: string; | ||
| 19 | +} | ||
| 20 | + | ||
| 21 | +@Entry | ||
| 22 | +@Component | ||
| 23 | +export struct RecommendAttentionRmh { | ||
| 24 | + @State recommendRmhList: RmhInfo[] = [ | ||
| 25 | + // { | ||
| 26 | + // authIcon: 'https://cdnjdphoto.aikan.pdnews.cn/creator-category/icon/auth/blue.png', | ||
| 27 | + // headPhotoUrl: 'https://uatjdcdnphoto.aikan.pdnews.cn/vod/content/202302/202302Sa121448724/TUw.png?x-oss-process=image/resize,l_100/auto-orient,1/quality,q_90/format,jpg', | ||
| 28 | + // introduction: '1。', | ||
| 29 | + // userName: '中国' | ||
| 30 | + // } as RmhInfo, | ||
| 31 | + ] | ||
| 32 | + @State selectedCount: number = 0 | ||
| 33 | + | ||
| 34 | + @Builder | ||
| 35 | + buildItemCard(item: RmhInfo) { | ||
| 36 | + Column() { | ||
| 37 | + Image(item.headPhotoUrl) | ||
| 38 | + .width(44) | ||
| 39 | + .aspectRatio(1 / 1) | ||
| 40 | + .margin(16) | ||
| 41 | + Text(item.userName) | ||
| 42 | + .fontSize(13) | ||
| 43 | + .maxLines(1) | ||
| 44 | + .textOverflow({ overflow: TextOverflow.Ellipsis }) | ||
| 45 | + } | ||
| 46 | + .width('100%') | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + build() { | ||
| 50 | + Column() { | ||
| 51 | + //顶部 | ||
| 52 | + this.CompHeader() | ||
| 53 | + GridRow({ | ||
| 54 | + gutter: 10, | ||
| 55 | + columns: { sm: 3, md: 4, lg: 8 }, | ||
| 56 | + breakpoints: { | ||
| 57 | + value: ['320vp', '520vp', '840vp'], | ||
| 58 | + reference: BreakpointsReference.WindowSize | ||
| 59 | + } | ||
| 60 | + }) { | ||
| 61 | + ForEach(this.recommendRmhList, (item: RmhInfo, index: number) => { | ||
| 62 | + GridCol() { | ||
| 63 | + CreatorItem({ item, index, list: $recommendRmhList, selectedCount: $selectedCount }) | ||
| 64 | + } | ||
| 65 | + }) | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + Button(`一键关注(${this.selectedCount})`, { type: ButtonType.Normal }) | ||
| 69 | + .borderRadius($r('app.float.button_border_radius')) | ||
| 70 | + .height(36) | ||
| 71 | + .backgroundColor($r('app.color.color_ED2800')) | ||
| 72 | + .margin({ top: 20 }) | ||
| 73 | + .onClick(() => { | ||
| 74 | + // TODO 调用一键关注的接口 | ||
| 75 | + const selectedLists = this.recommendRmhList.filter(item => { | ||
| 76 | + console.log(`选中状态:${item.isSelected}`) | ||
| 77 | + return item.isSelected !== false | ||
| 78 | + }) | ||
| 79 | + console.log(JSON.stringify(selectedLists)) | ||
| 80 | + }) | ||
| 81 | + } | ||
| 82 | + .padding({ | ||
| 83 | + left: $r('app.float.card_comp_pagePadding_lf'), | ||
| 84 | + right: $r('app.float.card_comp_pagePadding_lf'), | ||
| 85 | + top: $r('app.float.card_comp_pagePadding_tb'), | ||
| 86 | + bottom: $r('app.float.card_comp_pagePadding_tb') | ||
| 87 | + }) | ||
| 88 | + .backgroundColor($r('app.color.white')) | ||
| 89 | + .margin({ bottom: 8 }) | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + @Builder | ||
| 93 | + CompHeader() { | ||
| 94 | + Row() { | ||
| 95 | + Row() { | ||
| 96 | + Image($r("app.media.redLine")) | ||
| 97 | + .width(3) | ||
| 98 | + .height(16) | ||
| 99 | + .margin({ right: 4 }) | ||
| 100 | + Text('为你推荐优质号主') | ||
| 101 | + .fontSize($r("app.float.font_size_17")) | ||
| 102 | + .fontColor($r("app.color.color_222222")) | ||
| 103 | + .fontWeight(600) | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + Row() { | ||
| 107 | + Text("换一换") | ||
| 108 | + .fontSize($r("app.float.font_size_14")) | ||
| 109 | + .fontColor($r("app.color.color_999999")) | ||
| 110 | + .margin({ right: 1 }) | ||
| 111 | + Image($r("app.media.ic_refresh")) | ||
| 112 | + .width(14) | ||
| 113 | + .height(14) | ||
| 114 | + .onClick(() => { | ||
| 115 | + // TODO 通知父组件,重新查询推荐数据 | ||
| 116 | + }) | ||
| 117 | + } | ||
| 118 | + .padding({ | ||
| 119 | + right: $r('app.float.card_comp_pagePadding_lf'), | ||
| 120 | + }) | ||
| 121 | + } | ||
| 122 | + .justifyContent(FlexAlign.SpaceBetween) | ||
| 123 | + .margin({ top: 8, bottom: 8 }) | ||
| 124 | + .width('100%') | ||
| 125 | + } | ||
| 126 | +} | ||
| 127 | + | ||
| 128 | +@Extend(Text) | ||
| 129 | +function textOverflowStyle(maxLine: number) { | ||
| 130 | + .maxLines(maxLine) | ||
| 131 | + .textOverflow({ overflow: TextOverflow.Ellipsis }) | ||
| 132 | +} | ||
| 133 | + | ||
| 134 | +@Component | ||
| 135 | +struct CreatorItem { | ||
| 136 | + @Prop item: RmhInfo | ||
| 137 | + @Prop index: number | ||
| 138 | + @Link list: RmhInfo[] | ||
| 139 | + @Link selectedCount: number; | ||
| 140 | + @State isSelected: boolean = true; | ||
| 141 | + | ||
| 142 | + getSelectedCount() { | ||
| 143 | + const selected = this.list.filter(item => { | ||
| 144 | + return item.isSelected !== false | ||
| 145 | + }) | ||
| 146 | + this.selectedCount = selected.length | ||
| 147 | + } | ||
| 148 | + | ||
| 149 | + aboutToAppear(): void { | ||
| 150 | + this.getSelectedCount() | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + build() { | ||
| 154 | + Column() { | ||
| 155 | + Stack() { | ||
| 156 | + Image(this.item.headPhotoUrl) | ||
| 157 | + .width(44) | ||
| 158 | + .height(44) | ||
| 159 | + if (this.isSelected) { | ||
| 160 | + Image($r('app.media.MyCollection_selected_icon')) | ||
| 161 | + .width(16) | ||
| 162 | + .height(16) | ||
| 163 | + } else { | ||
| 164 | + Image($r('app.media.ic_succeed_refresh')) | ||
| 165 | + .width(16) | ||
| 166 | + .height(16) | ||
| 167 | + } | ||
| 168 | + } | ||
| 169 | + .margin({ top: 2, bottom: 5 }) | ||
| 170 | + .alignContent(Alignment.BottomEnd) | ||
| 171 | + | ||
| 172 | + Flex({ justifyContent: FlexAlign.Center }) { | ||
| 173 | + Text(this.item.userName) | ||
| 174 | + .fontColor($r('app.color.color_222222')) | ||
| 175 | + .fontSize($r('app.float.font_size_14')) | ||
| 176 | + .fontWeight(500) | ||
| 177 | + .textOverflowStyle(1) | ||
| 178 | + .textAlign(TextAlign.Center) | ||
| 179 | + Image(this.item.authIcon) | ||
| 180 | + .width(14) | ||
| 181 | + .height(14) | ||
| 182 | + .borderRadius(50) | ||
| 183 | + .flexShrink(0) | ||
| 184 | + } | ||
| 185 | + .width(CommonConstants.FULL_WIDTH) | ||
| 186 | + | ||
| 187 | + Text(this.item.introduction) | ||
| 188 | + .fontColor($r('app.color.color_B0B0B0')) | ||
| 189 | + .fontSize($r('app.float.font_size_12')) | ||
| 190 | + .margin({ top: 8, bottom: 14 }) | ||
| 191 | + .textOverflowStyle(2) | ||
| 192 | + .textAlign(TextAlign.Center) | ||
| 193 | + } | ||
| 194 | + .padding({ left: 6, right: 6 }) | ||
| 195 | + .width('100%') | ||
| 196 | + .onClick(() => { | ||
| 197 | + // 选中或者取消选中 | ||
| 198 | + this.isSelected = !this.isSelected | ||
| 199 | + this.list[this.index].isSelected = this.isSelected | ||
| 200 | + this.getSelectedCount() | ||
| 201 | + }) | ||
| 202 | + } | ||
| 203 | +} |
-
Please register or login to post a comment