陈剑华

Merge remote-tracking branch 'origin/main'

@@ -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) {
@@ -60,8 +60,7 @@ export struct ZhSingleRow04 { @@ -60,8 +60,7 @@ export struct ZhSingleRow04 {
60 .margin({ bottom: 8 }) 60 .margin({ bottom: 8 })
61 .width('100%') 61 .width('100%')
62 .padding({ 62 .padding({
63 - left: $r('app.float.card_comp_pagePadding_lf'),  
64 - right: $r('app.float.card_comp_pagePadding_lf') 63 + right: 10
65 }) 64 })
66 65
67 // 列表内容 66 // 列表内容
@@ -74,8 +73,8 @@ export struct ZhSingleRow04 { @@ -74,8 +73,8 @@ export struct ZhSingleRow04 {
74 } 73 }
75 ) 74 )
76 .margin({ 75 .margin({
77 - right: index === this.compDTO.operDataList.length - 1 ? 26 : 0, left:  
78 - index === 0 ? $r('app.float.card_comp_pagePadding_lf') : 0, 76 + right: index === this.compDTO.operDataList.length - 1 ? 26 : 0,
  77 + left: index === 0 ? 2 : 0,
79 top: 6 78 top: 6
80 }) 79 })
81 .onClick(() => { 80 .onClick(() => {