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-27 15:59:34 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c38bb9af6bbd74bd4aaece2afe81aba0e39e884e
c38bb9af
1 parent
e890d50e
页面布局里拆除comp解析逻辑;新增tab页面数据请求逻辑,避免初始化而大量接口请求
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
62 additions
and
29 deletions
PeopleDaily_Harmony/wdComponent/src/main/ets/components/CompParser.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/components/PageComponent.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/components/TopNavigationComponent.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/components/CompParser.ets
0 → 100644
View file @
c38bb9a
import { CommonConstants, CompStyle } from 'wdConstant';
import { CompDTO } from '../repository/bean/CompDTO';
import { BannerComponent } from './BannerComponent';
import { LabelComponent } from './LabelComponent';
import { TitleAbbrComponent } from './TitleAbbrComponent';
import { TitleAllComponent } from './TitleAllComponent';
/**
* comp适配器.
*/
@Component
export struct CompParser {
compDTO: CompDTO = {} as CompDTO;
compIndex: number = 0;
build() {
this.componentBuilder(this.compDTO, this.compIndex);
}
@Builder
componentBuilder(compDTO: CompDTO, compIndex: number) {
if (compDTO.compStyle === CompStyle.Label_03) {
LabelComponent({ compDTO: compDTO })
} 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
Text(compDTO.compStyle)
.width(CommonConstants.FULL_PARENT)
.padding(10)
// .backgroundColor(Color.Brown) // 展示本页未实现的compStyle
}
}
}
\ No newline at end of file
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/components/PageComponent.ets
View file @
c38bb9a
import { CommonConstants, CompStyle, ViewType } from 'wdConstant';
import { LazyDataSource, Logger } from 'wdKit';
import { CommonConstants, ViewType } from 'wdConstant';
import { Logger } from 'wdKit';
import { CompDTO } from '../repository/bean/CompDTO';
import PageViewModel from '../viewmodel/PageViewModel';
import { EmptyComponent } from './EmptyComponent';
import { ErrorComponent } from './ErrorComponent';
import { LabelComponent } from './LabelComponent';
import { TitleAbbrComponent } from './TitleAbbrComponent';
import { TitleAllComponent } from './TitleAllComponent';
import { BannerComponent } from './BannerComponent'
import PageModel from '../viewmodel/PageModel';
import { listTouchEvent } from '../utils/PullDownRefresh';
import RefreshLayout from './page/RefreshLayout';
...
...
@@ -15,6 +11,7 @@ import { RefreshLayoutBean } from './page/RefreshLayoutBean';
import NoMoreLayout from './page/NoMoreLayout';
import LoadMoreLayout from './page/LoadMoreLayout';
import CustomRefreshLoadLayout from './page/CustomRefreshLoadLayout';
import { CompParser } from './CompParser';
const TAG = 'PageComponent';
...
...
@@ -24,11 +21,10 @@ export struct PageComponent {
// Group数据及子组件数据
// @State compList: LazyDataSource<CompDTO> = new LazyDataSource();
@State private pageModel: PageModel = new PageModel();
currentTopNavSelected
Index: number = 0;
nav
Index: number = 0;
pageId: string = "";
channelId: string = "";
// @Link @Watch('onChange') paIndex:number
@Link @Watch('onChange') currentTopNavSelectedIndex: number
build() {
Column() {
...
...
@@ -68,7 +64,7 @@ export struct PageComponent {
LazyForEach(this.pageModel.compList, (compDTO: CompDTO, compIndex: number) => {
ListItem() {
Column() {
this.componentBuilder(compDTO, compIndex)
CompParser({ compDTO: compDTO, compIndex: compIndex });
}
}
})
...
...
@@ -100,27 +96,21 @@ export struct PageComponent {
$r('app.media.ic_pull_up_load'), $r('app.string.pull_up_load_text'), this.pageModel.pullDownRefreshHeight) })
}
@Builder
componentBuilder(compDTO: CompDTO, compIndex: number) {
if (compDTO.compStyle === CompStyle.Label_03) {
LabelComponent({ compDTO: compDTO })
} 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
Text(compDTO.compStyle)
.width(CommonConstants.FULL_PARENT)
.padding(10)
// .backgroundColor(Color.Brown) // 展示本页未实现的compStyle
async aboutToAppear() {
// 选中tab,才请求数据。拦截大量接口请求
if (this.navIndex === this.currentTopNavSelectedIndex) {
this.getData();
}
}
async aboutToAppear() {
Logger.info(TAG, `aboutToAppear id: ${this.pageId} , ${this.channelId} , navIndex: ${this.currentTopNavSelectedIndex}`);
onChange() {
if (this.navIndex === this.currentTopNavSelectedIndex) {
this.getData();
}
}
async getData() {
Logger.info(TAG, `getData id: ${this.pageId} , ${this.channelId} , navIndex: ${this.currentTopNavSelectedIndex}`);
this.pageModel.pageId = this.pageId;
this.pageModel.groupId = this.pageId;
this.pageModel.channelId = this.channelId;
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/components/TopNavigationComponent.ets
View file @
c38bb9a
...
...
@@ -21,7 +21,12 @@ export struct TopNavigationComponent {
Tabs() {
ForEach(this.topNavList, (navItem: TopNavDTO, index: number) => {
TabContent() {
PageComponent({ currentTopNavSelectedIndex: index, pageId: navItem.pageId, channelId: navItem.channelId })
PageComponent({
currentTopNavSelectedIndex: $currentTopNavSelectedIndex,
navIndex: index,
pageId: navItem.pageId,
channelId: navItem.channelId
})
}
.tabBar(this.tabBarBuilder(navItem, index))
}, (navItem: TopNavDTO) => JSON.stringify(navItem));
...
...
Please
register
or
login
to post a comment