#鸿蒙通关秘籍#在HarmonyOS NEXT中如何构建个人中心页面?

HarmonyOS
2024-11-28 16:17:19
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
系统小魔头

可以按如下方式实现个人中心页面:

@Entry
@Component
export default struct Mine {
  pageStack: NavPathStack = new NavPathStack()

  private favButtons: FavBtnItem[] = [
    {count: 0, title: "收藏影视", pagePath: ""},
    {count: 0, title: "播放历史", pagePath: ""},
    {count: 0, title: "收藏音乐", pagePath: ""},
    {count: 0, title: "我的足迹", pagePath: ""},
  ];

  private listButtons: ListBtnItem[] = [
    {title: "我的消息", pagePath: ""},
    {title: "意见反馈", pagePath: ""},
    {title: "分享链接", pagePath: ""},
    {title: "检查更新", pagePath: ""},
    {title: "关于我们", pagePath: ""},
  ];

  private funButtons: FunBtnItem[] = [
    {title: "电视直播", color: '#00FF00', icon: 'app.media.camera_video', pagePath: ""},
    {title: "本地视频", color: '#00FF00', icon: 'app.media.music', pagePath: ""},
    {title: "本地图片", color: '#00FF00', icon: 'app.media.music', pagePath: ""},
    {title: "在线音乐", color: '#00FF00', icon: 'app.media.music', pagePath: ""},
    {title: "播放链接", color: '#00FF00', icon: 'app.media.music', pagePath: ""},
  ];

  build() {
    Navigation(this.pageStack) {
      Column() {
        Column(){
            Button('登录').width(120).fontColor(Color.Green)
              .align(Alignment.Center).backgroundColor(Color.White);
        }
        .justifyContent(FlexAlign.Center)
        .backgroundColor('rgba(85, 170, 255,0.6)')
        .size({ width: '100%', height: 200 });

        Row({space: 30}){
          ForEach(this.favButtons, (item: FavBtnItem, idx) => {
            Column({space: 2}){
              Text(item.count.toString());
              Text(item.title).fontColor('#AAAAAA');
            }
          });
        }
        .justifyContent(FlexAlign.Center)
        .backgroundColor(Color.White)
        .width('100%').height(80);

        // 功能列表
        Column(){
          Text('功能列表').width('100%').padding(10);
          Grid() {
            ForEach(this.funButtons, (item: FunBtnItem, idx) => {
              GridItem() {
                Column({space: 2}){
                  Image($r(item.icon)).width(32).fillColor(item.color);
                  Text(item.title).fontSize(14);
                }
              }
            });
          }
          .rowsTemplate('1fr 1fr')
          .columnsTemplate('1fr 1fr 1fr 1fr')
          .width('100%').height(150);
        }.width('100%').height(200).justifyContent(FlexAlign.Start).backgroundColor(Color.White);

        // 菜单项
        List({ space: 15 }) {
          ForEach(this.listButtons, (item: ListBtnItem, idx) => {
            ListItem(){
              Row(){
                Text(item.title).layoutWeight(12);
                Text('>').fontColor('#AAAAAA').layoutWeight(1);
              }
            }
          });
        }.divider({strokeWidth: 2, color: '#F1F3F5'})
        .padding(10);
      }
      .backgroundColor('F4F4F4')
      .size({ width: '100%', height: '100%' });
    }
    .mode(NavigationMode.Stack)
    .titleMode(NavigationTitleMode.Mini)
    .title("我的")
    .hideBackButton(true)
    .width('100%').height('100%');
  }
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.

此代码利用Column、Row和Grid布局构建了页面,动态生成了收藏项、功能按钮及菜单项。

分享
微博
QQ
微信
回复
2024-11-28 16:11:11


相关问题