《仿盒马》app开发技术分享-- 首页商品流(7)

鸿蒙小林
• 阅读 3

技术栈

Appgallery connect

开发准备

上一节我们实现了首页banner模块的功能,现在我们的首页还需要添加商品列表,作为一个购物类应用,商品列表是非常重要的一个模块,所以我们尽量把它设计的足够完善,参数能更好的支持我们后期复杂的逻辑,它需要有图片的展示,适配的优惠券列表,限购,立减,划线价等,但他实际的参数还要更多,因为我们的列表是比较紧凑的,更多的数据需要从点击后的商品详情页展示出来。

代码实现 创建商品表 { "objectTypeName": "home_product_list", "fields": [ {"fieldName": "id", "fieldType": "Integer", "notNull": true, "belongPrimaryKey": true}, {"fieldName": "goods_list_id", "fieldType": "Integer", "notNull": true, "defaultValue": 0}, {"fieldName": "url", "fieldType": "String"}, {"fieldName": "name", "fieldType": "Text"}, {"fieldName": "price", "fieldType": "Double"}, {"fieldName": "original_price", "fieldType": "Double"}, {"fieldName": "amount", "fieldType": "Integer"}, {"fieldName": "text_message", "fieldType": "String"}, {"fieldName": "parameter", "fieldType": "String"}, {"fieldName": "delivery_time", "fieldType": "String"}, {"fieldName": "endTime", "fieldType": "String"}, {"fieldName": "sales_volume", "fieldType": "Integer"}, {"fieldName": "space_id", "fieldType": "Integer"}, {"fieldName": "max_loop_amount", "fieldType": "Integer"}, {"fieldName": "promotion_spread_price", "fieldType": "Double"}, {"fieldName": "coupon_id", "fieldType": "Integer"} ], "indexes": [ {"indexName": "field1IndexId", "indexList": [{"fieldName":"id","sortType":"ASC"}]} ], "permissions": [ {"role": "World", "rights": ["Read"]}, {"role": "Authenticated", "rights": ["Read", "Upsert"]}, {"role": "Creator", "rights": ["Read", "Upsert", "Delete"]}, {"role": "Administrator", "rights": ["Read", "Upsert", "Delete"]} ] }

填充数据

{ "cloudDBZoneName": "default", "objectTypeName": "home_product_list", "objects": [ { "id": 10, "goods_list_id": 1, "url": "在线图片链接", "name": "红颜草莓", "price": 10.5, "original_price": 18.5, "amount": 10, "text_message": "特价", "parameter": "冷藏", "delivery_time": "付款后24小时内发货", "endTime": "直降 | 结束时间2025年5月18日 10:00", "sales_volume": 9812, "space_id": 10, "max_loop_amount": 10, "promotion_spread_price": 5, "coupon_id": 10 }, { "id": 20, "goods_list_id": 1, "url": "在线图片链接", "name": "麒麟瓜", "price": 2.8, "original_price": 5.9, "amount": 1, "text_message": "当季新品", "parameter": "冷藏", "delivery_time": "付款后24小时内发货", "endTime": "直降 | 结束时间2025年5月18日 10:00", "sales_volume": 9812, "space_id": 11, "max_loop_amount": 10, "promotion_spread_price": 0, "coupon_id": 10 } ] }

我们接下来进行数据的查询 @State homeProduct:HomeProductList[]=[]//商品流数据

  let databaseZone = cloudDatabase.zone('default');
  let home_product=new cloudDatabase.DatabaseQuery(home_product_list);
  let list7 = await databaseZone.query(home_product);
  let json7 = JSON.stringify(list7)
  let data7:HomeProductList[]= JSON.parse(json7)
  this.homeProduct=data7

数据查出完成后,完善商品流的页面

import { HomeProductList } from "../entity/home_product_list"

@Component @Preview export struct WaterFlowGoods { @Link goodsList: Array

@State columns: number = 2

build() { WaterFlow() { ForEach(this.goodsList, (item:HomeProductList, index) => { FlowItem() { Column() { Image(item.url) .width('100%') .aspectRatio(1) .objectFit(ImageFit.Cover) .borderRadius({topLeft:10,topRight:10})

        Column() {
          Text(item.name)
            .fontSize(16)
            .fontColor('#333')
            .margin({ bottom: 4 })

          Text(item.text_message)
            .fontSize(12)
            .fontColor('#666')
            .margin({ bottom: 8 })


          Text("最高立减"+item.promotion_spread_price)
            .fontSize(12)
            .fontColor('#ffffff')
            .visibility(item.promotion_spread_price>0?Visibility.Visible:Visibility.None)
            .margin({ bottom: 8 })
            .padding({left:5,right:5,top:2,bottom:2})
            .linearGradient({
              angle:90,
              colors: [[0xff0000, 0], [0xff6666, 0.2], [0xff6666, 1]]
            })

          Row(){
            Text("限购")
              .width(40)
              .fontSize(12)
              .borderRadius(20)
              .backgroundColor("#FB424C")
              .padding(3)
              .textAlign(TextAlign.Center)
              Text("每人限购"+item.max_loop_amount+"件")
                .margin({left:5})
                .fontSize(12)
                .fontColor("#FB424C")
          }
          .borderRadius(20)
          .padding({top:2,bottom:2,right:10})
          .backgroundColor("#FEE3E3")
          .visibility(item.amount>0?Visibility.Visible:Visibility.None)

          Row() {
            Text(){
              Span("¥")
                .fontColor(Color.Red)
                .fontSize(14)

              Span(String(item.price))
                .fontSize(16)
                .fontColor(Color.Red)
            }
            Text(String(item.original_price))
              .fontSize(12)
              .fontColor('#999')
              .decoration({
                type: TextDecorationType.LineThrough,
                color: Color.Gray
              })
              .margin({left:10})


             Blank()
            Column() {
              Image($r('app.media.cart'))
                .width(20)
                .height(20)
            }
            .justifyContent(FlexAlign.Center)
            .width(36)
            .height(36)
            .backgroundColor("#ff2bd2fa")
            .borderRadius(18)
            }
            .margin({top:10})
            .width('100%')
            .justifyContent(FlexAlign.SpaceBetween)



        }
        .alignItems(HorizontalAlign.Start)
        .padding(12)
      }
      .backgroundColor(Color.White)
      .borderRadius(12)
      .onClick(() => {
      })
    }
    .margin({ bottom: 12 })
  })
}
.padding(10)
.columnsTemplate('1fr 1fr')
.columnsGap(12)
.onAreaChange((oldVal, newVal) => {
  this.columns = newVal.width > 600 ? 2 : 1
})

} } 然后在首页调用,传入参数 WaterFlowGoods({goodsList:this.homeProduct}) 到这里我们就实现了首页商品列表的内容

