Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
zhangbo1_wd
2024-01-26 18:19:23 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
1b946be20105b870f37a9e5f1e32e95c4550021b
1b946be2
1 parent
acd0d754
context上下文获取问题,先加传参。后续优化全局上下文的获取
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
13 additions
and
17 deletions
PeopleDaily_Harmony/wdComponent/src/main/ets/components/BottomNavigationComponent.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/components/PageComponent.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/viewmodel/PageViewModel.ets
PeopleDaily_Harmony/wdKit/src/main/ets/utils/ResourcesUtils.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/components/BottomNavigationComponent.ets
View file @
1b946be
...
...
@@ -31,7 +31,7 @@ export struct BottomNavigationComponent {
async aboutToAppear() {
Logger.info(TAG, `aboutToAppear currentNavIndex: ${this.currentNavIndex}`);
let bottomNav = await PageViewModel.getBottomNavData()
let bottomNav = await PageViewModel.getBottomNavData(
getContext(this)
)
if (bottomNav && bottomNav.bottomNavList != null) {
Logger.info(TAG, `aboutToAppear, bottomNav.length: ${bottomNav.bottomNavList.length}`);
this.bottomNavList = bottomNav.bottomNavList
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/components/PageComponent.ets
View file @
1b946be
...
...
@@ -80,7 +80,7 @@ export struct PageComponent {
// return
// }
Logger.debug(TAG,'lllllalalal: ' + this.pageId+' , ' + this.channelId);
let pageDto = await PageViewModel.getPageData(this.pageId, this.pageId, this.channelId)
let pageDto = await PageViewModel.getPageData(this.pageId, this.pageId, this.channelId
, getContext(this)
)
if (pageDto && pageDto.compList) {
this.compList.push(...pageDto.compList)
}
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/viewmodel/PageViewModel.ets
View file @
1b946be
import {
AppContext,
Logger, ResourcesUtils } from 'wdKit';
import { 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';
/**
...
...
@@ -29,17 +25,17 @@ export class PageViewModel extends BaseViewModel {
*
* @return BottomNavBean[] Nav Data List
*/
async getBottomNavData(): Promise<NavigationBodyDTO> {
async getBottomNavData(
context?: Context
): Promise<NavigationBodyDTO> {
Logger.info(TAG, `getBottomNavData start`);
if (mock_switch) {
return this.getBottomNavDataMock();
return this.getBottomNavDataMock(
context
);
}
return this.getNavData();
}
async getBottomNavDataMock(): Promise<NavigationBodyDTO> {
async getBottomNavDataMock(
context?: Context
): Promise<NavigationBodyDTO> {
Logger.info(TAG, `getBottomNavDataMock start`);
let compRes: ResponseDTO<NavigationBodyDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<NavigationBodyDTO>>('bottom_nav.json');
let compRes: ResponseDTO<NavigationBodyDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<NavigationBodyDTO>>('bottom_nav.json'
, context
);
if (!compRes || !compRes.data) {
Logger.info(TAG, `getBottomNavDataMock compRes bottomNavList is empty`);
return null
...
...
@@ -71,8 +67,8 @@ export class PageViewModel extends BaseViewModel {
*
* @return {GroupDTO} compRes.data
*/
private async getPageData1(): Promise<PageDTO> {
let compRes: ResponseDTO<PageDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<PageDTO>>('comp_list0.json');
private async getPageData1(context?: Context): Promise<PageDTO> {
let compRes: ResponseDTO<PageDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<PageDTO>>('comp_list0.json', context);
if (!compRes || !compRes.data) {
Logger.info(TAG, `getCompList compRes is empty`);
return {} as PageDTO
...
...
@@ -87,7 +83,7 @@ export class PageViewModel extends BaseViewModel {
* @return {GroupDTO} compRes.data
* @deprecated
*/
private async getPageData2(): Promise<PageDTO> {
private async getPageData2(
context?: Context
): 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`);
...
...
@@ -98,10 +94,10 @@ export class PageViewModel extends BaseViewModel {
return compRes.data
}
async getPageData(pageId: string, groupId: string, channelId: string): Promise<PageDTO> {
async getPageData(pageId: string, groupId: string, channelId: string
, context?: Context
): Promise<PageDTO> {
Logger.error(TAG, 'getPageData pageId: ' + pageId);
if (mock_switch) {
return this.getPageData1();
return this.getPageData1(
context
);
}
return new Promise<PageDTO>((success, error) => {
PageRepository.fetchPageData(pageId, groupId, channelId).then((resDTO: ResponseDTO<PageDTO>) => {
...
...
PeopleDaily_Harmony/wdKit/src/main/ets/utils/ResourcesUtils.ets
View file @
1b946be
...
...
@@ -20,7 +20,7 @@ export class ResourcesUtils {
}
return new Promise((success, error) => {
Logger.info(TAG, "ResourcesUtils getResourcesText filename:" + filename);
context.resourceManager.getRawFileContent(filename).then((content: Uint8Array) => {
context
?
.resourceManager.getRawFileContent(filename).then((content: Uint8Array) => {
if (!content) {
Logger.warn(TAG, 'getResourcesText then content is empty');
error("file is empty");
...
...
Please
register
or
login
to post a comment