|
|
@@ -5,21 +5,23 @@ import { BasicType, YtAvoid, yTRouter, yTToast } from 'basic';
|
|
|
struct Index {
|
|
|
@State currentIndex: number = 0
|
|
|
@StorageProp(YtAvoid.safeBottomKey) bottom: number = 0
|
|
|
+ //tabs展示内容
|
|
|
contentList: BasicType<undefined>[] = [
|
|
|
{
|
|
|
text: '首页',
|
|
|
src: this.currentIndex == 0 ? $r('app.media.app_icon') : $r('app.media.app_icon'),
|
|
|
- index: 0
|
|
|
},
|
|
|
{
|
|
|
text: '福利',
|
|
|
src: this.currentIndex == 1 ? $r('app.media.app_icon') : $r('app.media.app_icon'),
|
|
|
- index: 1
|
|
|
+ },
|
|
|
+ {
|
|
|
+ text: '福利',
|
|
|
+ src: this.currentIndex == 1 ? $r('app.media.app_icon') : $r('app.media.app_icon'),
|
|
|
},
|
|
|
{
|
|
|
text: '我的',
|
|
|
src: this.currentIndex == 2 ? $r('app.media.app_icon') : $r('app.media.app_icon'),
|
|
|
- index: 2
|
|
|
}
|
|
|
]
|
|
|
tabsController: TabsController = new TabsController()
|
|
|
@@ -35,9 +37,18 @@ struct Index {
|
|
|
Navigation(yTRouter) {
|
|
|
Column() {
|
|
|
Tabs({ controller: this.tabsController }) {
|
|
|
- ForEach(this.contentList, (item: BasicType<undefined>, index) => {
|
|
|
+ ForEach(this.contentList, (_: BasicType<undefined>, index) => {
|
|
|
TabContent() {
|
|
|
- Text(item.text)
|
|
|
+ if (index == 0) {
|
|
|
+ //放对应组件
|
|
|
+ Text(_.text)
|
|
|
+ } else if (index == 1) {
|
|
|
+ Text(_.text)
|
|
|
+ } else if (index == 2) {
|
|
|
+ Text(_.text)
|
|
|
+ } else {
|
|
|
+ Text(_.text)
|
|
|
+ }
|
|
|
}
|
|
|
})
|
|
|
}
|
|
|
@@ -49,7 +60,10 @@ struct Index {
|
|
|
|
|
|
Row() {
|
|
|
ForEach(this.contentList, (item: BasicType<undefined>, index) => {
|
|
|
- this.barBuilder(item)
|
|
|
+ this.barBuilder((() => {
|
|
|
+ item.index = index
|
|
|
+ return item
|
|
|
+ })())
|
|
|
})
|
|
|
}
|
|
|
.justifyContent(FlexAlign.SpaceAround)
|
|
|
@@ -81,7 +95,6 @@ struct Index {
|
|
|
.onClick(() => {
|
|
|
this.currentIndex = item.index!
|
|
|
this.tabsController.changeIndex(this.currentIndex)
|
|
|
-
|
|
|
})
|
|
|
}
|
|
|
}
|