点赞
收藏
评论区
推荐文章
鸿蒙小林 鸿蒙小林
9小时前
《仿盒马》app开发技术分享-- 首页活动配置(5)
技术栈Appgalleryconnect开发准备上一篇文章中我们实现了项目端云一体化首页部分模块动态配置,实现了对模块模块的后端控制显示和隐藏,这能让我们的app更加的灵活,也能应对更多的情况。现在我们来对配置模块进行完善,除了已有的模块以外,我们还有一些
鸿蒙小林 鸿蒙小林
9小时前
《仿盒马》app开发技术分享-- 首页banner(6)
技术栈Appgalleryconnect开发准备上一篇文章中我们实现了项目端云一体化首页商品活动入口列表,现在我们还差一个banner的模块,banner模块不仅可以用于展示一些信息,还可以在点击之后进行,跳转,弹窗,升级提示,信息提示等作用,我们直接坐的
鸿蒙小林 鸿蒙小林
9小时前
《仿盒马》app开发技术分享-- 首页地址选择&会员码(8)
技术栈Appgalleryconnect开发准备上一节我们实现了商品流标的创建,数据的填充和展示,并且在商品信息表中添加了许多我们后去需要使用到的参数。让我们的首页功能更加的丰富,截至目前首页板块可以说是完成了百分之五十了,跟展示有关的基本都已完成,接下来
鸿蒙小林 鸿蒙小林
9小时前
《仿盒马》app开发技术分享-- 加入购物车&加购列表展示(12)
技术栈Appgalleryconnect开发准备上一节我们实现了商品详情页面的规格选择弹窗,这在任何购物类应用中都是最常用的功能之一。当然了,作为一个购物类的应用,我们仅仅展示是用处不大的,我们还需要有添加的动作。这一节我们就来实现添加到购车里并且在购物车
鸿蒙小林 鸿蒙小林
9小时前
《仿盒马》app开发技术分享-- 购物车功能完善(14)
技术栈Appgalleryconnect开发准备上一节我们实现了购物车商品列表的状态切换,已添加商品数量的增减,已添加商品滑动删除,已添加商品在选中情况下的价格计算。这一节我们在这些功能的基础上实现云端记录,因为我们现在只有数据的查询是从云端获取的,其他的
鸿蒙小林 鸿蒙小林
9小时前
《仿盒马》app开发技术分享-- 分类模块顶部导航列表弹窗(16)
技术栈Appgalleryconnect开发准备上一节我们实现了分类页面的顶部导航栏列表,并且实现了首页金刚区跟首页导航栏的联动,这一节我们实现导航栏列表的弹窗功能,需要学习的知识点有自定义弹窗,同时我们的数据源需要跟分类页保持一一致。功能分析1.弹窗自定
鸿蒙小林 鸿蒙小林
2小时前
《仿盒马》app开发技术分享-- 扫一扫功能(35)
技术栈Appgalleryconnect开发准备随着app的逐渐完善,我们现在需要在细节处做更多的打磨,在首页我们添加了很多静态的按钮和组件,现在我们开始对这些组件进行功能的添加,这次首先实现的是首页头部的扫一扫功能,扫一扫我们实现扫码后跳转商品详情页功能
鸿蒙小林 鸿蒙小林
2小时前
《仿盒马》app开发技术分享-- 商品搜索页(顶部搜索bar&热门搜索)(37)
技术栈Appgalleryconnect开发准备随着开发功能的逐渐深入,我们的应用逐渐趋于完善,现在我们需要继续在首页给没有使用按钮以及组件添加对应的功能,这一节我们要实现的功能是商品搜索页面,这个页面我们从上到下开始实现功能,首先就是一个搜索的bar,然
鸿蒙小林 鸿蒙小林
2小时前
《仿盒马》app开发技术分享-- 商品搜索页(搜索记录&商品搜索)(38)
技术栈Appgalleryconnect开发准备上一节我们新建了商品搜索页,实现了顶部的搜索bar以及下方的推荐搜索列表,这一节我们要新增一个商品搜索记录列表,以及输入内容之后搜索出对应商品的功能,我们还需要保证搜索内容的唯一性,以及搜索记录的本地数据持久
鸿蒙小林 鸿蒙小林
2小时前
《仿盒马》app开发技术分享-- 领取优惠券(56)
技术栈Appgalleryconnect开发准备在之前的功能开发中,我们有些功能只有展示的能力并没有与云端产生任何的交互,后续经过我们的迭代,更多的能力有了交互能力,这一节我们就要开始着手给那些静态展示的模块添加业务逻辑,我们现在要实现的是首页的新人优惠券