-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
项目界面
- Loading branch information
Showing
8 changed files
with
124 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,61 @@ | ||
// 导入页面路由模块 | ||
import router from '@ohos.router'; | ||
import { ProjectItem } from '../bean/ProjectBean'; | ||
import Constants from '../common/constants/Constants'; | ||
import ProjectList from '../view/ProjectList'; | ||
import ProjectViewModel from '../viewmodel/ProjectViewModel'; | ||
|
||
/** | ||
* @desc:3-项目 | ||
*/ | ||
|
||
@Entry | ||
@Component | ||
export default struct ProjectPage { | ||
|
||
@State projectData: ProjectItem[] = []; | ||
@State currentIndex: number = 0; | ||
@State optionsDic: Map<number, number> = new Map(); | ||
//页面即将显示时 | ||
aboutToAppear() { | ||
//1-项目分类 | ||
ProjectViewModel.getProject().then(result => { | ||
ProjectViewModel.getProject().then((result: ProjectItem[]) => { | ||
console.log('project>>>', result) | ||
this.projectData = result | ||
this.projectData.forEach((project, index) => { | ||
this.optionsDic[index] = project.id //将tab_index对应的cid放到map中 | ||
}) | ||
}) | ||
//2-项目列表 | ||
ProjectViewModel.getProjectList(1, 294).then(result => { | ||
console.log('getProjectList>>>', result) | ||
} | ||
|
||
//自定义Tab | ||
@Builder TabBuilder(index: number) { | ||
Column() { | ||
Text(this.projectData[index].name) | ||
.height(Constants.FULL_PERCENT) | ||
.fontSize(this.currentIndex === index ? $r('app.float.24fp') : $r('app.float.18fp')) | ||
.fontWeight(this.currentIndex === index ? Constants.TYPE_FONT_WEIGHT : Constants.DESC_FONT_WEIGHT) | ||
.fontColor($r('app.color.black')) | ||
} | ||
.padding({ left: $r('app.float.8vp'), right: $r('app.float.8vp') }) | ||
.margin({ | ||
left: index === 0 ? $r('app.float.8vp') : 0, | ||
right: index === this.projectData.length - 1 ? $r('app.float.8vp') : 0 | ||
}) | ||
} | ||
|
||
build() { | ||
Row() { | ||
Column() { | ||
Text("项目") | ||
.fontSize(50) | ||
.fontWeight(FontWeight.Bold) | ||
} | ||
.width('100%') | ||
Tabs({ barPosition: BarPosition.Start }) { | ||
ForEach(this.projectData, (projectItem: ProjectItem, index?: number) => { | ||
TabContent() { | ||
ProjectList({ index, optionsDic: this.optionsDic, currentIndex: $currentIndex }) | ||
}.tabBar(this.TabBuilder(index)) | ||
}, (tabItem: ProjectItem) => JSON.stringify(tabItem)) | ||
} | ||
.height('100%') | ||
.barHeight($r('app.float.50vp')) | ||
.height(Constants.FULL_PERCENT) | ||
.barMode(BarMode.Scrollable) | ||
.onChange((index: number) => { | ||
this.currentIndex = index; | ||
}) | ||
.vertical(false) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* @desc:项目-列表 | ||
*/ | ||
import { Article, ArticleList } from '../bean/ArticleBean'; | ||
import ProjectViewModel from '../viewmodel/ProjectViewModel'; | ||
import ArticleItem from './ArticleItem'; | ||
|
||
@Component | ||
export default struct ProjectList { | ||
index: number = 0; | ||
optionsDic: Map<number, number> = new Map | ||
@Watch('changeTab') @Link currentIndex: number; | ||
@State articleListData: ArticleList = new ArticleList(); | ||
|
||
//与@Watch('changeTab')中的changeTab保持一致。 @Watch装饰器:状态变量更改通知 @Link装饰器:父子双向同步 | ||
changeTab() { | ||
if (this.currentIndex !== this.index) { | ||
return; | ||
} | ||
//2-项目列表 | ||
ProjectViewModel.getProjectList(1, this.optionsDic[this.currentIndex]).then((data: ArticleList) => { | ||
console.log('getProjectList>>>', data) | ||
this.articleListData = data | ||
}) | ||
// ProjectViewModel.getProjectList(1, 294).then((data: ArticleList) => { | ||
// this.articleListData = data | ||
// }) | ||
} | ||
|
||
aboutToAppear() { | ||
// Load data. | ||
this.changeTab() | ||
} | ||
|
||
build() { | ||
//Article | ||
List() { | ||
ForEach(this.articleListData.datas, (article: Article) => { | ||
ListItem() { | ||
ArticleItem({ article: article }) | ||
} | ||
}) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters