chenjun1_wd

换一换与安卓对齐

... ... @@ -14,7 +14,7 @@ const TAG = 'Zh_Single_Column-09'
@Entry
@Component
export struct ZhSingleColumn09 {
@State fullyTraversed: boolean = false;
@State fullyTraversed: boolean = false; //换一换置灰标记
@State private pageModel: PageModel = new PageModel();
@State pageId: string = '';
@State pageName: string = '';
... ... @@ -26,11 +26,46 @@ export struct ZhSingleColumn09 {
@State compIndex: number = 0;
@State currentOperDataListIndex: number = 0; //记录换一换点击次数
@State visitedIndices: Set<number> = new Set<number>();
private currentIndex: number = 0;
@State currentDataList: ContentDTO[] = []
async aboutToAppear(): Promise<void> {
this.loadImg = await onlyWifiLoadImg();
this.operDataList = this.shuffleArray(this.compDTO?.operDataList)
// this.operDataList = this.shuffleArray(this.compDTO?.operDataList)
this.operDataList = this.padData(this.compDTO?.operDataList)
this.currentOperDataListIndex = this.compDTO?.operDataList.length
this.currentDataList = this.getNextBatch()
}
/**
* 若数据不满足8个以上直接返回
* 若最后一屏不够补齐至8个
* */
private padData(data: ContentDTO[]): ContentDTO[] {
if (data.length < 9) {
return data
}
const remainder = data.length % 8;
if (remainder === 0) {
return data;
}
const paddingCount = 8 - remainder;
const padding = data.slice(0, paddingCount);
return [...data, ...padding];
}
/**
* 换一换切换数据
* */
public getNextBatch(): ContentDTO[] {
const batch = this.operDataList.slice(this.currentIndex, this.currentIndex + 8);
this.currentIndex += 8;
if (this.currentIndex >= this.operDataList.length) {
this.fullyTraversed = true //数据展现完毕,置灰标记
}
return batch;
}
trackClick(type: 'close_interest_card_click' | 'interest_card_selecting_click') {
... ... @@ -142,8 +177,8 @@ export struct ZhSingleColumn09 {
.justifyContent(FlexAlign.SpaceBetween)
.width('100%')
Flex({wrap: FlexWrap.Wrap}) {
ForEach(this.operDataList.slice(0, 8), (item: ContentDTO, index: number) => {
Flex({ wrap: FlexWrap.Wrap }) {
ForEach(this.currentDataList, (item: ContentDTO, index: number) => {
Row() {
Stack({ alignContent: Alignment.TopEnd }) {
Image(this.loadImg ? item.coverUrl : '')
... ... @@ -204,10 +239,14 @@ export struct ZhSingleColumn09 {
return
}
if (this.compDTO?.operDataList.length > 8) {
this.operDataList = this.shuffleArray(this.operDataList)
// this.operDataList = this.shuffleArray(this.operDataList)
// if (this.pageModel) {
// this.pageModel.compList.deleteItem(this.compIndex)
// }
if (this.fullyTraversed) {
return; // 所有数据已取完
}
this.currentDataList = this.getNextBatch()
this.activeIndexs = [];
}
})
... ...