《仿盒马》app开发技术分享-- 个人中心页面(19)

鸿蒙小林
• 阅读 5

技术栈

Appgallery connect

开发准备

上一节我们实现了分类页面的所有联动效果,这一节我们要开始完成一个新的页面,这个页面是我们主界面的第四个板块,就是个人中心页面。在这个模块,我们可以显示一些用户信息,以及用户相关的各类功能的入口

功能分析

要实现个人中心页面,首先我们要规划好整体的布局,我们选择从上到下实现,分为三块,一块显示用户信息,一块显示关键信息,一块用来展示用户相关的各种入口列表

代码实现

因为我们要实现列表所以我们需要先创建实体类并且填充对应的数据

export class SectionLine { title: string; subtitle: string; url: string|ResourceStr; showDividerLine: boolean

constructor(title: string, subtitle: string, url: string|ResourceStr,showDividerLine:boolean) { this.title = title; this.subtitle = subtitle; this.url = url; this.showDividerLine=showDividerLine; }

} 这里的url 类型我们注意写成多类型,这样后期我们的内容要修改,我们的改动就会比较小

然后添加数据,我们暂时只添加三个入口

import { SectionLine } from "../entity/SectionLine";

export class SectionLineViewModel { getSectionListOne():Array{ let listData:SectionLine[]=[ new SectionLine("订单", "", $r('app.media.order'), true), new SectionLine("地址簿", "设置常用地址", $r('app.media.address'), false), ] return listData }

getSectionListTwo():Array{ let listData:SectionLine[]=[

  new SectionLine("关于",
    "",
    $r('app.media.guanyu'),
    true),
]
return listData

} }

export default new SectionLineViewModel(); 添加完成后我们来到页面完善我们设计的三块内容

import { SectionLine } from '../entity/SectionLine'; import SectionLineViewModel from '../model/SectionLineViewModel';

@Component export struct Mine {

@State num:number=0 @Builder MenuItem(item: SectionLine){ Column(){ Row(){ Image(item.url).width(20).height(20) .objectFit(ImageFit.Cover) .interpolation(ImageInterpolation.High) Text(item.title) .margin({left:10}) .fontColor("#ff333333") .fontSize(16)

    Blank()
    Text(item.subtitle)
      .fontColor($r('app.color.color_999'))
      .fontSize(14)
      .margin({right:6})
    Image($r('app.media.back_right_recycle'))
      .width(7).height(13)
      .objectFit(ImageFit.Contain)
      .interpolation(ImageInterpolation.High)
  }
  .padding({left:13,right:13})
  .alignItems(VerticalAlign.Center)
  .height($r('app.float.size_49'))
  .width('100%')
  .backgroundColor(Color.White)
  if (item.showDividerLine){
    Divider().width('100%').height(0.8)
      .color("#e6e6e6")
  }

}
.width('100%')

}

aboutToAppear(){

}

build() { Column() {

  Stack({alignContent:Alignment.Top}){
    Row().width('100%')
      .height('100%')
      .linearGradient({
        angle:180,
        colors: [[0xff0000, 0], [0xff6666, 0.2], [0xffffff, 1]]
      })
    Column(){
      Row() {
        Image($r('app.media.background'))
          .height(55)
          .width(55)
          .borderRadius(27)
          .objectFit(ImageFit.Contain)
          .interpolation(ImageInterpolation.High)
        Column() {
          Text('用户111')
            .fontSize(24)
            .maxLines(1)
            .textOverflow({ overflow: TextOverflow.Ellipsis })
          Text('vip6')
            .fontSize(14)
        }
        .alignItems(HorizontalAlign.Start)
        .margin({ left: 10 })
        Blank()
          .layoutWeight(1)
        Image($r('app.media.ic_arrow_bold'))
          .height(16)
          .width(16)
          .margin(20)
          .objectFit(ImageFit.Contain)
          .interpolation(ImageInterpolation.High)
      }
      .justifyContent(FlexAlign.Start)
      .margin({top: 30 })

      Row(){
        Row(){
          Image($r('app.media.balance'))
            .margin({left:8})
            .height(34)
            .width(34)
            .objectFit(ImageFit.Contain)
            .interpolation(ImageInterpolation.High)
          Column(){
            Text("¥15")
              .fontSize(16)
              .fontColor($r('app.color.color_333'))
            Row(){
              Text("余额")
                .fontSize(13)
                .fontColor($r('app.color.color_999'))
              Image($r('app.media.back_right_recycle'))
                .margin({left:6})
                .height(14)
                .width(14)
                .objectFit(ImageFit.Contain)
                .interpolation(ImageInterpolation.High)
            }
          }
          .alignItems(HorizontalAlign.Start)
          .margin({left:13})
          .onClick(()=>{
          })
        }
        .width('40%')
        Divider()
          .vertical(true)
          .height('100%').margin({top:5,bottom:5})
          .margin({left:20})
        Row(){
          Image($r('app.media.points'))
            .height(34)
            .width(34)
            .objectFit(ImageFit.Contain)
            .interpolation(ImageInterpolation.High)
          Column(){
            Text("积分商城")
              .fontSize(16)
              .fontColor($r('app.color.color_333'))
            Row(){
              Text("积分兑换")
                .fontSize(13)
                .fontColor($r('app.color.color_reds'))
              Image($r('app.media.back_right_recycle'))
                .margin({left:6})
                .height(14)
                .width(14)
                .objectFit(ImageFit.Contain)
                .interpolation(ImageInterpolation.High)
            }

          }
          .margin({left:8})
          .alignItems(HorizontalAlign.Start)
        }
        .margin({left:8})
        .alignItems(VerticalAlign.Center)
        .width('40%')

      }
      .justifyContent(FlexAlign.Start)
      .height(80)
      .width('100%')
      .padding(8)
      .margin({top:40})
      .backgroundColor(Color.White)
      .borderRadius(8)
    }
    .padding({left:12,right:12})
    .height('100%')
    .justifyContent(FlexAlign.Center)
  }
  .height(180)

  Column(){
    ForEach(SectionLineViewModel.getSectionListOne(),(item:SectionLine)=>{
      this.MenuItem(item)
    })
  }
  .borderRadius(10)
  .margin({top:35,left:12,right:12})
  Column(){
    ForEach(SectionLineViewModel.getSectionListTwo(),(item:SectionLine)=>{
      this.MenuItem(item)
    })
  }
  .width('100%')
  .borderRadius(10)
  .margin({top:10,left:12,right:12})

}
.height('100%')
.backgroundColor("#f7f7f7")
.justifyContent(FlexAlign.Start)
.alignItems(HorizontalAlign.Start)

} } 到这里我们就实现了个人中心的静态页面了

