import { FirstPage } from './FirstPage'
@Entry
@Component
struct Index {
mainPageState: boolean | undefined
@State fontColor: string = ‘#182431’
@State selectedFontColor: string = ‘#007DFF’
@State currentIndex: number = 0
private controller: TabsController = new TabsController()
@State mainPageChange:number = 0
@Builder tabBuilder(index: number, name: string) {
Column() {
Text(name)
.fontColor(this.currentIndex === index ? this.selectedFontColor : this.fontColor)
.fontSize(16)
.fontWeight(this.currentIndex === index ? 500 : 400)
.lineHeight(22)
.margin({ top: 17, bottom: 7 })
Divider()
.strokeWidth(2)
.color(’#007DFF’)
.opacity(this.currentIndex === index ? 1 : 0)
}.width(‘100%’)
}
build() {
Column() {
Tabs({ barPosition: BarPosition.End, index: this.currentIndex, controller: this.controller }) {
TabContent() {
Column().width(‘100%’).height(‘100%’).backgroundColor(’#FFBF00’)
}.tabBar(this.tabBuilder(0, ‘首页’))
TabContent() {
Column().width(‘100%’).height(‘100%’).backgroundColor(’#007DFF’)
}.tabBar(this.tabBuilder(1, ‘咨询’))
TabContent() {
FirstPage({mainPageChange:this.mainPageChange}).width(‘100%’).height(‘100%’).backgroundColor(’#00CB87’)
}.tabBar(this.tabBuilder(2, ‘我的’))
}
.vertical(false)
.barMode(BarMode.Fixed)
.barWidth(‘100%’)
.barHeight(56)
.animationDuration(400)
.onChange((index: number) => {
this.currentIndex = index
if (index == 2) {
console.log(‘展示了我的页面’)
this.mainPageChange = new Date().getTime();
}
})
.width(‘100%’)
.height(‘100%’)
// .margin({ top: 52 })
.backgroundColor(’#F1F3F5’)
}.width(‘100%’)
}
onPageShow(): void {
console.log(‘index— onPageShow’)
// this.mainPageState = true
this.mainPageChange = new Date().getTime();
}
onPageHide(): void {
console.log(‘index— onPageHide’)
this.mainPageState = false
}
}