Showing
1 changed file
with
14 additions
and
5 deletions
| @@ -14,6 +14,7 @@ const TAG = 'Zh_Single_Column-09' | @@ -14,6 +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 private pageModel: PageModel = new PageModel(); | 18 | @State private pageModel: PageModel = new PageModel(); |
| 18 | @State pageId: string = ''; | 19 | @State pageId: string = ''; |
| 19 | @State pageName: string = ''; | 20 | @State pageName: string = ''; |
| @@ -24,6 +25,7 @@ export struct ZhSingleColumn09 { | @@ -24,6 +25,7 @@ export struct ZhSingleColumn09 { | ||
| 24 | @State loadImg: boolean = false; | 25 | @State loadImg: boolean = false; |
| 25 | @State compIndex: number = 0; | 26 | @State compIndex: number = 0; |
| 26 | @State currentOperDataListIndex: number = 0; //记录换一换点击次数 | 27 | @State currentOperDataListIndex: number = 0; //记录换一换点击次数 |
| 28 | + @State visitedIndices: Set<number> = new Set<number>(); | ||
| 27 | 29 | ||
| 28 | async aboutToAppear(): Promise<void> { | 30 | async aboutToAppear(): Promise<void> { |
| 29 | this.loadImg = await onlyWifiLoadImg(); | 31 | this.loadImg = await onlyWifiLoadImg(); |
| @@ -77,12 +79,21 @@ export struct ZhSingleColumn09 { | @@ -77,12 +79,21 @@ export struct ZhSingleColumn09 { | ||
| 77 | } | 79 | } |
| 78 | 80 | ||
| 79 | shuffleArray(array: ContentDTO[]) { | 81 | shuffleArray(array: ContentDTO[]) { |
| 80 | - for (let i = array.length - 1; i > 0; i--) { | 82 | + for (let i = array.length - 1; i >= 0; i--) { |
| 81 | const j = Math.floor(Math.random() * (i + 1)); | 83 | const j = Math.floor(Math.random() * (i + 1)); |
| 84 | + console.info(`cj2024 shuffleArray i = ${i} array.length = ${array.length}`) | ||
| 85 | + | ||
| 86 | + // 记录被选中的索引 j | ||
| 87 | + this.visitedIndices.add(j); | ||
| 88 | + console.info(`cj2024 shuffleArray j = ${j} visitedIndices = ${this.visitedIndices.size}`) | ||
| 82 | const tempArray = array[i]; | 89 | const tempArray = array[i]; |
| 83 | array[i] = array[j]; | 90 | array[i] = array[j]; |
| 84 | array[j] = tempArray | 91 | array[j] = tempArray |
| 85 | } | 92 | } |
| 93 | + | ||
| 94 | + // 检查是否所有元素都被遍历过 | ||
| 95 | + this.fullyTraversed = this.visitedIndices.size === array.length; | ||
| 96 | + | ||
| 86 | return array | 97 | return array |
| 87 | } | 98 | } |
| 88 | 99 | ||
| @@ -182,16 +193,14 @@ export struct ZhSingleColumn09 { | @@ -182,16 +193,14 @@ export struct ZhSingleColumn09 { | ||
| 182 | Row() { | 193 | Row() { |
| 183 | Text('换一换') | 194 | Text('换一换') |
| 184 | .fontSize(14) | 195 | .fontSize(14) |
| 185 | - .fontColor(this.compDTO?.operDataList.length > 8 && this.currentOperDataListIndex > 0 ? 0xed2800 : 0xB0B0B0) | 196 | + .fontColor(this.compDTO?.operDataList.length > 8 && !this.fullyTraversed ? 0xed2800 : 0xB0B0B0) |
| 186 | .margin({ right: 4 }) | 197 | .margin({ right: 4 }) |
| 187 | Image(this.compDTO?.operDataList.length > 8 ? $r('app.media.icon_refresh') : $r('app.media.ic_refresh')) | 198 | Image(this.compDTO?.operDataList.length > 8 ? $r('app.media.icon_refresh') : $r('app.media.ic_refresh')) |
| 188 | .width(14) | 199 | .width(14) |
| 189 | .height(14) | 200 | .height(14) |
| 190 | } | 201 | } |
| 191 | .onClick(() => { | 202 | .onClick(() => { |
| 192 | - if (this.currentOperDataListIndex > 0) { | ||
| 193 | - this.currentOperDataListIndex-- | ||
| 194 | - } else { | 203 | + if (this.fullyTraversed) { |
| 195 | return | 204 | return |
| 196 | } | 205 | } |
| 197 | if (this.compDTO?.operDataList.length > 8) { | 206 | if (this.compDTO?.operDataList.length > 8) { |
-
Please register or login to post a comment