鸿蒙实现简单日报
时间:2023-03-21 22:40:21
科技观察
了解更多开源请访问:开源基础软件社区https://ost.51cto.com指南这是一篇文章讲解如何实现简单日报基于鸿蒙JS。1.可滚动区域在很多场景下,页面上都会有一块区域可以滚动。比如这样一个简单的每日新闻模块:上方的新闻类型是水平滚动区域,下方的新闻列表是垂直滚动区域。要滚动的区域。在鸿蒙js组件中,如果要实现一个可滚动的区域,需要用到列表组件。list只支持垂直滚动,tab用于水平滚动。2.list+list-item这里以本地新闻模块为例,从天行数据接口请求数据:https://www.tianapi.com/apiview/154顶部是一个搜索框,底部是新闻列表。搜索框的高度是固定的,那么如何让新闻列表占据屏幕的其余部分呢?只需将父容器设置为flex布局,将列表设置为flex即可:1.将list-item直接放在列表下方,总高度超过列表高度后即可上下滚动。hml:
{{$item.title}}{{$item.source}}{{$item.ctime}} css:/*本地新闻*/.searchView{width:100%;高度:140px;背景色:#f0f0f0;显示:弹性;对齐项目:中心;}.searchView>图像{边距:040px040px;高度:60px;width:60px;}.searchView>input{margin-right:40px;}.localView{width:100%;弹性:1;显示:弹性;flex-direction:column;}.localContent{margin-left:20px;}.newsItem{width:100%;高度:240px;border-bottom:1pxsolid#bbbbbb;显示:弹性;对齐项目:中心;}.newsContent{显示:flex;弹性方向:列;右边距:20px;margin-left:20px;}.newsContent>text{margin-top:20px;高度:140px;字体大小:34px;颜色:#333333;}.newsDesc{高度:60px;行高:60px;显示:弹性;只是ify-content:space-between;}.newsDesc>text{字体大小:28px;颜色:#777777;}js:searchLocalNews(){leturl='http://api.tianapi.com/areanews/index?key=xxxx&areaname=江苏';如果(this.searchWord){url=url+'&word'+this.searchWord;}fetch.fetch({url:url,responseType:'json',success:res=>{letdata=JSON.parse(res.data);this.localNews=data.newslist;}})},新闻列表可以滚动而不影响搜索框的位置3.list+list-item-group+list-itemlist组件list-item-group的子元素也可以是list-item-group,顾名思义,它应该是分组列表项,list-item是list-item-group的子元素。试用示例:
分组1子项1分组1子项2分组1子项3分组2子项1分组2子项2分组2子项3
.manageList{高度:100%;宽度:100%;}.list-item-group{宽度:100%;高度:450px;}.list-item{宽度:100%;高度:150px;显示:弹性;证明内容:居中;对齐项目:居中;border-bottom:1pxsolidgray;}.list-item>text{line-height:100px;}可见list-item-group是一个可折叠的列表分组,默认是折叠的。单击右侧的小箭头以展开列表。如果list-item-group给的是height,折叠展开后该区域的高度不变。折叠时,显示第一个列表项的内容。那么如果每个list-item-group中的list-item个数不固定的话,展开后的布局会很难看。如下:其实不定义list-item-group的高度就够了。折叠高度是列表项的高度。展开后高度自适应增长。它可以滚动到列表的高度之外。功能还是很强大的。更改css后的效果如下:这种分组列表可以做一个简单的后台管理系统菜单界面。这里我把菜单数据文件和图片文件放到nginx服务器的目录下,然后通过内网穿透访问资源。注意数据的格式。list-item-group和list-item之间存在父标签关系,所以数据中也应该存在父关系。list-item-group显示的内容是其下的第一个list-item,这里用双for循环实现:":"http://milkytea.free.idcfengye.com/images/christools/icon/org.png","subList":[{"name":"查询机构","icon":"http://milkytea.free.idcfengye.com/images/christools/icon/search.png"},{"name":"添加组织","icon":"http://milkytea.free.idcfengye.com/images/christools/icon/add.png"},{"name":"删除组织","icon":"http://milkytea.free.idcfengye.com/images/christools/icon/delete.png"}]},{"name":"人事管理","icon":"http://milkytea.free.idcfengye.com/images/christools/icon/person.png","subList":[{"name":"查询人”,"icon":"http://milkytea.free.idcfengye.com/images/christools/icon/search.png"},{"name":"加人","icon":"http://milkytea.free.idcfengye.com/images/christools/icon/add.png"},{"name":"批量导入人员","icon":"http://milkytea.free.idcfengye.com/images/christools/icon/add.png"},{"name":"删除人","icon":"http://milkytea.free.idcfengye.com/images/christools/icon/delete.png"},{"name":"Editor","icon":"http://milkytea.free.idcfengye.com/images/christools/icon/update.png"}]},{"name":"卡片管理","icon":"http://milkytea.free.idcfengye.com/images/christools/icon/card.png","subList":[{"name":"开卡","icon":"http://milkytea.free.idcfengye.com/images/christools/icon/add.png"},{"name":"退卡","icon":"http://milkytea.free.idcfengye.com/images/christools/icon/delete.png"}]}]}hml:
{{$item.name}}{{value.name}}
js:getManageList(){leturl="http://milkytea.free.idcfengye.com/text/manage.json";fetch.fetch({url:url,responseType:'json',success:res=>{letdata=JSON.parse(res.data);this.manageList=data.manageList;}})}想了解更多For更多开源信息请访问:开源基础软件社区https://ost.51cto.com