点赞
收藏
评论区
推荐文章
鸿蒙小林 鸿蒙小林
11小时前
《仿盒马》app开发技术分享-- 分类模块顶部导航列表弹窗(16)
技术栈Appgalleryconnect开发准备上一节我们实现了分类页面的顶部导航栏列表,并且实现了首页金刚区跟首页导航栏的联动,这一节我们实现导航栏列表的弹窗功能,需要学习的知识点有自定义弹窗,同时我们的数据源需要跟分类页保持一一致。功能分析1.弹窗自定
鸿蒙小林 鸿蒙小林
4小时前
《仿盒马》app开发技术分享-- 分类左侧列表(17)
技术栈Appgalleryconnect开发准备上一节我们实现了分类页面的顶部导航栏全选弹窗列表,并实现了跟顶部列表的点击选中联动效果,这一节我们要实现的功能是,分类模块的左侧列表,它同样也需要跟弹窗列表的点击,顶部列表的点击有联动的效果功能分析1.列表展
鸿蒙小林 鸿蒙小林
4小时前
《仿盒马》app开发技术分享-- 用户登陆页面(静态)(20)
技术栈Appgalleryconnect开发准备上一节我们实现了个人中心页面的静态展示,项目进行到这里呢,我们也是时候添加用户相关的内容了,因为到了后期,我们的数据都是跟用户绑定的,各个用户之间的数据并不互通,现在为了实现我们的用户绑定制度,我们需要给应用
鸿蒙小林 鸿蒙小林
4小时前
《仿盒马》app开发技术分享-- 个人中心页or静态头像选择(业务逻辑)(22)
技术栈Appgalleryconnect开发准备上一节我们实现了登录页面的业务逻辑,并且成功的实现了数据的查询,同时我们新增了用户首选项的工具类,现在主界面往登录页面跳转,登录成功后我们关闭登录页面,这时候我们就会回到个人中心页面,那么现在我们的业务逻辑是
鸿蒙小林 鸿蒙小林
4小时前
《仿盒马》app开发技术分享-- 个人信息页(23)
技术栈Appgalleryconnect开发准备上一节我们实现了个人中心的业务逻辑,实现了个人信息修改后的动态更换,而且实现了一个静态的头像选择弹窗,但是这个弹窗我们并没有使用。这一节我们在个人信息页面就会使用到这个弹窗并且还涉及其他的弹窗。以及信息的同步
鸿蒙小林 鸿蒙小林
4小时前
《仿盒马》app开发技术分享-- 地址管理页(24)
技术栈Appgalleryconnect开发准备上一节我们实现了个人信息页面的信息展示和页面修改,并且实现了数据的同步修改,这一节我们来实现电商应用里比较重要的模块,地址模块。首先我们来实现地址的展示。功能分析地址列表的展示相对来说是比较简单的,首先我们要
鸿蒙小林 鸿蒙小林
4小时前
《仿盒马》app开发技术分享-- 商品搜索页(顶部搜索bar&热门搜索)(37)
技术栈Appgalleryconnect开发准备随着开发功能的逐渐深入,我们的应用逐渐趋于完善,现在我们需要继续在首页给没有使用按钮以及组件添加对应的功能,这一节我们要实现的功能是商品搜索页面,这个页面我们从上到下开始实现功能,首先就是一个搜索的bar,然
鸿蒙小林 鸿蒙小林
4小时前
《仿盒马》app开发技术分享-- 个人中心页优化(62)
技术栈Appgalleryconnect开发准备上一节我们实现了订单逻辑的优化,现在我们的app功能更加的完善了,并且随着我们的迭代逻辑疏漏越来越少,现在我们继续进行优化,在之前的业务逻辑中我们的个人中心页面展示了用户的余额以及积分商城入口,这里我们要展示
鸿蒙小林 鸿蒙小林
4小时前
《仿盒马》app开发技术分享-- 我的积分页(63)
技术栈Appgalleryconnect开发准备上一节我们实现了个人中心页面的业务逻辑优化,成功的在用户登陆退出状态下展示对应的组件内容,这一节我们来实现app中另外一个比较重要的模块积分模块。功能分析因为我们的回收订单是跟回收金积分是绑定的,我们在完成回
鸿蒙小林 鸿蒙小林
4小时前
《仿盒马》app开发技术分享-- 待发货兑换订单列表(76)
技术栈Appgalleryconnect开发准备上一节我们实现了兑换订单展示页面的框架,这一节我们要进行兑换订单的展示,在兑换订单提交后,默认的状态是待发货状态,我们用列表的方式展示出来功能分析进入页面时我们就要通过用户的userid去查询对应的订单,获取