中国优质的IT技术网站
专业IT技术创作平台
IT职业在线教育平台
微信扫码分享
@Entry @Component export default struct OrderPage { @State message: string = 'Hello OrderPage' @State subCurrentIndex: number = 0 @State parentCurrentIndex: number = 0 @State fontColor: string = '#000000' @State selectFontColor: string = '#00A73B' private parentTabBgkColor:string = '#F5F6F9' private parentTabBgkSelColor: string = '#00A73B' private parentTabs: string[] = ['订水订单','商城订单'] private subTabs: string[] = ['今天','预约','全部'] build() { Tabs({barPosition: BarPosition.Start}){ TabContent(){ Column(){ Tabs(){ TabContent(){ Text('今天').fontSize(20).fontColor(Color.Blue) }.tabBar('今天') TabContent(){ Text('预约').fontSize(20).fontColor(Color.Pink) }.tabBar('预约') TabContent(){ Text('全部').fontSize(20).fontColor(Color.Orange) }.tabBar('全部') }.divider({strokeWidth: 1,color: '#F1F2F4'}).onChange(index => this.subCurrentIndex = index) } }.tabBar(this.ParentTabBuilder(0)) TabContent(){ Text('商城订单页面').fontSize(50).fontWeight(FontWeight.Bold) }.tabBar(this.ParentTabBuilder(1)) }.barWidth(200).barHeight(30) .divider({strokeWidth: 1,color: '#F1F2F4'}).barMode(BarMode.Fixed) .barBackgroundColor(Color.White) // .background(this.ParentTabBarBgk()) .padding(0) .onChange(index => this.parentCurrentIndex = index) } @Builder ParentTabBarBgk(){ Text() .size({width: 100,height: 30}) // .borderWidth(1) .borderRadius({ topLeft: 20, bottomLeft:20 }) .backgroundColor(this.parentTabBgkColor) } @Builder ParentTabBarBgk1(){ Text() .size({width: 100,height: 30}) // .borderWidth(1) .borderRadius({ topRight: 20, bottomRight:20 }) .backgroundColor(this.parentTabBgkColor) } @Builder ParentTabBuilder(index: number){ /*Button(this.parentTabs[index],{type:ButtonType.Capsule,stateEffect: false}).backgroundColor(this.parentCurrentIndex === index ? this.parentTabBgkSelColor : this.parentTabBgkColor) .fontColor(this.parentCurrentIndex === index ? Color.White : Color.Black)*/ if (index===0){ Stack(){ this.ParentTabBarBgk() Text(this.parentTabs[index]) .border({ width: 0, radius: 20 }) .padding({left: 16,right: 16,top: 5,bottom: 5}) .backgroundColor(this.parentCurrentIndex === index ? this.parentTabBgkSelColor : this.parentTabBgkColor) .fontColor(this.parentCurrentIndex === index ? Color.White : Color.Black) } }else { Stack(){ this.ParentTabBarBgk1() Text(this.parentTabs[index]) .border({ width: 0, radius: 20 }) .padding({left: 16,right: 16,top: 5,bottom: 5}) .backgroundColor(this.parentCurrentIndex === index ? this.parentTabBgkSelColor : this.parentTabBgkColor) .fontColor(this.parentCurrentIndex === index ? Color.White : Color.Black) } } } @Builder SubTabBuilder(index: number){ Text(this.subTabs[index]) .fontColor(index === this.subCurrentIndex ? this.selectFontColor : this.fontColor) .borderWidth(2) .borderColor(index === this.subCurrentIndex ? this.selectFontColor : this.fontColor) } }