fanmingyou3_wd

Merge branch 'main' of http://192.168.1.42/developOne/harmonyPool into main

Showing 89 changed files with 4446 additions and 0 deletions

Too many changes to show.

To preserve performance only 89 of 89+ files are displayed.

... ... @@ -105,6 +105,18 @@
]
}
]
},
{
"name": "wdLayout",
"srcPath": "./wdLayout",
"targets": [
{
"name": "default",
"applyToProducts": [
"default"
]
}
]
}
]
}
\ No newline at end of file
... ...
export { CommonConstants } from './src/main/ets/constants/CommonConstants';
export { BreakpointConstants } from './src/main/ets/constants/BreakpointConstants';
export { ConfigConstants } from './src/main/ets/constants/ConfigConstants';
\ No newline at end of file
... ...
/**
* Config Constants.
*/
export class ConfigConstants {
/**
* 应用id/appId
*
*/
static readonly appId: string = "";
/**
* 终端id/terminalId
*
*/
static readonly terminalId: string = "android";
/**
* 36_渠道编码(sappType)
*
*/
// static readonly appType: string = "2"; // wap
static readonly appType: string = "3"; // 手机客户端App(安卓)
static readonly clientType: string = "";
/**
* SourceID
*
*/
static readonly sourceId: string = "";
/**
* 产品渠道应用对照关系:
*/
static readonly appCode: string = "";
/**
* 基线代码和客户端应用版本号规范
*/
static readonly ptvCode: string = "";
/**
* 省份code/province(02->上海)
*/
static readonly province: string = "02";
/**
* 正在播放的节目ID
*/
static playingContentId?: string = null
/**
* 设备Id/deviceId
* 设备Id或者能标识请求端的唯一标识
*/
static readonly DEVICE_ID: string = "5bfed7be-0497-487f-990b-991e5b828a6e";
/**
* base url VOD
*/
static readonly BASE_URL_VOD: string = "";
/**
* base url Live
*/
static readonly BASE_URL_LIVE: string = "";
/**
* 获取用户信息的服务器
*/
static readonly BASE_URL: string = "";
/**
* 内容列表路径
*/
static readonly CONTENT_LIST_PATH: string = "/display/v4/static";
/**
* 电视台(直播)列表路径
*/
static readonly LIVE_TV_PATH: string = "/live/v2/tv-data";
}
\ No newline at end of file
... ...
... ... @@ -4,6 +4,10 @@ export { ResourcesUtils } from './src/main/ets/utils/ResourcesUtils'
export { StringUtils } from './src/main/ets/utils/StringUtils'
export { ArrayUtils } from './src/main/ets/utils/ArrayUtils';
export { AppUtils } from './src/main/ets/utils/AppUtils';
export { BasicDataSource } from './src/main/ets/utils/BasicDataSource';
export { LazyDataSource } from './src/main/ets/utils/LazyDataSource'
... ...
import common from '@ohos.app.ability.common';
import bundleManager from '@ohos.bundle.bundleManager';
const TAG: string = 'AppUtils';
/**
* 与应用相关属性或操作
*/
export class AppUtils {
/**
* 获取应用名称
* 即:咪咕视频
*/
static getAppName(context: common.Context): string {
// todo:获取到的是 $string:app_name
// return context.applicationInfo?.label;
return context.resourceManager.getStringByNameSync("app_name");
}
/**
* 获取应用的包名
* 即:com.cmcc.myapplication
*/
static getPackageName(context: common.Context): string {
return context.applicationInfo?.name;
}
/**
* 获取应用版本号,如:1.0.0.0
* @returns 版本号字符串
*/
static getAppVersionName(): string {
try {
let bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT)
return bundleInfo?.versionName
} catch (e) {
}
return "";
}
/**
* 获取应用版本编码,如:1000000
* @returns 应用版本编码
*/
static getAppVersionCode(): string {
return "2600010700"
// try {
// let bundleInfo = bundleManager.getBundleInfoForSelfSync(bundleManager.BundleFlag.GET_BUNDLE_INFO_DEFAULT)
// return bundleInfo?.versionCode
// } catch (e) {
// Logger.warn(TAG, 'get app version error:' + e?.message);
// }
// return 0;
}
}
... ...
import LinkList from '@ohos.util.List';
export class ArrayUtils {
/**
* The Array utils tag.
*/
private static readonly TAG: string = 'ArrayUtils';
static isArray(value: any): boolean {
if (typeof Array.isArray === 'function') {
return Array.isArray(value);
} else {
return Object.prototype.toString.call(value) === '[object Array]';
}
}
/**
* Check collection is empty or not.
* @param collection any[]
* @returns {boolean} true(empty)
*/
static isEmpty(collection?: any[]): boolean {
return!collection || collection.length === 0;
}
/**
* Check collection is empty or not.
* @param collection any[]
* @returns {boolean} true(not empty)
*/
static isNotEmpty(collection?: any[]): boolean {
if (!collection) {
return false
}
return collection.length > 0;
}
static getListSize(collection?: any[]): number {
return ArrayUtils.isEmpty(collection) ? 0 : collection.length;
}
static getListElement(collection?: any[], index?: number): any {
if (ArrayUtils.isEmpty(collection) || index === undefined) {
return null;
}
return index >= 0 && index < collection.length ? collection[index] : null;
}
static convertArray<T>(objectList: T[] | T): T[] {
if (ArrayUtils.isArray(objectList)) {
return objectList as T[];
} else {
return [objectList as T];
}
}
/**
* 把list2合入list1后
* @param list1
* @param list2
* @returns
*/
static addAll<T>(list1: LinkList<T>, list2: LinkList<T>): LinkList<T> {
if (!list1) {
list1 = new LinkList<T>();
}
if (!list2) {
return list1;
}
for (let index = 0; index < list2.length; index++) {
list1.add(list2[index])
}
return list1
}
static deepCopy(objectList: any[]): any[] {
const list: any[] = [];
for (const objectItem of objectList) {
if (typeof objectItem !== 'object') {
list.push(objectItem);
continue;
}
if (objectItem.constructor === Date) {
list.push(new Date(objectItem));
continue;
}
if (objectItem.constructor === RegExp) {
list.push(new RegExp(objectItem));
continue;
}
if (objectItem.clone) {
list.push(objectItem.clone());
continue;
}
const newObj = new objectItem.constructor();
for (const key in objectItem) {
if (Object.hasOwnProperty.call(objectItem, key)) {
const val = objectItem[key];
newObj[key] = val;
}
}
list.push(newObj);
}
return list;
}
static deepCopyNumber(values: Set<number>): Set<number> {
const newSet: Set<number> = new Set();
values.forEach((value => {
newSet.add(value);
}));
return newSet;
}
/**
* Uint8Array to string
* @param fileData Uint8Array
*/
static uint8ArrayToString(fileData: Uint8Array): string {
return decodeURIComponent(escape(String.fromCharCode(...fileData)));
}
/**
* string to Uint8Array
* @param str string
*/
static stringToUint8Array(str: string): Uint8Array {
// spilt('') Each character is divided between them
const arr = unescape(encodeURIComponent(str)).split('').map(val => val.charCodeAt(0));
return new Uint8Array(arr);
}
}
\ No newline at end of file
... ...
export { PageUtils } from './src/main/ets/utils/PageUtils'
export { WDPage } from "./src/main/ets/layout/WDPage"
export { WDGroup } from "./src/main/ets/layout/WDGroup"
export { WDComp } from "./src/main/ets/layout/WDComp"
export { Lego } from "./src/main/ets/lego/LegoService"
export { PageViewModel } from "./src/main/ets/viewmodel/PageViewModel"
\ No newline at end of file
... ...
{
"apiType": "stageMode",
"buildOption": {
"arkOptions": {
// "apPath": "./modules.ap" /* Profile used for profile-guided optimization (PGO), a compiler optimization technique to improve app runtime performance. */
}
},
"buildOptionSet": [
{
"name": "release",
"arkOptions": {
"obfuscation": {
"ruleOptions": {
"enable": true,
"files": [
"./obfuscation-rules.txt"
]
}
}
}
},
],
"targets": [
{
"name": "default"
}
]
}
\ No newline at end of file
... ...
import { hspTasks } from '@ohos/hvigor-ohos-plugin';
export default {
system: hspTasks, /* Built-in plugin of Hvigor. It cannot be modified. */
plugins:[] /* Custom plugin to extend the functionality of Hvigor. */
}
... ...
# Define project specific obfuscation rules here.
# You can include the obfuscation configuration files in the current module's build-profile.json5.
#
# For more details, see
# https://gitee.com/openharmony/arkcompiler_ets_frontend/blob/master/arkguard/README.md
# Obfuscation options:
# -disable-obfuscation: disable all obfuscations
# -enable-property-obfuscation: obfuscate the property names
# -enable-toplevel-obfuscation: obfuscate the names in the global scope
# -compact: remove unnecessary blank spaces and all line feeds
# -remove-log: remove all console.* statements
# -print-namecache: print the name cache that contains the mapping from the old names to new names
# -apply-namecache: reuse the given cache file
# Keep options:
# -keep-property-name: specifies property names that you want to keep
# -keep-global-name: specifies names that you want to keep in the global scope
\ No newline at end of file
... ...
{
"name": "wdlayout",
"version": "1.0.0",
"description": "Please describe the basic information.",
"main": "Index.ets",
"author": "",
"license": "Apache-2.0",
"dependencies": {
"wdKit": "file:../wdKit",
"wdNetwork": "file:../wdNetwork",
"wdConstant": "file:../wdConstant"
}
}
\ No newline at end of file
... ...
import { Params } from './Params';
export interface Action {
type: string;
name?: string; // 行为的名称,目前值与type相同,暂不启用
params?: Params; // 参数集合
androidMinVersion?: string; // 最低版本号, -1(-1表示不限制)
iosMinVersion?: string; // -1(-1表示不限制)
}
\ No newline at end of file
... ...
export interface AdInfo {
adPosition: string[];
materialStyle: string[];
adID: string[];
startPosition: string;
displayStride: string;
}
\ No newline at end of file
... ...
export interface Baseline {
baselineShow: string;
}
\ No newline at end of file
... ...
/**
* 底导数据容器
*/
import { NavButton } from './NavButton';
export class BottomBar {
backgroundImg?: string;
buttons: NavButton[];
}
\ No newline at end of file
... ...
import { ButtonDTO } from './ButtonDTO';
import { ItemBean } from './ItemBean';
@Observed
export class ButtonBean extends ItemBean {
label: string; // button类型,即:按钮1/按钮2
title: string; // 标题,如:换一换/更多/更多热播电视剧/更多好剧/更多综艺/更多热点/古装剧场/燃剧场
subTitle: string; // 副标题
icon?: string; // 小图标
constructor(dto: ButtonDTO) {
super(dto);
this.label = dto.label;
this.title = dto.title;
this.subTitle = dto.subTitle;
this.icon = dto.icon;
}
}
\ No newline at end of file
... ...
import { ItemDTO } from './ItemDTO';
export class ButtonDTO extends ItemDTO {
label: string; // button类型,即:按钮1/按钮2
title: string; // 标题,如:换一换/更多/更多热播电视剧/更多好剧/更多综艺/更多热点/古装剧场/燃剧场
subTitle: string; // 副标题
icon?: string; // 小图标
}
\ No newline at end of file
... ...
export interface CacheTrace {
refreshTime?: string;
updateTime?: string;
description?: string;
traceId?: string;
updateTimeStamp?: string;
}
\ No newline at end of file
... ...
/**
* 组件DTO
*/
import { Action } from './Action';
import { AdInfo } from './AdInfo';
import { DataSourceRequest } from './DataSourceRequest';
import { ExtraDTO } from './ExtraDTO';
import { OsVersion } from './OsVersion';
export class CompDTO {
id: string; // 组件id
name: string; // 组件名称
title?: string; // 标题:若无值,则不露出该字段
description?: string; // 描述:若无值,则不露出该字段
compType: string; // 组件类型
compStyle: string; // 组件样式
fetchDataType: string; // 获取数据方式
dataCount: string; // 需要填充的数据数量
dataSource?: string; // Comp的数据源:若无值,则不露出该字段
vomsNodeID?: string; // VOMS展现对象节点ID:若无值,则不露出该字段(暂不维护)
searchCondition?: string; // 搜索条件:若无值,则不露出该字段
// bodyComponent?: BodyComponent; // 可保存二次请求的数据【组件id】对应/映射BodyComponent的id
// contentInfoData?: ContentInfoData; // 可保存二次请求的数据【剧集/节目id】
// bodyPlayUrl?:BodyPlayUrl;// 保存二次请求的数据播放数据
extraData?: ExtraDTO; // 辅助数据
isWaterfallFlow: string; // 是否以瀑布流形式展示0:否 1:是
isContainAD: number; // 是否内嵌广告,数据字典:0:否1:是
adInfo?: AdInfo; // 广告信息
sortValue: string; // 展现顺序
icon?: string; // comp的icon图标: 若无值,则不露出该字段
status: string; // 状态,0为无效,1为有效
location: string; // comp所在页面路径
action?: Action; // 事件对象
fitArea: string[]; // 适用地区
displayCount: string; // 展示数量
platformId: string[]; // 适用平台
zIndex: string; // 浮层高度
iosVersion?: OsVersion; // ios版本号
androidVersion?: OsVersion; // 安卓版本号
// 符合的用户类型:
// 非会员 0,体验会员 1,世界杯会员 2,黄金会员 3,钻石会员 4,钻石会员(TV尊享)5,超级会员 6,大站包会员 7,未登录用户 -1,咪爱会员 8
userType: string[];
ipadVersion?: OsVersion; // ipad版本号
dataSourceRequest?: DataSourceRequest[]; // 数据源请求(目前只支持“猜你喜欢”): 若无值,则不露出该字段
vrVersion?: OsVersion; // vr版本
styleRefreshStrategy: string;
yingshizongShowTv: string;
}
\ No newline at end of file
... ...
/**
* 组件对应服务器返回的comp数据Body
*/
import { ItemDTO } from './ItemDTO';
import { ProgrammeDTO } from './ProgrammeDTO';
export class CompDataDTO extends ItemDTO {
id: string; // 组件主键ID
name: string; // 名称
branchMark: boolean; // 是否有分众数据标志位 true表示存在分众信息
data: ProgrammeDTO[]; // Object是被Wrapper后的节目数据
// totalPage: string = ''; // 总页数
// totalCount: string = ''; // 总数据条数
// refreshTime: string = ''; // 缓存刷新时间
// dataSourceType: string = ''; // 数据源类型
// fitArea: string[] = []; //适用地区
// cacheTraceVO?: CacheTraceVO = {}; // comp缓存链路跟踪信息
}
\ No newline at end of file
... ...
export class CopyRightVo {
terminal: string;
area: string;
beginDate: string;
endDate: string;
way: string;
}
\ No newline at end of file
... ...
export interface DataSourceRequest {
method: string; // 请求方式
responseDataType: number;
paramter: any; // JSON 请求参数
header: any; // JSON 请求头信息入参
poolId: string; //池ID(新数据源存在,原老comp数据源不存在)
// 数据源类型
dataSourceType: string;
timeout: number; // 数据源超时时间,单位毫秒
// 客户端数据刷新策略
// CACHE:本地缓存优先
// NET:网络数据优先,
// NET_ONLY:只读网络(客户端未适配)
dataRefresh: string;
h5uri: string; // h5URI
uri: string; // 客户端URI
locationValue: string; //
displayCount: number; //
backupDataSource: DataSourceRequest; // 备用数据源
}
\ No newline at end of file
... ...
export class DisplayName {
first: string;
second: string[];
}
\ No newline at end of file
... ...
import { ButtonDTO } from './ButtonDTO';
import { FilterCategoryDTO } from './FilterCategoryDTO';
import { ItemDTO } from './ItemDTO';
import { LabelDTO } from './LabelDTO';
import { Tab01DTO } from './Tab01DTO';
import { Tab22DTO } from './Tab22DTO';
export class ExtraDTO extends ItemDTO {
menus?: Tab01DTO[];
tabs?: Tab22DTO[];
labels?: LabelDTO[];
buttons?: ButtonDTO[];
screenList: FilterCategoryDTO[]; // 筛选条件的种类列表/筛查
focusId?: string; // 聚焦项MenuId/导航栏id
backgroundColor?: string; // 背景颜色
backgroundImg?: string; // 背景图片
expandable?: string; // 是否可展开
tabBarExpandStyle?: string; // 导航栏展开样式
grayFilter?: string;
showWeather?: string;
subTitleIntervaltime?: string;
// paster?: any;
regulationId?: string;
mute?: string;
autoPlay?: string;
isPlaytimesForbidden?: string;
// cards: Card[]; // SHORT_WITH_LONG 混合短带长
// isInsertCards: string;
starID?: string; // 明星Id,用于Params的extra中
showMemberResources?: string;
defaultStyle?: string;
// memberResourcesData?: { activityId: string };
mgdbID?: string;
isNewH5Page: string;
pageURL: string;
}
\ No newline at end of file
... ...
/**
* CLASSIFY_FILTER_BAR-02
* 筛选条件的种类/过滤器
*/
import { FilterCategoryDTO } from './FilterCategoryDTO';
import { ItemBean } from './ItemBean';
import { PairFilter } from './PairFilter';
@Observed
export class FilterCategoryBean extends ItemBean {
categoryValue: string;
categoryKey: string;
content: PairFilter[];
constructor(dto: FilterCategoryDTO) {
super(dto);
this.categoryValue = dto.categoryValue;
this.categoryKey = dto.categoryKey;
this.content = dto.content;
}
}
... ...
/**
* 筛选条件的种类:
* mediaType(类型)/mediaArea(地区)/mediaYear(年代)/rankingType(排序类型)/payType(付费类型)/mediaMovieForm(规格)
*/
import { ItemDTO } from './ItemDTO';
import { PairFilter } from './PairFilter';
export class FilterCategoryDTO extends ItemDTO {
categoryValue: string; // 类型/地区/年代/排序类型/付费类型/规格
categoryKey: string; // mediaType/mediaArea/mediaYear/rankingType/payType/mediaMovieForm
content: PairFilter[];
}
\ No newline at end of file
... ...
import { CompDTO } from './CompDTO';
import { ItemDTO } from './ItemDTO';
import { OsVersion } from './OsVersion';
export class GroupDTO extends ItemDTO {
id: string; // group主键ID
name: string; // 名称
branchMark: boolean;
fitArea?: string[];
components: CompDTO[]; // Components集合的布局信息
platformId?: string[];
iosVersion?: OsVersion;
androidVersion?: OsVersion;
userType?: string[];
isSegmentLine?: string;
isPopup?: string;
ipadVersion?: OsVersion;
vrVersion?: OsVersion;
groupType?: string;
fitTelecomOperators?: string[];
channelCode?: string;
removeRepeat?: boolean;
}
\ No newline at end of file
... ...
/**
* 对应服务器返回的group数据
*/
import { CompDataDTO } from './CompDataDTO';
import { ItemDTO } from './ItemDTO';
export class GroupDataDTO extends ItemDTO {
id: string; // Group主键ID
name: string; // 名称
branchMark: boolean;
components: CompDataDTO[];
}
\ No newline at end of file
... ...
/**
* 绑定到组件comp/view的数据Bean
*/
import { Action } from './Action';
import { ItemDTO } from './ItemDTO';
import { Pic } from './Pic';
@Observed
export abstract class ItemBean {
action?: Action; // 事件行为
actionId?: string; // 点击事件id
pics?: Pic
h5pics: Pic;
landscapeCover?: string; // 横向低分辨封面图片
portraitCover?: string; // 竖向低分辨封面图片
highLandscapeCover?: string; // 横向高分辨封面图片
highPortraitCover?: string; // 竖向高分辨封面图片
lowResolutionV34?: string; // 低清竖图(3:4比例), 取图逻辑 3:4低清竖图-->3:4高清竖图-->低分辨率竖图-->高分辨率竖图
highResolutionV34?: string; // 高清竖图(3:4比例), 取图逻辑 3:4高清竖图-->3:4低清竖图-->高分辨率竖图-->低分辨率竖图
/**
* 是否被曝光
*/
exposed: boolean;
/**
* 曝光位置
*/
position: string;
constructor(dto: ItemDTO) {
this.action = dto.action
this.actionId = dto.actionId
this.pics = dto.pics
this.h5pics = dto.h5pics
this.landscapeCover = !dto.pics ? "" : !dto.pics.lowResolutionH ? dto.pics.highResolutionH : dto.pics.lowResolutionH;
this.portraitCover = !dto.pics ? "" : !dto.pics.lowResolutionV ? dto.pics.highResolutionV : dto.pics.lowResolutionV;
this.highLandscapeCover = !dto.pics ? "" : !dto.pics.highResolutionH ? dto.pics.lowResolutionH : dto.pics.highResolutionH;
this.highPortraitCover = !dto.pics ? "" : !dto.pics.highResolutionV ? dto.pics.lowResolutionV : dto.pics.highResolutionV;
this.lowResolutionV34 = !dto.pics ? "" : (!dto.pics.lowResolutionV34 ? dto.pics.lowResolutionV34 : (!dto.pics.highResolutionV34 ? dto.pics.highResolutionV34 : this.portraitCover));
this.highResolutionV34 = !dto.pics ? "" : (!dto.pics.highResolutionV34 ? dto.pics.highResolutionV34 : (!dto.pics.lowResolutionV34 ? dto.pics.lowResolutionV34 : this.highPortraitCover));
this.exposed = false
this.position = "0"
}
public setAction(action: Action): void {
this.action = action
}
public getAction(): Action {
return this.action ?? {} as Action
}
}
... ...
/**
* 组件comp/view对应的服务端数据
* DTO 数据传输实体类接口,所有数据传输层数据结构体需实现该接口
*/
import { Action } from './Action';
import { Pic } from './Pic';
export abstract class ItemDTO {
action?: Action; // 事件对象
actionId?: string; // 点击事件id
pics?: Pic // 图片
h5pics: Pic; // 图片
}
\ No newline at end of file
... ...
import { ItemBean } from './ItemBean';
import { LabelDTO } from './LabelDTO';
@Observed
export class LabelBean extends ItemBean {
icon?: string;
defaultTextColor?: string;
label: string;
title: string;
subTitle?: string;
description?: string;
bottomColor?: string;
isShow?: boolean;
constructor(dto: LabelDTO) {
super(dto);
this.label = dto.label;
this.title = dto.title;
this.subTitle = dto.subTitle;
}
}
\ No newline at end of file
... ...
/**
* 标题 —— 标题(LABEL-01)
*/
import { ItemDTO } from './ItemDTO';
export class LabelDTO extends ItemDTO {
icon?: string; // icon图片/小图标
defaultTextColor?: string; // 文本颜色
label: string; // label类型,如:主标题/子标题
title: string; // 标题,如:重磅推荐/热门视频彩铃/更多下饭剧/4K超高清/更多>/更多动画
subTitle?: string; // 副标题/二级标题
description?: string; // 描述信息
bottomColor?: string; // 标题底色
isShow?: boolean;
}
\ No newline at end of file
... ...
/**
* 搜索bar左边的logo图标
*/
import { Action } from './Action';
export interface Logo {
name: string;
logoLightImg: string;
logoLightImg2: string;
logoLightImgBackground: string;
logoLightImgBackground2: string;
logoDarkImg: string;
logoDarkImg2: string;
logoDarkImgBackground: string;
logoDarkImgBackground2: string;
action: Action;
}
\ No newline at end of file
... ...
/**
* 导航Body数据
*/
import { NavigationBean } from './NavigationBean';
export class NavBody {
isConfigData: string;
list: NavigationBean[];
}
\ No newline at end of file
... ...
/**
* 底部或顶部导航按钮Bean
*/
import { Action } from './Action';
export class NavButton {
// name: string; // 底导名称
displayText: string; // 展示名称
action: Action; // 跳转事件
// bottomBar下的按钮属性
lightClieckAnimation?: string; // 浅色点击动画json串
lightDefaultImg?: string; // 浅色默认图片
lightActivatedImg?: string; // 浅色点击图片
lightDefaultTextColor?: string; // 浅色默认文字颜色
lightActivatedTextColor?: string; // 浅色点击文字颜色
lightOtherImageMode?: number; // 浅色其它图模式
lightBackgroundColor?: string; // 浅色背景颜色
darkClieckAnimation?: string; // 深色点击动画json串
darkDefaultImg?: string; // 深色模式默认图片
darkActivatedImg?: string; // 深色模式点击图片
darkDefaultTextColor?: string; // 深色文字默认颜色
darkActivatedTextColor?: string; // 深色文字点击颜色
darkOtherImageMode?: number; // 深色其它图模式 深色其它图模式 1:浅色模式 2:深色模式
darkBackgroundColor?: string; // 深色背景颜色
topBarID?: string; // 对应顶导框架ID
// topBar下的按钮属性
buttonType?: string; // 按钮类型:FUN
lightIconImg?: string; // 浅色Icon图片
darkIconImg?: string; // 深色Icon图片
// 其他属性
lightDefaultColor?: string;
lightSelectedColor?: string;
darkDefaultColor?: string;
darkSelectedColor?: string;
// defaultTextColor?: string;
// activatedTextColor?: string;
// defaultImg?: string;
// originPageId?: string;
}
... ...
/**
* 当前客户端底导/顶导全部数据
*/
import { BottomBar } from './BottomBar';
import { TopBar } from './TopBar';
export class NavigationBean {
id: string;
name: string;
bottomBar: BottomBar; // 底导数据
topBars: TopBar[]; // 顶导数据
updateTime?: number;
status?: number;
byVersion?: string;
beginVersion?: string;
endVersion?: string;
}
\ No newline at end of file
... ...
/**
* ios版本号: IosVersion
* 安卓版本号: AndroidVersion
* ipad版本号: IpadVersion
* Vr版本号: VrVersion
*/
export class OsVersion {
// 是否展示:-1 不展示、1 全部版本、0 指定版本
isAllVersion?: string;
// 最小版本号
min?: string;
// 最大版本号
max?: string;
// 排除的版本号
exclude?: string[];
}
\ No newline at end of file
... ...
import { Baseline } from './Baseline';
import { CacheTrace } from './CacheTrace';
import { ExtraDTO } from './ExtraDTO';
import { GroupDTO } from './GroupDTO';
import { OsVersion } from './OsVersion';
export class PageDTO {
id: string; // 主键ID
name: string; // 名称
title: string; // 标题
branchMark: boolean; // 分众标志位 true表示存在分众信息
isEmbedPopupPage: string; // 是否内嵌弹出页面。0:不内嵌弹出页面 1:内嵌弹出页面
groups: GroupDTO[]; // page下的group布局信息
fitArea: string[]; //
isShared: string;
shareMainTitle?: string;
shareSubTitle?: string;
shareUrl?: string;
shareIcon?: string;
pageSearchText: string[]; // 页面顶部搜索hint文本数组
platformId: string[];
iosVersion: OsVersion;
androidVersion: OsVersion;
backgroundColor: string;
transparency: string;
extraData: ExtraDTO; // 辅助数据
ipadVersion: OsVersion;
backToTop: string;
// theme: Theme;
baseline: Baseline;
refreshTime: string;
cacheTraceVO: CacheTrace;
vrVersion: OsVersion;
grayFilter: string;
preloadingGroupCount: string;
}
... ...
/**
* 筛选/过滤的键值对
*/
export class PairFilter {
value: string;
key: string;
}
\ No newline at end of file
... ...
import { DataSourceRequest } from './DataSourceRequest';
import { ExtraDTO } from './ExtraDTO';
import { ReportingData } from './ReportingData';
export class Params {
pageID: string;
// 需要展现Fame类型,数据字典为:
// default-frame:不包含搜索栏、底部tab工具条的frame
// main-frame:包含搜索栏、底部tab工具条的frame
frameID?: string;
contentID?: string; // 如果type是节目详情类型,字段为需要播放的节目ID(必传),如:656057406
longVideoID?: string; // 关联的长视频节目ID/综艺关联正片id
path?: string; // 需要跳转/刷新的内部路径,这个路径可以是pageID,也可是compID
url?: string; // 需要跳转到的URL地址/H5打开链接
location: string; // 当前事件的发起comp路径,格式:PageID#GroupID#CompID
extra?: ExtraDTO; // 跳转时额外需要带的参数:map<String,String> 即仅有一层的json
supportRuleEngine?: boolean;
fitArea?: string[]; // 分省策略(用于埋点数据统计)
programTypeV2?: string; // 节目类型(可用于节目对应详情页映射)
albumID?: string; // 专辑壳ID(适用于某节目属于多个专辑的情况下,指定某专辑播放)
autoPlayType?: string; // 自动连播类型(沉浸式播放-VERTICAL_PLAYER;)
popType?: string; // 弹出页面类型(适用于新页面半屏弹出),数据字典为:// DEFAULT:默认类型(半屏); // FULL: 全屏
reportingData?: ReportingData; // 埋点上报数据对象:将数据埋点需要的数据上报给客户端
compstyle?: string; // COMP样式
targetComp?: string; // 需要触发操作的目标COMP
dataSourceRequest?: DataSourceRequest; // 数据源请求
crbtID?:string; // 彩铃ID(适用于彩铃节目)
crbtCopyRightID?:string; // 彩铃版权ID(适用于彩铃节目)
assetId?:string; // 媒资ID(若乐高运营的节目未查出关联媒资ID,则字段不展示。)
tabsIndex?: number;
detailPageID?:string;
detailPageType?:number;
mgdbId?:string; // 挂件ID
serviceId?:string; // 商品id
androidServiceid?:string; // 安卓serviceId
androidGoodscode?:string; // 安卓goodsCode
iosServiceid?:string; // ios serviceId
iosGoodscode?:string; // ios goodsCode
keywords?: string;
videoCategory?: string;
dataSource?:string; // 事件发生的位置
intfId?: string;
}
\ No newline at end of file
... ...
/**
* 图片
* Pic 同 H5pic
*/
export interface Pic {
lowResolutionH?: string; //低清横图
lowResolutionV?: string; // 低清竖图
lowResolutionV34?: string; // 低清竖图(3:4比例)
highResolutionH?: string; // 高清横图
highResolutionV?: string; // 高清竖图
highResolutionV34?: string; // 高清竖图(3:4比例)
gkResolution1?: string; // g客视频1配图
gkResolution2?: string; // g客视频2配图
}
\ No newline at end of file
... ...
/**
* 解说员信息/节目主持人名称
*/
export class Presenter {
name: string;
}
\ No newline at end of file
... ...
/**
* 节目/剧集Item
* CompType:
* TOP_IMG_BOTTOM_TXT
* BIG_STATIC_IMG
* BIG_PLAY_IMG
* SLIDER_IMG
* MY_HOME
*/
import { ItemBean } from './ItemBean';
import { ProgrammeDTO } from './ProgrammeDTO';
import { StrategyTipMap } from './StrategyTipMap';
import { Tip } from './Tip';
@Observed
export class ProgrammeBean extends ItemBean {
name?: string; // 节目名称
title?: string; // 标题
pID?: string // 节目ID
programTypeV2?: string; // 节目类型:
detail?: string; // 描述
// pics?: Pic; // 图片(放到父类ItemBean中)
score?: string; // 得分
updateEP?: string; // 更新集数(示例:更新至28集)
stateTime?: string; // 已完结/"每周四12:00更新1期"
programs?: ProgrammeDTO[];
index?: string; // 在剧集中的序号(从1开始)
duration?: string; // 节目时长,"02:04:27",
author?: string; // 节目上传者(若为G客内容,则DataVo 中输出该字段)
avator?: string; // 节目上传者头像(若为G客内容,则DataVo 中输出该字段)
screenType?: string; // 屏幕类型。1: 竖屏; 2: 横屏;
subTxt?: string;
strategyTipMap?: StrategyTipMap;
startTime?: string; // 开始时间,YYYYMMDDHHmm,如202311262305
endTime?: string; // 比赛结束时间/推流结束时间(YYYYMMDDHHmm,如202311270130)
tip?: Tip; // 角标,枚举类:(code, msg)
tip2?: Tip; // 清晰度角标,枚举类:(code, msg)/4K角标
showTip?: Tip;
topRightTipImgUrl?: string; // 右上角角标
topLeftTipImgUrl?: string; // 左上角角标
constructor(dto: ProgrammeDTO) {
super(dto);
this.name = dto.name
this.title = dto.title
this.pID = dto.pID
this.programTypeV2 = dto.programTypeV2
this.detail = dto.detail
this.score = dto.score
this.updateEP = dto.updateEP
this.stateTime = dto.stateTime
this.programs = dto.programs;
this.index = dto.index;
this.duration = dto.duration
this.author = dto.author
this.avator = dto.avator
this.screenType = dto.screenType
this.subTxt = dto.subTxt?.txt
this.strategyTipMap = dto.strategyTipMap;
this.tip = dto.tip;
this.showTip = dto.showTip;
}
}
\ No newline at end of file
... ...
/**
* 节目/剧集Item
*/
import { CopyRightVo } from './CopyRightVo';
import { DisplayName } from './DisplayName';
import { ItemDTO } from './ItemDTO';
import { Presenter } from './Presenter';
import { Resolution } from './Resolution';
import { ShieldStrategy } from './ShieldStrategy';
import { StrategyTipMap } from './StrategyTipMap';
import { SubTxt } from './SubTxt';
import { Team } from './Team';
import { Tip } from './Tip';
export class ProgrammeDTO extends ItemDTO {
name?: string; // 节目名称
pID?: string // 节目ID
publishTime?: string; // 发布时间
updateTimeDesc?: string; // 节目更新时间描述
duration?: string; // 节目时长
assetID?: string; // 媒资ID
mediaSize?: number; // 节目文件大小(字节)
contentType?: string; // 内容形态
director?: string; // 导演
actor?: string; // 演员
year?: string; // 发布年份
contentStyle?: string; // 剧集类型,如:动作/剧情
displayName?: DisplayName;
copyRightVo?: CopyRightVo;
auth?: string; // 权限
title?: string; // 标题
subTitle?: string; // 子标题
type?: string; // 数据类型
programType?: string; // 节目类型(不再维护)
// 节目类型:
// http://confluence.cmvideo.cn/confluence/pages/viewpage.action?pageId=55822514
// 节目为云直播时,值为LIVE
// 节目为挂件时,值为LIVE
programTypeV2?: string;
detail?: string; // 描述
// 视频类型
// 1.GKE G客
// 2.LIVE 直播
// 3.VOD 点播
// 4.GRAPHIC 图文
videoType?: string;
source?: string; // 来源
score?: string; // 得分
subTxt?: SubTxt; // 角标右下角文字规则
updateEP?: string; // 更新集数(示例:更新至28集)
updateV?: string; // 更新集数(示例:28)
// pics?: Pic; // 图片(放到父类ItemDTO中)
// h5pics?: Pic; // 图片(放到父类ItemDTO中)
sign?: string; // 上传者简介(若为G客内容,则DataVo 中输出该字段)
gkeUserid?: string; // G客号用户id(若为G客内容,则DataVo 中输出该字段)
author?: string; // 节目上传者(若为G客内容,则DataVo 中输出该字段)
avator?: string; // 节目上传者头像(若为G客内容,则DataVo 中输出该字段)
shieldStrategy?: ShieldStrategy; // 屏蔽策略
tip?: Tip; // 角标,枚举类:(code, msg)
tip2?: Tip; // 清晰度角标,枚举类:(code, msg)/4K角标
showTip?: Tip;
downloadTip?: Tip; // 下载角标,枚举类:(code, msg)
strategyTipMap?: StrategyTipMap; // 不同策略计算第一象限默认角标时的结果。目前提供给VR客户端用。
// action?: Action; // 配置事件行为(移动到父类ItemDTO中)
// 适配多action
// actions?: {
// defaultAction: Action; // 对应原action
// CRBTAction?: Action; //对应彩铃action
// };
isGkeContent?: boolean; // 是G客节目
dataType?: number; // 数据类型枚举 // 1.点播节目,2.广告对象,3.挂件对象,4.云直播节目,5.图文,6.开路直播节目单,7.用户数据,8.直播间数据,9.通用对象
screenType?: string; // 屏幕类型。1: 竖屏; 2: 横屏;
fitArea?: string[]; // 适配地区
branchMark?: boolean; // 分众标志位 true表示存在分众信息
programGroupId?: string;
compId?: string;
sortValue?: string;
programs?: ProgrammeDTO[]; // 剧集列表
fetchStrategy?: string;
position?: string;
label_4K?: string;
resolution?: Resolution;
index?: string; // 在剧集中的序号(从1开始)
way?: string;
displayType?: string;
isUFC?: string;
isPrevue?: string;
KEYWORDS?: string;
stateTime?: string; // 已完结/"每周四12:00更新1期"
// 精选赛事列表的item
activityType?: string; // 活动类型(0:体育赛事;1:娱乐)
competitionType?: string; // 比赛类型(0 :非对抗赛, 1: 对抗)
competitionName?: string; // 赛事名称
logo?: string; // 非对抗赛图标
unionLogo?: string; // 联盟通标识图标
phase?: string; // 阶段信息
round?: string; // 轮次信息
teamShowType?: string; // 对阵球队展示顺序:teamShowType:0:主队在左,客队在右 1:客队在左,主队在右
teams?: Team[]; // 对阵球队信息
matchStartTime?: number; // 开赛时间/比赛开始时间(时间戳/单位:毫秒),如:1701011700000
startTime?: string; // 开始时间,YYYYMMDDHHmm,如202311262305
endTime?: string; // 比赛结束时间/推流结束时间(YYYYMMDDHHmm,如202311270130)
presenters?: Presenter[]; // 解说员信息
mgdbBackgroundColor?: string;
}
\ No newline at end of file
... ...
export class ReportingData {
type: string;
detail?: string; // 上报数据,格式为json
}
\ No newline at end of file
... ...
export class Resolution {
mediaWidth: number;
mediaHeight: number;
}
\ No newline at end of file
... ...
/**
* 搜索bar数据
*/
import { Action } from './Action';
export class Searchbar {
defaultSearchText: string;
voiceAction: Action;
searchAction: Action;
lightVoiceIcon: string;
lightSearchIcon: string;
darkVoiceIcon: string;
darkSearchIcon: string;
}
\ No newline at end of file
... ...
/**
* 屏蔽策略
*/
export class ShieldStrategy {
allowBarrage: boolean; // 允许弹幕
allowComment: boolean; // 允许评论
allowRedPacket: boolean; // 允许红包
allowShare: boolean; // 允许分享
allowLike: boolean; // 允许喜欢
allowCommentShare: boolean;
}
\ No newline at end of file
... ...
import { Tip } from './Tip';
export interface StrategyTipMap {
CHARGE: Tip;
}
\ No newline at end of file
... ...
/**
* 角标右下角文字规则
*/
export class SubTxt {
txt: string;
subTxtStyle: string;
}
\ No newline at end of file
... ...
/**
* NAV_BAR-01
* 导航栏(顶导/首页/体育/vip)
*/
import { ItemBean } from './ItemBean';
import { Tab01DTO } from './Tab01DTO';
@Observed
export class Tab01Bean extends ItemBean {
title: string; // 导航栏标题
tabImg?: string; // TAB图片
defaultTextColor?: string; // 导航文字默认颜色
headBackgroundImg?: string; // 头部背景色(搜索bar背景图片)
// backgroundImg?: string;
// actTextColor?: string;
constructor(dto: Tab01DTO) {
super(dto);
this.title = dto.title
this.tabImg = dto.tabImg
this.defaultTextColor = dto.defaultTextColor
this.headBackgroundImg = dto.headBackgroundImg
// this.backgroundImg = dto.backgroundImg
// this.actTextColor = dto.actTextColor
}
}
... ...
/**
* NAV_BAR-01
* menu:导航栏(顶导/首页/体育/vip)
*/
import { ItemDTO } from './ItemDTO';
export class Tab01DTO extends ItemDTO {
icon?: string; // 导航栏icon
title: string; // 导航栏标题
defaultTextColor?: string; // 导航文字默认颜色
defTextColor?: string; // 导航文字颜色
activatedTextColor?: string; // 导航文字Active默认颜色
actTextColor?: string; // 导航文字Active颜色
headBackgroundColor?: string; // 头部背景色
backgroundImg?: string; // 背景图片
headBackgroundImg?: string; // 头部背景色(搜索bar背景图片)
tipImg?: string; // 标签图片
manageIcon?: string; // 频道管理图标
deletable?: string; // 是否可删除
recommendable?: string; // 是否主推荐
topBarId?: string; // 顶部导航栏模板
id?: string; // 导航栏id
tabImg?: string; // TAB图片
// tabImgSize?: any; // TAB图片尺寸
grayFilter?: string;
output?: string;
}
\ No newline at end of file
... ...
/**
* NAV_BAR-22
* 播放详情底部tab
*/
import { ItemBean } from './ItemBean';
import { Tab22DTO } from './Tab22DTO';
@Observed
export class Tab22Bean extends ItemBean {
tabText: string; // 详情/讨论/(热播榜-特惠-抽周边-有奖征集)/(赛程-热门直播)
tabType: string; // detail/discuss/H5Page/nativePage
selectedColor?: string;
unselectedColor?: string;
// showCommentCount?: string;
backgroundColor?: string;
// backgroundImg?: string;
// bottomBarBackgroundImg?: string;
// bottomBarIconUnselectedColor?: string;
// bottomBarIconSelectedColor?: string;
// bottomBarBackgroundColor?: string;
normalTextColor?: string = "";
activeTextColor?: string = "";
constructor(dto: Tab22DTO) {
super(dto);
this.tabText = dto.tabText
this.tabType = dto.tabType
this.selectedColor = dto.selectedColor
this.unselectedColor = dto.unselectedColor
this.backgroundColor = dto.backgroundColor
}
}
... ...
/**
* NAV_BAR-22
* 播放详情,播放器下面的tab
*/
import { ItemDTO } from './ItemDTO';
export class Tab22DTO extends ItemDTO {
tabText: string; // 详情/讨论/(热播榜-特惠-抽周边-有奖征集)/(赛程-热门直播)
tabType: string; // detail/discuss/H5Page/nativePage
selectedColor?: string; // TAB项选中文字颜色
unselectedColor?: string; // TAB项未选中文字颜色
showCommentCount?: string; //
backgroundColor?: string; // TAB背景颜色
backgroundImg?: string; // TAB背景图片
bottomBarBackgroundImg?: string;
bottomBarIconUnselectedColor?: string;
bottomBarIconSelectedColor?: string;
bottomBarBackgroundColor?: string;
}
\ No newline at end of file
... ...
/**
* ConfrontTeam/NBATeam.
* 赛事的对战对/对抗团队/队伍(主队/客队)
*/
export class Team {
teamId?: string; // 球队id
teamName?: string; // 队伍名称
teamLogo?: string; // 队伍icon
isHome?: string; // 是否主队("1"是主队,“0”是客队)
score?: string; // 比赛队伍(当前)得分 -1表示无分数
}
\ No newline at end of file
... ...
/**
* 角标,枚举类:(code,msg)
*/
export class Tip {
code: string;
msg: string;
}
\ No newline at end of file
... ...
/**
* 顶部bar数据(包含搜索bar)
*/
import { Logo } from './Logo';
import { NavButton } from './NavButton';
import { Searchbar } from './Searchbar';
export class TopBar {
id: string;
name: string;
// type?: number; // 0-顶导 1-挂件、2-长视频播放详情页、3-短视频播放详情页、4-开路直播播放详情页。
logo: Logo; // 搜索bar左外侧的logo图标
searchbars?: Searchbar;
buttons: NavButton[];
lightBackImg?: string;
// lightBackImgColor?:string;
darkBackImg?: string;
// darkBackImgColor?:string;
isForceUse?: number;
}
\ No newline at end of file
... ...
/**
* 组件Style/展示样式(字典值)
*/
export const enum CompStyle {
LABEL_01 = 'LABEL-01', // 标题
BUTTON_01 = 'BUTTON-01', // 按钮/更多/更多热点/更多热播电视剧/换一换
NAV_BAR_01 = 'NAV_BAR-01', // 导航栏(顶导/首页/体育/vip)
// NAV_BAR_08 = 'NAV_BAR-08', // 导航栏(顶导/短视频tab)
NAV_BAR_22 = 'NAV_BAR-22', // 导航栏(顶导/播放详情底部tab)
NAV_BAR_03 = 'NAV_BAR-03', // 圆形按钮导航栏(横滑)
BIG_STATIC_IMG_01 = 'BIG_STATIC_IMG-01', // 静态大图
BIG_CAROUSEL_IMG_01 = 'BIG_CAROUSEL_IMG-01', // 轮播大图,即Banner/焦点图
BIG_PLAY_IMG_01 = 'BIG_PLAY_IMG-01', // 播放大图
TOP_IMG_BOTTOM_TXT_01 = 'TOP_IMG_BOTTOM_TXT-01', // 横图-上图下文/重磅推荐
TOP_IMG_BOTTOM_TXT_02 = 'TOP_IMG_BOTTOM_TXT-02', // 竖图-上图下文/大家都在看/短剧
TOP_IMG_BOTTOM_TXT_12 = 'TOP_IMG_BOTTOM_TXT-12', // 竖图-上图下文/瀑布流形式
BINGE_WATCHING_02 = 'BINGE_WATCHING-02', // 猜你在追/猜你会追(横滑)
SLIDER_IMG_16 = 'SLIDER_IMG-16', // 滑动图/(横滑)/精彩小视频/为你推荐区
MATCH_LIST_04 = 'MATCH_LIST-04', // 精选赛事列表(横滑)
// MY_HOME_INFO = 'MY_HOME-INFO', // 我的信息:头像/用户名等个人信息
// MY_HOME_SERVICE_NEW = 'MY_HOME-SERVICE_NEW', // 服务区(新)/个人服务
// MY_HOME_VERSION_NUMBER = 'MY_HOME-VERSION-NUMBER', // 客户端名称及版本号
// PLAYER_01 = 'PLAYER-01', // 播放区/播放器
PROGRAM_DESC_01 = 'PROGRAM_DESC-01', // 节目简介区
PROGRAM_SET_01 = 'PROGRAM_SET-01', // "选集区"/"剧集区"
CLASSIFY_FILTER_BAR_02 = 'CLASSIFY_FILTER_BAR-02', // 筛选条件区
WORLDCUP_PLAYBILL = 'WORLDCUP-PLAYBILL', // 赛程页
}
\ No newline at end of file
... ...
/**
* 组件Type/展示类型
*/
export const enum CompType {
LABEL = 'LABEL', // 标题
BUTTON = 'BUTTON', // 按钮/换一换
NAV_BAR = 'NAV_BAR', // tab导航栏/按钮导航区
BIG_STATIC_IMG = 'BIG_STATIC_IMG', // 静态大图
BIG_CAROUSEL_IMG = 'BIG_CAROUSEL_IMG', // 轮播大图,即Banner/焦点图
BIG_PLAY_IMG = 'BIG_PLAY_IMG', // 播放大图
TOP_IMG_BOTTOM_TXT = 'TOP_IMG_BOTTOM_TXT', // 上图下文
BINGE_WATCHING = 'BINGE_WATCHING', // 猜你在追/猜你会追(横滑)
SLIDER_IMG = 'SLIDER_IMG', // 精彩小视频/为你推荐区
MATCH_LIST = 'MATCH_LIST', // 精选赛事列表(横滑)
MY_HOME = 'MY_HOME', // 我的
PLAYER = 'PLAYER', // 播放区
PROGRAM_DESC = 'PROGRAM_DESC', // 节目简介区
PROGRAM_SET = 'PROGRAM_SET', // "选集区"/"剧集区"
CLASSIFY_FILTER_BAR = 'CLASSIFY_FILTER_BAR', // 筛选条件区
WORLDCUP = 'WORLDCUP', // 赛程页
}
... ...
/**
* 请求网络数据状态类型/也是View Type
*/
export const enum NetDataStatusType {
// 已初始化,但尚未发出请求
INITIAL = 0,
// 取消请求/或无需网络请求/或不关心请求结果/或调用方没有设置回调callback
CANCEL,
// 已发出请求,但请求尚未返回;
LOADING,
// 请求已失败返回;
FAILED,
// 请求已成功返回;
LOADED
}
\ No newline at end of file
... ...
/**
* 详情 的 tab item类型
*/
export const enum TabType {
detail = 'detail', // 详情
discuss = 'discuss', // 讨论
H5Page = 'H5Page', // 热播榜-特惠-抽周边-有奖征集
nativePage = 'nativePage', // 赛程-热门直播
}
\ No newline at end of file
... ...
/**
* 主界面更多,按钮Comp
*/
import { ButtonBean } from '../bean/ButtonBean';
import { CompDTO } from '../bean/CompDTO';
import { NetDataStatusType } from '../enum/NetDataStatusType';
import { DataFromExtraComp } from './DataFromExtraComp';
import List from '@ohos.util.List';
import { ExtraDTO } from '../bean/ExtraDTO';
import { ButtonDTO } from '../bean/ButtonDTO';
import { WDGroup } from './WDGroup';
export class ButtonComp extends DataFromExtraComp<ButtonBean> {
constructor(parent: WDGroup, compDTO: CompDTO, initParams: Map<string, Object>) {
super(parent, compDTO, initParams);
this.status = NetDataStatusType.LOADED
}
public getItems(): List<ButtonBean> {
return this.items;
}
protected convertDto2Vo(extraDataDTO: ExtraDTO): List<ButtonBean> {
if (!extraDataDTO) {
return new List<ButtonBean>();
}
let beanList: List<ButtonBean> = new List<ButtonBean>();
// let dtoArray: ButtonDTO[] | undefined = extraDataDTO["buttons"]
let dtoArray: ButtonDTO[] | undefined= extraDataDTO.buttons
if (!dtoArray) {
return new List<ButtonBean>();
}
for (let index = 0; index < dtoArray.length; index = index + 1) {
let dto: ButtonDTO = dtoArray[index];
let bean: ButtonBean = new ButtonBean(dto);
beanList.add(bean);
}
return beanList;
}
}
\ No newline at end of file
... ...
/**
* DataFromExtraComp是指数据从comp的extraData中获取的这类comp
*/
import { CompDataDTO } from '../bean/CompDataDTO';
import { CompDTO } from '../bean/CompDTO';
import { ExtraDTO } from '../bean/ExtraDTO';
import { ItemBean } from '../bean/ItemBean';
import { WDComp } from './WDComp';
import { WDGroup } from './WDGroup';
export abstract class DataFromExtraComp<VO extends ItemBean> extends WDComp<VO, ExtraDTO> {
constructor(parent: WDGroup, compDTO: CompDTO, initParams: Map<string, Object>) {
super(parent, compDTO, initParams);
this.items = this.convertDto2Vo(this.compDTO.extraData ?? {} as ExtraDTO);
}
public setData(compDataDTO: CompDataDTO): void {
}
public loadMore(): void {
}
public loadFirst(): void {
}
public loadWithGroupData(): boolean {
return false;
}
public hasMoreData(): boolean {
return false;
}
public isLoaded(): boolean {
return true;
}
public needCheckIntegrity(): boolean {
return false;
}
}
\ No newline at end of file
... ...
/**
* 瀑布流形式的comp
*/
import { CompDTO } from '../bean/CompDTO';
import { ItemBean } from '../bean/ItemBean';
import { ItemDTO } from '../bean/ItemDTO';
import { WDComp } from './WDComp';
import { WDGroup } from './WDGroup';
import List from '@ohos.util.List';
import { CompDataDTO } from '../bean/CompDataDTO';
export class FlowComp<VO extends ItemBean, DTO extends ItemDTO> extends WDComp<VO, DTO> {
constructor(parent: WDGroup, compDTO: CompDTO, initParams: Map<string, Object>) {
super(parent, compDTO, initParams);
}
protected convertDto2Vo(dto: DTO): List<VO> {
return new List()
}
public setData(compDataDTO: CompDataDTO) {
}
}
\ No newline at end of file
... ...
/**
* 主界面更多,按钮Comp
*/
import { CompDTO } from '../bean/CompDTO';
import { LabelBean } from '../bean/LabelBean';
import { NetDataStatusType } from '../enum/NetDataStatusType';
import { DataFromExtraComp } from './DataFromExtraComp';
import List from '@ohos.util.List';
import { LabelDTO } from '../bean/LabelDTO';
import { ExtraDTO } from '../bean/ExtraDTO';
import { WDGroup } from './WDGroup';
export class LabelComp extends DataFromExtraComp<LabelBean> {
constructor(parent: WDGroup, compDTO: CompDTO, initParams: Map<string, Object>) {
super(parent, compDTO, initParams);
this.status = NetDataStatusType.LOADED
}
public getItems(): List<LabelBean> {
return this.items;
}
protected convertDto2Vo(extraDataDTO: ExtraDTO): List<LabelBean> {
if (!extraDataDTO) {
return new List<LabelBean>();
}
let beanList: List<LabelBean> = new List<LabelBean>();
// let dtoArray: LabelDTO[] | undefined = extraDataDTO["labels"]
let dtoArray: LabelDTO[] | undefined= extraDataDTO.labels
if (!dtoArray) {
return new List<LabelBean>();
}
for (let index = 0; index < dtoArray.length; index = index + 1) {
let dto: LabelDTO = dtoArray[index];
let bean: LabelBean = new LabelBean(dto);
beanList.add(bean);
}
return beanList;
}
}
\ No newline at end of file
... ...
/**
* Page状态监听
*/
export interface PageListener {
/**
* Page数据加载完成
* @param page MGPage实例
*/
onPageLoaded: (page: WDPage) => void;
/**
* Page数据加载失败
* @param page MGPage实例
*/
onPageFailed: (page: WDPage) => void;
/**
* Group数据加载完成
* @param page 所在的MGPage实例
* @param group MGGroup实例
*/
onGroupLoaded: (page: WDPage, group: WDGroup) => void;
/**
* Group数据加载失败
* @param page 所在的MGPage实例
* @param group MGGroup实例
*/
onGroupFailed: (page: WDPage, group: WDGroup) => void;
/**
* Comp数据加载完成
* @param page 所在的MGPage实例
* @param group 所在的MGGroup实例
* @param comp MGComp实例
*/
onCompLoaded: (page: WDPage, group: WDGroup, comp: WDComp<ItemBean, ItemDTO>) => void;
/**
* Comp数据加载失败
* @param page 所在的MGPage实例
* @param group 所在的MGGroup实例
* @param comp MGComp实例
*/
onCompFailed: (page: WDPage, group: WDGroup, comp: WDComp<ItemBean, ItemDTO>) => void;
}
\ No newline at end of file
... ...
/**
* 剧集相关Comp,数据源无需ProgrammeComp自己加载,从MGComp中控制获得数据
* CompType:
* BIG_CAROUSEL_IMG
* TOP_IMG_BOTTOM_TXT
* BIG_STATIC_IMG
* BIG_PLAY_IMG
* SLIDER_IMG
* NAV_BAR_03
* BINGE_WATCHING
* MY_HOME
*/
import { CompDataDTO } from '../bean/CompDataDTO';
import { CompDTO } from '../bean/CompDTO';
import { WDComp } from './WDComp';
import { WDGroup } from './WDGroup';
import List from '@ohos.util.List';
import { ProgrammeDTO } from '../bean/ProgrammeDTO';
import { CompType } from '../enum/CompType';
import { ProgrammeBean } from '../bean/ProgrammeBean';
import { PageUtils } from '../utils/PageUtils';
export class ProgrammeComp extends WDComp<ProgrammeBean, CompDataDTO> {
constructor(parent: WDGroup, compDTO: CompDTO, initParams: Map<string, Object>) {
super(parent, compDTO, initParams);
}
protected convertDto2Vo(compDataDTO: CompDataDTO): List<ProgrammeBean> {
if (!compDataDTO || !compDataDTO.data) {
return new List<ProgrammeBean>();
}
let programmeBeanList: List<ProgrammeBean> = new List<ProgrammeBean>();
for (let index = 0; index < compDataDTO.data.length; index = index + 1) {
let programmeData: ProgrammeDTO = compDataDTO.data[index];
let bean: ProgrammeBean = new ProgrammeBean(programmeData);
this.buildTip(bean)
programmeBeanList.add(bean);
}
if (this.getCompType() == CompType.TOP_IMG_BOTTOM_TXT) {
programmeBeanList = this.complementTrimData(programmeBeanList)
}
return programmeBeanList;
}
/**
* build角标等数据
*/
buildTip(bean: ProgrammeBean): void {
bean.topRightTipImgUrl = PageUtils.getTopRightTipImgUrl(bean)
bean.topLeftTipImgUrl = PageUtils.getTopLeftTipImgUrl(bean)
}
public setData(compDataDTO: CompDataDTO) {
if (!compDataDTO || !compDataDTO.data) {
return;
}
this.items = this.convertDto2Vo(compDataDTO);
}
public hasMoreData(): boolean {
return false;
}
// public isLoaded(): boolean {
// return this.items.length > 0;
// }
}
\ No newline at end of file
... ...
/**
* CompStyle:NAV_BAR-01
* 导航栏(顶导/首页/体育/vip)tab
*/
import { CompDTO } from '../bean/CompDTO';
import { Tab01Bean } from '../bean/Tab01Bean';
import { NetDataStatusType } from '../enum/NetDataStatusType';
import { DataFromExtraComp } from './DataFromExtraComp';
import List from '@ohos.util.List';
import { ExtraDTO } from '../bean/ExtraDTO';
import { Tab01DTO } from '../bean/Tab01DTO';
import { CompFilterUtil } from '../utils/CompFilterUtil';
import { WDGroup } from './WDGroup';
export class TabBar01Comp extends DataFromExtraComp<Tab01Bean> {
constructor(parent: WDGroup, compDTO: CompDTO, initParams: Map<string, Object>) {
super(parent, compDTO, initParams);
this.status = NetDataStatusType.LOADED
}
public getItems(): List<Tab01Bean> {
return this.items;
}
protected convertDto2Vo(extraDataDTO: ExtraDTO): List<Tab01Bean> {
if (!extraDataDTO) {
return new List<Tab01Bean>();
}
let beanList: List<Tab01Bean> = new List<Tab01Bean>();
// let dtoArray: Tab01DTO[] | undefined = extraDataDTO["menus"]
let dtoArray: Tab01DTO[] | undefined= extraDataDTO.menus
if (!dtoArray) {
return new List<Tab01Bean>();
}
for (let index = 0; index < dtoArray.length; index = index + 1) {
let dto: Tab01DTO = dtoArray[index];
if (!CompFilterUtil.filterTab01(dto)) {
continue
}
let bean: Tab01Bean = new Tab01Bean(dto);
beanList.add(bean);
}
return beanList;
}
}
\ No newline at end of file
... ...
/**
* CompStyle:NAV_BAR-22
* 播放详情底部tab
*/
import { CompDTO } from '../bean/CompDTO';
import { Tab22Bean } from '../bean/Tab22Bean';
import { NetDataStatusType } from '../enum/NetDataStatusType';
import { DataFromExtraComp } from './DataFromExtraComp';
import List from '@ohos.util.List';
import { ExtraDTO } from '../bean/ExtraDTO';
import { Tab22DTO } from '../bean/Tab22DTO';
import { WDGroup } from './WDGroup';
import { TabType } from '../enum/TabType';
export class TabBar22Comp extends DataFromExtraComp<Tab22Bean> {
constructor(parent: WDGroup, compDTO: CompDTO, initParams: Map<string, Object>) {
super(parent, compDTO, initParams);
this.status = NetDataStatusType.LOADED
}
public getItems(): List<Tab22Bean> {
return this.items;
}
protected convertDto2Vo(extraDataDTO: ExtraDTO): List<Tab22Bean> {
if (!extraDataDTO) {
return new List<Tab22Bean>();
}
let beanList: List<Tab22Bean> = new List<Tab22Bean>();
// let dtoArray: Tab22DTO[] | undefined = extraDataDTO["tabs"]
let dtoArray: Tab22DTO[] | undefined = extraDataDTO.tabs
if (!dtoArray) {
return new List<Tab22Bean>();
}
for (let index = 0; index < dtoArray.length; index = index + 1) {
let dto: Tab22DTO = dtoArray[index];
if (dto.tabType != TabType.discuss) { // 过滤掉【讨论】tab
let bean: Tab22Bean = new Tab22Bean(dto);
this.buildTextColor(bean)
beanList.add(bean);
}
}
return beanList;
}
private buildTextColor(bean: Tab22Bean): void {
let normalTextColor = bean.unselectedColor;
if (!normalTextColor) {
normalTextColor = "#666666";
}
bean.normalTextColor = normalTextColor;
let activeTextColor = bean.selectedColor;
if (!activeTextColor) {
activeTextColor = "#333333";
}
bean.activeTextColor = activeTextColor;
return
}
}
\ No newline at end of file
... ...
/**
* Comp数据获取管理及相关业务逻辑处理
*
* @param <VO> 业务展示数据对象,显示Comp item的数据对象
* @param <DTO> 网络传输数据对象,与服务器端接口定义的字段一致
*/
import { CompDTO } from '../bean/CompDTO';
import { ItemBean } from '../bean/ItemBean';
import { ItemDTO } from '../bean/ItemDTO';
import List from '@ohos.util.List';
import { WDGroup } from './WDGroup';
import { NetDataStatusType } from '../enum/NetDataStatusType';
import { DataSourceRequest } from '../bean/DataSourceRequest';
import { LayoutCallback } from '../service/LayoutCallback';
import { ArrayUtils, StringUtils } from 'wdKit';
import { CompDataDTO } from '../bean/CompDataDTO';
import { CommonDataService } from '../service/CommonDataService';
export abstract class WDComp<VO extends ItemBean, DTO extends ItemDTO> {
protected parent: WDGroup;
protected compDTO: CompDTO;
protected initParams: Map<string, Object> = new Map<string, Object>();
// view展示的由DTO转换Bean后的数据列表
protected items: List<VO> = new List<VO>();
// 当前组件数据加载状态
protected status: number = NetDataStatusType.INITIAL;
/**
* 标记是否为需要合并请求的Comp
*/
private isTeamwork: boolean = false;
private isRefresh: boolean = false;
/**
* 标记是否为无限瀑布流
*/
// private isFeed: boolean = false;
/**
* 标记是否为黑白化
*/
// private isGrayMode: boolean = false;
// protected data: HashMap<String, List<VO>> = new HashMap<string, List<VO>>();
// protected dynamicData: HashMap<String, VO> = new HashMap<String, VO>();
/**
* 构造函数
*
* @param parent WDGroup
* @param compDTO 服务器返回的CompDTO
* @param initParams 初始化参数
*/
constructor(parent: WDGroup, compDTO: CompDTO, initParams: Map<string, Object>) {
this.parent = parent;
this.compDTO = compDTO;
this.initParams = initParams;
if (parent) {
this.isTeamwork = parent.getIsTeamWork() && compDTO.dataSource == "CONTENT_POOL_PER_RECOMMAND";
// this.isGrayMode = parent.getIsGrayMode();
}
}
/**
* 加载第一页的数据
*/
public loadFirst(): void {
this.loadData();
}
/**
* 在分页加载时,加载下一页的数据, 默认加载第一页数据, 加载更多数据时,需要重写该方法
*/
public loadMore() {
this.loadFirst();
}
/**
* 重新加载数据/切换comp数据,一般用于换一换功能
* @param params
*/
public reloadData(params: Map<String, Object>): void {
this.loadFirst();
}
/**
* 加载Comp数据
*/
public loadData() {
// TODO: 调用onLoadData加载数据
if (this.isTeamWork() || this.status == NetDataStatusType.LOADING) {
return;
}
this.onLoadData()
}
/**
* 加载comp(默认通用)数据源
*/
protected onLoadData(): void {
// TODO: 通过CommonData
if (this.dataSourceEnabled() && this.compDTO && this.compDTO.dataSourceRequest) {
// let isBackupDataSource = false;
let callback: LayoutCallback<DTO> = {
onSuccess: (dto: DTO): void => {
this.transformResponseData(dto);
if (this.items.length > 0) {
this.onLoadDataFinished()
} else {
this.onLoadDataFailed()
}
return
},
onFailed: (code: number, message: string): void => {
// todo:
this.onLoadDataFailed()
return
}
};
let service: CommonDataService = new CommonDataService();
for (let index = 0; index < this.compDTO.dataSourceRequest.length; index++) {
let request: DataSourceRequest = this.compDTO.dataSourceRequest[index]
// request.locationValue = getLocation();
if (this.isTeamWork()) {
continue;
}
this.status = NetDataStatusType.LOADING;
service.loadDataSource<DTO>(this.compDTO, request, callback)
}
}
}
/**
* 数据转换:转换网络请求的response DTO为业务展示的bean
*
* @param dto 网络请求的数据
*/
protected transformResponseData(dto: DTO): void {
// TODO: 调用convertDto2Vo转换并记录数据
let beanList: List<VO> = this.convertDto2Vo(dto);
if (beanList && beanList.length > 0) {
if (this.isRefresh) {
this.items.clear();
this.isRefresh = false;
}
this.items = ArrayUtils.addAll(this.items, beanList)
}
}
// 根据compDTO.displayCount字段值,在列表尾部补全数据或把列表尾部数据截断
protected complementTrimData(originalList: List<VO>): List<VO> {
let displayCount: number = this.getCompDisplayCount(); // 展示数量
if (!originalList || displayCount == 0 || originalList.length == displayCount) {
return originalList;
}
if (originalList.length < displayCount) {
let newItemList: List<VO> = originalList;
// 在尾部补全数据
let complementCount = displayCount - originalList.length;
let complementIndex = 0
while (complementIndex < complementCount) {
// 从原有数据前(循环)依次取数据,补充到列表后部,
let itemIndex = complementIndex % originalList.length // 取模(余数)
newItemList.add(originalList.get(itemIndex))
complementIndex++
}
return newItemList;
} else if (originalList.length > displayCount) {
// 截取/截断
// return originalList.getSubList(0, displayCount); // 异常报错
let newItemList: List<VO> = new List<VO>()
let itemIndex = 0
while (itemIndex < displayCount) {
newItemList.add(originalList.get(itemIndex))
itemIndex++
}
return newItemList;
} else {
return originalList;
}
}
/**
* 留给业务实现的数据转换
*/
protected abstract convertDto2Vo(dto: DTO): List<VO>;
/**
* 获取Comp的数据源,将一个data DTO设置为Comp的数据;设置comp对应的compDataDTO
*/
public abstract setData(compDataDTO: CompDataDTO): void;
/**
* 使用动态数据替换静态数据
* @param programme 动态数据
*/
// public replaceStaticData(data: ProgrammeData): boolean {
// // TODO: 数据替换
// // let item: VO = this.dynamicData.get(data.position);
// // if (item instanceof ProgrammeBean) {
// // // item.transform(data);
// // return true;
// // } else {
// return false;
// // }
// }
/**
* 是否正在加载中
* @returns
*/
public getIsLoading(): boolean {
// TODO: 是否正在加载中
return this.status == NetDataStatusType.LOADING;
}
/**
* 是否加载完毕
* @returns
*/
public isLoaded(): boolean {
// TODO: 是否已经加载完毕
return this.status == NetDataStatusType.LOADED || this.status == NetDataStatusType.FAILED || this.status == NetDataStatusType.CANCEL;
}
/**
* 是否(成功)加载完毕
* @returns
*/
public isLoadedSuccess(): boolean {
return this.status == NetDataStatusType.LOADED;
}
/**
* 是否还有更多数据待加载 / 判断是否还有下一页/,需要重写该方法
*/
public hasMoreData(): boolean {
// TODO: 判断是否有存在更多数据
return false;
}
/**
* Group中所有的Comp是否都已加载完毕
* @returns
*/
public hasDataLoaded(): boolean {
// TODO: 所有Comp是否都已经加载完数据
return false;
}
/**
* 是否需要加载动态数据
* @returns
*/
public hasDynamicData(): boolean {
// TODO: 判断数据源的dataSourceType是否为“POMS_NODE”,是则需要加载动态数据。
if (this.compDTO && this.compDTO.dataSourceRequest && this.compDTO.dataSourceRequest.length > 0) {
for (let index = 0; index < this.compDTO.dataSourceRequest.length; index++) {
let request: DataSourceRequest = this.compDTO.dataSourceRequest[index]
if (request.dataSourceType == "POMS_NODE") {
return true;
}
}
}
return false;
}
public isTeamWork(): boolean {
return this.isTeamwork;
}
protected dataSourceEnabled(): boolean {
return true;
}
/**
* 获取该comp所在的group
*/
public getParent(): WDGroup {
return this.parent;
}
/**
* 获取comp对应的compDTO
*/
public getCompDTO(): CompDTO {
return this.compDTO;
}
/**
* 获取comp Id
*/
public getId(): string {
return!this.compDTO ? "" : this.compDTO.id;
}
/**
* 获取Comp Type
*/
public getCompType(): string {
return!this.compDTO ? "" : this.compDTO.compType;
}
/**
* 获取Comp Style
*/
public getCompStyle(): string {
return!this.compDTO ? "" : this.compDTO.compStyle;
}
/**
* 获取组件DisplayCount
*/
public getCompDisplayCount(): number {
if (!this.compDTO) {
return 0
}
return StringUtils.parseNumber(this.compDTO.displayCount)
}
/**
* 检查父Group是否需要加载数据,默认为true, 某些Comp的数据源是从{@link CompDTO}的extraData或其他字段中获取,
* 如Label, button等, 则该Comp无需父group再去请求数据
*/
public loadWithGroupData(): boolean {
return true;
}
/**
* 检查是否独立加载数据
*
* @returns 如果该comp是独立加载数据的返回true, 否则返回false.
*/
public separateLoad(): boolean {
if (!this.compDTO) {
return false;
}
// if (this.compDTO.compType === CompType.LABEL || this.compDTO.compType === CompType.BUTTON) {
// return false
// }
if (!this.compDTO.dataSourceRequest || this.compDTO.dataSourceRequest.length == 0) {
return false;
}
return true;
}
// public getIsFeed(): boolean {
// return this.isFeed;
// }
//
// public setIsFeed(isFeed: boolean): void {
// this.isFeed = isFeed;
// }
//
// public getIsGrayMode(): boolean {
// return this.isGrayMode;
// }
//
// public setIsGrayMode(isGrayMode: boolean): void {
// this.isGrayMode = isGrayMode;
// }
// public isLongFeed(): boolean {
// return this.compDTO.dataSource == "SHORT_WITH_LONG_FEED" || this.compDTO.dataSource == "FOCUS_FEED";
// }
/**
* 获取所有的数据项
*/
public getItems(): List<VO> {
return this.items;
}
/**
* 向Comp中添加一个数据源/
* 向Comp中指定位置{@code index}位置添加一个数据源
*/
public addItem(item: VO, index?: number): void {
if (item == null) {
return;
}
if (this.items == null) {
this.items = new List<VO>();
}
if (index == undefined) {
this.items.add(item);
} else {
if (index >= this.items.length) {
this.items.add(item);
} else if (index < 0) {
this.items.insert(item, 0);
} else {
this.items.insert(item, index);
}
}
}
// public getPath():string {return ''}
/**
* 获取初始化参数
*/
// public getInitParams(): Map<String, Object> {
// return this.initParams;
// }
/**
* 获取在index位置的数据项
*/
public getItem(index: number): VO | null {
if (this.items == null || index >= this.items.length || index < 0) {
return null;
}
return this.items.get(index);
}
/**
* 获取Comp item 数量
*/
public getItemCount(): number {
return this.items == null ? 0 : this.items.length;
}
public getAllItemCount(): number {
return this.getItemCount();
}
/**
* 判断数据是否完整,当{@link #needCheckIntegrity()} 返回true时
* @returns 如果数据完整的返回true, 否则返回false.
*/
// public isDataIntegrity(): boolean {
// return this.items != null && this.items.length > 0;
// }
/**
* 判断是否需要检查数据完整性
*/
// public needCheckIntegrity(): boolean {
// return false;
// }
// public changeProgramme( programmeBean:ProgrammeBean) :void{
// }
/**
* 用于在合并请求的场景下请求备用数据源
*/
// public loadBackupDataSource(isRefresh: boolean): void {
// if (this.getIsLoading()) {
// return;
// }
//
// this.isRefresh = isRefresh;
// this.onLoadBackupData();
// }
//
// protected onLoadBackupData(): void {
// }
// public onDynamicDataCallback(isReplaceStaticData: boolean): void {
// }
/**
* 是否清理group数据,默认清除
*/
// public isClearItemsData(): boolean {
// return true;
// }
// protected onDataRequestSuccess(poolId: string, items: List<VO>): void {
// }
// public onDataLoaded(poolId: string): void {
// if (this.items.length != 0) {
// for (let index = 0; index < this.items.length; index++) {
// let item: VO = this.items[index]
// if (StringUtils.isNotEmpty(item.position)) {
// this.dynamicData.set(item.position, item);
// }
// }
// }
// if (poolId != null) {
// this.data.set(poolId, this.items);
// this.onDataRequestSuccess(poolId, this.items);
// let defaultId: string | null = this.getFirstPoolId();
// if (defaultId != null) {
// this.items = this.data.get(defaultId);
// if (defaultId == poolId) {
// this.onLoadDataFinished();
// }
// }
// } else {
// this.data.set("DEFAULT", this.items);
// this.onLoadDataFinished();
// }
// }
// private getFirstPoolId(): string | null {
// if (!this.compDTO || this.compDTO.dataSourceRequest == null || this.compDTO.dataSourceRequest.length == 0) {
// return null;
// } else {
// return this.compDTO.dataSourceRequest[0].poolId ?? null;
// }
// }
// protected Class getDtoCls(): {
// return null;
// }
protected doCompDataFilter(data: DTO): DTO {
return data;
}
public getStatus(): number {
return this.status;
}
/**
* 获取页面位置
*/
// public getLocation(): string {
// if (this.compDTO == null) {
// return "";
// }
// return this.compDTO.location;
// }
/**
* 获取location stamp
*
* @return
*/
// public getLocationStamp(): string {
// let group: WDGroup = this.getParent();
// if (group == null) {
// return "000000";
// }
// let page: MGPage = group.getParent();
//
// if (page == null) {
// return "000000";
// }
//
// let compIndex: number = group.indexOfMGComp(this) + 1;
// let groupIndex: number = page.indexOfGroup(group) + 1;
// return String.format("%03d%03d", groupIndex, compIndex);
// }
/**
* 判断是否是瀑布流
*/
// public isWaterfallFlow(): boolean {
// if (this.compDTO == null) {
// return false;
// }
//
// return "1" == this.compDTO.isWaterfallFlow;
// }
/**
* 获取Comp所在页面的page id
*/
public getPageId(): string {
if (!this.getParent() || !this.getParent().getParent()) {
return "";
}
return this.getParent().getParent().getId();
}
// public getSessionId(): string {
// if (this.getParent() == null || this.getParent().getParent() == null) {
// return "";
// }
// return this.getParent().getParent().getSessionId();
// }
/**
* 获取Group Id
*/
public getGroupId(): string {
if (!this.getParent()) {
return "";
}
return this.getParent().getId();
}
/**
* 判断是否包含广告
*/
// public containsAd(): boolean {
// return this.compDTO != null && this.compDTO.isContainAD == 1;
// }
// public setCompDTO(compDTO: CompDTO): void {
// this.compDTO = compDTO;
// }
// private setLocation(dto:DTO):void { }
// private appendLocation(url:string, location:string):string {}
/**
* 判断comp中是否有extra data
*/
// public hasExtraData(): boolean {
// if (this.compDTO == null) {
// return false;
// }
//
// return this.compDTO.extraData != null;
// }
/**
* 获取comp的extra data
*/
// public getExtraData(): ExtraData | undefined {
// if (this.compDTO == null) {
// return undefined;
// }
// return this.compDTO.extraData;
// }
/**
* 判断是否有分割线
*/
// public hasSeparator(): boolean {
// // if (this.compDTO == null) {
// return false;
// // }
// // return this.compDTO.isSegmentLine == 1;
// }
/**
* 请求结束后通知刷新界面
*/
protected onLoadDataFinished(): void {
if (!this.getParent() || !this.getParent().getParent()) {
return;
}
this.status = NetDataStatusType.LOADED;
this.getParent().getParent().notifyCompDataLoaded(this);
}
/**
* 请求失败后通知界面
*/
protected onLoadDataFailed(): void {
if (!this.getParent() || !this.getParent().getParent()) {
return;
}
this.status = NetDataStatusType.FAILED;
this.getParent().getParent().notifyCompDataFailed(this);
}
/**
* 请求结束后异步通知刷新界面
*/
// protected notifyLoadDataFinished(): void {
// this.onLoadDataFinished();
// }
}
\ No newline at end of file
... ...
import { GroupDTO } from '../bean/GroupDTO';
import { LayoutService } from '../service/LayoutService';
import List from '@ohos.util.List';
import { ItemBean } from '../bean/ItemBean';
import { ItemDTO } from '../bean/ItemDTO';
import { WDComp } from './WDComp';
import { WDPage } from './WDPage';
import { NetDataStatusType } from '../enum/NetDataStatusType';
import { LayoutCallback } from '../service/LayoutCallback';
import { GroupDataDTO } from '../bean/GroupDataDTO';
import { CompDataDTO } from '../bean/CompDataDTO';
import { CompDTO } from '../bean/CompDTO';
import { LabelComp } from './LabelComp';
import { CompType } from '../enum/CompType';
import { CompFilterUtil } from '../utils/CompFilterUtil';
import { ButtonComp } from './ButtonComp';
import { CompStyle } from '../enum/CompStyle';
import { TabBar01Comp } from './TabBar01Comp';
import { TabBar22Comp } from './TabBar22Comp';
import { ProgrammeComp } from './ProgrammeComp';
import { FlowComp } from './FlowComp';
const TAG = 'WDGroup';
/**
* Group数据获取管理及相关业务逻辑处理
*/
export class WDGroup {
private layoutService: LayoutService;
/**
* group配置定义实体
*/
private groupDTO: GroupDTO;
protected parent: WDPage;
private initParams: Map<string, Object> = new Map<string, Object>();
/**
* 所有的comp列表
*/
private comps: List<WDComp<ItemBean, ItemDTO>> = new List();
/**
* 需要合并请求的comp列表
*/
private teamworkCompList: List<WDComp<ItemBean, ItemDTO>>;
/**
* 标记是否包含需要合并请求Comp的Group
*/
private isTeamwork: boolean = false;
/**
* 标记是否需要加载数据,当所有comp都是独立加载数据则group无需再加载数据
*/
private needLoadData: boolean = false;
// /**
// * 标记是否已加载数据
// */
// private isLoaded: boolean = false;
// /**
// * 标记是否在加载数据
// */
// private isLoading: boolean = false;
// 当前group数据加载状态
protected status: number = NetDataStatusType.INITIAL;
// private IWDCompParser parser;
// private isLongFeed: boolean = false;
// private WDComp feedWDComp;
// private WDComp longWDComp;
private displayCount: number = 0;
private hasMoreGroupData: boolean = false;
// private isLongFeedLoaded: boolean = false;
// private isLongFeedLoading: boolean = false;
/**
* 标记是否为黑白化
*/
private isGrayMode: boolean = false;
/**
* 构造函数
*
* @param group 发出请求的WDGroup实例
*/
constructor(page: WDPage, groupDTO: GroupDTO, initParams: Map<string, Object>) {
this.parent = page;
this.groupDTO = groupDTO;
this.initParams = initParams;
this.layoutService = new LayoutService();
this.comps = new List();
this.teamworkCompList = new List();
if (groupDTO) {
// if (page != null && page.getTeamworkGroupIds() != null) {
// isTeamwork = page.getTeamworkGroupIds().contains(group.id);
// }
// setId(group.id);
this.initComp(groupDTO.components, initParams);
}
}
public getParent(): WDPage {
return this.parent;
}
public getGroupDTO(): GroupDTO {
return this.groupDTO;
}
/**
* 获取group中的所有Comp
*/
public getCompList(): List<WDComp<ItemBean, ItemDTO>> {
return this.comps;
}
/**
* 请求Group数据
* @param isRefresh 是否为刷新
*/
public sendRequest(isRefresh: boolean) {
// TODO: 通过LayoutService获取Group数据
if (this.status == NetDataStatusType.LOADING) {
return;
}
// 当group需要请求网络加载数据时
if (this.needLoadData) {
if (this.layoutService) {
let callback: LayoutCallback<GroupDataDTO> = {
onSuccess: (groupDataDTO: GroupDataDTO): void => {
// 包含分众数据,请求分众页面
if (groupDataDTO.branchMark) {
// this.loadDynamicGroup(pageId, bean, isRefresh, layoutCallback);
} else {
this.status = NetDataStatusType.LOADED
this.parseGroup(groupDataDTO)
this.parent.notifyGroupDataLoaded(this)
}
return
},
onFailed: (code: number, message: string): void => {
// todo:
this.status = NetDataStatusType.FAILED
this.parent.notifyGroupDataFailed(this)
return
}
};
this.status = NetDataStatusType.LOADING;
this.layoutService.getGroup(this.getPageId(), this.getId(), isRefresh, callback);
} else {
// "Layout service not initialed
this.status = NetDataStatusType.FAILED;
this.parent.notifyGroupDataFailed(this)
}
//return;
}
this.loadCompData();
this.loadDynamicData();
}
public getPageId(): string {
if (this.getParent() == null) {
return "";
}
return this.getParent().getId();
}
/**
* 解析Group数据
* @param groupBean Group数据对象
*/
private parseGroup(groupDataDTO: GroupDataDTO) {
// TODO: 调用initGroup初始化Group对象
if (groupDataDTO.components) {
groupDataDTO.components.forEach((compDataDTO: CompDataDTO) => {
let wdComp: WDComp<ItemBean, ItemDTO> | null = this.getCompById(compDataDTO.id);
if (wdComp && !wdComp.separateLoad()) {
wdComp.setData(compDataDTO);
}
})
}
}
/**
* 初始化WDComp对象
* @param compList Comp数据对象列表
*/
private initComp(compList: CompDTO[], initParams: Map<string, Object>) {
// TODO:遍历初始化Comp
if (compList == null || compList.length == 0) {
return;
}
this.needLoadData = false;
for (let num = 0; num < compList.length; num++) {
let compDTO: CompDTO = compList[num];
let wdComp: WDComp<ItemBean, ItemDTO>;
if (!CompFilterUtil.filter(compDTO)) {
continue
}
if (compDTO.compType == CompType.LABEL) {
wdComp = new LabelComp(this, compDTO, initParams);
} else if (compDTO.compType == CompType.BUTTON) {
wdComp = new ButtonComp(this, compDTO, initParams);
} else if (compDTO.compType == CompType.NAV_BAR) {
if (compDTO.compStyle == CompStyle.NAV_BAR_01) {
wdComp = new TabBar01Comp(this, compDTO, initParams);
} else if (compDTO.compStyle == CompStyle.NAV_BAR_22) {
wdComp = new TabBar22Comp(this, compDTO, initParams);
} else if (compDTO.compStyle == CompStyle.NAV_BAR_03) {
wdComp = new ProgrammeComp(this, compDTO, initParams);
} else {
// todo:不同的comp,临时用FlowComp
wdComp = new FlowComp(this, compDTO, initParams);
}
} else if (compDTO.compType == CompType.BIG_STATIC_IMG
|| compDTO.compType == CompType.BIG_CAROUSEL_IMG
|| compDTO.compType == CompType.BIG_PLAY_IMG
|| compDTO.compType == CompType.TOP_IMG_BOTTOM_TXT
|| compDTO.compType == CompType.BINGE_WATCHING
|| compDTO.compType == CompType.SLIDER_IMG) {
wdComp = new ProgrammeComp(this, compDTO, initParams);
}else {
// todo:不同的comp,临时用FlowComp
wdComp = new FlowComp(this, compDTO, initParams);
}
if (!wdComp.separateLoad() && wdComp.loadWithGroupData()) {
// todo:临时把走获取group本身数据的逻辑屏蔽,否则逐层获取gourp数据流程会中断。
// this.needLoadData = true;
}
this.comps.add(wdComp);
if (wdComp.isTeamWork()) {
this.teamworkCompList.add(wdComp);
}
}
}
/**
* Group是否需要加载数据
* @returns
*/
public shouldLoadData(): boolean {
// TODO: 当所有comp都是独立加载数据则group无需再加载数据
if (this.needLoadData) {
return this.hasMoreData() || this.status == NetDataStatusType.INITIAL;
}
let loaded = true;
// 若group无需请求网络加载数据时,则判断所有独立加载数据的comp是否都以完成加载
for (let num = 0; num < this.comps.length; num++) {
let wdComp: WDComp<ItemBean, ItemDTO> = this.comps[num];
if (wdComp.separateLoad() && (!wdComp.isLoaded() || wdComp.hasMoreData())) {
loaded = false;
break;
}
}
return !loaded;
}
/**
* 是否正在加载中
* @returns
*/
public isGroupLoading(): boolean {
// TODO: 遍历所有Comp是否正在加载中
if (this.status == NetDataStatusType.LOADING) {
return true;
}
for (let index = 0; index < this.comps.length; index = index + 1) {
let comp = this.comps.get(index);
if (!comp.separateLoad()) {
continue;
}
if (comp.getIsLoading()) {
return true;
}
}
return false;
}
private loadCompData(): void {
for (let index = 0; index < this.comps.length; index++) {
let wdComp: WDComp<ItemBean, ItemDTO> = this.comps[index];
if (!wdComp.separateLoad()) {
continue;
}
if (!wdComp.isLoaded() || wdComp.hasMoreData()) {
wdComp.loadMore();
}
}
}
/**
* Group中所有的Comp是否都已加载完毕
* @returns
*/
public hasDataLoaded(): boolean {
// TODO: 所有Comp是否都已经加载完数据
if (this.needLoadData) {
return this.status == NetDataStatusType.LOADED || this.status == NetDataStatusType.FAILED;
} else {
// 若group无需请求网络加载数据时,则判断所有独立加载数据的Comp是否都以完成加载
for (let index = 0; index < this.comps.length; index = index + 1) {
let comp = this.comps.get(index);
if (comp.separateLoad() && !comp.isLoaded()) {
return false;
}
}
return true;
}
}
/**
* Group中所有的Comp是否都已(成功)加载完毕
* @returns
*/
public hasAllCompLoadedSuccess(): boolean {
if (this.needLoadData) {
return this.status == NetDataStatusType.LOADED;
} else {
// 若group无需请求网络加载数据时,则判断所有独立加载数据的Comp是否都以完成加载
for (let index = 0; index < this.comps.length; index = index + 1) {
let comp = this.comps.get(index);
if (comp.separateLoad() && !comp.isLoadedSuccess()) {
return false;
}
}
return true;
}
}
/**
* 是否还有更多数据待加载
*/
public hasMoreData(): boolean {
// TODO: 判断是否有加载更多数据的Comp并且存在更多数据
if (this.comps == null) {
return false;
}
for (let index = 0; index < this.comps.length; index = index + 1) {
let comp = this.comps.get(index);
if (comp.hasMoreData()) {
return true;
}
}
return false;
}
public loadMore(): void {
let hasMoreCompData: boolean = false;
if (this.comps && !this.comps.isEmpty()) {
for (let index = this.comps.length - 1; index >= 0; index = index - 1) {
let comp = this.comps.get(index);
if (comp) {
hasMoreCompData = comp.hasMoreData();
if (hasMoreCompData) {
break;
}
}
}
}
if (!hasMoreCompData && this.hasMoreGroupData) {
// LogUtil.d("WDGroup[" + this.toString() + "]: loadMore");
// requestLongFeed(false);
}
}
/**
* 是否需要加载动态数据
* @returns
*/
public needLoadDynamicData(): boolean {
// TODO: 遍历所有Comp,判断数据源的dataSourceType是否为“POMS_NODE”,是则需要加载动态数据。
return false;
}
/**
* 加载动态数据
*/
public loadDynamicData() {
// TODO: 通过LayoutService加载动态数据,通过WDComp#replaceStaticData替换静态数据。
}
public getId(): string {
return this.groupDTO?.id ?? "";
}
/**
* 通过Comp id查找相应的comp实例
*
* @param id comp id
*/
public getCompById(id: string): WDComp<ItemBean, ItemDTO> | null {
for (let index = 0; index < this.comps.length; index++) {
let wdComp: WDComp<ItemBean, ItemDTO> = this.comps[index];
if (wdComp.getId() == id) {
return wdComp;
}
}
return null;
}
public getIsTeamWork(): boolean {
return this.isTeamwork;
}
public getIsGrayMode(): boolean {
return this.isGrayMode;
}
/**
* 获取comp在Group中的位置
*
* @param comp WDComp实例
*/
public indexOfComp(comp: WDComp<ItemBean, ItemDTO>): number {
if (comp == null || this.comps == null) {
return -1;
}
return this.comps.getIndexOf(comp);
}
}
\ No newline at end of file
... ...
/**
* Page数据获取管理及相关业务逻辑处理
*/
import { PageDTO } from '../bean/PageDTO';
import { LayoutService } from '../service/LayoutService';
import { PageListener } from './PageListener';
import { WDGroup } from './WDGroup';
import List from '@ohos.util.List';
import { LayoutCallback } from '../service/LayoutCallback';
import { GroupDTO } from '../bean/GroupDTO';
import { ItemBean } from '../bean/ItemBean';
import { ItemDTO } from '../bean/ItemDTO';
import { CompStyle } from '../enum/CompStyle';
import { WDComp } from './WDComp';
import { IGroupFilter } from './filter/IGroupFilter';
export class WDPage {
private layoutService: LayoutService;
private listener?: PageListener;
private pageId: string;
private pageDTO?: PageDTO;
private groups: List<WDGroup> = new List();
private initParams: Map<string, Object> = new Map<string, Object>();
private groupFilters: IGroupFilter[] = [];
/**
* 标记是否在加载数据
*/
private isLoading: boolean = false;
/**
* 页面顶部搜索提示文本
*/
private searchText?: string;
constructor(pageId: string, initParams: Map<string, Object>, groupFilters: IGroupFilter[]) {
this.pageId = pageId;
this.initParams = initParams;
this.groupFilters = groupFilters;
this.layoutService = new LayoutService();
}
public setListener(listener: PageListener): void {
this.listener = listener;
}
/**
* 请求Page数据
* @param isRefresh 是否为刷新
*/
public sendRequest(isRefresh: boolean) {
// TODO: 由于PageID在构造函数中传入,所以这里的参数不需要PageID。
// TODO: 通过LayoutService获取Page数据
if (this.isLoading) {
return;
}
this.isLoading = true;
if (this.layoutService) {
let callback: LayoutCallback<PageDTO> = {
onSuccess: (pageDTO: PageDTO): void => {
this.isLoading = false;
this.parsePage(pageDTO);
if (this.listener) {
this.listener.onPageLoaded(this);
}
return
},
onFailed: (code: number, message: string): void => {
// todo:
this.isLoading = false;
if (this.listener) {
this.listener.onPageFailed(this)
}
return
}
};
this.layoutService.getPage(this.pageId, isRefresh, callback);
}
}
/**
* 解析Page数据
* @param pageDTO Page数据对象
*/
private parsePage(pageDTO: PageDTO) {
// TODO: 调用initGroup初始化Group对象
this.pageDTO = pageDTO;
if (pageDTO.groups) {
this.initGroup(pageDTO.groups, this.initParams);
}
if (pageDTO.pageSearchText && pageDTO.pageSearchText.length > 0) {
this.searchText = pageDTO.pageSearchText[0];
} else {
// 设置searchText为空字符串表示page接口已经返回
this.searchText = "";
}
}
public getPageDTO(): PageDTO {
return this.pageDTO ?? {} as PageDTO;
}
public getSearchText(): string | undefined {
return this.searchText;
}
/**
* 初始化WDGroup对象
* @param groupList Group数据对象列表
*/
private initGroup(groupList: GroupDTO[], initParams: Map<string, Object>) {
if (groupList == null || groupList.length == 0) {
return;
}
// TODO:遍历初始化Group
for (let num = 0; num < groupList.length; num++) {
let groupBean: GroupDTO = groupList[num];
if (!this.filterGroup(groupBean)) {
continue;
}
let wdGroup: WDGroup = new WDGroup(this, groupBean, initParams);
if (!this.filterGroupAfterFilterComp(wdGroup)) {
continue;
}
this.groups.add(wdGroup);
}
}
/**
* 本楼层是否被过滤掉
* @param groupBean 待过滤的GroupBean数据
* @returns 保留此项数据:返回true;否则(舍弃此项数据),返回false;
*/
private filterGroup(groupBean: GroupDTO): boolean {
if (this.groupFilters == null || this.groupFilters.length <= 0) {
return true;
}
for (let index = 0; index < this.groupFilters.length; index++) {
let filter = this.groupFilters[index];
if (!filter.filter(groupBean)) {
return false;
}
}
return true;
}
/**
* 第二次过滤group/业务逻辑过滤/不合理过滤/本楼层是否被过滤掉
* @param WDGroup 待过滤的WDGroup数据
* @returns 保留此项数据:返回true;否则(舍弃此项数据),返回false;
*/
private filterGroupAfterFilterComp(wdGroup: WDGroup): boolean {
if (!wdGroup || wdGroup.getCompList().length == 0) {
// 本楼层所有组件已被过滤掉
return false
}
let wdComp: WDComp<ItemBean, ItemDTO> = wdGroup.getCompList().get(0)
let compStyle: string = wdComp.getCompStyle()
if (wdGroup.getCompList().length == 1) { // 楼层仅包含一个组件数据
if (compStyle === CompStyle.LABEL_01) { // 即一个楼层仅包含LABEL_01,其他的都被过滤掉时,则这个LABEL_01也要过滤掉
return false
}
if (compStyle === CompStyle.NAV_BAR_01) { //
// http://display-sc.miguvideo.com/display/v4/static/965823946cac4bf3b78c7b99b76b728b
// 目前会配置3个顶导楼层,取第2楼顶导
if (wdGroup.getParent().getGroups().length > 1) { // 若配置了多个group顶导:则过滤掉max不等于-1的group
if (wdGroup.getGroupDTO().androidVersion) {
if (wdGroup.getGroupDTO().androidVersion?.max != '-1') { // 把限制版本的顶导过滤掉 // todo:
// if (WDComp.getCompDTO()?.androidVersion?.max != '-1') { // 把限制版本的顶导过滤掉 // todo:
return false
}
}
}
}
} else { // 楼层包含多个组件数据
if (compStyle !== CompStyle.LABEL_01) {
// 但本楼层第一个组件不是label
// return false // 配置的可能是LABEL-04
}
}
return true;
}
/**
* 获取page中所有的group
*/
public getGroups(): List<WDGroup> {
return this.groups;
}
public getId(): string {
return this.pageId ?? "";
}
public notifyPageLayoutLoaded(): void {
if (this.listener) {
this.listener.onPageLoaded(this);
}
}
public notifyPageLayoutFailed(): void {
if (this.listener) {
this.listener.onPageFailed(this)
}
}
public notifyGroupDataLoaded(group: WDGroup): void {
if (this.listener) {
this.listener.onGroupLoaded(this, group)
}
}
public notifyGroupDataFailed(group: WDGroup): void {
if (this.listener) {
this.listener.onGroupFailed(this, group);
}
}
public notifyCompDataLoaded(comp: WDComp<ItemBean, ItemDTO>): void {
if (this.listener) {
this.listener.onCompLoaded(this, comp.getParent(), comp)
}
}
public notifyCompDataFailed(comp: WDComp<ItemBean, ItemDTO>): void {
if (this.listener) {
this.listener.onCompFailed(this, comp.getParent(), comp)
}
}
/**
* Desc: 加载count个未加载的group
* @return 如果有加载未加载的group或者有正在加载数据的group则返回true,否则返回false
*/
public loadNextGroups(count: number, isRefresh: boolean): boolean {
let cnt: number = count;
if (this.groups == null || this.groups.isEmpty()) {
return false;
}
let hasLoading: boolean = false;
let hasLongFeed: boolean = false;
for (let index = 0; index < this.groups.length; index = index + 1) {
let group = this.groups.get(index);
if (count <= 0) {
return true;
}
if (group.shouldLoadData()) {
group.sendRequest(isRefresh);
--count;
} else if (!hasLoading && group.isGroupLoading()) {
hasLoading = true;
}
group.loadMore();
// hasLongFeed = group.getLongFeedComp() != null;
hasLongFeed = false
}
return hasLoading || cnt != count || hasLongFeed;
}
}
\ No newline at end of file
... ...
/**
* Comp过滤器,用于根据不同场景是否显示某个Comp,例如某些Comp只在指定的省份才显示。
*/
import { CompDTO } from '../../bean/CompDTO';
export interface ICompFilter {
/**
* 过滤逻辑的实现
* @param compDTO: 待过滤CompDTO数据
* @returns 保留此项数据:返回true;否则(舍弃此项数据),返回false;
*/
filter(compDTO: CompDTO): boolean;
}
\ No newline at end of file
... ...
/**
* Group过滤器,用于根据不同场景是否显示某个Group,例如某些Group只在指定的省份才显示。
*/
import { GroupDTO } from '../../bean/GroupDTO';
export interface IGroupFilter {
/**
* 过滤逻辑的实现
* @param groupDTO: 待过滤GroupDTO数据
* @returns 保留此项数据:返回true;否则(舍弃此项数据),返回false;
*/
filter(groupDTO: GroupDTO): boolean;
}
\ No newline at end of file
... ...
/**
* Group数据请求调度
* 处理MGGroup的数据请求,并同步所有包含的MGComp的请求结果并一同返回给调用者。
*/
import { ItemBean } from '../bean/ItemBean';
import { ItemDTO } from '../bean/ItemDTO';
import { WDComp } from '../layout/WDComp';
import { WDGroup } from '../layout/WDGroup';
import List from '@ohos.util.List';
import { FlowComp } from '../layout/FlowComp';
export class GroupRequest {
/**
* 发起Group数据请求
* @param isRefresh 是否为刷新
* @param group MGGroup对象
* @returns 是否发起了请求
*/
public request(isRefresh: boolean, group: WDGroup): boolean {
// TODO: 通过MGGroup获取数据,或遍历所包含的MGComp获取数据。
if (group == null || group.getCompList() == null || group.getCompList().isEmpty()) {
return false;
}
if (group.shouldLoadData()) {
group.sendRequest(isRefresh);
return true;
} else {
return false;
}
}
/**
* 如果Group中的Comp可以加载更多数据,则加载更多数据。
* @param group MGGroup对象
* @returns 是否加载了更多数据
*/
public loadMore(group: WDGroup | undefined): boolean {
// TODO: 如果Group中的Comp可以加载更多数据,通过MGComp#loadMore获取数据。
if (group != undefined) {
let compList:List<WDComp<ItemBean, ItemDTO>> = group?.getCompList();
if (compList) {
for (let i = 0; i < compList.length; i++) {
let mgComp = compList.get(i);
if (mgComp instanceof FlowComp && mgComp.hasMoreData()) {
if (!mgComp.getIsLoading()) {
mgComp.loadMore();
}
return true;
}
}
// if (group.isHasMoreGroupData()) {
// group.requestLongFeed(false);
// return true;
// }
}
}
return false;
}
}
\ No newline at end of file
... ...
/**
* 乐高数据请求调度
*/
import { NetDataStatusType } from '../enum/NetDataStatusType';
import { WDGroup } from '../layout/WDGroup';
import { WDPage } from '../layout/WDPage';
import { Synchronizer } from './Synchronizer';
import List from '@ohos.util.List';
import { WDComp } from '../layout/WDComp';
import { ItemBean } from '../bean/ItemBean';
import { ItemDTO } from '../bean/ItemDTO';
import { PageListener } from '../layout/PageListener';
import { LegoUtil } from '../utils/LegoUtil';
import { Logger } from 'wdKit';
import { Lego } from './LegoService';
import { GroupRequest } from './GroupRequest';
const TAG = 'LegoRequest';
export class LegoRequest {
/**
* 记录MGPage的数据请求状态
*/
private pageStatus: number = NetDataStatusType.INITIAL;
/**
* MGPage对象,所有数据请求都是基于此对象进行。
*/
private page: WDPage;
/**
* 最后一次请求的MGGroup对象
*/
private lastGroup?: WDGroup;
/**
* 最后一次请求的MGGroup对象所对应的Index
*/
private lastGroupIndex: number = -1;
/**
* 同步管理器
*/
private synchronizer: Synchronizer;
/**
* 待处理的任务列表
*/
private taskList: List<Lego.Callback> = new List();
/**
* 当前MGPage对象中所包含的所有MGGroup对象
*/
private allGroupList: List<WDGroup> = new List();
/**
* 记录所有返回的MGGroup,用于判断是首次返回还是更新。
*/
private callbackGroupList: List<WDGroup> = new List();
/**
* 记录所有返回的MGComp,用于判断是首次返回还是更新。
*/
private callbackCompList: List<WDComp<ItemBean, ItemDTO>> = new List();
/**
* 调试开关
*/
// public static DEBUG: boolean = false;
/**
* 构造函数:Lego数据请求统筹对象
* @param page 目标MGPage对象
*/
constructor(page: WDPage) {
this.page = page;
this.synchronizer = new Synchronizer();
}
/**
* 数据请求
* @param isRefresh 是否为刷新
* @param callback 回调
*/
public request(isRefresh: boolean, legoCallback: Lego.Callback) {
// TODO: 通过MGPage#sendRequest获取Page数据,PageListener监听状态。
if (isRefresh) {
this.synchronizer = new Synchronizer();
this.lastGroup = undefined;
this.allGroupList.clear();
this.callbackGroupList.clear();
this.callbackCompList.clear();
this.pageStatus = NetDataStatusType.INITIAL;
// 如果刷新任务过来,前面待处理的任务会被清空。
// 如果对业务产生不良影响,后续改进。
this.taskList.clear();
}
// 如果Page正在请求中,则需要等待请求结束。
if (this.pageStatus == NetDataStatusType.LOADING && !isRefresh) {
this.taskList.add(legoCallback);
}
if (this.allGroupList.isEmpty() || isRefresh) {
let pageListener: PageListener = {
onPageLoaded: (page: WDPage): void => {
this.pageStatus = NetDataStatusType.LOADED;
// Page级别回调
legoCallback.onPageLoaded(page);
this.allGroupList.clear();
let groups: List<WDGroup> = this.page.getGroups();
if (groups) {
this.allGroupList = groups;
}
if (this.allGroupList.isEmpty()) {
let msg: string = "onPageLayoutLoaded : allGroupList is empty --> PageID = " + LegoUtil.getPageId(page);
this.synchronizer.onError(page, msg, legoCallback);
} else {
this.doNext(isRefresh, legoCallback);
// 开始进行待处理的任务
if (!this.taskList.isEmpty()) {
for (let index = 0; index < this.taskList.length; index++) {
let legoCb: Lego.Callback = this.taskList[index]
this.doNext(false, legoCb);
}
}
this.taskList.clear();
}
return
},
onPageFailed: (page: WDPage): void => {
this.pageStatus = NetDataStatusType.FAILED;
let msg: string = "onPageLayoutFailed --> PageID = " + LegoUtil.getPageId(page);
this.synchronizer.onError(page, msg, legoCallback);
return
},
onGroupLoaded: (page: WDPage, group: WDGroup): void => {
// todo:
// if (this.callbackGroupList.has(group)) {
// this.synchronizer.onGroupUpdate(group, legoCallback);
// } else {
// this.callbackGroupList.add(group);
// this.synchronizer.checkStatus("onGroupLoaded", group, legoCallback);
// }
legoCallback.onGroupUpdate(group);
return
},
onGroupFailed: (page: WDPage, group: WDGroup): void => {
if (!this.callbackGroupList.has(group)) {
this.callbackGroupList.add(group);
let msg: string = "onGroupFailed --> PageID = " + LegoUtil.getPageId(group.getParent()) + ", GroupID = " + LegoUtil.getGroupId(group);
this.synchronizer.onFailed(msg, group, legoCallback);
}
return
},
onCompLoaded: (page: WDPage, group: WDGroup, comp: WDComp<ItemBean, ItemDTO>): void => {
Logger.info(TAG, `onCompLoaded page.getId: ${page.getId()}, group.getId: ${group.getId()}, comp.getId: ${comp.getId()}`);
// if (this.callbackCompList.has(comp)) {
// this.synchronizer.onCompUpdate(comp, legoCallback);
// } else {
// this.callbackCompList.add(comp);
// this.synchronizer.checkStatus("onCompLoaded", comp.getParent(), legoCallback);
// }
if (group.hasDataLoaded()) {
if (group.hasAllCompLoadedSuccess()) {
// 回调到界面展示
legoCallback.onLoaded(group);
// legoCallback.onGroupUpdate(group);
}
// 同时请求下一个group
this.doNext(false, legoCallback)
}
return
},
onCompFailed: (page: WDPage, group: WDGroup, comp: WDComp<ItemBean, ItemDTO>): void => {
Logger.info(TAG, `onCompFailed page.getId: ${page.getId()}, group.getId: ${group.getId()}, comp.getId: ${comp.getId()}`);
// if (!this.callbackCompList.has(comp)) {
// this.callbackCompList.add(comp);
// this.synchronizer.checkStatus("onCompFailed", comp.getParent(), legoCallback);
// }
if (group.hasDataLoaded()) {
// 回调到界面展示
// legoCallback.onLoaded(group);
// legoCallback.onGroupUpdate(group);
// 同时请求下一个group
this.doNext(false, legoCallback)
}
return
}
};
this.page.setListener(pageListener);
this.pageStatus = NetDataStatusType.LOADING;
this.page.sendRequest(isRefresh);
} else {
this.doNext(false, legoCallback);
}
}
/**
* 进行下一步处理流程
* 根据请求顺序获取待请求MGGroup,并将请求动作交给GroupRequest继续处理。
*/
private doNext(isRefresh: boolean, legoCallback: Lego.Callback) {
// TODO: 通过GroupRequest获取Group数据
let groupRequest: GroupRequest = new GroupRequest();
// 加载更多
if (groupRequest.loadMore(this.lastGroup)) {
return;
}
// 首次请求状态初始化
if (!this.lastGroup) {
this.lastGroupIndex = -1;
}
let groupIndex: number = this.lastGroupIndex + 1;
if (groupIndex < 0) {
groupIndex = 0;
}
// 合法性校验
if (!this.checkIndex(groupIndex)) {
return;
}
Logger.info(TAG, `doNext groupIndex: ${groupIndex}`);
if (!this.allGroupList.isEmpty() && groupIndex < this.allGroupList.length) {
let tempGroup: WDGroup = this.allGroupList.get(groupIndex);
// 状态记录
this.lastGroup = tempGroup;
this.lastGroupIndex = groupIndex;
if (tempGroup) {
this.synchronizer.addGroup(tempGroup, legoCallback);
let isRequest: boolean = groupRequest.request(isRefresh, tempGroup);
// 如果当前Group没有可以请求的Comp则尝试下一个Group
if (!isRequest) {
// 无需请求直接返回回调
// this.synchronizer.checkStatus("groupLoaded", tempGroup, legoCallback);
// 回调到界面展示
if (!tempGroup.getGroupDTO()?.branchMark) {
legoCallback.onLoaded(tempGroup);
}
// 同时请求下一个group
this.doNext(false, legoCallback)
}
}
} else {
// Page中所有Group已加载完毕
legoCallback.onCompleted(this.page);
}
}
// todo
private checkIndex(groupIndex: number): boolean {
return true;
}
}
\ No newline at end of file
... ...
/**
* 数据模块队外接口服务
*/
import { ItemBean } from '../bean/ItemBean';
import { ItemDTO } from '../bean/ItemDTO';
import { IGroupFilter } from '../layout/filter/IGroupFilter';
import { WDComp } from '../layout/WDComp';
import { WDGroup } from '../layout/WDGroup';
import { WDPage } from '../layout/WDPage';
import { LegoRequest } from './LegoRequest';
export namespace Lego {
/**
* 乐高数据服务
*/
export class LegoService {
pageId: string;
page: WDPage;
initParams: Map<string, Object> = new Map<string, Object>();
groupFilters: IGroupFilter[];
legoRequest: LegoRequest;
constructor(builder: Builder) {
this.pageId = builder.pageId;
this.initParams = builder.initParams;
this.groupFilters = builder.groupFilters;
// 创建MGPage对象
if (!builder.page) {
this.page = new WDPage(this.pageId, this.initParams, this.groupFilters);
} else {
this.page = builder.page;
}
this.legoRequest = new LegoRequest(this.page);
}
/**
* 数据请求
* @param isRefresh 是否为刷新
* @param callback 回调
*/
public request(isRefresh: boolean, callback: Lego.Callback) {
// TODO: 通过LegoRequest#request发出请求
this.legoRequest.request(isRefresh, callback);
}
}
export class Builder {
pageId: string = '';
contentId: string = '';
page?: WDPage;
initParams: Map<string, Object> = new Map<string, Object>();
groupFilters: IGroupFilter[] = [];
setPageId(pageId: string) {
this.pageId = pageId;
return this;
}
setContentId(contentId: string) {
this.contentId = contentId;
return this;
}
setPage(page: WDPage) {
this.page = page
return this;
}
setParams(initParams: Map<string, Object>) {
this.initParams = initParams
return this;
}
setGroupFilters(...groupFilters: IGroupFilter[]) {
this.groupFilters = groupFilters
return this;
}
public build(): LegoService {
return new LegoService(this);
}
}
/**
* 数据请求回调接口
*/
export interface Callback {
/**
* 一次数据请求成功的回调
* @param group Group实例
*/
onLoaded: (group: WDGroup) => void;
/**
* 一次数据请求失败的回调
* @param group 本次请求的Group
* @param msg 失败描述
*/
onFailed: (group: WDGroup, msg: String) => void;
/**
* Page级错误回调,Page请求异常无法进行后续流程。
* @param page Page实例
* @param msg 错误描述
*/
onError: (page: WDPage, msg: String) => void;
/**
* 整个Page已全部请求完成的回调
* @param page Page实例
*/
onCompleted: (page: WDPage) => void;
/**
* Page接口请求成功的回调
* @param page Page实例
*/
onPageLoaded: (page: WDPage) => void;
/**
* Group数据更新的回调
* @param group Group实例
*/
onGroupUpdate: (group: WDGroup) => void;
/**
* Comp数据更新的回调
* @param comp Comp实例
*/
onCompUpdate: (comp: WDComp<ItemBean, ItemDTO>) => void;
}
}
\ No newline at end of file
... ...
/**
* 同步管理器,用于同步一个MGGroup中所有MGComp的数据响应。
* 当全部MGComp数据都请求完毕后,一次性返回所有数据。
*/
import { WDGroup } from '../layout/WDGroup';
import List from '@ohos.util.List';
import { Timeout } from './TimeoutManager';
import { WDPage } from '../layout/WDPage';
import { WDComp } from '../layout/WDComp';
import { ItemBean } from '../bean/ItemBean';
import { ItemDTO } from '../bean/ItemDTO';
import { LegoUtil } from '../utils/LegoUtil';
import { Lego } from './LegoService';
export class Synchronizer {
/**
* 正在处理中的MGGroup列表,用于记录和按顺序回调给调用者。
*/
private workingList: List<WDGroup> = new List();
/**
* 已经返回的MGGroup列表
*/
private completedList: List<WDGroup> = new List();
private failedList: List<WDGroup> = new List();
/**
* 任务超时管理器
*/
private timeoutManager: Timeout.TimeoutManager;
/**
* 构造函数:Lego数据请求统筹对象
* @param page 目标MGPage对象
*/
constructor() {
let callback: Timeout.Callback = {
onTimeout: (group: WDGroup, callback: Lego.Callback) => {
this.onTimeout(group, callback);
}
}
this.timeoutManager = new Timeout.TimeoutManager(callback)
}
/**
* 记录正在进行中的任务
* @param group 正在进行数据请求的MGGroup对象
* @param callback 回调
*/
public addGroup(group: WDGroup, legoCallback: Lego.Callback) {
// TODO: 记录Group
this.workingList.add(group);
this.timeoutManager.addTask(group, legoCallback);
}
/**
* 同步按顺序控制回调
* @param callback 回调
*/
private syncCallback(callback: Lego.Callback) {
// TODO: 判断是否可以回调与遍历可回调Group
while (this.workingList.length > 0) {
// 严格按照任务顺序返回,若出现未完成任务,则等待下次处理。
let tempGroup: WDGroup = this.workingList.get(0)
if (this.completedList.has(tempGroup)) {
this.workingList.remove(tempGroup);
this.completedList.remove(tempGroup);
// todo
// callback.onLoaded(tempGroup);
} else if (this.failedList.has(tempGroup)) {
this.workingList.remove(tempGroup);
this.failedList.remove(tempGroup);
// todo
// callback.onFailed(tempGroup, "");
} else {
break;
}
}
}
public onTimeout(group: WDGroup, callback: Lego.Callback): void {
// 目前简单的处理成超时则不显示该Group
this.onFailed("Timeout", group, callback);
}
/**
* MGGroup数据加载完毕,按照顺序回调。
*
* @param group 数据请求完毕的MGGroup对象
* @param callback 回调对象
*/
public onLoaded(group: WDGroup, callback: Lego.Callback): void {
this.timeoutManager.removeTask(group);
this.completedList.add(group);
this.syncCallback(callback);
}
/**
* MGGroup数据加载失败,按照顺序回调。
*
* @param msg 携带的描述信息,主要用于调试。
* @param group 数据请求完毕的MGGroup对象
* @param callback 回调对象
*/
public onFailed(msg: string, group: WDGroup, callback: Lego.Callback): void {
this.timeoutManager.removeTask(group);
this.failedList.add(group);
this.syncCallback(callback);
}
/**
* MGPage级别的错误,无法恢复。
*
* @param msg 携带的描述信息,主要用于调试。
* @param callback 回调对象
*/
public onError(page: WDPage, msg: string, callback: Lego.Callback) {
callback.onError(page, msg);
}
/**
* MGGroup数据更新
*
* @param group 数据更新的MGGroup对象
* @param callback 回调对象
*/
public onGroupUpdate(group: WDGroup, callback: Lego.Callback) {
if (!this.workingList.has(group)) {
callback.onGroupUpdate(group);
}
}
/**
* MGComp数据更新
*
* @param comp 数据更新的MGComp对象
* @param callback 回调对象
*/
public onCompUpdate(comp: WDComp<ItemBean, ItemDTO>, callback: Lego.Callback): void {
if (!this.workingList.has(comp.getParent())) {
callback.onCompUpdate(comp);
}
}
/**
* 检查MGGroup中的所有MGComp的数据是否加载完毕
*
* @param group MGGroup实例
* @param callback 请求的回调对象
*/
public checkStatus(msg: string, group: WDGroup, callback: Lego.Callback): void {
if (group) {
// 如果没有主动请求这个Group,而这个Group的comp数据返回,则不处理回调判断。
if (!this.workingList.has(group)) {
return;
}
let compList: List<WDComp<ItemBean, ItemDTO>> = group.getCompList();
if (compList && !compList.isEmpty()) {
let isCompleted: boolean = true;
for (let i = 0; i < compList.length; i++) {
let comp: WDComp<ItemBean, ItemDTO> = compList.get(i);
// 检查是否有未加载完毕的Comp
// if (comp instanceof FlowComp) {
// let itemCount: number = comp.getItemCount()
// // let itemCount:number = ((FlowComp) comp).getItemCount();
// if (itemCount <= 0) {
// isCompleted = false;
// break;
// }
// } else
if (comp && comp.separateLoad() && !comp.isLoaded()) {
isCompleted = false;
break;
}
}
if (isCompleted) {
// this.onLoaded(group, callback);
callback.onLoaded(group)
}
} else {
msg = "checkStatus: comp list is empty -- > PageID = " + LegoUtil.getPageId(group.getParent()) + ", GroupID = " + LegoUtil.getGroupId(group);
// this.onFailed(msg, group, callback);
callback.onFailed(group, msg)
}
}
}
}
\ No newline at end of file
... ...
/**
* 超时控制与管理
*
* setTimeout和setInterval函数,都返回一个整数值,表示计数器编号。
*
* let timerId = setTimeout(func|code, delay);
* setTimeout函数接受两个参数,第一个参数func|code是将要推迟执行的函数名或者一段代码,第二个参数delay是推迟执行的毫秒数。
* setTimeout的第二个参数如果省略,则默认为0。
*
* 如:
* let timerId1 = setTimeout(fun1, 1000);
*
* setInterval函数的用法与setTimeout完全一致,区别仅仅在于setInterval指定某个任务每隔一段时间就执行一次,也就是无限次的定时执行。
* let intervalId1 = setInterval(fun2, 1000);
* 上面代码中,每隔1000毫秒就会执行fun2函数,会无限运行下去,直到关闭当前窗口。
*
* 注意:
* setInterval指定的是“开始执行”之间的间隔,并不考虑每次任务执行本身所消耗的时间。因此实际上,两次执行之间的间隔会小于指定的时间。
* 比如,setInterval指定每 100ms 执行一次,每次执行需要 5ms,那么第一次执行结束后95毫秒,第二次执行就会开始。如果某次执行耗时特别长,比如需要105毫秒,那么它结束后,下一次执行就会立即开始。
*
*
* setTimeout和setInterval函数,都返回一个整数值,表示计数器编号。将该整数传入clearTimeout和clearInterval函数,就可以取消对应的定时器。
*
* clearTimeout(timerId1)
* clearInterval(intervalId1)
*/
import { WDGroup } from '../layout/WDGroup';
import HashMap from '@ohos.util.HashMap';
import { Lego } from './LegoService';
export namespace Timeout {
/**
* 超时管理
*/
export class TimeoutManager {
/**
* 超时时长
*/
private static TASK_TIMEOUT: number = 5000;
/**
* 任务超时回调
*/
private callback: Callback;
/**
* 用于存放所有进行中的任务
*/
private taskMap: HashMap<WDGroup, Task>;
/**
* 超时管理器单例实例
*/
private static instance: TimeoutManager;
private intervalId:number = -1;
/**
* 构造函数
*
* @param group 发出请求的MGGroup实例
* @param startTime 任务开始时间戳
* @param timeout 超时限制时常
*/
constructor(callback: Callback) {
this.taskMap = new HashMap<WDGroup, Task>();
this.callback = callback;
// todo:
// 如果队列中没有检查消息,TASK_TIMEOUT后检查。
// if (this.intervalId == -1) {
// this.intervalId = setInterval(() => {
// this.checkTimeout();
// }, TimeoutManager.TASK_TIMEOUT);
// }
}
/**
* 添加任务,监控超时状态。
* @param group MGGroup对象
* @param callback 回调
*/
public addTask(group: WDGroup, callback: Lego.Callback) {
let task: Task = this.taskMap.get(group);
let timestamp: number = new Date().getTime(); // 单位毫秒
if (task == null) {
this.taskMap.set(group, new Task(group, callback, timestamp, TimeoutManager.TASK_TIMEOUT));
} else {
task.setStartTime(timestamp);
task.setCallback(callback);
}
}
/**
* 移除任务,说明任务已经完成,不再监控超时状态。
* @param group MGGroup对象
*/
public removeTask(group: WDGroup) {
this.taskMap.remove(group);
}
/**
* 检查是否有已经超时的任务,如有则回调超时状态。
*/
private checkTimeout() {
// TODO: 遍历任务列表检查是否有超时任务
this.taskMap.forEach((task: Task, group: WDGroup) => {
if (task == null || task.isTimeout()) {
// 超时回调
if (this.callback) {
this.callback.onTimeout(group, task.callback);
}
}
})
}
}
/**
* 任务
*/
class Task {
/**
* MGGroup实例
*/
private group: WDGroup;
/**
* 请求回调
*/
public callback: Lego.Callback;
/**
* 任务开始时间戳
*/
private startTime: number;
/**
* 超时限制时常
*/
private timeout: number;
/**
* 构造函数
*
* @param group 发出请求的MGGroup实例
* @param startTime 任务开始时间戳
* @param timeout 超时限制时常
*/
constructor(group: WDGroup, callback: Lego.Callback, startTime: number, timeout: number) {
this.group = group;
this.callback = callback;
this.startTime = startTime;
this.timeout = timeout;
}
/**
* 更新任务开始时间戳
*
* @param startTime 任务开始时间戳
*/
public setStartTime(startTime: number): void {
this.startTime = startTime;
}
public setCallback(callback: Lego.Callback): void {
this.callback = callback;
}
/**
* 检查任务是否超时
*
* @return 是否超时
*/
public isTimeout(): boolean {
let timestamp: number = new Date().getTime(); // 单位毫秒
return timestamp - this.startTime - this.timeout >= 0;
}
}
/**
* 超时回调
*/
export interface Callback {
/**
* Group请求超时回调
* @param group MGGroup对象
* @param callback 回调';
*/
onTimeout: (group: WDGroup, callback: Lego.Callback) => void;
}
}
\ No newline at end of file
... ...
/**
1.主界面底部五个tab
请求底导数据(无参数):
2.请求首页顶部的tab:
请求顶导数据(参数是:当前选中的底导item的${page}):
3.请求页面组件列表数据(参数是:当前选中的顶导item的${path}):
4.请求每个组件内容列表url(参数是:PageID,groupId, compId)
*/
import { ConfigConstants } from 'wdConstant';
import { WDHttp } from 'wdNetwork';
import { NavBody } from '../bean/NavBody';
import { PageDTO } from '../bean/PageDTO';
const TAG = 'PageRepository';
export class PageRepository {
/**
* 主界面底部五个tab:首页、体育、VIP、广场、我的
*
* @returns ResponseDTO<NavBody>
*/
static fetchNavigationDataApi() {
const appId: string = ConfigConstants.appId;
const terminalId: string = ConfigConstants.terminalId;
const province: string = ConfigConstants.province;
const navigationUrl = `https://app-sc.miguvideo.com/app-management/v4/staticcache/navigation-list/${appId}/${terminalId}/${province}`
return WDHttp.Request.get<WDHttp.ResponseDTO<NavBody>>(navigationUrl)
};
/**
* 请求/获取首页顶部导航tab菜单列表
*
* 参考fetchGroupList函数
*/
static fetchMenuList(pageId: string): Promise<WDHttp.ResponseDTO<PageDTO>> {
return PageRepository.fetchGroupList(pageId)
};
/**
* display-v4接口
* pageLayout接口(请求栏目列表)
*
* @param pageID 页面Id
* @returns ResponseDTO<BodyPage>
*/
static fetchGroupList(pageID: string) {
const pageUrl: string = `${ConfigConstants.BASE_URL_VOD}${ConfigConstants.CONTENT_LIST_PATH}/${pageID}`;
return WDHttp.Request.get<WDHttp.ResponseDTO<PageDTO>>(pageUrl)
};
/**
* display-v4接口
* 获取comp数据接口(请求栏目内容)
*
* @param pageId 页面Id
* @param groupId 区段id
* @param componentId 组件id
* @returns ResponseDTO<BodyComponent>
*/
// static fetchComponentData(pageID: string, groupID: string, compID: string) {
// const pageUrl: string = `${ConfigConstants.BASE_URL_VOD}${ConfigConstants.CONTENT_LIST_PATH}/${pageID}/${groupID}/${compID}`;
// Logger.info(TAG, "getGroupList pageUrl:" + pageUrl);
// let headers: Record<string, string> = {
// 'provinceCode': ConfigConstants.province,
// 'terminalId': ConfigConstants.terminalId,
// 'appId': ConfigConstants.appId,
// };
// let options: MGHttp.RequestOptions = {
// header: headers,
// };
// return MGHttp.Request.get<MGHttp.ResponseDTO<BodyComponent>>(pageUrl, options)
// };
}
\ No newline at end of file
... ...
import { ConfigConstants } from 'wdConstant';
import {Logger} from 'wdKit';
import {WDHttp} from 'wdNetwork';
import { CompDataDTO } from '../bean/CompDataDTO';
import { CompDTO } from '../bean/CompDTO';
import { DataSourceRequest } from '../bean/DataSourceRequest';
import { ReplaceUtil } from '../utils/ReplaceUtil';
const TAG = 'CompRequest';
export class CompRequest {
static fetch(pageID: string, groupID: string, compID: string, page: number, pageSize: number, isRefresh: boolean) {
const url: string = `${ConfigConstants.BASE_URL_VOD}${ConfigConstants.CONTENT_LIST_PATH}/${pageID}/${groupID}/${compID}`;
Logger.info(TAG, "fetch url:" + url);
return WDHttp.Request.get<WDHttp.ResponseDTO<CompDataDTO>>(url)
};
static fetchDataSource<T>(compDTO: CompDTO,dataSourceRequest: DataSourceRequest) {
// if (dataSourceRequest.dataSourceType == 'GUESS_YOU_LIKE') {}
Logger.info(TAG, "fetchDataSource url:" + dataSourceRequest.uri);
const url: string = ReplaceUtil.replaceUrl(dataSourceRequest.uri, compDTO, dataSourceRequest)
Logger.info(TAG, "new url:" + url);
let options: WDHttp.RequestOptions = {
method: dataSourceRequest.method.toUpperCase() === "POST" ? WDHttp.RequestMethod.POST : WDHttp.RequestMethod.GET,
header: ReplaceUtil.replaceHeader(dataSourceRequest.header, compDTO, dataSourceRequest),
// 读超时时间 单位s 默认60
readTimeout: dataSourceRequest.timeout,
// 连接超时时间 单位s 默认60
connectTimeout: dataSourceRequest.timeout,
params: ReplaceUtil.replaceHeader(dataSourceRequest.paramter, compDTO, dataSourceRequest)
};
Logger.info(TAG, "fetchDataSource options:" + JSON.stringify(options));
return WDHttp.Request.request<WDHttp.ResponseDTO<T>>(url, options)
};
}
... ...
import { ConfigConstants } from 'wdConstant';
import { WDHttp } from 'wdNetwork';
import { GroupDataDTO } from '../bean/GroupDataDTO';
const TAG = 'StaticGroupRequest';
export class StaticGroupRequest {
static fetch(pageID: string, groupID: string) {
const url: string = `${ConfigConstants.BASE_URL_VOD}${ConfigConstants.CONTENT_LIST_PATH}/${pageID}/${groupID}`;
return WDHttp.Request.get<WDHttp.ResponseDTO<GroupDataDTO>>(url)
};
}
\ No newline at end of file
... ...
import { ConfigConstants } from 'wdConstant';
import { WDHttp } from 'wdNetwork';
import { PageDTO } from '../bean/PageDTO';
export class StaticPageRequest {
static fetch(pageID: string) {
const url: string = `${ConfigConstants.BASE_URL_VOD}${ConfigConstants.CONTENT_LIST_PATH}/${pageID}`;
return WDHttp.Request.get<WDHttp.ResponseDTO<PageDTO>>(url)
};
}
\ No newline at end of file
... ...
import { CompDTO } from '../bean/CompDTO';
import { DataSourceRequest } from '../bean/DataSourceRequest';
import {Logger} from 'wdKit';
import {WDHttp} from 'wdNetwork';
import { LayoutCallback } from './LayoutCallback';
import { BusinessError } from '@ohos.base';
import http from '@ohos.net.http';
import { CompRequest } from '../request/CompRequest';
const TAG = 'CommonDataService';
/**
* 数据源服务
*/
export class CommonDataService {
public loadDataSource<T>(compDTO: CompDTO, request: DataSourceRequest, callback: LayoutCallback<T>): boolean {
CompRequest.fetchDataSource<T>(compDTO, request).then((resDTO: WDHttp.ResponseDTO<T>) => {
if (!resDTO) {
Logger.error(TAG, 'loadDataSource then resDTO is empty');
if (callback) {
callback.onFailed(WDHttp.ErrorCode.FAILED, 'Empty response');
}
return
}
if (resDTO.code != http.ResponseCode.OK || !resDTO.body) {
Logger.error(TAG, `loadDataSource then code:${resDTO.code}, message:${resDTO.message}`);
if (callback) {
callback.onFailed(resDTO.code, resDTO.message)
}
return
}
Logger.info(TAG, "loadDataSource then,resDTO.timeStamp:" + resDTO.timeStamp);
if (callback) {
callback.onSuccess(resDTO.body);
}
}).catch((error: BusinessError) => {
Logger.error(TAG, `loadDataSource catch, error.code : ${error.code}, error.message:${error.message}`);
if (callback) {
callback.onFailed(WDHttp.ErrorCode.FAILED, error.message);
}
})
return true;
}
}
\ No newline at end of file
... ...
/**
* LayoutService数据请求的回调接口
*/
export interface LayoutCallback<T> {
/**
* 成功
* @param data 数据
*/
onSuccess: (data: T) => void;
/**
* 失败
* @param code 错误码
* @param message 描述
*/
onFailed: (code: number, message: string) => void;
}
\ No newline at end of file
... ...
/**
* 用于请求乐高数据,对外提供服务。
*/
import { PageDTO } from '../bean/PageDTO';
import { LayoutCallback } from './LayoutCallback';
import {Logger} from 'wdKit';
import { WDHttp } from 'wdNetwork';
import http from '@ohos.net.http';
import { BusinessError } from '@ohos.base';
import { CompDTO } from '../bean/CompDTO';
import { CompDataDTO } from '../bean/CompDataDTO';
import { GroupDataDTO } from '../bean/GroupDataDTO';
export class LayoutService {
static readonly TAG: string = 'LayoutService';
/**
* 获取Page数据
* @param pageId Page ID
* @param isRefresh 是否为刷新
* @param callback 回调
*/
public getPage(pageId: string, isRefresh: boolean, callback: LayoutCallback<PageDTO>) {
// TODO: 调用StaticPageRequest请求数据
StaticPageRequest.fetch(pageId).then((resDTO: WDHttp.ResponseDTO<PageDTO>) => {
if (!resDTO) {
Logger.error(LayoutService.TAG, 'then pageResDTO is empty');
if (callback) {
callback.onFailed(WDHttp.ErrorCode.FAILED, 'Empty response');
}
return
}
if (resDTO.code != http.ResponseCode.OK || !resDTO.body) {
Logger.error(LayoutService.TAG, `then code:${resDTO.code}, message:${resDTO.message}`);
if (callback) {
callback.onFailed(resDTO.code, resDTO.message)
}
return
}
Logger.info(LayoutService.TAG, "then,resDTO.timeStamp:" + resDTO.timeStamp);
if (callback) {
callback.onSuccess(resDTO.body);
}
}).catch((error: BusinessError) => {
Logger.error(LayoutService.TAG, `getPage catch, error.code : ${error.code}, error.message:${error.message}`);
if (callback) {
callback.onFailed(WDHttp.ErrorCode.FAILED, error.message);
}
})
}
/**
* 获取Group数据
* @param pageId Page ID
* @param groupId Group ID
* @param isRefresh 是否为刷新
* @param callback 回调
*/
public getGroup(pageId: string, groupId: string, isRefresh: boolean, callback: LayoutCallback<GroupDataDTO>) {
// TODO: 调用StaticGroupRequest请求数据
StaticGroupRequest.fetch(pageId, groupId).then((resDTO: WDHttp.ResponseDTO<GroupDataDTO>) => {
if (!resDTO) {
Logger.error(LayoutService.TAG, 'getGroup then resDTO is empty');
if (callback) {
callback.onFailed(WDHttp.ErrorCode.FAILED, 'Empty response');
}
return
}
if (resDTO.code != http.ResponseCode.OK || !resDTO.body) {
Logger.error(LayoutService.TAG, `getGroup then code:${resDTO.code}, message:${resDTO.message}`);
if (callback) {
callback.onFailed(resDTO.code, resDTO.message)
}
return
}
Logger.info(LayoutService.TAG, "getGroup then,resDTO.timeStamp:" + resDTO.timeStamp);
if (callback) {
callback.onSuccess(resDTO.body);
}
}).catch((error: BusinessError) => {
Logger.error(LayoutService.TAG, `getGroup catch, error.code : ${error.code}, error.message:${error.message}`);
if (callback) {
callback.onFailed(WDHttp.ErrorCode.FAILED, error.message);
}
})
}
/**
* 获取Comp数据
* @param pageId Page ID
* @param groupId Group ID
* @param compId Comp ID
* @param isRefresh 是否为刷新
* @param callback 回调
*/
public getComp(pageId: string, groupId: string, compId: string, isRefresh: boolean, callback: LayoutCallback<CompDataDTO>) {
// TODO: 调用CompDataRequest请求数据
CompRequest.fetch(pageId, groupId, compId, -1, 10, isRefresh).then((resDTO: WDHttp.ResponseDTO<CompDataDTO>) => {
if (!resDTO) {
Logger.error(LayoutService.TAG, 'getComp then resDTO is empty');
if (callback) {
callback.onFailed(WDHttp.ErrorCode.FAILED, 'Empty response');
}
return
}
if (resDTO.code != http.ResponseCode.OK || !resDTO.body) {
Logger.error(LayoutService.TAG, `getComp then code:${resDTO.code}, message:${resDTO.message}`);
if (callback) {
callback.onFailed(resDTO.code, resDTO.message)
}
return
}
Logger.info(LayoutService.TAG, "getComp then,resDTO.timeStamp:" + resDTO.timeStamp);
if (callback) {
callback.onSuccess(resDTO.body);
}
}).catch((error: BusinessError) => {
Logger.error(LayoutService.TAG, `getComp catch, error.code : ${error.code}, error.message:${error.message}`);
if (callback) {
callback.onFailed(WDHttp.ErrorCode.FAILED, error.message);
}
})
}
/**
* 获取动态Group数据
* @param pageId Page ID
* @param groupId Group ID
* @param isRefresh 是否为刷新
* @param callback 回调
*/
public getDynamicGroup(pageId: string, groupId: string, isRefresh: boolean, callback: LayoutCallback<CompDTO>) {
// TODO: 调用DynamicGroupRequest请求数据
}
}
\ No newline at end of file
... ...
import { AppUtils } from 'wdKit';
import { CompDTO } from '../bean/CompDTO';
import { Tab01DTO } from '../bean/Tab01DTO';
import { CompStyle } from '../enum/CompStyle';
export class CompFilterUtil {
static whiteList: string[] = [
CompStyle.LABEL_01,
// CompStyle.BUTTON_01,
CompStyle.NAV_BAR_01,
CompStyle.NAV_BAR_22,
CompStyle.NAV_BAR_03,
CompStyle.BIG_STATIC_IMG_01,
CompStyle.BIG_CAROUSEL_IMG_01,
CompStyle.BIG_PLAY_IMG_01,
CompStyle.TOP_IMG_BOTTOM_TXT_01,
CompStyle.TOP_IMG_BOTTOM_TXT_02,
CompStyle.TOP_IMG_BOTTOM_TXT_12,
CompStyle.BINGE_WATCHING_02,
CompStyle.SLIDER_IMG_16,
CompStyle.MATCH_LIST_04,
// CompStyle.MY_HOME_INFO,
// CompStyle.MY_HOME_SERVICE_NEW,
// CompStyle.MY_HOME_VERSION_NUMBER,
CompStyle.PROGRAM_DESC_01,
CompStyle.PROGRAM_SET_01,
CompStyle.CLASSIFY_FILTER_BAR_02,
CompStyle.WORLDCUP_PLAYBILL,
];
// 待被过滤的tab,赛程PageId与各种筛选PageId
static pathIdList: string[] = [
'7a93bb0699c5490bb5eb56bce5444582', // 关注tab
'MATCH_SCHEDULE_LIST', // 赛程
'af6b9358a1e94d7ba28e254fa0940fb9', // 赛程
'013d73e3fbf940b394e6b07bcc9b62ea', // 电视剧
'256c7c16a17848778fc7602fe24da95a', // 电影
'62a6103b3afd4844abb412f091a3b316', // 综艺
'a29987d1308a4e22b153d3aeb69bf58d', // 少儿
'2a6b09068a474003bf974d14e94fd0b1', // 纪实
'047a996e72184536a99aa9496c160823',// 动漫
];
constructor() {
}
// filter true需要处理,false就不需要处理
public static filter(compDTO: CompDTO): boolean {
//临时处理comp过滤,首页轮播图和重磅推荐
let title = "";
try {
if (compDTO.extraData && compDTO.extraData.labels && compDTO.extraData.labels.length > 0) {
title = compDTO.extraData.labels[0].title ?? "";
}
} catch (e){}
if (compDTO.compStyle == CompStyle.BIG_CAROUSEL_IMG_01 || compDTO.compStyle == CompStyle.TOP_IMG_BOTTOM_TXT_01 || title == "重磅推荐") {
if (compDTO.androidVersion) {
compDTO.androidVersion.max = "-1";
}
}
if (compDTO == null) {
return false
}
if (compDTO.compStyle == null) {
return false
}
if (CompFilterUtil.checkWhiteList(compDTO)) {
return CompFilterUtil.checkVersionCode(compDTO)
} else {
return false
}
}
private static checkWhiteList(compDTO: CompDTO) {
return CompFilterUtil.whiteList.indexOf(compDTO.compStyle) != -1
}
private static checkVersionCode(compDTO: CompDTO): boolean {
let curVersionCode = Number.parseInt(AppUtils.getAppVersionCode());
let curVersionName = AppUtils.getAppVersionName();
let version = compDTO?.androidVersion
let isAllVersion = version?.isAllVersion
if (isAllVersion == "1"){
return true
}
let exclusion: string[] | undefined = version?.exclude
if (exclusion) {
for (let i = 0; i < exclusion.length; i++){
let temp = exclusion[i]
if (curVersionName == temp){
return false
}
}
}
if (version && version.max && version.min) {
let maxVersionCode = Number.parseInt(version.max)
let minVersionCode = Number.parseInt(version.min)
if ((curVersionCode <= maxVersionCode || maxVersionCode == -1) && curVersionCode >= minVersionCode) {
return true
} else {
return false
}
}
return true
}
/**
* 筛选/过滤
* @param dto
* @returns 保留此项数据:返回true;否则(舍弃此项数据),返回false;
*/
public static filterTab01(tab01DTO: Tab01DTO): boolean {
if (!tab01DTO) {
return false;
}
// if (tab01DTO.title == '关注') { // todo:过滤掉【关注】tab
// return false;
// }
return !CompFilterUtil.pathIdList.includes(tab01DTO?.action?.params?.path ?? "")
}
}
\ No newline at end of file
... ...
/**
* 乐高Util。
*/
import { ItemBean } from '../bean/ItemBean'
import { ItemDTO } from '../bean/ItemDTO'
import { WDComp } from '../layout/WDComp'
import { WDGroup } from '../layout/WDGroup'
import { WDPage } from '../layout/WDPage'
export class LegoUtil {
/**
* 格式化Page的ID
* @param page MGPage
* @returns String
*/
public static getPageId(page: WDPage): string {
return ''
}
public static getGroupId(group: WDGroup): string {
return ''
}
public static getCompId(comp: WDComp<ItemBean, ItemDTO>): string {
return ''
}
}
\ No newline at end of file
... ...