Showing
1 changed file
with
44 additions
and
5 deletions
| @@ -14,7 +14,7 @@ const TAG = 'Zh_Single_Column-09' | @@ -14,7 +14,7 @@ const TAG = 'Zh_Single_Column-09' | ||
| 14 | @Entry | 14 | @Entry |
| 15 | @Component | 15 | @Component |
| 16 | export struct ZhSingleColumn09 { | 16 | export struct ZhSingleColumn09 { |
| 17 | - @State fullyTraversed: boolean = false; | 17 | + @State fullyTraversed: boolean = false; //换一换置灰标记 |
| 18 | @State private pageModel: PageModel = new PageModel(); | 18 | @State private pageModel: PageModel = new PageModel(); |
| 19 | @State pageId: string = ''; | 19 | @State pageId: string = ''; |
| 20 | @State pageName: string = ''; | 20 | @State pageName: string = ''; |
| @@ -26,11 +26,46 @@ export struct ZhSingleColumn09 { | @@ -26,11 +26,46 @@ export struct ZhSingleColumn09 { | ||
| 26 | @State compIndex: number = 0; | 26 | @State compIndex: number = 0; |
| 27 | @State currentOperDataListIndex: number = 0; //记录换一换点击次数 | 27 | @State currentOperDataListIndex: number = 0; //记录换一换点击次数 |
| 28 | @State visitedIndices: Set<number> = new Set<number>(); | 28 | @State visitedIndices: Set<number> = new Set<number>(); |
| 29 | + private currentIndex: number = 0; | ||
| 30 | + @State currentDataList: ContentDTO[] = [] | ||
| 29 | 31 | ||
| 30 | async aboutToAppear(): Promise<void> { | 32 | async aboutToAppear(): Promise<void> { |
| 31 | this.loadImg = await onlyWifiLoadImg(); | 33 | this.loadImg = await onlyWifiLoadImg(); |
| 32 | - this.operDataList = this.shuffleArray(this.compDTO?.operDataList) | 34 | + // this.operDataList = this.shuffleArray(this.compDTO?.operDataList) |
| 35 | + this.operDataList = this.padData(this.compDTO?.operDataList) | ||
| 33 | this.currentOperDataListIndex = this.compDTO?.operDataList.length | 36 | this.currentOperDataListIndex = this.compDTO?.operDataList.length |
| 37 | + this.currentDataList = this.getNextBatch() | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * 若数据不满足8个以上直接返回 | ||
| 42 | + * 若最后一屏不够补齐至8个 | ||
| 43 | + * */ | ||
| 44 | + private padData(data: ContentDTO[]): ContentDTO[] { | ||
| 45 | + if (data.length < 9) { | ||
| 46 | + return data | ||
| 47 | + } | ||
| 48 | + const remainder = data.length % 8; | ||
| 49 | + if (remainder === 0) { | ||
| 50 | + return data; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + const paddingCount = 8 - remainder; | ||
| 54 | + const padding = data.slice(0, paddingCount); | ||
| 55 | + | ||
| 56 | + return [...data, ...padding]; | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * 换一换切换数据 | ||
| 61 | + * */ | ||
| 62 | + public getNextBatch(): ContentDTO[] { | ||
| 63 | + const batch = this.operDataList.slice(this.currentIndex, this.currentIndex + 8); | ||
| 64 | + this.currentIndex += 8; | ||
| 65 | + if (this.currentIndex >= this.operDataList.length) { | ||
| 66 | + this.fullyTraversed = true //数据展现完毕,置灰标记 | ||
| 67 | + } | ||
| 68 | + return batch; | ||
| 34 | } | 69 | } |
| 35 | 70 | ||
| 36 | trackClick(type: 'close_interest_card_click' | 'interest_card_selecting_click') { | 71 | trackClick(type: 'close_interest_card_click' | 'interest_card_selecting_click') { |
| @@ -142,8 +177,8 @@ export struct ZhSingleColumn09 { | @@ -142,8 +177,8 @@ export struct ZhSingleColumn09 { | ||
| 142 | .justifyContent(FlexAlign.SpaceBetween) | 177 | .justifyContent(FlexAlign.SpaceBetween) |
| 143 | .width('100%') | 178 | .width('100%') |
| 144 | 179 | ||
| 145 | - Flex({wrap: FlexWrap.Wrap}) { | ||
| 146 | - ForEach(this.operDataList.slice(0, 8), (item: ContentDTO, index: number) => { | 180 | + Flex({ wrap: FlexWrap.Wrap }) { |
| 181 | + ForEach(this.currentDataList, (item: ContentDTO, index: number) => { | ||
| 147 | Row() { | 182 | Row() { |
| 148 | Stack({ alignContent: Alignment.TopEnd }) { | 183 | Stack({ alignContent: Alignment.TopEnd }) { |
| 149 | Image(this.loadImg ? item.coverUrl : '') | 184 | Image(this.loadImg ? item.coverUrl : '') |
| @@ -204,10 +239,14 @@ export struct ZhSingleColumn09 { | @@ -204,10 +239,14 @@ export struct ZhSingleColumn09 { | ||
| 204 | return | 239 | return |
| 205 | } | 240 | } |
| 206 | if (this.compDTO?.operDataList.length > 8) { | 241 | if (this.compDTO?.operDataList.length > 8) { |
| 207 | - this.operDataList = this.shuffleArray(this.operDataList) | 242 | + // this.operDataList = this.shuffleArray(this.operDataList) |
| 208 | // if (this.pageModel) { | 243 | // if (this.pageModel) { |
| 209 | // this.pageModel.compList.deleteItem(this.compIndex) | 244 | // this.pageModel.compList.deleteItem(this.compIndex) |
| 210 | // } | 245 | // } |
| 246 | + if (this.fullyTraversed) { | ||
| 247 | + return; // 所有数据已取完 | ||
| 248 | + } | ||
| 249 | + this.currentDataList = this.getNextBatch() | ||
| 211 | this.activeIndexs = []; | 250 | this.activeIndexs = []; |
| 212 | } | 251 | } |
| 213 | }) | 252 | }) |
-
Please register or login to post a comment