第十八讲_HarmonyOS应用开发实战(实现电商首页)

HarmonyOS应用开发实战(实现电商首页)

  • [1. 项目涉及知识点罗列](#1. 项目涉及知识点罗列)
  • [2. 项目目录结构介绍](#2. 项目目录结构介绍)
  • [3. 最终的效果图](#3. 最终的效果图)
  • [4. 部分源码展示](#4. 部分源码展示)

1. 项目涉及知识点罗列

  • 掌握HUAWEI DevEco Studio开发工具
  • 掌握创建HarmonyOS应用工程
  • 掌握ArkUI自定义组件
  • 掌握@Entry@Component@Builder等装饰器
  • 掌握@State@Link等状态管理装饰器
  • 掌握ColumnRowFlexListTextImageTabsScroll等系统组件
  • 掌握资源的定义和应用

2. 项目目录结构介绍

3. 最终的效果图

4. 部分源码展示

typescript 复制代码
import Home from '../components/Home';
import { MainPageConstants } from '../constants/MainPageConstants';
import { TabBarData, tabBarData } from '../viewmodel/MainPageData';

/*
* 电商主页
*/
@Entry
@Component
struct MainPage {
  @State currentIndex: number = 0;

  // 自定义底部导航图标
  @Builder TabBar(tabBarData: TabBarData) {
    Column({space: MainPageConstants.TAB_SPACE}) {
      Image(this.currentIndex === tabBarData.index ? tabBarData.selectImg : tabBarData.img)
        .height($r('app.float.main_page_tab_image_size'))
        .width($r('app.float.main_page_tab_image_size'))
      Text(tabBarData.title)
        .fontSize($r('app.float.main_page_tab_title_size'))
        .fontColor(this.currentIndex === tabBarData.index ? $r('app.color.main_page_tar_title_select_color') : Color.Black)
    }
  }

  build() {
    Tabs({
      index: this.currentIndex,
      barPosition: BarPosition.End
    }) {
      // 首页
      TabContent() {
        Home()
      }
      .tabBar(this.TabBar(tabBarData[0]))

      // 新品
      TabContent() {
        Column() {
          Text($r('app.string.main_page_tab_product'))
            .fontSize($r('app.float.product_page_text_size'))
        }
        .height(MainPageConstants.FULL_HEIGHT)
        .width(MainPageConstants.FULL_WIDTH)
        .justifyContent(FlexAlign.Center)
      }
      .tabBar(this.TabBar(tabBarData[1]))

      // 购物车
      TabContent() {
        Column() {
          Text($r('app.string.main_page_tab_cart'))
            .fontSize($r('app.float.product_page_text_size'))
        }
        .height(MainPageConstants.FULL_HEIGHT)
        .width(MainPageConstants.FULL_WIDTH)
        .justifyContent(FlexAlign.Center)
      }
      .tabBar(this.TabBar(tabBarData[2]))

      // 我的
      TabContent() {
        Column() {
          Text($r('app.string.main_page_tab_personal'))
            .fontSize($r('app.float.product_page_text_size'))
        }
        .height(MainPageConstants.FULL_HEIGHT)
        .width(MainPageConstants.FULL_WIDTH)
        .justifyContent(FlexAlign.Center)
      }
      .tabBar(this.TabBar(tabBarData[3]))
    }
    .backgroundColor($r('app.color.main_page_background_color'))
    .onChange((index: number) => {
      this.currentIndex = index;
    })
  }
}

ps:需要完整源码的同学,可以在评论区留言!!!

相关推荐
GISer_Jing8 分钟前
Three.js着色器编译机制深度解析
javascript·webgl·着色器
丷丩10 分钟前
MapLibre GL JS第22课:查看本地GeoJSON
前端·javascript·map·mapbox·maplibre gl js
AI玫瑰助手11 分钟前
Python函数:默认参数的定义与注意事项
开发语言·python·信息可视化
不羁的木木18 分钟前
HarmonyOS文件基础服务(Core File Kit)实战演练04-文件监听与流式读写
华为·harmonyos
油炸自行车19 分钟前
Claude Code 错误:API Error: 400 Failed to deserialize the JSON body into the
开发语言·javascript·json·trae·claude code·api error 400
肩上风骋27 分钟前
C++14特性
开发语言·c++·c++14特性
不羁的木木1 小时前
ArkWeb实战学习笔记05-综合实战:构建混合应用
笔记·学习·harmonyos
JAVA社区2 小时前
Java高级全套教程(十)—— SpringCloudAlibaba超详细实战详解
java·开发语言·spring cloud·面试·职场和发展
弥树子2 小时前
踩坑记录:服务器内网调用接口,真实请求URL与官方公开URL不一致问题排查
开发语言·php
z落落2 小时前
C# ToCharArray + foreach遍历 + String与StringBuilder
开发语言·c#