王士厅
... ... @@ -14,6 +14,7 @@ const TAG = 'Zh_Single_Column-09'
@Entry
@Component
export struct ZhSingleColumn09 {
@State fullyTraversed: boolean = false;
@State private pageModel: PageModel = new PageModel();
@State pageId: string = '';
@State pageName: string = '';
... ... @@ -24,6 +25,7 @@ export struct ZhSingleColumn09 {
@State loadImg: boolean = false;
@State compIndex: number = 0;
@State currentOperDataListIndex: number = 0; //记录换一换点击次数
@State visitedIndices: Set<number> = new Set<number>();
async aboutToAppear(): Promise<void> {
this.loadImg = await onlyWifiLoadImg();
... ... @@ -77,12 +79,21 @@ export struct ZhSingleColumn09 {
}
shuffleArray(array: ContentDTO[]) {
for (let i = array.length - 1; i > 0; i--) {
for (let i = array.length - 1; i >= 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
console.info(`cj2024 shuffleArray i = ${i} array.length = ${array.length}`)
// 记录被选中的索引 j
this.visitedIndices.add(j);
console.info(`cj2024 shuffleArray j = ${j} visitedIndices = ${this.visitedIndices.size}`)
const tempArray = array[i];
array[i] = array[j];
array[j] = tempArray
}
// 检查是否所有元素都被遍历过
this.fullyTraversed = this.visitedIndices.size === array.length;
return array
}
... ... @@ -182,16 +193,14 @@ export struct ZhSingleColumn09 {
Row() {
Text('换一换')
.fontSize(14)
.fontColor(this.compDTO?.operDataList.length > 8 && this.currentOperDataListIndex > 0 ? 0xed2800 : 0xB0B0B0)
.fontColor(this.compDTO?.operDataList.length > 8 && !this.fullyTraversed ? 0xed2800 : 0xB0B0B0)
.margin({ right: 4 })
Image(this.compDTO?.operDataList.length > 8 ? $r('app.media.icon_refresh') : $r('app.media.ic_refresh'))
.width(14)
.height(14)
}
.onClick(() => {
if (this.currentOperDataListIndex > 0) {
this.currentOperDataListIndex--
} else {
if (this.fullyTraversed) {
return
}
if (this.compDTO?.operDataList.length > 8) {
... ...