《仿盒马》app开发技术分享-- 积分页组件新增(64)

举报
yd_215151764 发表于 2025/06/30 10:44:40 2025/06/30
【摘要】 ## 技术栈Appgallery connect## 开发准备上一节我们创建了积分页,给页面添加了标题栏和积分展示的组件。这一节我们继续丰富积分页的内容,添加引导栏,积分明细展示等区域## 功能分析因为页面的关联不强,我们采用组件引入的方式实现引导栏,同时,在下方继续添加对应的tabs组件,方便我们积分明细的展示和查看## 代码实现首先我们实现引导栏的内容```cssimport route...


## 技术栈

Appgallery connect

## 开发准备
上一节我们创建了积分页,给页面添加了标题栏和积分展示的组件。这一节我们继续丰富积分页的内容,添加引导栏,积分明细展示等区域


## 功能分析
因为页面的关联不强,我们采用组件引入的方式实现引导栏,同时,在下方继续添加对应的tabs组件,方便我们积分明细的展示和查看


## 代码实现
首先我们实现引导栏的内容

```css

import router from '@ohos.router'

@Component
export struct CenterButton {
  iconList:ESObject[]=[{
    icon:$r('app.media.jifendengji'),
    name:"积分等级"
  },{
    icon:null,
    name:""
  },{
    icon:$r('app.media.jifenduihuan'),
    name:"积分兑换"
  }]
  @Builder
  IconBar(){
    Row(){
      ForEach(this.iconList,(item:ESObject,index)=>{
        this.IconButton(item,index)
      })
    }
    .IconBarBg()
    .height(80)
    .borderRadius(10)
    .width('100%')
    .padding({left:50,right:50})
    .justifyContent(FlexAlign.SpaceBetween)
  }
  @Builder
  IconButton(item:ESObject,index:number){
    Column(){
      Image(item.icon)
        .height(20)
        .width(20)
        .objectFit(ImageFit.Contain)
        .interpolation(ImageInterpolation.High)
      Text(item.name)
        .margin({top:6})
        .fontColor("#000000")
        .fontSize(14)
    }
    .onClick(()=>{
      switch (item.name) {
        case "积分等级":
          router.pushUrl({url:''})
          break;
        case "":
          break;
        case "积分兑换":
          router.pushUrl({url:''})
          break;
        default:
          break;
      }
    })
  }
  build() {
    Row() {
      this.IconBar()
    }
    .padding({left:12,right:12})
    .margin({top:14})
    .width(
      '100%'
    )
  }
}
@Extend(Row) function IconBarBg(){
  .linearGradient({
    angle: 180,
    colors: [[0xff0000, 0], [0xff6666, 0.5], [0xffffff, 1]]

  })
}

```
在引导栏中我们给按钮添加点击事件,方便我们后期跳转到对应的页面。


然后我们开始实现tabs,我们通过@Builder的方式创建标题栏,同时添加对应的切换事件

```css
@State arr:string[]=["全部","获得",'兑换']
  @State fontColor: string = '#182431'
  @State selectedFontColor: string = '#007DFF'
  @State currentIndex: number = 0
  private controller: TabsController = new TabsController()
```

```css
@Builder TabBuilder(index: number, name: string) {
    Column() {
      Text(name)
        .fontColor(this.currentIndex === index ? this.fontColor : this.fontColor)
        .fontSize(this.currentIndex === index ? 16:15)
        .fontWeight(this.currentIndex === index ? FontWeight.Bold : FontWeight.Normal)
        .lineHeight(22)
      Divider()
        .strokeWidth(3)
        .width(30)
        .color(0xff0000)
        .opacity(this.currentIndex === index ? 1 : 0)
        .margin({top:2})
    }
    .height(50)
    .width('100%')
    .justifyContent(FlexAlign.Center)
  }
```
创建完标题栏我们添加tabs

```css

      Tabs({ barPosition: BarPosition.Start, controller: this.controller }) {
        ForEach(this.arr,(item:string,index)=>{
          TabContent() {
            Column(){
              if (item=='全部') {
              }
              if (item=='获得') {
              }
              if (item=='兑换') {
              }
            }
          }
          .tabBar(this.TabBuilder(index, item))
          .borderRadius(10)
          .backgroundColor(Color.White)
        })
      }
      .vertical(false)
      .barMode(BarMode.Fixed)
      .barWidth('100%')
      .barHeight(50)
      .backgroundColor(Color.White)
      .animationDuration(300)
      .onChange((index: number) => {
        this.currentIndex = index
      })
      .width('100%')
      .height('100%')
      .layoutWeight(1)
      .margin({ top: 10 })
```
到这里我们的积分页组件就全部添加上了,后续我们开始实现对应的逻辑

【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。