xingzhaojie

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

# Conflicts:
#	PeopleDaily_Harmony/entry/src/main/resources/rawfile/comp_list0.json
#	PeopleDaily_Harmony/wdComponent/src/main/ets/Index.ets
#	PeopleDaily_Harmony/wdComponent/src/main/ets/components/PageComponent.ets
Showing 29 changed files with 580 additions and 87 deletions
import UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import window from '@ohos.window';
import { AppContext } from 'wdKit';
export default class EntryAbility extends UIAbility {
onCreate(want, launchParam) {
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
AppContext.init(this.context)
}
onDestroy() {
... ...
... ... @@ -15,4 +15,7 @@ export { TopNavigationComponent } from "./components/TopNavigationComponent"
export { LabelComponent } from "./components/LabelComponent"
export { SmallVideoCardComponent } from "./components/SmallVideoCardComponent"
export { BannerComponent } from "./components/BannerComponent"
... ...
import { BottomNavi, CommonConstants } from 'wdConstant';
import { LazyDataSource, Logger } from 'wdKit';
import { Logger } from 'wdKit';
import { TopNavigationComponent } from './TopNavigationComponent';
import { PageComponent } from './PageComponent';
import { BottomNavDTO } from '../repository/bean/BottomNavDTO';
import { PageViewModel } from '../Index';
import { UIUtils } from '../repository/UIUtils';
import { MinePageComponent } from './MinePageComponent';
import PageViewModel from '../viewmodel/PageViewModel';
const TAG = 'BottomNavigationComponent';
... ... @@ -28,13 +29,12 @@ export struct BottomNavigationComponent {
*/
readonly SIXTY_OPACITY: number = 0.6;
async aboutToAppear() {
Logger.info(TAG, `aboutToAppear currentNavIndex: ${this.currentNavIndex}`);
let bottomNav = await PageViewModel.getBottomNavData(getContext(this))
if (bottomNav) {
Logger.info(TAG, `aboutToAppear, bottomNav.length: ${bottomNav.length}`);
this.bottomNavList = bottomNav
let bottomNav = await PageViewModel.getBottomNavData()
if (bottomNav && bottomNav.bottomNavList != null) {
Logger.info(TAG, `aboutToAppear, bottomNav.length: ${bottomNav.bottomNavList.length}`);
this.bottomNavList = bottomNav.bottomNavList
}
}
... ... @@ -47,8 +47,9 @@ export struct BottomNavigationComponent {
ForEach(this.bottomNavList, (navItem: BottomNavDTO, index: number) => {
TabContent() {
Column() {
if (navItem.topNavChannelList && navItem.topNavChannelList.length == 0 && navItem.name == '我的') {
PageComponent({ compList: new LazyDataSource() }) // todo:我的页面组件数据列表
if (UIUtils.isMine(navItem)) {
// 我的页面组件数据列表
MinePageComponent()
} else {
TopNavigationComponent({ topNavList: navItem.topNavChannelList })
}
... ...
const TAG = 'PageComponent';
/**
* 我的页面
*/
@Component
export struct MinePageComponent {
// TODO 待完善
build() {
Text('我的页面')
}
}
... ...
import { CommonConstants, CompStyle, ViewType } from 'wdConstant';
import { LazyDataSource, Logger } from 'wdKit';
import { CompDTO } from '../repository/bean/CompDTO';
import { PageViewModel } from '../viewmodel/PageViewModel';
import PageViewModel from '../viewmodel/PageViewModel';
import { EmptyComponent } from './EmptyComponent';
import { ErrorComponent } from './ErrorComponent';
import { LabelComponent } from './LabelComponent';
import { LoadingComponent } from './LoadingComponent';
import { TitleAbbrComponent } from './TitleAbbrComponent';
import { TitleAllComponent } from './TitleAllComponent';
import {BannerComponent} from './BannerComponent'
const TAG = 'PageComponent';
@Component
... ... @@ -22,6 +18,10 @@ export struct PageComponent {
// Group数据及子组件数据
@State compList: LazyDataSource<CompDTO> = new LazyDataSource();
@State currentTopNavSelectedIndex: number = 0;
@State pageId: string = "";
@State channelId: string = "";
// @Link @Watch('onChange') paIndex:number
build() {
if (this.viewType == ViewType.LOADING) {
... ... @@ -49,7 +49,11 @@ export struct PageComponent {
componentBuilder(compDTO: CompDTO, compIndex: number) {
if (compDTO.compStyle === CompStyle.Label_03) {
LabelComponent({ compDTO: compDTO })
}else if(compDTO.compStyle === CompStyle.Carousel_Layout_01) {
} else if (compDTO.compStyle === CompStyle.Title_Abbr_01) {
TitleAbbrComponent({ compDTO: compDTO })
} else if (compDTO.compStyle === CompStyle.Title_All_01) {
TitleAllComponent({ compDTO: compDTO })
} else if(compDTO.compStyle === CompStyle.Carousel_Layout_01) {
BannerComponent({ compDTO: compDTO })
} else {
// todo:组件未实现 / Component Not Implemented
... ... @@ -62,18 +66,27 @@ export struct PageComponent {
async aboutToAppear() {
Logger.info(TAG, `aboutToAppear, this.pageId: ${this.viewType} this.currentTopNavSelectedIndex: ${this.currentTopNavSelectedIndex}`);
if (this.currentTopNavSelectedIndex === 1) { // 顶导tab的第0个item是【热点】,第1个item是【推荐】
this.compList.replaceAll()
let pageDto = await PageViewModel.getPageData2(getContext(this))
if (pageDto && pageDto.compList) {
this.compList.push(...pageDto.compList)
}
} else {
let pageDto = await PageViewModel.getPageData1(getContext(this))
// if (this.currentTopNavSelectedIndex === 1) { // 顶导tab的第0个item是【热点】,第1个item是【推荐】
// this.compList.replaceAll()
// let pageDto = await PageViewModel.getPageData2(getContext(this))
// if (pageDto && pageDto.compList) {
// this.compList.push(...pageDto.compList)
// }
// } else {
// let pageDto = await PageViewModel.getPageData1(getContext(this))
// if (pageDto && pageDto.compList) {
// this.compList.push(...pageDto.compList)
// }
// }
// if (this.currentTopNavSelectedIndex != 1) { // 顶导tab的第0个item是【热点】,第1个item是【推荐】
// return
// }
Logger.debug(TAG,'lllllalalal: ' + this.pageId+' , ' + this.channelId);
let pageDto = await PageViewModel.getPageData(this.pageId, this.pageId, this.channelId)
if (pageDto && pageDto.compList) {
this.compList.push(...pageDto.compList)
}
}
}
}
... ...
import { CommonConstants } from 'wdConstant/src/main/ets/constants/CommonConstants'
@Entry
@Component
export struct SmallVideoCardComponent {
build() {
Row() {
Column() {
Text('“畅享亚运”新模式活动打卡,看杭州打开“金角银边活动启动 跟着体育明星云打卡,看杭州打开“金角银边')
.fontWeight(400)
.fontSize($r('app.float.font_size_17'))
.maxLines(4)
.textOverflow({ overflow: TextOverflow.Ellipsis })
.fontColor($r('app.color.color_222222'))
.lineHeight(25)
Row() {
Text('人民日报')
.labelTextStyle()
Image($r('app.media.point'))
.width(16)
.height(16)
Text('20分钟前')
.labelTextStyle()
.margin({
right: 6
})
Text('2000评')
.labelTextStyle()
}
}
.height(156)
.layoutWeight(1)
.justifyContent(FlexAlign.SpaceBetween)
.alignItems(HorizontalAlign.Start)
.margin({ right: 12 })
Stack({ alignContent: Alignment.BottomEnd }) {
Image('https://www.harmonyos.com/resource/image/partner/harmonyos-connect/pic_shengtai_connect_qudao_xianxia.jpg')
.width(117)
.aspectRatio(117 / 156)
.border({ radius: 4 })
Row() {
Image($r('app.media.iv_card_play_yellow_flag'))
.width(22)
.height(18)
Text('10:00')
.fontSize($r('app.float.font_size_13'))
.fontWeight(400)
.fontColor($r('app.color.color_fff'))
}
.height(18)
.padding({ right: 4 })
.margin({
right: 4,
bottom: 4
})
.backgroundColor($r('app.color.color_4d000000'))
}
}
.width(CommonConstants.FULL_WIDTH)
.height(184)
.padding({
top: 14,
bottom: 14,
left: 16,
right: 16
})
}
}
@Extend(Text) function labelTextStyle() {
.fontSize($r('app.float.font_size_12'))
.fontWeight(400)
.fontColor($r('app.color.color_B0B0B0'))
}
\ No newline at end of file
... ...
//缩略标题
import { CommonConstants } from 'wdConstant'
import { CompDTO } from '../repository/bean/CompDTO'
@Component
export struct TitleAbbrComponent {
@State compDTO: CompDTO = {} as CompDTO
build() {
Column() {
Text(this.compDTO.operDataList[0].title)
.fontSize($r("app.float.font_size_16"))
.fontColor($r("app.color.color_222222"))
.maxLines(3)
.textOverflow({ overflow: TextOverflow.Ellipsis })
.width(CommonConstants.FULL_WIDTH)
Row() {
Text("锐评")
.fontSize($r("app.float.font_size_12"))
.fontColor($r("app.color.color_ED2800"))
Text(this.compDTO.operDataList[0].source)
.fontSize($r("app.float.font_size_12"))
.fontColor($r("app.color.color_B0B0B0"))
.margin({ left: 6 })
Image($r("app.media.point"))
.width(16)
.height(16)
Text("46分钟前")
.fontSize($r("app.float.font_size_12"))
.fontColor($r("app.color.color_B0B0B0"))
}.width(CommonConstants.FULL_WIDTH)
.justifyContent(FlexAlign.Start)
.margin({ top: 8 })
}.width(CommonConstants.FULL_WIDTH)
.padding({
top: 14,
left: 16,
right: 16,
bottom: 14
})
.backgroundColor($r("app.color.white"))
.margin({ bottom: 8 })
}
}
\ No newline at end of file
... ...
//全标题 "compStyle":"3",
import { CommonConstants } from 'wdConstant'
import { CompDTO } from '../repository/bean/CompDTO'
@Component
export struct TitleAllComponent {
@State compDTO: CompDTO = {} as CompDTO
build() {
Column() {
Text(this.compDTO.operDataList[0].title)
.fontSize($r("app.float.font_size_16"))
.fontColor($r("app.color.color_222222"))
.width(CommonConstants.FULL_WIDTH)
Row() {
Text("锐评")
.fontSize($r("app.float.font_size_12"))
.fontColor($r("app.color.color_ED2800"))
Text(this.compDTO.operDataList[0].source)
.fontSize($r("app.float.font_size_12"))
.fontColor($r("app.color.color_B0B0B0"))
.margin({ left: 6 })
Image($r("app.media.point"))
.width(16)
.height(16)
Text("46分钟前")
.fontSize($r("app.float.font_size_12"))
.fontColor($r("app.color.color_B0B0B0"))
}.width(CommonConstants.FULL_WIDTH)
.justifyContent(FlexAlign.Start)
.margin({ top: 8 })
}.width("100%")
.padding({
top: 14,
left: 16,
right: 16,
bottom: 14
})
.backgroundColor($r("app.color.white"))
.margin({ bottom: 8 })
}
}
\ No newline at end of file
... ...
... ... @@ -21,7 +21,7 @@ export struct TopNavigationComponent {
Tabs() {
ForEach(this.topNavList, (navItem: TopNavDTO, index: number) => {
TabContent() {
PageComponent({ currentTopNavSelectedIndex: index })
PageComponent({ currentTopNavSelectedIndex: index, pageId: navItem.pageId, channelId: navItem.channelId })
}
.tabBar(this.tabBarBuilder(navItem, index))
}, (navItem: TopNavDTO) => JSON.stringify(navItem));
... ...
import HashMap from '@ohos.util.HashMap'
import { ConfigConstants } from 'wdConstant/src/main/ets/constants/ConfigConstants'
import { DateTimeUtils, Logger } from 'wdKit'
/**
* 网络请求业务侧工具类
*/
export class HttpUrlUtils {
/**
* 现网地址
*/
static readonly HOST: string = "https://pd-apis-uat.pdnews.cn";
/**
* 启动接口(底导接口)
*/
static readonly BOTTOM_NAV_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/bottomNavGroup";
/**
* 展现comp接口
*/
static readonly COMP_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/compInfo";
static getCommonHeaders(): HashMap<string, string> {
let headers: HashMap<string, string> = new HashMap<string, string>()
headers.set('User-Agent', 'Dalvik/2.1.0 (Linux; U; Android 13; 22101317C Build/TKQ1.221013.002)')
headers.set('channel', this.getChannel())
headers.set('appCode', ConfigConstants.appCode)
headers.set('plat', this.getPlat())
headers.set('Authorization', 'APPCODE 83092caa603a421aa0222308b3f6b27a')
headers.set('Content-Type', 'application/json; charset=utf-8')
headers.set('timestamp', this.getTimestamp())
headers.set('RMRB-X-TOKEN', this.getXToken())
headers.set('device_id', this.getDeviceId())
headers.set('cookie', 'RMRB-X-TOKEN=eyJhbGciOiJIUzI1NiIsImtpZCI6ImQ4WkI2QkhxSEZrdjJ2U25BNlRwZEdKRjBHcjItVzBvS2FaYzdLOUUycmcifQ.eyJpc3MiOiJwZW9wbGVzLWRhaWx5LWZvdXJhIiwic3ViIjoicGVvcGxlcy1kYWlseS1mb3VyYSIsImV4cCI6MTcwMzY0OTYwNiwidXNlcklkIjo0NTk3NzYyOTc0NzQ5NDksInVzZXJWZXJzaW9uIjoiNDU5Nzc2Mjk3NDc0OTQ5XzIiLCJ1c2VyTmFtZSI6IkJ1bGlraWtpMTgxIiwidXNlclR5cGUiOjIsImNyZWF0b3JJZCI6NDI2NTM5MH0.jhQ9kylcm3FxWf0-lBMZuLkdtIQ6XpFnAi0AFZJNwfc')
headers.set('build_version', this.getVersion())
headers.set('adcode', this.getAdCode())
headers.set('os_version', this.getOsVersion())
headers.set('X-Ca-Stage', 'PRE')
headers.set('versionCode', this.getVersionCode())
headers.set('system', this.getTerminalId())
headers.set('version_name', 'debug')
headers.set('EagleEye-TraceID', '0B6DE03D2997435BA875FFBE05425ED2')
headers.set('imei', this.getImei())
headers.set('Accept-Language', 'zh')
headers.set('city', this.getCity())
headers.set('city_dode', this.getCityCode())
// TODO 判断是否登录
headers.set('userId', this.getUserId())
headers.set('userType', this.getUserType())
Logger.debug("TAG", 'getCommonHeaders headers: ' + headers);
return headers;
}
static getBottomNavGroupUrl() {
// https: //pd-apis-uat.pdnews.cn/api/rmrb-bff-display-zh/display/zh/c/bottomNavGroup
return this.HOST + this.BOTTOM_NAV_PATH;
}
static getCompInfoUrl(pageId: string, groupId: string, channelId: string) {
let url = this.HOST + this.COMP_PATH;
// TODO 暂定只请求第一页,后续对接分页加载,参数再调整
url = url + "?channelStrategy=2&pageSize=20&pageNum=1&loadStrategy=first_load"
+ "&districtCode=" + this.getDistrictCode()
+ "&provinceCode=" + this.getProvinceCode()
+ "&cityCode=" + this.getCityCode()
// + "&refreshTime=" + DateTimeUtils.getCurrentTimeMillis()
+ "&refreshTime=" + "1703472405653"
+ "&pageId=" + pageId
+ "&groupId=" + groupId
+ "&channelId=" + channelId;
return url;
}
private static getCity() {
// TODO 对接定位
return '%E5%90%88%E8%82%A5%E5%B8%82';
}
private static getChannel() {
// TODO 对接配置
return 'rmrb_china_0000';
}
private static getPlat() {
return 'Phone';
}
private static getTimestamp() {
// return DateTimeUtils.getCurrentTime() + '';
return '155203523';
}
private static getXToken() {
return 'eyJhbGciOiJIUzI1NiIsImtpZCI6ImQ4WkI2QkhxSEZrdjJ2U25BNlRwZEdKRjBHcjItVzBvS2FaYzdLOUUycmcifQ.eyJpc3MiOiJwZW9wbGVzLWRhaWx5LWZvdXJhIiwic3ViIjoicGVvcGxlcy1kYWlseS1mb3VyYSIsImV4cCI6MTcwMzY0OTYwNiwidXNlcklkIjo0NTk3NzYyOTc0NzQ5NDksInVzZXJWZXJzaW9uIjoiNDU5Nzc2Mjk3NDc0OTQ5XzIiLCJ1c2VyTmFtZSI6IkJ1bGlraWtpMTgxIiwidXNlclR5cGUiOjIsImNyZWF0b3JJZCI6NDI2NTM5MH0.jhQ9kylcm3FxWf0-lBMZuLkdtIQ6XpFnAi0AFZJNwfc';
}
private static getDeviceId() {
// TODO
return 'b5cf725d-193d-3215-8c77-e76fe15ce64d';
}
private static getVersion() {
// TODO
return '202312251034';
}
private static getVersionCode() {
// TODO
return '7301';
}
private static getAdCode() {
return '340000';
}
private static getOsVersion() {
// TODO
return '13';
}
private static getCityCode() {
// TODO
return '340100';
}
private static getProvinceCode() {
// TODO
return '340000';
}
/**
* 地区code
*/
private static getDistrictCode() {
// TODO
return '340103';
}
private static getTerminalId() {
return 'Android';
}
private static getImei() {
// TODO
return 'b5cf725d-193d-3215-8c77-e76fe15ce64d';
}
private static getUserId() {
// TODO 对接登录
return '459776297474949';
}
private static getUserType() {
return '2';
}
}
\ No newline at end of file
... ...
import { ResponseDTO, WDHttp } from 'wdNetwork';
import { NavigationBodyDTO } from './bean/NavigationBodyDTO';
import { PageDTO } from './bean/PageDTO';
import HashMap from '@ohos.util.HashMap';
import { HttpUrlUtils } from '../network/HttpUrlUtils';
export class PageRepository {
static fetchNavigationDataApi(url: string) {
return WDHttp.get<ResponseDTO<NavigationBodyDTO>>(url)
static fetchNavigationDataApi() {
let url = HttpUrlUtils.getBottomNavGroupUrl();
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return WDHttp.get<ResponseDTO<NavigationBodyDTO>>(url, headers)
};
static fetchPageData(url: string) {
return WDHttp.get<ResponseDTO<PageDTO>>(url)
static fetchPageData(pageId: string, groupId: string, channelId: string) {
let url = HttpUrlUtils.getCompInfoUrl(pageId, groupId, channelId)
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return WDHttp.get<ResponseDTO<PageDTO>>(url, headers)
};
}
\ No newline at end of file
... ...
/**
* 网络请求业务侧工具类
*/
import { BottomNavDTO } from './bean/BottomNavDTO';
export class UIUtils {
/**
* 判断是否为我的页面
*/
static isMine(navItem: BottomNavDTO): boolean {
if (navItem == null) {
return false;
}
return navItem.type == '2';
}
}
\ No newline at end of file
... ...
... ... @@ -36,5 +36,6 @@ export interface BottomNavDTO {
statusBarColor: number;
topNavChannelList: TopNavDTO[];
topStyle: string;
// 1-普通页面,2-我的
type: string;
}
\ No newline at end of file
... ...
... ... @@ -33,4 +33,5 @@ export interface ContentDTO {
title: string;
vImageUrl: string;
screenType: string;
source:string;
}
\ No newline at end of file
... ...
... ... @@ -2,7 +2,7 @@
* 顶导
*/
export interface TopNavDTO {
channelId: number;
channelId: string;
channelStyle: number;
channelType: number;
defaultPermitted: number;
... ... @@ -21,7 +21,7 @@ export interface TopNavDTO {
myChannel: string;
name: string;
num: number;
pageId: number;
pageId: string;
pageType: string;
underlineCColor: string;
}
... ...
import { Logger } from 'wdKit';
import { ResponseDTO } from 'wdNetwork';
/**
* 处理返回后的数据
*/
export abstract class BaseViewModel {
abstract getLogTag(): string;
public isRespondsInvalid(resDTO: ResponseDTO<any>, tag?: string): boolean {
if (resDTO == null) {
Logger.error(this.getLogTag(), `${tag == null ? '' : tag + ', '}resDTO is empty`);
return true;
}
// code = 0, success
if (resDTO.code != 0) {
Logger.error(this.getLogTag(), `${tag == null ? '' : tag + ', '}code error, code:${resDTO.code}, message:${resDTO.message}`);
return true;
}
if (!resDTO.data) {
Logger.error(this.getLogTag(), `${tag == null ? '' : tag + ', '}resDTO.data is null`);
return true;
}
return false;
}
}
\ No newline at end of file
... ...
import { Logger, ResourcesUtils } from 'wdKit';
import { AppContext, Logger, ResourcesUtils } from 'wdKit';
import { ResponseDTO, } from 'wdNetwork';
import { PageRepository } from '../repository/PageRepository';
import http from '@ohos.net.http';
import { NavigationBodyDTO } from '../repository/bean/NavigationBodyDTO';
import { BottomNavDTO } from '../repository/bean/BottomNavDTO';
import { PageDTO } from '../repository/bean/PageDTO';
import { BaseViewModel } from './BaseViewModel';
import Router from '@system.router';
import router from '@ohos.router';
const TAG = 'PageViewModel';
/**
* mock数据开关,默认关。
* mock数据是本地json数据,可自行修改内容(‘entry\src\main\resources\rawfile\’目录)
*/
const mock_switch = true;
/**
* 处理返回后的数据
*/
export class PageViewModel {
export class PageViewModel extends BaseViewModel {
getLogTag() {
return TAG;
}
/**
* get Nav Data from Resource .
*
* @return BottomNavBean[] Nav Data List
*/
static async getBottomNavData(context: Context): Promise<BottomNavDTO[]> {
async getBottomNavData(): Promise<NavigationBodyDTO> {
Logger.info(TAG, `getBottomNavData start`);
let compRes: ResponseDTO<NavigationBodyDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<NavigationBodyDTO>>(context, 'bottom_nav.json');
if (!compRes || !compRes.data || !compRes.data.bottomNavList) {
Logger.info(TAG, `getBottomNavData compRes bottomNavList is empty`);
return []
if (mock_switch) {
return this.getBottomNavDataMock();
}
Logger.info(TAG, `getBottomNavData getResourcesJsonSync compRes : ${JSON.stringify(compRes)}`);
return compRes.data.bottomNavList
return this.getNavData();
}
static getNavData(url: string): Promise<NavigationBodyDTO> {
return new Promise<NavigationBodyDTO>((success, error) => {
Logger.info(TAG, `getNavData start`);
PageRepository.fetchNavigationDataApi(url).then((navResDTO: ResponseDTO<NavigationBodyDTO>) => {
if (!navResDTO) {
Logger.error(TAG, 'getNavData then navResDTO is empty');
error('navResDTO is empty');
return
async getBottomNavDataMock(): Promise<NavigationBodyDTO> {
Logger.info(TAG, `getBottomNavDataMock start`);
let compRes: ResponseDTO<NavigationBodyDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<NavigationBodyDTO>>('bottom_nav.json');
if (!compRes || !compRes.data) {
Logger.info(TAG, `getBottomNavDataMock compRes bottomNavList is empty`);
return null
}
if (navResDTO.code != http.ResponseCode.OK) {
Logger.error(TAG, `getNavData then code:${navResDTO.code}, message:${navResDTO.message}`);
error('navResDTO Response Code is failure');
return
Logger.info(TAG, `getBottomNavDataMock getResourcesJsonSync compRes : ${JSON.stringify(compRes)}`);
return compRes.data
}
if (!navResDTO.data?.bottomNavList) {
error('navResDTO list is empty');
private getNavData(): Promise<NavigationBodyDTO> {
return new Promise<NavigationBodyDTO>((success, error) => {
Logger.info(TAG, `getNavData start`);
PageRepository.fetchNavigationDataApi().then((navResDTO: ResponseDTO<NavigationBodyDTO>) => {
if (this.isRespondsInvalid(navResDTO, 'getNavData')) {
error("page data invalid");
return
}
// let navResStr = JSON.stringify(navResDTO);
Logger.info(TAG, "getNavData then,navResDTO.timeStamp:" + navResDTO.timestamp);
let navigationBean = navResDTO.data
success(navigationBean);
... ... @@ -62,8 +71,8 @@ export class PageViewModel {
*
* @return {GroupDTO} compRes.data
*/
static async getPageData1(context: Context): Promise<PageDTO> {
let compRes: ResponseDTO<PageDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<PageDTO>>(context, 'comp_list0.json');
private async getPageData1(): Promise<PageDTO> {
let compRes: ResponseDTO<PageDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<PageDTO>>('comp_list0.json');
if (!compRes || !compRes.data) {
Logger.info(TAG, `getCompList compRes is empty`);
return {} as PageDTO
... ... @@ -76,29 +85,28 @@ export class PageViewModel {
* Get Group data.
*
* @return {GroupDTO} compRes.data
* @deprecated
*/
static async getPageData2(context: Context): Promise<PageDTO> {
let compRes: ResponseDTO<PageDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<PageDTO>>(context, 'comp_list2.json');
private async getPageData2(): Promise<PageDTO> {
let compRes: ResponseDTO<PageDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<PageDTO>>('comp_list2.json');
if (!compRes || !compRes.data) {
Logger.info(TAG, `getCompList compRes is empty`);
return {} as PageDTO
}
// router.push('')
Logger.info(TAG, `getCompList getResourcesJson compRes : ${JSON.stringify(compRes)}`);
return compRes.data
}
static getPageData(url: string): Promise<PageDTO> {
return new Promise<PageDTO>((success, error) => {
PageRepository.fetchPageData(url).then((resDTO: ResponseDTO<PageDTO>) => {
if (!resDTO) {
Logger.error(TAG, 'getPageData then resDTO is empty');
error("page data is empty");
return
async getPageData(pageId: string, groupId: string, channelId: string): Promise<PageDTO> {
Logger.error(TAG, 'getPageData pageId: ' + pageId);
if (mock_switch) {
return this.getPageData1();
}
if (resDTO.code != http.ResponseCode.OK || !resDTO.data) {
Logger.error(TAG, `getPageData then code:${resDTO.code}, message:${resDTO.message}`);
error(`get page data error code:${resDTO.code}, message:${resDTO.message}`);
return new Promise<PageDTO>((success, error) => {
PageRepository.fetchPageData(pageId, groupId, channelId).then((resDTO: ResponseDTO<PageDTO>) => {
if (this.isRespondsInvalid(resDTO, 'getPageData')) {
error("page data invalid");
return
}
Logger.info(TAG, "getPageData then,resDTO.timeStamp:" + resDTO.timestamp);
... ... @@ -112,7 +120,6 @@ export class PageViewModel {
}
let pageViewModel = new PageViewModel();
export default pageViewModel as PageViewModel;
\ No newline at end of file
... ...
... ... @@ -19,6 +19,26 @@
{
"name": "color_FE4B05",
"value": "#FE4B05"
},
{
"name": "color_222222",
"value": "#222222"
},
{
"name": "color_ED2800",
"value": "#ED2800"
},
{
"name": "color_B0B0B0",
"value": "#B0B0B0"
},
{
"name": "color_fff",
"value": "#ffffff"
},
{
"name": "color_4d000000",
"value": "#4d000000"
}
]
}
\ No newline at end of file
... ...
... ... @@ -10,7 +10,11 @@
},
{
"name": "font_size_12",
"value": "11fp"
"value": "12fp"
},
{
"name": "font_size_13",
"value": "13fp"
},
{
"name": "font_size_14",
... ... @@ -21,6 +25,10 @@
"value": "16fp"
},
{
"name": "font_size_17",
"value": "17fp"
},
{
"name": "normal_text_size",
"value": "16fp"
},
... ...
... ... @@ -28,7 +28,7 @@ export class ConfigConstants {
/**
* 产品渠道应用对照关系:
*/
static readonly appCode: string = "";
static readonly appCode: string = "83092caa603a421aa0222308b3f6b27a";
/**
* 基线代码和客户端应用版本号规范
*/
... ...
... ... @@ -19,4 +19,6 @@ export const enum CompStyle {
Grid_Layout_01 = 'Grid_Layout-01', // 横屏宫格卡:视频、直播
Grid_Layout_02 = 'Grid_Layout-02', // 竖屏宫格卡:视频、直播、榜单
Masonry_Layout_01 = 'Masonry_Layout-01', // 双列瀑布流/瀑布流卡:视频、直播、专题、活动
Title_Abbr_01 = 'Title_Abbr_01', // 标题缩略
Title_All_01 = 'Title_All_01', // 全标题
}
... ...
... ... @@ -10,3 +10,7 @@ export { BasicDataSource } from './utils/BasicDataSource';
export { LazyDataSource } from './utils/LazyDataSource'
export { DateTimeUtils } from './utils/DateTimeUtils'
export { AppContext } from './utils/AppContext'
... ...
/**
* 应用ability上下文管理类
*/
export class AppContext {
private static sContext: Context;
public static init(abilityContext: Context) {
this.sContext = abilityContext;
}
public static getAbilityContext() {
return this.sContext;
}
}
\ No newline at end of file
... ...
... ... @@ -316,6 +316,21 @@ export class DateTimeUtils {
static isTomorrow(date: number): boolean {
return this.isSameDay(date, this.addDays(Date.now(), 1).getTime());
}
/**
* 获取当前时间戳,秒
* */
public static getCurrentTime(): number {
let time: number = new Date().getTime();
return Math.floor(time / 1000);
}
/**
* 获取当前时间戳,毫秒
* */
public static getCurrentTimeMillis(): number {
return new Date().getTime();
}
}
// const dateTimeUtils = new DateTimeUtils()
\ No newline at end of file
... ...
import buffer from '@ohos.buffer';
import { AppContext } from './AppContext';
import { Logger } from './Logger';
const TAG = "ResourcesUtils";
... ... @@ -13,7 +14,10 @@ export class ResourcesUtils {
* @param filename 仅文件名(不包含路径,文件在src\main\resources\rawfile下),如:"agconnect-services.json",test.xml,
* @returns text 字符串
*/
static getResourcesText(context: Context, filename: string): Promise<string> {
static getResourcesText(filename: string, context?: Context): Promise<string> {
if (context == null) {
context = AppContext.getAbilityContext();
}
return new Promise((success, error) => {
Logger.info(TAG, "ResourcesUtils getResourcesText filename:" + filename);
context.resourceManager.getRawFileContent(filename).then((content: Uint8Array) => {
... ... @@ -53,14 +57,17 @@ export class ResourcesUtils {
* 调用方式:
* let compRes: MGHttp.ResponseDTO<BodyComponent> = await ResourcesUtils.getResourcesJson<MGHttp.ResponseDTO<BodyComponent>>(context, 'model/componentList.json');
*/
static getResourcesJson<R>(context:Context, filename: string): Promise<R> {
static getResourcesJson<R>(filename: string, context?: Context): Promise<R> {
Logger.info(TAG, `getResourcesJson filename: ${filename}`);
if (context == null) {
context = AppContext.getAbilityContext();
}
return new Promise<R>((resolve, reject) => {
ResourcesUtils.getResourcesText(context, filename)
ResourcesUtils.getResourcesText(filename, context)
.then((text: string) => {
try {
// let config: R = JSON.parse(text)
let config:R = JSON.parse(text) as R;
let config: R = JSON.parse(text) as R;
if (config) {
Logger.info(TAG, "getResourcesJson parse JSON file success.");
// Logger.info(TAG, `getResourcesJson config : ${JSON.stringify(config)}`);
... ... @@ -74,7 +81,7 @@ export class ResourcesUtils {
reject(err)
}
})
.catch((error:Error) => {
.catch((error: Error) => {
reject(error)
})
})
... ...
import type { AxiosError, AxiosRequestConfig} from '@ohos/axios';
import { AxiosError, AxiosHeaders, AxiosRequestConfig, RawAxiosRequestHeaders } from '@ohos/axios';
import HashMap from '@ohos.util.HashMap';
import service from './AxiosRequest';
export class HttpRequest {
... ... @@ -6,17 +7,28 @@ export class HttpRequest {
static request<T = any>(config: AxiosRequestConfig): Promise<T> {
return new Promise<T>((resolve, reject) => {
service.request<any, T>(config)
.then((res:T) => {
.then((res: T) => {
resolve(res)
})
.catch((err:AxiosError) => {
.catch((err: AxiosError) => {
reject(err)
})
})
// return service.request<any, T>(config)
}
static get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T> {
private static get0<T = any>(url: string, config?: AxiosRequestConfig): Promise<T> {
return service.get(url, config)
}
static get<T = any>(url: string, headers?: HashMap<string, string>): Promise<T> {
let requestHeaders: AxiosHeaders = new AxiosHeaders()
headers?.forEach((v, k) => {
requestHeaders.set(k, v);
});
let config: AxiosRequestConfig = {
headers: requestHeaders as RawAxiosRequestHeaders
}
return service.get(url, config)
}
... ...