《仿盒马》app 开发技术分享 -- 首页商品流(7)
技术栈
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[]=[]//商品流数据
数据查出完成后,完善商品流的页面
import { HomeProductList } from "../entity/home_product_list"
@Component@Previewexport struct WaterFlowGoods {@Link goodsList: Array<HomeProductList>
@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})
}}然后在首页调用,传入参数 WaterFlowGoods({goodsList:this.homeProduct})到这里我们就实现了首页商品列表的内容
评论