chenjun3_wd

根据groupid按顺序请求并加载,直播回看加载及展现

@@ -25,11 +25,11 @@ export class CollectionUtils { @@ -25,11 +25,11 @@ export class CollectionUtils {
25 * @returns {boolean} true(empty) 25 * @returns {boolean} true(empty)
26 */ 26 */
27 static isEmpty(collection?: any[]): boolean { 27 static isEmpty(collection?: any[]): boolean {
28 - return !collection || collection.length === 0; 28 + return!collection || collection.length === 0;
29 } 29 }
30 30
31 static isEmptyList<T>(list1?: LinkList<T>): boolean { 31 static isEmptyList<T>(list1?: LinkList<T>): boolean {
32 - return !list1 || list1.length === 0; 32 + return!list1 || list1.length === 0;
33 } 33 }
34 34
35 static isEmptyHashMap(obj?: HashMap<any, any>): boolean { 35 static isEmptyHashMap(obj?: HashMap<any, any>): boolean {
@@ -179,5 +179,13 @@ export class CollectionUtils { @@ -179,5 +179,13 @@ export class CollectionUtils {
179 ss; 179 ss;
180 return collection.slice(start, end); 180 return collection.slice(start, end);
181 } 181 }
  182 +
  183 +
  184 + static getElement(collection?: any[], index?: number): any {
  185 + if (CollectionUtils.isEmpty(collection) || index === undefined) {
  186 + return null;
  187 + }
  188 + return index >= 0 && index < collection.length ? collection[index] : null;
  189 + }
182 } 190 }
183 191
@@ -48,7 +48,7 @@ export struct CompParser { @@ -48,7 +48,7 @@ export struct CompParser {
48 } else if (compDTO.compStyle === CompStyle.Zh_Single_Row_03) { 48 } else if (compDTO.compStyle === CompStyle.Zh_Single_Row_03) {
49 LiveHorizontalReservationComponent({ compDTO: compDTO }) 49 LiveHorizontalReservationComponent({ compDTO: compDTO })
50 } else if (compDTO.compStyle === CompStyle.Zh_Grid_Layout_02) { 50 } else if (compDTO.compStyle === CompStyle.Zh_Grid_Layout_02) {
51 - // ZhGridLayout02({ compDTO: compDTO }) 51 + ZhGridLayout02({ compDTO: compDTO })
52 } else if (compDTO.compStyle === CompStyle.Zh_Grid_Layout_03) { 52 } else if (compDTO.compStyle === CompStyle.Zh_Grid_Layout_03) {
53 ZhGridLayout03({ compDTO: compDTO }) 53 ZhGridLayout03({ compDTO: compDTO })
54 } else if (compDTO.compStyle === CompStyle.Zh_Single_Row_04) { 54 } else if (compDTO.compStyle === CompStyle.Zh_Single_Row_04) {
1 import { CompDTO, ContentDTO } from 'wdBean'; 1 import { CompDTO, ContentDTO } from 'wdBean';
  2 +import { CommonConstants } from 'wdConstant/Index';
2 3
3 const TAG = 'Zh_Grid_Layout-02'; 4 const TAG = 'Zh_Grid_Layout-02';
4 const FULL_PARENT: string = '100%'; 5 const FULL_PARENT: string = '100%';
@@ -22,16 +23,40 @@ export struct ZhGridLayout02 { @@ -22,16 +23,40 @@ export struct ZhGridLayout02 {
22 } 23 }
23 24
24 build() { 25 build() {
25 - GridRow({  
26 - columns: { sm: listSize, md: 2 },  
27 - breakpoints: { value: ['320vp', '520vp', '840vp'] }  
28 - }) {  
29 - ForEach(this.compDTO.operDataList, (item: ContentDTO, index: number) => {  
30 - GridCol() {  
31 - this.buildItemCard(this.compDTO.operDataList[index]);  
32 - }  
33 - }) 26 + Column() {
  27 + Row() {
  28 + Image($r("app.media.redLine"))
  29 + .width(3)
  30 + .height(16)
  31 + .margin({ right: 4 })
  32 + Text(this.compDTO.objectTitle)
  33 + .fontSize($r("app.float.font_size_17"))
  34 + .fontColor($r("app.color.color_222222"))
  35 + .fontWeight(600)
  36 + }
  37 + .justifyContent(FlexAlign.Start)
  38 + .margin({ top: 8, bottom: 8 })
  39 + .width(CommonConstants.FULL_WIDTH)
  40 +
  41 +
  42 + GridRow({
  43 + columns: { sm: listSize, md: 2 },
  44 + breakpoints: { value: ['320vp', '520vp', '840vp'] }
  45 + }) {
  46 + ForEach(this.compDTO.operDataList, (item: ContentDTO, index: number) => {
  47 + GridCol() {
  48 + this.buildItemCard(this.compDTO.operDataList[index]);
  49 + }
  50 + })
  51 + }
34 } 52 }
  53 + .width(CommonConstants.FULL_WIDTH)
  54 + .padding({
  55 + top: 14,
  56 + left: 16,
  57 + right: 16
  58 + })
  59 +
35 } 60 }
36 61
37 /** 62 /**
@@ -42,13 +67,13 @@ export struct ZhGridLayout02 { @@ -42,13 +67,13 @@ export struct ZhGridLayout02 {
42 @Builder 67 @Builder
43 buildItemCard(item: ContentDTO) { 68 buildItemCard(item: ContentDTO) {
44 Column() { 69 Column() {
45 - Image(item.coverUrl)  
46 - .width(44)  
47 - .aspectRatio(1 / 1) 70 + Image(item.fullColumnImgUrls[0].url)
  71 + .width(170)
  72 + .height(95)
48 .margin(16) 73 .margin(16)
49 Text(item.newsTitle) 74 Text(item.newsTitle)
50 .fontSize(13) 75 .fontSize(13)
51 - .maxLines(1) 76 + .maxLines(2)
52 .textOverflow({ overflow: TextOverflow.Ellipsis }) 77 .textOverflow({ overflow: TextOverflow.Ellipsis })
53 } 78 }
54 .width('100%') 79 .width('100%')
1 -import { CommonConstants, ViewType } from 'wdConstant'; 1 +import { CommonConstants, CompStyle, ViewType } from 'wdConstant';
2 import { DateTimeUtils, Logger } from 'wdKit'; 2 import { DateTimeUtils, Logger } from 'wdKit';
3 import PageViewModel from '../../viewmodel/PageViewModel'; 3 import PageViewModel from '../../viewmodel/PageViewModel';
4 import { EmptyComponent } from '../view/EmptyComponent'; 4 import { EmptyComponent } from '../view/EmptyComponent';
@@ -12,7 +12,7 @@ import LoadMoreLayout from './LoadMoreLayout'; @@ -12,7 +12,7 @@ import LoadMoreLayout from './LoadMoreLayout';
12 import CustomRefreshLoadLayout from './CustomRefreshLoadLayout'; 12 import CustomRefreshLoadLayout from './CustomRefreshLoadLayout';
13 import { CompParser } from '../CompParser'; 13 import { CompParser } from '../CompParser';
14 import { VideoChannelDetail } from 'wdDetailPlayShortVideo/Index'; 14 import { VideoChannelDetail } from 'wdDetailPlayShortVideo/Index';
15 -import { CompDTO, LiveReviewDTO } from 'wdBean'; 15 +import { CompDTO, LiveReviewDTO, PageDTO } from 'wdBean';
16 16
17 const TAG = 'PageComponent'; 17 const TAG = 'PageComponent';
18 18
@@ -23,6 +23,14 @@ export struct PageComponent { @@ -23,6 +23,14 @@ export struct PageComponent {
23 pageId: string = ""; 23 pageId: string = "";
24 channelId: string = ""; 24 channelId: string = "";
25 pageNum: number = 1; 25 pageNum: number = 1;
  26 + isFirstIn: boolean = true
  27 + pageDto: PageDTO = {
  28 + pageId: '',
  29 + id: 0,
  30 + name: '',
  31 + branchMark: false,
  32 + compList: []
  33 + }
26 liveReviewDTO: LiveReviewDTO = { 34 liveReviewDTO: LiveReviewDTO = {
27 hasNext: false, 35 hasNext: false,
28 pageNum: 0, 36 pageNum: 0,
@@ -126,41 +134,92 @@ export struct PageComponent { @@ -126,41 +134,92 @@ export struct PageComponent {
126 } 134 }
127 135
128 onChange() { 136 onChange() {
129 - Logger.info(TAG, `onChangezz id: ${this.pageId} , ${this.channelId} , ${this.navIndex} , navIndex: ${this.currentTopNavSelectedIndex}`);  
130 - if (this.navIndex === this.currentTopNavSelectedIndex) { 137 + Logger.info(TAG, `onChangezz id: ${this.pageId} , ${this.channelId} , ${this.navIndex} , ${this.isFirstIn} , navIndex: ${this.currentTopNavSelectedIndex}`);
  138 + if (this.navIndex === this.currentTopNavSelectedIndex && !this.isFirstIn) {
131 this.getData(); 139 this.getData();
132 } 140 }
133 } 141 }
134 142
  143 + /**
  144 + * 要按顺序处理pageInfo.groups中的每个元素,并确保每个异步操作完成后再继续执行下一个,你应该避免使用forEach。
  145 + * 取而代之的是,你可以使用for...of循环,并配合async/await来确保按顺序执行操作。
  146 + * */
135 async getData() { 147 async getData() {
136 Logger.info(TAG, `getData id: ${this.pageId} , ${this.channelId} , navIndex: ${this.currentTopNavSelectedIndex}`); 148 Logger.info(TAG, `getData id: ${this.pageId} , ${this.channelId} , navIndex: ${this.currentTopNavSelectedIndex}`);
137 this.pageModel.pageId = this.pageId; 149 this.pageModel.pageId = this.pageId;
138 this.pageModel.groupId = this.pageId; 150 this.pageModel.groupId = this.pageId;
139 this.pageModel.channelId = this.channelId; 151 this.pageModel.channelId = this.channelId;
140 this.pageModel.currentPage = 1; 152 this.pageModel.currentPage = 1;
141 - let pageDto = await PageViewModel.getPageData(this.pageModel.pageId, this.pageModel.pageId, this.pageModel.channelId  
142 - , this.pageModel.currentPage, this.pageModel.pageSize, getContext(this))  
143 - this.pageModel.timestamp = DateTimeUtils.getTimeStamp().toString()  
144 - if (pageDto && pageDto.compList && pageDto.compList.length > 0) {  
145 - this.pageModel.viewType = ViewType.LOADED;  
146 - this.pageModel.compList.push(...pageDto.compList)  
147 - if (pageDto.compList.length === this.pageModel.pageSize) {  
148 - this.pageModel.currentPage++;  
149 - this.pageModel.hasMore = true; 153 + let pageInfo = await PageViewModel.getPageUrlData(this.pageModel.pageId);
  154 + if (pageInfo == null) {
  155 + this.pageModel.viewType = ViewType.EMPTY;
  156 + return;
  157 + }
  158 + Logger.debug(TAG, 'getPageUrlData ' + pageInfo.id);
  159 + // pageInfo.groups.forEach(async (group) => { 不能按顺序加载用for...of替代
  160 + for (const group of pageInfo.groups) {
  161 + this.pageDto = await PageViewModel.getPageData(this.pageModel.pageId, `${group.id}`, this.pageModel.channelId
  162 + , this.pageModel.currentPage, this.pageModel.pageSize, getContext(this))
  163 + this.pageModel.timestamp = DateTimeUtils.getTimeStamp().toString()
  164 + if (this.pageDto && this.pageDto.compList && this.pageDto.compList.length > 0) {
  165 + this.pageDto.compList.forEach((comp) => {
  166 + if (comp.compStyle === CompStyle.Zh_Grid_Layout_02 && this.liveReviewDTO && this.liveReviewDTO.list && this.liveReviewDTO.list.length > 0) {
  167 + comp.operDataList.push(...this.liveReviewDTO.list)
  168 + }
  169 + })
  170 +
  171 + this.pageModel.viewType = ViewType.LOADED;
  172 + this.pageModel.compList.push(...this.pageDto.compList)
  173 + if (this.pageDto.compList.length === this.pageModel.pageSize) {
  174 + this.pageModel.currentPage++;
  175 + this.pageModel.hasMore = true;
  176 + } else {
  177 + this.pageModel.hasMore = false;
  178 + }
  179 + // // 二次请求,批查互动数据
  180 + // PageViewModel.getInteractData(pageDto.compList).then((data: CompDTO[]) => {
  181 + // // 刷新,替换所有数据
  182 + // this.pageModel.compList.replaceAll(...data)
  183 + // this.pageModel.timestamp = DateTimeUtils.getTimeStamp().toString()
  184 + // })
  185 + this.isFirstIn = false
  186 + Logger.debug(TAG, 'cj111');
150 } else { 187 } else {
151 - this.pageModel.hasMore = false; 188 + Logger.debug(TAG, 'aboutToAppear, data response page ' + this.pageId + ', comp list is empty.');
  189 + this.pageModel.viewType = ViewType.EMPTY;
152 } 190 }
153 - // 二次请求,批查互动数据  
154 - PageViewModel.getInteractData(pageDto.compList).then((data: CompDTO[]) => {  
155 - // 刷新,替换所有数据  
156 - this.pageModel.compList.replaceAll(...data)  
157 - this.pageModel.timestamp = DateTimeUtils.getTimeStamp().toString()  
158 - })  
159 - } else {  
160 - Logger.debug(TAG, 'aboutToAppear, data response page ' + this.pageId + ', comp list is empty.');  
161 - this.pageModel.viewType = ViewType.EMPTY;  
162 } 191 }
163 192
  193 + // this.isFirstIn = false
  194 + // let groupInfo: Group = CollectionUtils.getElement(pageInfo.groups, 0);
  195 + // if (groupInfo != null) {
  196 + // this.pageModel.groupStrategy = groupInfo.groupStrategy;
  197 + // this.pageModel.isRecGroup = groupInfo.groupStrategy === 1;
  198 + // this.pageModel.groupId = "" + groupInfo.id;
  199 + // }
  200 + // let pageDto = await PageViewModel.getPageData(this.pageModel.pageId, this.pageModel.pageId, this.pageModel.channelId
  201 + // , this.pageModel.currentPage, this.pageModel.pageSize, getContext(this))
  202 + // this.pageModel.timestamp = DateTimeUtils.getTimeStamp().toString()
  203 + // if (pageDto && pageDto.compList && pageDto.compList.length > 0) {
  204 + // this.pageModel.viewType = ViewType.LOADED;
  205 + // this.pageModel.compList.push(...pageDto.compList)
  206 + // if (pageDto.compList.length === this.pageModel.pageSize) {
  207 + // this.pageModel.currentPage++;
  208 + // this.pageModel.hasMore = true;
  209 + // } else {
  210 + // this.pageModel.hasMore = false;
  211 + // }
  212 + // // 二次请求,批查互动数据
  213 + // PageViewModel.getInteractData(pageDto.compList).then((data: CompDTO[]) => {
  214 + // // 刷新,替换所有数据
  215 + // this.pageModel.compList.replaceAll(...data)
  216 + // this.pageModel.timestamp = DateTimeUtils.getTimeStamp().toString()
  217 + // })
  218 + // } else {
  219 + // Logger.debug(TAG, 'aboutToAppear, data response page ' + this.pageId + ', comp list is empty.');
  220 + // this.pageModel.viewType = ViewType.EMPTY;
  221 + // }
  222 +
164 } 223 }
165 224
166 async getPreviewData() { 225 async getPreviewData() {
@@ -174,6 +174,12 @@ export class PageRepository { @@ -174,6 +174,12 @@ export class PageRepository {
174 return WDHttp.get<ResponseDTO<MorningEveningPaperDTO>>(url, headers) 174 return WDHttp.get<ResponseDTO<MorningEveningPaperDTO>>(url, headers)
175 }; 175 };
176 176
  177 + static fetchPageUrlData(pageId: string) {
  178 + let url = PageRepository.getPageUrl(pageId)
  179 + let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
  180 + return WDHttp.get<ResponseDTO<PageInfoBean>>(url, headers)
  181 + };
  182 +
177 static fetchPageData(pageId: string, groupId: string, channelId: string, currentPage: number, pageSize: number) { 183 static fetchPageData(pageId: string, groupId: string, channelId: string, currentPage: number, pageSize: number) {
178 let url = PageRepository.getCompInfoUrl(pageId, groupId, channelId, currentPage, pageSize) 184 let url = PageRepository.getCompInfoUrl(pageId, groupId, channelId, currentPage, pageSize)
179 let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); 185 let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
@@ -341,4 +347,10 @@ export class PageRepository { @@ -341,4 +347,10 @@ export class PageRepository {
341 Logger.info(TAG, "postRecommendList url = " + url + JSON.stringify(params)) 347 Logger.info(TAG, "postRecommendList url = " + url + JSON.stringify(params))
342 return WDHttp.post<ResponseDTO<ContentDTO[]>>(url, params, headers) 348 return WDHttp.post<ResponseDTO<ContentDTO[]>>(url, params, headers)
343 }; 349 };
  350 +
  351 + static getPageUrl(pageId: string) {
  352 + const url = HttpUrlUtils.getHost() + HttpUrlUtils.PAGE_INFO_PATH + "?pageId=" + pageId;
  353 + Logger.info(TAG, "getPageUrl url = " + url)
  354 + return url;
  355 + }
344 } 356 }
@@ -34,4 +34,6 @@ export default class PageModel { @@ -34,4 +34,6 @@ export default class PageModel {
34 isCanLoadMore: boolean = false; 34 isCanLoadMore: boolean = false;
35 // keyGenerator相关字符串,用于刷新list布局 35 // keyGenerator相关字符串,用于刷新list布局
36 timestamp: String = '1'; 36 timestamp: String = '1';
  37 + groupStrategy: number = 0;
  38 + isRecGroup: boolean = false;
37 } 39 }
@@ -6,7 +6,8 @@ import { @@ -6,7 +6,8 @@ import {
6 LiveReviewDTO, 6 LiveReviewDTO,
7 MorningEveningPaperDTO, 7 MorningEveningPaperDTO,
8 NavigationBodyDTO, 8 NavigationBodyDTO,
9 - PageDTO 9 + PageDTO,
  10 + PageInfoBean
10 } from 'wdBean'; 11 } from 'wdBean';
11 12
12 import { CollectionUtils, Logger, ResourcesUtils, StringUtils } from 'wdKit'; 13 import { CollectionUtils, Logger, ResourcesUtils, StringUtils } from 'wdKit';
@@ -168,6 +169,31 @@ export class PageViewModel extends BaseViewModel { @@ -168,6 +169,31 @@ export class PageViewModel extends BaseViewModel {
168 }) 169 })
169 } 170 }
170 171
  172 + async getPageUrlData(pageId: string): Promise<PageInfoBean> {
  173 + Logger.debug(TAG, 'getPageUrlData pageId: ' + pageId);
  174 + return new Promise<PageInfoBean>((success, error) => {
  175 + PageRepository.fetchPageUrlData(pageId)
  176 + .then((resDTO: ResponseDTO<PageInfoBean>) => {
  177 + if (!resDTO || !resDTO.data) {
  178 + Logger.error(TAG, 'fetchPageUrlData then resDTO is empty');
  179 + error('resDTO is empty');
  180 + return
  181 + }
  182 + if (resDTO.code != 0) {
  183 + Logger.error(TAG, `fetchPageUrlData then code:${resDTO.code}, message:${resDTO.message}`);
  184 + error('resDTO Response Code is failure');
  185 + return
  186 + }
  187 + Logger.info(TAG, "fetchPageUrlData then,resDTO.timestamp:" + resDTO.timestamp);
  188 + success(resDTO.data);
  189 + })
  190 + .catch((err: Error) => {
  191 + Logger.error(TAG, `fetchPageUrlData catch, error.name : ${err.name}, error.message:${err.message}`);
  192 + error(err);
  193 + })
  194 + })
  195 + }
  196 +
171 async getInteractData(compList: CompDTO[]) { 197 async getInteractData(compList: CompDTO[]) {
172 let param: InteractParam = this.getInteractParams(compList); 198 let param: InteractParam = this.getInteractParams(compList);
173 const SIZE = 20; 199 const SIZE = 20;