Showing
18 changed files
with
333 additions
and
54 deletions
| 1 | import UIAbility from '@ohos.app.ability.UIAbility'; | 1 | import UIAbility from '@ohos.app.ability.UIAbility'; |
| 2 | import hilog from '@ohos.hilog'; | 2 | import hilog from '@ohos.hilog'; |
| 3 | import window from '@ohos.window'; | 3 | import window from '@ohos.window'; |
| 4 | - | 4 | +import { AppContext } from 'wdKit'; |
| 5 | export default class EntryAbility extends UIAbility { | 5 | export default class EntryAbility extends UIAbility { |
| 6 | onCreate(want, launchParam) { | 6 | onCreate(want, launchParam) { |
| 7 | hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); | 7 | hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate'); |
| 8 | + AppContext.init(this.context) | ||
| 8 | } | 9 | } |
| 9 | 10 | ||
| 10 | onDestroy() { | 11 | onDestroy() { |
| @@ -4,6 +4,8 @@ import { TopNavigationComponent } from './TopNavigationComponent'; | @@ -4,6 +4,8 @@ import { TopNavigationComponent } from './TopNavigationComponent'; | ||
| 4 | import { PageComponent } from './PageComponent'; | 4 | import { PageComponent } from './PageComponent'; |
| 5 | import { BottomNavDTO } from '../repository/bean/BottomNavDTO'; | 5 | import { BottomNavDTO } from '../repository/bean/BottomNavDTO'; |
| 6 | import { PageViewModel } from '../Index'; | 6 | import { PageViewModel } from '../Index'; |
| 7 | +import { UIUtils } from '../repository/UIUtils'; | ||
| 8 | +import { MinePageComponent } from './MinePageComponent'; | ||
| 7 | 9 | ||
| 8 | const TAG = 'BottomNavigationComponent'; | 10 | const TAG = 'BottomNavigationComponent'; |
| 9 | 11 | ||
| @@ -28,10 +30,9 @@ export struct BottomNavigationComponent { | @@ -28,10 +30,9 @@ export struct BottomNavigationComponent { | ||
| 28 | */ | 30 | */ |
| 29 | readonly SIXTY_OPACITY: number = 0.6; | 31 | readonly SIXTY_OPACITY: number = 0.6; |
| 30 | 32 | ||
| 31 | - | ||
| 32 | async aboutToAppear() { | 33 | async aboutToAppear() { |
| 33 | Logger.info(TAG, `aboutToAppear currentNavIndex: ${this.currentNavIndex}`); | 34 | Logger.info(TAG, `aboutToAppear currentNavIndex: ${this.currentNavIndex}`); |
| 34 | - let bottomNav = await PageViewModel.getBottomNavData(getContext(this)) | 35 | + let bottomNav = await PageViewModel.getBottomNavData() |
| 35 | if (bottomNav) { | 36 | if (bottomNav) { |
| 36 | Logger.info(TAG, `aboutToAppear, bottomNav.length: ${bottomNav.length}`); | 37 | Logger.info(TAG, `aboutToAppear, bottomNav.length: ${bottomNav.length}`); |
| 37 | this.bottomNavList = bottomNav | 38 | this.bottomNavList = bottomNav |
| @@ -47,8 +48,9 @@ export struct BottomNavigationComponent { | @@ -47,8 +48,9 @@ export struct BottomNavigationComponent { | ||
| 47 | ForEach(this.bottomNavList, (navItem: BottomNavDTO, index: number) => { | 48 | ForEach(this.bottomNavList, (navItem: BottomNavDTO, index: number) => { |
| 48 | TabContent() { | 49 | TabContent() { |
| 49 | Column() { | 50 | Column() { |
| 50 | - if (navItem.topNavChannelList && navItem.topNavChannelList.length == 0 && navItem.name == '我的') { | ||
| 51 | - PageComponent({ compList: new LazyDataSource() }) // todo:我的页面组件数据列表 | 51 | + if (UIUtils.isMine(navItem)) { |
| 52 | + // 我的页面组件数据列表 | ||
| 53 | + MinePageComponent() | ||
| 52 | } else { | 54 | } else { |
| 53 | TopNavigationComponent({ topNavList: navItem.topNavChannelList }) | 55 | TopNavigationComponent({ topNavList: navItem.topNavChannelList }) |
| 54 | } | 56 | } |
| 1 | import { CommonConstants, CompStyle, ViewType } from 'wdConstant'; | 1 | import { CommonConstants, CompStyle, ViewType } from 'wdConstant'; |
| 2 | import { LazyDataSource, Logger } from 'wdKit'; | 2 | import { LazyDataSource, Logger } from 'wdKit'; |
| 3 | import { CompDTO } from '../repository/bean/CompDTO'; | 3 | import { CompDTO } from '../repository/bean/CompDTO'; |
| 4 | -import { PageViewModel } from '../viewmodel/PageViewModel'; | 4 | +import PageViewModel from '../viewmodel/PageViewModel'; |
| 5 | import { EmptyComponent } from './EmptyComponent'; | 5 | import { EmptyComponent } from './EmptyComponent'; |
| 6 | import { ErrorComponent } from './ErrorComponent'; | 6 | import { ErrorComponent } from './ErrorComponent'; |
| 7 | import { LabelComponent } from './LabelComponent'; | 7 | import { LabelComponent } from './LabelComponent'; |
| @@ -17,6 +17,10 @@ export struct PageComponent { | @@ -17,6 +17,10 @@ export struct PageComponent { | ||
| 17 | // Group数据及子组件数据 | 17 | // Group数据及子组件数据 |
| 18 | @State compList: LazyDataSource<CompDTO> = new LazyDataSource(); | 18 | @State compList: LazyDataSource<CompDTO> = new LazyDataSource(); |
| 19 | @State currentTopNavSelectedIndex: number = 0; | 19 | @State currentTopNavSelectedIndex: number = 0; |
| 20 | + @State pageId: string = ""; | ||
| 21 | + @State channelId: string = ""; | ||
| 22 | + | ||
| 23 | + // @Link @Watch('onChange') paIndex:number | ||
| 20 | 24 | ||
| 21 | build() { | 25 | build() { |
| 22 | if (this.viewType == ViewType.LOADING) { | 26 | if (this.viewType == ViewType.LOADING) { |
| @@ -59,17 +63,26 @@ export struct PageComponent { | @@ -59,17 +63,26 @@ export struct PageComponent { | ||
| 59 | 63 | ||
| 60 | async aboutToAppear() { | 64 | async aboutToAppear() { |
| 61 | Logger.info(TAG, `aboutToAppear, this.pageId: ${this.viewType} this.currentTopNavSelectedIndex: ${this.currentTopNavSelectedIndex}`); | 65 | Logger.info(TAG, `aboutToAppear, this.pageId: ${this.viewType} this.currentTopNavSelectedIndex: ${this.currentTopNavSelectedIndex}`); |
| 62 | - if (this.currentTopNavSelectedIndex === 1) { // 顶导tab的第0个item是【热点】,第1个item是【推荐】 | ||
| 63 | - this.compList.replaceAll() | ||
| 64 | - let pageDto = await PageViewModel.getPageData2(getContext(this)) | ||
| 65 | - if (pageDto && pageDto.compList) { | ||
| 66 | - this.compList.push(...pageDto.compList) | ||
| 67 | - } | ||
| 68 | - } else { | ||
| 69 | - let pageDto = await PageViewModel.getPageData1(getContext(this)) | ||
| 70 | - if (pageDto && pageDto.compList) { | ||
| 71 | - this.compList.push(...pageDto.compList) | ||
| 72 | - } | 66 | + // if (this.currentTopNavSelectedIndex === 1) { // 顶导tab的第0个item是【热点】,第1个item是【推荐】 |
| 67 | + // this.compList.replaceAll() | ||
| 68 | + // let pageDto = await PageViewModel.getPageData2(getContext(this)) | ||
| 69 | + // if (pageDto && pageDto.compList) { | ||
| 70 | + // this.compList.push(...pageDto.compList) | ||
| 71 | + // } | ||
| 72 | + // } else { | ||
| 73 | + // let pageDto = await PageViewModel.getPageData1(getContext(this)) | ||
| 74 | + // if (pageDto && pageDto.compList) { | ||
| 75 | + // this.compList.push(...pageDto.compList) | ||
| 76 | + // } | ||
| 77 | + // } | ||
| 78 | + | ||
| 79 | + // if (this.currentTopNavSelectedIndex != 1) { // 顶导tab的第0个item是【热点】,第1个item是【推荐】 | ||
| 80 | + // return | ||
| 81 | + // } | ||
| 82 | + Logger.debug(TAG,'lllllalalal: ' + this.pageId+' , ' + this.channelId); | ||
| 83 | + let pageDto = await PageViewModel.getPageData(this.pageId, this.pageId, this.channelId) | ||
| 84 | + if (pageDto && pageDto.compList) { | ||
| 85 | + this.compList.push(...pageDto.compList) | ||
| 73 | } | 86 | } |
| 74 | } | 87 | } |
| 75 | } | 88 | } |
| @@ -21,7 +21,7 @@ export struct TopNavigationComponent { | @@ -21,7 +21,7 @@ export struct TopNavigationComponent { | ||
| 21 | Tabs() { | 21 | Tabs() { |
| 22 | ForEach(this.topNavList, (navItem: TopNavDTO, index: number) => { | 22 | ForEach(this.topNavList, (navItem: TopNavDTO, index: number) => { |
| 23 | TabContent() { | 23 | TabContent() { |
| 24 | - PageComponent({ currentTopNavSelectedIndex: index }) | 24 | + PageComponent({ currentTopNavSelectedIndex: index, pageId: navItem.pageId, channelId: navItem.channelId }) |
| 25 | } | 25 | } |
| 26 | .tabBar(this.tabBarBuilder(navItem, index)) | 26 | .tabBar(this.tabBarBuilder(navItem, index)) |
| 27 | }, (navItem: TopNavDTO) => JSON.stringify(navItem)); | 27 | }, (navItem: TopNavDTO) => JSON.stringify(navItem)); |
| 1 | +import HashMap from '@ohos.util.HashMap' | ||
| 2 | +import { ConfigConstants } from 'wdConstant/src/main/ets/constants/ConfigConstants' | ||
| 3 | +import { DateTimeUtils, Logger } from 'wdKit' | ||
| 4 | + | ||
| 5 | +/** | ||
| 6 | + * 网络请求业务侧工具类 | ||
| 7 | + */ | ||
| 8 | +export class HttpUrlUtils { | ||
| 9 | + /** | ||
| 10 | + * 现网地址 | ||
| 11 | + */ | ||
| 12 | + static readonly HOST: string = "https://pd-apis-uat.pdnews.cn"; | ||
| 13 | + /** | ||
| 14 | + * 展现comp接口 | ||
| 15 | + */ | ||
| 16 | + static readonly COMP_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/compInfo"; | ||
| 17 | + | ||
| 18 | + static getCommonHeaders(): HashMap<string, string> { | ||
| 19 | + let headers: HashMap<string, string> = new HashMap<string, string>() | ||
| 20 | + headers.set('User-Agent', 'Dalvik/2.1.0 (Linux; U; Android 13; 22101317C Build/TKQ1.221013.002)') | ||
| 21 | + headers.set('channel', this.getChannel()) | ||
| 22 | + headers.set('appCode', ConfigConstants.appCode) | ||
| 23 | + headers.set('plat', this.getPlat()) | ||
| 24 | + headers.set('Authorization', 'APPCODE 83092caa603a421aa0222308b3f6b27a') | ||
| 25 | + headers.set('Content-Type', 'application/json; charset=utf-8') | ||
| 26 | + headers.set('timestamp', this.getTimestamp()) | ||
| 27 | + headers.set('RMRB-X-TOKEN', this.getXToken()) | ||
| 28 | + headers.set('device_id', this.getDeviceId()) | ||
| 29 | + headers.set('cookie', 'RMRB-X-TOKEN=eyJhbGciOiJIUzI1NiIsImtpZCI6ImQ4WkI2QkhxSEZrdjJ2U25BNlRwZEdKRjBHcjItVzBvS2FaYzdLOUUycmcifQ.eyJpc3MiOiJwZW9wbGVzLWRhaWx5LWZvdXJhIiwic3ViIjoicGVvcGxlcy1kYWlseS1mb3VyYSIsImV4cCI6MTcwMzY0OTYwNiwidXNlcklkIjo0NTk3NzYyOTc0NzQ5NDksInVzZXJWZXJzaW9uIjoiNDU5Nzc2Mjk3NDc0OTQ5XzIiLCJ1c2VyTmFtZSI6IkJ1bGlraWtpMTgxIiwidXNlclR5cGUiOjIsImNyZWF0b3JJZCI6NDI2NTM5MH0.jhQ9kylcm3FxWf0-lBMZuLkdtIQ6XpFnAi0AFZJNwfc') | ||
| 30 | + headers.set('build_version', this.getVersion()) | ||
| 31 | + headers.set('adcode', this.getAdCode()) | ||
| 32 | + headers.set('os_version', this.getOsVersion()) | ||
| 33 | + headers.set('X-Ca-Stage', 'PRE') | ||
| 34 | + headers.set('versionCode', this.getVersionCode()) | ||
| 35 | + headers.set('system', this.getTerminalId()) | ||
| 36 | + headers.set('version_name', 'debug') | ||
| 37 | + headers.set('EagleEye-TraceID', '0B6DE03D2997435BA875FFBE05425ED2') | ||
| 38 | + headers.set('imei', this.getImei()) | ||
| 39 | + headers.set('Accept-Language', 'zh') | ||
| 40 | + headers.set('city', this.getCity()) | ||
| 41 | + headers.set('city_dode', this.getCityCode()) | ||
| 42 | + // TODO 判断是否登录 | ||
| 43 | + headers.set('userId', this.getUserId()) | ||
| 44 | + headers.set('userType', this.getUserType()) | ||
| 45 | + Logger.debug("TAG", 'getCommonHeaders headers: ' + headers); | ||
| 46 | + return headers; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + static getCompInfoUrl(pageId: string, groupId: string, channelId: string) { | ||
| 50 | + let url = this.HOST + this.COMP_PATH; | ||
| 51 | + // TODO 暂定只请求第一页,后续对接分页加载,参数再调整 | ||
| 52 | + url = url + "?channelStrategy=2&pageSize=20&pageNum=1&loadStrategy=first_load" | ||
| 53 | + + "&districtCode=" + this.getDistrictCode() | ||
| 54 | + + "&provinceCode=" + this.getProvinceCode() | ||
| 55 | + + "&cityCode=" + this.getCityCode() | ||
| 56 | + // + "&refreshTime=" + DateTimeUtils.getCurrentTimeMillis() | ||
| 57 | + + "&refreshTime=" + "1703472405653" | ||
| 58 | + + "&pageId=" + pageId | ||
| 59 | + + "&groupId=" + groupId | ||
| 60 | + + "&channelId=" + channelId; | ||
| 61 | + return url; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + | ||
| 65 | + private static getCity() { | ||
| 66 | + // TODO 对接定位 | ||
| 67 | + return '%E5%90%88%E8%82%A5%E5%B8%82'; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + private static getChannel() { | ||
| 71 | + // TODO 对接配置 | ||
| 72 | + return 'rmrb_china_0000'; | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + private static getPlat() { | ||
| 76 | + return 'Phone'; | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + private static getTimestamp() { | ||
| 80 | + // return DateTimeUtils.getCurrentTime() + ''; | ||
| 81 | + return '155203523'; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + private static getXToken() { | ||
| 85 | + return 'eyJhbGciOiJIUzI1NiIsImtpZCI6ImQ4WkI2QkhxSEZrdjJ2U25BNlRwZEdKRjBHcjItVzBvS2FaYzdLOUUycmcifQ.eyJpc3MiOiJwZW9wbGVzLWRhaWx5LWZvdXJhIiwic3ViIjoicGVvcGxlcy1kYWlseS1mb3VyYSIsImV4cCI6MTcwMzY0OTYwNiwidXNlcklkIjo0NTk3NzYyOTc0NzQ5NDksInVzZXJWZXJzaW9uIjoiNDU5Nzc2Mjk3NDc0OTQ5XzIiLCJ1c2VyTmFtZSI6IkJ1bGlraWtpMTgxIiwidXNlclR5cGUiOjIsImNyZWF0b3JJZCI6NDI2NTM5MH0.jhQ9kylcm3FxWf0-lBMZuLkdtIQ6XpFnAi0AFZJNwfc'; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + private static getDeviceId() { | ||
| 89 | + // TODO | ||
| 90 | + return 'b5cf725d-193d-3215-8c77-e76fe15ce64d'; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + private static getVersion() { | ||
| 94 | + // TODO | ||
| 95 | + return '202312251034'; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + private static getVersionCode() { | ||
| 99 | + // TODO | ||
| 100 | + return '7301'; | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + private static getAdCode() { | ||
| 104 | + return '340000'; | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | + private static getOsVersion() { | ||
| 108 | + // TODO | ||
| 109 | + return '13'; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + private static getCityCode() { | ||
| 113 | + // TODO | ||
| 114 | + return '340100'; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + private static getProvinceCode() { | ||
| 118 | + // TODO | ||
| 119 | + return '340000'; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + /** | ||
| 123 | + * 地区code | ||
| 124 | + */ | ||
| 125 | + private static getDistrictCode() { | ||
| 126 | + // TODO | ||
| 127 | + return '340103'; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + private static getTerminalId() { | ||
| 131 | + return 'Android'; | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + private static getImei() { | ||
| 135 | + // TODO | ||
| 136 | + return 'b5cf725d-193d-3215-8c77-e76fe15ce64d'; | ||
| 137 | + } | ||
| 138 | + | ||
| 139 | + private static getUserId() { | ||
| 140 | + // TODO 对接登录 | ||
| 141 | + return '459776297474949'; | ||
| 142 | + } | ||
| 143 | + | ||
| 144 | + private static getUserType() { | ||
| 145 | + return '2'; | ||
| 146 | + } | ||
| 147 | +} |
| 1 | import { ResponseDTO, WDHttp } from 'wdNetwork'; | 1 | import { ResponseDTO, WDHttp } from 'wdNetwork'; |
| 2 | import { NavigationBodyDTO } from './bean/NavigationBodyDTO'; | 2 | import { NavigationBodyDTO } from './bean/NavigationBodyDTO'; |
| 3 | import { PageDTO } from './bean/PageDTO'; | 3 | import { PageDTO } from './bean/PageDTO'; |
| 4 | +import HashMap from '@ohos.util.HashMap'; | ||
| 5 | +import { HttpUrlUtils } from '../network/HttpUrlUtils'; | ||
| 4 | 6 | ||
| 5 | export class PageRepository { | 7 | export class PageRepository { |
| 6 | - | ||
| 7 | static fetchNavigationDataApi(url: string) { | 8 | static fetchNavigationDataApi(url: string) { |
| 8 | - return WDHttp.get<ResponseDTO<NavigationBodyDTO>>(url) | 9 | + let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); |
| 10 | + return WDHttp.get<ResponseDTO<NavigationBodyDTO>>(url, headers) | ||
| 9 | }; | 11 | }; |
| 10 | 12 | ||
| 11 | - static fetchPageData(url: string) { | ||
| 12 | - return WDHttp.get<ResponseDTO<PageDTO>>(url) | 13 | + static fetchPageData(pageId: string, groupId: string, channelId: string) { |
| 14 | + let url = HttpUrlUtils.getCompInfoUrl(pageId, groupId, channelId) | ||
| 15 | + let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); | ||
| 16 | + return WDHttp.get<ResponseDTO<PageDTO>>(url, headers) | ||
| 13 | }; | 17 | }; |
| 14 | } | 18 | } |
| 1 | +/** | ||
| 2 | + * 网络请求业务侧工具类 | ||
| 3 | + */ | ||
| 4 | +import { BottomNavDTO } from './bean/BottomNavDTO'; | ||
| 5 | + | ||
| 6 | +export class UIUtils { | ||
| 7 | + | ||
| 8 | + /** | ||
| 9 | + * 判断是否为我的页面 | ||
| 10 | + */ | ||
| 11 | + static isMine(navItem: BottomNavDTO): boolean { | ||
| 12 | + if (navItem == null) { | ||
| 13 | + return false; | ||
| 14 | + } | ||
| 15 | + return navItem.type == '2'; | ||
| 16 | + } | ||
| 17 | +} |
| @@ -36,5 +36,6 @@ export interface BottomNavDTO { | @@ -36,5 +36,6 @@ export interface BottomNavDTO { | ||
| 36 | statusBarColor: number; | 36 | statusBarColor: number; |
| 37 | topNavChannelList: TopNavDTO[]; | 37 | topNavChannelList: TopNavDTO[]; |
| 38 | topStyle: string; | 38 | topStyle: string; |
| 39 | + // 1-普通页面,2-我的 | ||
| 39 | type: string; | 40 | type: string; |
| 40 | } | 41 | } |
| @@ -2,7 +2,7 @@ | @@ -2,7 +2,7 @@ | ||
| 2 | * 顶导 | 2 | * 顶导 |
| 3 | */ | 3 | */ |
| 4 | export interface TopNavDTO { | 4 | export interface TopNavDTO { |
| 5 | - channelId: number; | 5 | + channelId: string; |
| 6 | channelStyle: number; | 6 | channelStyle: number; |
| 7 | channelType: number; | 7 | channelType: number; |
| 8 | defaultPermitted: number; | 8 | defaultPermitted: number; |
| @@ -21,7 +21,7 @@ export interface TopNavDTO { | @@ -21,7 +21,7 @@ export interface TopNavDTO { | ||
| 21 | myChannel: string; | 21 | myChannel: string; |
| 22 | name: string; | 22 | name: string; |
| 23 | num: number; | 23 | num: number; |
| 24 | - pageId: number; | 24 | + pageId: string; |
| 25 | pageType: string; | 25 | pageType: string; |
| 26 | underlineCColor: string; | 26 | underlineCColor: string; |
| 27 | } | 27 | } |
| 1 | +import { Logger } from 'wdKit'; | ||
| 2 | +import { ResponseDTO } from 'wdNetwork'; | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * 处理返回后的数据 | ||
| 6 | + */ | ||
| 7 | +export abstract class BaseViewModel { | ||
| 8 | + abstract getLogTag(): string; | ||
| 9 | + | ||
| 10 | + public isRespondsInvalid(resDTO: ResponseDTO<any>, tag?: string): boolean { | ||
| 11 | + if (resDTO == null) { | ||
| 12 | + Logger.error(this.getLogTag(), `${tag == null ? '' : tag + ', '}resDTO is empty`); | ||
| 13 | + return true; | ||
| 14 | + } | ||
| 15 | + // code = 0, success | ||
| 16 | + if (resDTO.code != 0) { | ||
| 17 | + Logger.error(this.getLogTag(), `${tag == null ? '' : tag + ', '}code error, code:${resDTO.code}, message:${resDTO.message}`); | ||
| 18 | + return true; | ||
| 19 | + } | ||
| 20 | + if (!resDTO.data) { | ||
| 21 | + Logger.error(this.getLogTag(), `${tag == null ? '' : tag + ', '}resDTO.data is null`); | ||
| 22 | + return true; | ||
| 23 | + } | ||
| 24 | + return false; | ||
| 25 | + } | ||
| 26 | +} |
| 1 | -import { Logger, ResourcesUtils } from 'wdKit'; | 1 | +import { AppContext, Logger, ResourcesUtils } from 'wdKit'; |
| 2 | import { ResponseDTO, } from 'wdNetwork'; | 2 | import { ResponseDTO, } from 'wdNetwork'; |
| 3 | import { PageRepository } from '../repository/PageRepository'; | 3 | import { PageRepository } from '../repository/PageRepository'; |
| 4 | import http from '@ohos.net.http'; | 4 | import http from '@ohos.net.http'; |
| 5 | import { NavigationBodyDTO } from '../repository/bean/NavigationBodyDTO'; | 5 | import { NavigationBodyDTO } from '../repository/bean/NavigationBodyDTO'; |
| 6 | import { BottomNavDTO } from '../repository/bean/BottomNavDTO'; | 6 | import { BottomNavDTO } from '../repository/bean/BottomNavDTO'; |
| 7 | import { PageDTO } from '../repository/bean/PageDTO'; | 7 | import { PageDTO } from '../repository/bean/PageDTO'; |
| 8 | +import { BaseViewModel } from './BaseViewModel'; | ||
| 8 | 9 | ||
| 9 | const TAG = 'PageViewModel'; | 10 | const TAG = 'PageViewModel'; |
| 11 | +/** | ||
| 12 | + * mock数据开关,默认关。 | ||
| 13 | + * mock数据是本地json数据,可自行修改内容(‘entry\src\main\resources\rawfile\’目录) | ||
| 14 | + */ | ||
| 15 | +const mock_switch = false; | ||
| 10 | 16 | ||
| 11 | /** | 17 | /** |
| 12 | * 处理返回后的数据 | 18 | * 处理返回后的数据 |
| 13 | */ | 19 | */ |
| 14 | -export class PageViewModel { | 20 | +export class PageViewModel extends BaseViewModel { |
| 21 | + getLogTag() { | ||
| 22 | + return TAG; | ||
| 23 | + } | ||
| 24 | + | ||
| 15 | /** | 25 | /** |
| 16 | * get Nav Data from Resource . | 26 | * get Nav Data from Resource . |
| 17 | * | 27 | * |
| 18 | * @return BottomNavBean[] Nav Data List | 28 | * @return BottomNavBean[] Nav Data List |
| 19 | */ | 29 | */ |
| 20 | - static async getBottomNavData(context: Context): Promise<BottomNavDTO[]> { | 30 | + static async getBottomNavData(): Promise<BottomNavDTO[]> { |
| 21 | Logger.info(TAG, `getBottomNavData start`); | 31 | Logger.info(TAG, `getBottomNavData start`); |
| 22 | - let compRes: ResponseDTO<NavigationBodyDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<NavigationBodyDTO>>(context, 'bottom_nav.json'); | 32 | + let compRes: ResponseDTO<NavigationBodyDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<NavigationBodyDTO>>('bottom_nav.json'); |
| 23 | if (!compRes || !compRes.data || !compRes.data.bottomNavList) { | 33 | if (!compRes || !compRes.data || !compRes.data.bottomNavList) { |
| 24 | Logger.info(TAG, `getBottomNavData compRes bottomNavList is empty`); | 34 | Logger.info(TAG, `getBottomNavData compRes bottomNavList is empty`); |
| 25 | return [] | 35 | return [] |
| @@ -62,8 +72,8 @@ export class PageViewModel { | @@ -62,8 +72,8 @@ export class PageViewModel { | ||
| 62 | * | 72 | * |
| 63 | * @return {GroupDTO} compRes.data | 73 | * @return {GroupDTO} compRes.data |
| 64 | */ | 74 | */ |
| 65 | - static async getPageData1(context: Context): Promise<PageDTO> { | ||
| 66 | - let compRes: ResponseDTO<PageDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<PageDTO>>(context, 'comp_list0.json'); | 75 | + static async getPageData1(): Promise<PageDTO> { |
| 76 | + let compRes: ResponseDTO<PageDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<PageDTO>>('comp_list0.json'); | ||
| 67 | if (!compRes || !compRes.data) { | 77 | if (!compRes || !compRes.data) { |
| 68 | Logger.info(TAG, `getCompList compRes is empty`); | 78 | Logger.info(TAG, `getCompList compRes is empty`); |
| 69 | return {} as PageDTO | 79 | return {} as PageDTO |
| @@ -77,8 +87,8 @@ export class PageViewModel { | @@ -77,8 +87,8 @@ export class PageViewModel { | ||
| 77 | * | 87 | * |
| 78 | * @return {GroupDTO} compRes.data | 88 | * @return {GroupDTO} compRes.data |
| 79 | */ | 89 | */ |
| 80 | - static async getPageData2(context: Context): Promise<PageDTO> { | ||
| 81 | - let compRes: ResponseDTO<PageDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<PageDTO>>(context, 'comp_list2.json'); | 90 | + async getPageData2(): Promise<PageDTO> { |
| 91 | + let compRes: ResponseDTO<PageDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<PageDTO>>('comp_list2.json'); | ||
| 82 | if (!compRes || !compRes.data) { | 92 | if (!compRes || !compRes.data) { |
| 83 | Logger.info(TAG, `getCompList compRes is empty`); | 93 | Logger.info(TAG, `getCompList compRes is empty`); |
| 84 | return {} as PageDTO | 94 | return {} as PageDTO |
| @@ -87,18 +97,12 @@ export class PageViewModel { | @@ -87,18 +97,12 @@ export class PageViewModel { | ||
| 87 | return compRes.data | 97 | return compRes.data |
| 88 | } | 98 | } |
| 89 | 99 | ||
| 90 | - | ||
| 91 | - static getPageData(url: string): Promise<PageDTO> { | 100 | + async getPageData(pageId: string, groupId: string, channelId: string): Promise<PageDTO> { |
| 101 | + Logger.error(TAG, 'getPageData pageId: ' + pageId); | ||
| 92 | return new Promise<PageDTO>((success, error) => { | 102 | return new Promise<PageDTO>((success, error) => { |
| 93 | - PageRepository.fetchPageData(url).then((resDTO: ResponseDTO<PageDTO>) => { | ||
| 94 | - if (!resDTO) { | ||
| 95 | - Logger.error(TAG, 'getPageData then resDTO is empty'); | ||
| 96 | - error("page data is empty"); | ||
| 97 | - return | ||
| 98 | - } | ||
| 99 | - if (resDTO.code != http.ResponseCode.OK || !resDTO.data) { | ||
| 100 | - Logger.error(TAG, `getPageData then code:${resDTO.code}, message:${resDTO.message}`); | ||
| 101 | - error(`get page data error code:${resDTO.code}, message:${resDTO.message}`); | 103 | + PageRepository.fetchPageData(pageId, groupId, channelId).then((resDTO: ResponseDTO<PageDTO>) => { |
| 104 | + if (this.isRespondsInvalid(resDTO, 'getPageData')) { | ||
| 105 | + error("page data invalid"); | ||
| 102 | return | 106 | return |
| 103 | } | 107 | } |
| 104 | Logger.info(TAG, "getPageData then,resDTO.timeStamp:" + resDTO.timestamp); | 108 | Logger.info(TAG, "getPageData then,resDTO.timeStamp:" + resDTO.timestamp); |
| @@ -112,7 +116,6 @@ export class PageViewModel { | @@ -112,7 +116,6 @@ export class PageViewModel { | ||
| 112 | } | 116 | } |
| 113 | 117 | ||
| 114 | 118 | ||
| 115 | - | ||
| 116 | let pageViewModel = new PageViewModel(); | 119 | let pageViewModel = new PageViewModel(); |
| 117 | 120 | ||
| 118 | export default pageViewModel as PageViewModel; | 121 | export default pageViewModel as PageViewModel; |
| @@ -28,7 +28,7 @@ export class ConfigConstants { | @@ -28,7 +28,7 @@ export class ConfigConstants { | ||
| 28 | /** | 28 | /** |
| 29 | * 产品渠道应用对照关系: | 29 | * 产品渠道应用对照关系: |
| 30 | */ | 30 | */ |
| 31 | - static readonly appCode: string = ""; | 31 | + static readonly appCode: string = "83092caa603a421aa0222308b3f6b27a"; |
| 32 | /** | 32 | /** |
| 33 | * 基线代码和客户端应用版本号规范 | 33 | * 基线代码和客户端应用版本号规范 |
| 34 | */ | 34 | */ |
| @@ -10,3 +10,7 @@ export { BasicDataSource } from './utils/BasicDataSource'; | @@ -10,3 +10,7 @@ export { BasicDataSource } from './utils/BasicDataSource'; | ||
| 10 | 10 | ||
| 11 | export { LazyDataSource } from './utils/LazyDataSource' | 11 | export { LazyDataSource } from './utils/LazyDataSource' |
| 12 | 12 | ||
| 13 | +export { DateTimeUtils } from './utils/DateTimeUtils' | ||
| 14 | + | ||
| 15 | +export { AppContext } from './utils/AppContext' | ||
| 16 | + |
| @@ -316,6 +316,21 @@ export class DateTimeUtils { | @@ -316,6 +316,21 @@ export class DateTimeUtils { | ||
| 316 | static isTomorrow(date: number): boolean { | 316 | static isTomorrow(date: number): boolean { |
| 317 | return this.isSameDay(date, this.addDays(Date.now(), 1).getTime()); | 317 | return this.isSameDay(date, this.addDays(Date.now(), 1).getTime()); |
| 318 | } | 318 | } |
| 319 | + | ||
| 320 | + | ||
| 321 | + /** | ||
| 322 | + * 获取当前时间戳,秒 | ||
| 323 | + * */ | ||
| 324 | + public static getCurrentTime(): number { | ||
| 325 | + let time: number = new Date().getTime(); | ||
| 326 | + return Math.floor(time / 1000); | ||
| 327 | + } | ||
| 328 | + /** | ||
| 329 | + * 获取当前时间戳,毫秒 | ||
| 330 | + * */ | ||
| 331 | + public static getCurrentTimeMillis(): number { | ||
| 332 | + return new Date().getTime(); | ||
| 333 | + } | ||
| 319 | } | 334 | } |
| 320 | 335 | ||
| 321 | // const dateTimeUtils = new DateTimeUtils() | 336 | // const dateTimeUtils = new DateTimeUtils() |
| 1 | import buffer from '@ohos.buffer'; | 1 | import buffer from '@ohos.buffer'; |
| 2 | +import { AppContext } from './AppContext'; | ||
| 2 | import { Logger } from './Logger'; | 3 | import { Logger } from './Logger'; |
| 3 | 4 | ||
| 4 | const TAG = "ResourcesUtils"; | 5 | const TAG = "ResourcesUtils"; |
| @@ -13,7 +14,10 @@ export class ResourcesUtils { | @@ -13,7 +14,10 @@ export class ResourcesUtils { | ||
| 13 | * @param filename 仅文件名(不包含路径,文件在src\main\resources\rawfile下),如:"agconnect-services.json",test.xml, | 14 | * @param filename 仅文件名(不包含路径,文件在src\main\resources\rawfile下),如:"agconnect-services.json",test.xml, |
| 14 | * @returns text 字符串 | 15 | * @returns text 字符串 |
| 15 | */ | 16 | */ |
| 16 | - static getResourcesText(context: Context, filename: string): Promise<string> { | 17 | + static getResourcesText(filename: string, context?: Context): Promise<string> { |
| 18 | + if (context == null) { | ||
| 19 | + context = AppContext.getAbilityContext(); | ||
| 20 | + } | ||
| 17 | return new Promise((success, error) => { | 21 | return new Promise((success, error) => { |
| 18 | Logger.info(TAG, "ResourcesUtils getResourcesText filename:" + filename); | 22 | Logger.info(TAG, "ResourcesUtils getResourcesText filename:" + filename); |
| 19 | context.resourceManager.getRawFileContent(filename).then((content: Uint8Array) => { | 23 | context.resourceManager.getRawFileContent(filename).then((content: Uint8Array) => { |
| @@ -53,14 +57,17 @@ export class ResourcesUtils { | @@ -53,14 +57,17 @@ export class ResourcesUtils { | ||
| 53 | * 调用方式: | 57 | * 调用方式: |
| 54 | * let compRes: MGHttp.ResponseDTO<BodyComponent> = await ResourcesUtils.getResourcesJson<MGHttp.ResponseDTO<BodyComponent>>(context, 'model/componentList.json'); | 58 | * let compRes: MGHttp.ResponseDTO<BodyComponent> = await ResourcesUtils.getResourcesJson<MGHttp.ResponseDTO<BodyComponent>>(context, 'model/componentList.json'); |
| 55 | */ | 59 | */ |
| 56 | - static getResourcesJson<R>(context:Context, filename: string): Promise<R> { | 60 | + static getResourcesJson<R>(filename: string, context?: Context): Promise<R> { |
| 57 | Logger.info(TAG, `getResourcesJson filename: ${filename}`); | 61 | Logger.info(TAG, `getResourcesJson filename: ${filename}`); |
| 62 | + if (context == null) { | ||
| 63 | + context = AppContext.getAbilityContext(); | ||
| 64 | + } | ||
| 58 | return new Promise<R>((resolve, reject) => { | 65 | return new Promise<R>((resolve, reject) => { |
| 59 | - ResourcesUtils.getResourcesText(context, filename) | 66 | + ResourcesUtils.getResourcesText(filename, context) |
| 60 | .then((text: string) => { | 67 | .then((text: string) => { |
| 61 | try { | 68 | try { |
| 62 | // let config: R = JSON.parse(text) | 69 | // let config: R = JSON.parse(text) |
| 63 | - let config:R = JSON.parse(text) as R; | 70 | + let config: R = JSON.parse(text) as R; |
| 64 | if (config) { | 71 | if (config) { |
| 65 | Logger.info(TAG, "getResourcesJson parse JSON file success."); | 72 | Logger.info(TAG, "getResourcesJson parse JSON file success."); |
| 66 | // Logger.info(TAG, `getResourcesJson config : ${JSON.stringify(config)}`); | 73 | // Logger.info(TAG, `getResourcesJson config : ${JSON.stringify(config)}`); |
| @@ -74,7 +81,7 @@ export class ResourcesUtils { | @@ -74,7 +81,7 @@ export class ResourcesUtils { | ||
| 74 | reject(err) | 81 | reject(err) |
| 75 | } | 82 | } |
| 76 | }) | 83 | }) |
| 77 | - .catch((error:Error) => { | 84 | + .catch((error: Error) => { |
| 78 | reject(error) | 85 | reject(error) |
| 79 | }) | 86 | }) |
| 80 | }) | 87 | }) |
| 1 | -import type { AxiosError, AxiosRequestConfig} from '@ohos/axios'; | 1 | +import { AxiosError, AxiosHeaders, AxiosRequestConfig, RawAxiosRequestHeaders } from '@ohos/axios'; |
| 2 | +import HashMap from '@ohos.util.HashMap'; | ||
| 2 | import service from './AxiosRequest'; | 3 | import service from './AxiosRequest'; |
| 3 | 4 | ||
| 4 | export class HttpRequest { | 5 | export class HttpRequest { |
| @@ -6,17 +7,28 @@ export class HttpRequest { | @@ -6,17 +7,28 @@ export class HttpRequest { | ||
| 6 | static request<T = any>(config: AxiosRequestConfig): Promise<T> { | 7 | static request<T = any>(config: AxiosRequestConfig): Promise<T> { |
| 7 | return new Promise<T>((resolve, reject) => { | 8 | return new Promise<T>((resolve, reject) => { |
| 8 | service.request<any, T>(config) | 9 | service.request<any, T>(config) |
| 9 | - .then((res:T) => { | 10 | + .then((res: T) => { |
| 10 | resolve(res) | 11 | resolve(res) |
| 11 | }) | 12 | }) |
| 12 | - .catch((err:AxiosError) => { | 13 | + .catch((err: AxiosError) => { |
| 13 | reject(err) | 14 | reject(err) |
| 14 | }) | 15 | }) |
| 15 | }) | 16 | }) |
| 16 | // return service.request<any, T>(config) | 17 | // return service.request<any, T>(config) |
| 17 | } | 18 | } |
| 18 | 19 | ||
| 19 | - static get<T = any>(url: string, config?: AxiosRequestConfig): Promise<T> { | 20 | + private static get0<T = any>(url: string, config?: AxiosRequestConfig): Promise<T> { |
| 21 | + return service.get(url, config) | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + static get<T = any>(url: string, headers?: HashMap<string, string>): Promise<T> { | ||
| 25 | + let requestHeaders: AxiosHeaders = new AxiosHeaders() | ||
| 26 | + headers.forEach((v, k) => { | ||
| 27 | + requestHeaders.set(k, v); | ||
| 28 | + }); | ||
| 29 | + let config: AxiosRequestConfig = { | ||
| 30 | + headers: requestHeaders as RawAxiosRequestHeaders | ||
| 31 | + } | ||
| 20 | return service.get(url, config) | 32 | return service.get(url, config) |
| 21 | } | 33 | } |
| 22 | 34 |
-
Please register or login to post a comment