HarmonyOS NEXT开发实战教程—淘宝搜索页
今天忙里偷闲,分享一个淘宝搜索页实现过程,先上效果图:

界面部分比较简单,大体分为导航栏、历史搜索、猜你想搜和热搜榜几个部分,历史搜索采用用户首选项进行存储数据。
导航栏部分相关代码如下:
Flex({direction:FlexDirection.Row,wrap:FlexWrap.NoWrap,alignItems:ItemAlign.Center}){ Image($r('app.media.back')) .width(30) .height(30) .objectFit(ImageFit.Contain) Flex({direction:FlexDirection.Row,wrap:FlexWrap.NoWrap,alignItems:ItemAlign.Center}){ TextInput({placeholder:'长款羽绒服',text:this.searchText}) .width('100%') .placeholderColor(Color.Gray) .fontSize(14) .backgroundColor('rgb(226,226,226)') .enterKeyType(EnterKeyType.Search) .onChange((str)=>{ this.searchText = str }) .onSubmit(()=>{ this.saveHistory(this.searchText) this.searchText = '' }) Image($r('app.media.scan')) .width(22) .height(22) .margin({left:5}) .constraintSize({minWidth:22}) .objectFit(ImageFit.Contain) Text('搜索') .width(60) .height(28) .backgroundColor(Color.Orange) .borderRadius(4) .fontColor(Color.White) .textAlign(TextAlign.Center) .fontSize(12) .margin({left:5}) } .padding({left:5,right:5}) .width('100%') .height(34) .backgroundColor('rgb(226,226,226)') .borderRadius(8) .margin({left:5})}.padding({left:10,right:10}).width('100%').backgroundColor(Color.White).height(45)
历史搜索部分采用Flex布局实现:
Flex({direction:FlexDirection.Row,wrap:FlexWrap.Wrap}){ ForEach(this.hisList,(str:string,index)=>{ Text(str) .fontColor('#4a4a4a') .fontSize(12) .padding({left:6,right:6,top:4,bottom:4}) .borderWidth(1) .borderColor('rgb(216,216,216)') .borderStyle(BorderStyle.Solid) .margin({left:5,top:5}) .textAlign(TextAlign.Center) .borderRadius(4) })}
猜你想搜部分,同样使用Flex布局:
Flex({direction:FlexDirection.Row,wrap:FlexWrap.Wrap}){ ForEach(this.guessList,(str:string,index)=>{ Text(str) .fontColor('#4a4a4a') .fontSize(15) .margin({top:6}) .width('50%') })}
热搜榜部分使用一个Scroll和一个Swiper实现联动效果:
Column(){ Scroll(this.scrollController){ Row({space:30}){ ForEach(this.hotTitleList,(str:string,index)=>{ Text(str) .fontSize(15) .fontColor(this.hotIndex == index?Color.Orange:Color.Gray) .fontWeight(this.hotIndex == index?FontWeight.Bold:FontWeight.Normal) .onClick(()=>{ this.hotIndex = index this.swiperController.changeIndex(this.hotIndex,true) }) }) } .height(45) .alignItems(VerticalAlign.Center) } .scrollable(ScrollDirection.Horizontal) .scrollBar(BarState.Off) .width('100%') Swiper(this.swiperController){ ForEach(this.hotTitleList,(str:string,index)=>{ Column(){ ForEach(this.hotContentList,(str:string,index)=>{ Row(){ Row(){ Text((index+1).toString()) .fontSize(15) .fontColor('#4a4a4a') .fontWeight(FontWeight.Bold) .width(40) .textAlign(TextAlign.Center) Text(str) .fontSize(15) .fontColor('#4a4a4a') } Text('热度100万') .fontSize(12) .fontColor(Color.Gray) } .width('100%') .height(40) .justifyContent(FlexAlign.SpaceBetween) .alignItems(VerticalAlign.Center) .borderRadius(10) .margin({top:8}) .linearGradient({ angle: 90, colors: [[index<3?0xfff8f3:0xf9f9f9, 0.0], [index<4?0xfffbfa:0xfcfcfc, 0.4], [0xffffff, 1.0]] }) }) } .width('100%') .alignItems(HorizontalAlign.Start) }) } .vertical(false) .indicator(false) .loop(false) .onAnimationEnd((index: number, extraInfo: SwiperAnimationEvent) => { this.hotIndex = index console.info("index: " + index) console.info("current offset: " + extraInfo.currentOffset) const xOffset: number = this.scrollController.currentOffset().xOffset; this.scrollController.scrollTo({ xOffset: index*70, yOffset: 0 }) })}
HarmonyOS NEXT开发实战教程—淘宝搜索页的更多相关文章
- 学习用java基于webMagic+selenium+phantomjs实现爬虫Demo爬取淘宝搜索页面
由于业务需要,老大要我研究一下爬虫. 团队的技术栈以java为主,并且我的主语言是Java,研究时间不到一周.基于以上原因固放弃python,选择java为语言来进行开发.等之后有时间再尝试pytho ...
- Swift游戏开发实战教程(霸内部信息大学)
Swift游戏开发实战教程(大学霸内部资料) 试读下载地址:http://pan.baidu.com/s/1sj7DvQH 介绍:本教程是国内第一本Swift游戏开发专向资料. 本教程具体解说记忆配对 ...
- JS实现选择菜单栏(配合慕课网淘宝搜索框的课程)
以下是关于实现慕课网淘宝搜索框的JS代码,不过只有选择菜单栏(其余比较容易实现). <!doctype html> <html> <head> <!--在IE ...
- selenium+PhantomJS 抓取淘宝搜索商品
最近项目有些需求,抓取淘宝的搜索商品,抓取的品类还多.直接用selenium+PhantomJS 抓取淘宝搜索商品,快速完成. #-*- coding:utf-8 -*-__author__ =''i ...
- asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发4- 后台模板html页面创建
上一篇教程<asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发3-登录模块开发>完成了本项目的登录模块,登录后就需要进入后台管理首页了,需要准备一个后台模 ...
- asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发2-Model层建立
上篇(asp.net mvc+jquery easyui开发实战教程之网站后台管理系统开发1-准备工作)文章讲解了开发过程中的准备工作,主要创建了项目数据库及项目,本文主要讲解项目M层的实现,M层这里 ...
- 微信小程序-云开发实战教程
微信小程序-云开发实战教程 云函数,云存储,云数据库,云调用 https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/gettin ...
- JS仿淘宝详情页菜单条智能定位效果
类似于淘宝详情页菜单条智能定位 对于每个人来说并不陌生!如下截图所示:红色框的那部分! 基本原理: 是用JS侦听滚动事件,当页面的滚动距离(页面滚动的高度)大于或者等于 "对象"( ...
- Web——在淘宝搜索到看到商品
[摘自]http://blog.renren.com/blog/254459622/799372165 浏览器首先查询DNS服务器,将www.taobao.com转换成ip地址.负载均衡的第一步,将你 ...
- Python开发实战教程(8)-向网页提交获取数据
来这里找志同道合的小伙伴!↑↑↑ Python应用现在如火如荼,应用范围很广.因其效率高开发迅速的优势,快速进入编程语言排行榜前几名.本系列文章致力于可以全面系统的介绍Python语言开发知识和相关知 ...
随机推荐
- flutter-延时执行
//1秒后这个i行 Future.delayed(Duration(milliseconds: 1000), () { //代码省略 });
- [WC2006] 水管局长 题解
最大值最小的路径肯定在最小生成树上,考虑用 \(LCT\) 维护最小生成树,只需要维护长度最长的边即可实现.由于 \(LCT\) 维护最小生成树不支持删边,所以采用倒序加边的方式处理. 时间复杂度 \ ...
- 推荐几款开源且免费的 .NET MAUI 组件库
前言 今天大姚给大家推荐 3 款开源且免费的 .NET MAUI 组件库. .NET MAUI介绍 .NET 多平台应用 UI (.NET MAUI) 是一个跨平台框架,用于使用 C# 和 XAML ...
- Thymeleaf 嵌套循环
<label th:each="role:${roles}" class="check-box"> <input th:each=" ...
- FastAPI路由:微服务架构下的路由艺术与工程实践 🌐
title: FastAPI路由专家课:微服务架构下的路由艺术与工程实践 date: 2025/3/4 updated: 2025/3/4 author: cmdragon excerpt: 用API ...
- Windows 提权-RunAs
本文通过 Google 翻译 RunAs – Windows Privilege Escalation 这篇文章所产生,本人仅是对机器翻译中部分表达别扭的字词进行了校正及个别注释补充. 导航 0 前言 ...
- 记录使用wsl环境nginx代理超时的处理方法
有问题的配置 set $webpack_server http://127.0.0.1:3030; location ~ ^/static-dist { proxy_pass $webpack_ser ...
- nnUNet 论文解析
一些废话: 毕业论文用 nnUNet 及其自带的功能大概做了一个医学图像的分割模块.现将自己在学习过程中看过的相关论文及相关能找到的笔记记录整理在此.一些浅显的内容目的是在为自己做记录的同时,也希望能 ...
- SetupFactory-脚本
1.写注册表 lResult = Registry.DoesKeyExist(HKEY_LOCAL_MACHINE, "SOFTWARE\\MapInfo\\MapX\\5.0") ...
- SLAM建图导航信息(仿真)
博客地址:https://www.cnblogs.com/zylyehuo/ 基于[基于机器人自主移动实现SLAM建图],详见之前的博客 基于机器人自主移动实现SLAM建图 - zylyehuo - ...