欢迎成都祈钰瑶科技有限公司!我们将竭诚为您服务
✕

成都企业级IDC服务,成都服务器托管租用,成都国产化定制服务器,成都BGP智能运维

鸿蒙js开发7鸿蒙分组列表和弹出Menu菜单

想了解更多内容,请访问:

和华为官方合作共建的鸿蒙技术社区

https://harmonyos./#zz

任正非:现在华为必须全面靠自己打造产品,要敢于将鸿蒙推入竞争,星光不问赶路人,时光不负有心人。

1.鸿蒙视图效果

点击menu菜单一项,跳转页面,底部菜单栏和轮播布局和轮播图

2.js业务数据和事件

 
 
 
 
  1. import prompt from '@system.prompt';
  2. import router from '@system.router';
  3. export default {
  4.     data: {
  5.         title: 'World',
  6.         fundatas:[{"fathermenu":"员工管理","childmenu":[{"icon":"/common/emp.png","text":"查询员工"},{"icon":"/common/emp.png","text":"添加员工"},{"icon":"/common/emp.png","text":"删除员工"},{"icon":"/common/emp.png","text":"更新员工"}]},
  7.                   {"fathermenu":"客户服务","childmenu":[{"icon":"/common/customer.png","text":"一卡通兑"},{"icon":"/common/customer.png","text":"银联服务"},{"icon":"/common/customer.png","text":"票据业务"}]},
  8.                   {"fathermenu":"内部管理","childmenu":[{"icon":"","text":""},{"icon":"","text":""},{"icon":"","text":""}]},
  9.                   {"fathermenu":"合同管理","childmenu":[{"icon":"","text":""},{"icon":"","text":""},{"icon":"","text":""}]},
  10.                   {"fathermenu":"资产管理","childmenu":[{"icon":"","text":""},{"icon":"","text":""},{"icon":"","text":""}]},
  11.                   {"fathermenu":"绩效管理","childmenu":[{"icon":"","text":""},{"icon":"","text":""},{"icon":"","text":""}]},
  12.         ]
  13.     },
  14.     clickitem(itemvalue)
  15.     {
  16.         if(itemvalue=="查询员工")
  17.         {
  18.             this.$element("menu").show({
  19.                 x: 360,
  20.                 y: 120
  21.             });
  22.             //this.$element("menu").show();
  23.         }
  24.         prompt.showToast({
  25.             message:"点击了菜单"+itemvalue
  26.         })
  27.     },
  28.     menuSelected(e) {
  29.         prompt.showToast({
  30.             message:"你选择查询的值是:"+e.value
  31.         })
  32.         router.push({
  33.             uri:"pages/index/index"
  34.         })
  35.     }
  36. }

 3.页面视图代码

  
 
 
 
  1. <div class="container">
  2.     
  3.     <list  class="listview">
  4.        <block  for="{{fundatas}}">
  5.            <list-item-group  class="groupview">
  6.                <list-item class="listitem">
  7.                    <text  class="tv1">{{$item.fathermenu}}</text>
  8.                </list-item>
  9.                <block  for="{{ (index,value)  in $item.childmenu}}">
  10.                  <list-item class="listitemone" onclick="clickitem({{value.text}})">
  11.                     <image  class="cimg"  src="{{value.icon}}"></image>
  12.                     <text class="tv2">{{value.text}}</text>
  13.                  </list-item>
  14.                </block>
  15.            </list-item-group>
  16.        
  17.        </block>
  18.     
  19.     
  20.     </list>
  21.     <menu id="menu"  title="员工性别"  onselected="menuSelected">
  22.         <option value="男性员工">
  23.             男性员工
  24.         </option>
  25.         <option value="女性员工">
  26.             女性员工
  27.         </option>
  28.     </menu>
  29. </div>

 4.样式代码

 
 
 
 
  1. .container {
  2.     width: 100%;
  3.     height: 1200px;
  4. }
  5. .listview{
  6.     width: 100%;
  7.     height: 100%;
  8. }
  9. .groupview{
  10.     width: 100%;
  11.     height: 46%;
  12.     border-bottom: 5px solid  #DCDCDC;
  13. }
  14. .listitem{
  15.     width: 100%;
  16.     height: 20%;
  17.     display: flex;
  18.     justify-content: space-around;
  19. }
  20. .listitemone {
  21.     width: 50%;
  22.     height: 6%;
  23.     border-bottom: 1px  solid  #DCDCDC;
  24.     display: flex;
  25.     justify-content: space-around;
  26. }
  27. .cimg{
  28.     width: 40px;
  29.     height: 40px;
  30. }
  31. .tv1{
  32.     font-size: 35px;
  33.     font-weight: bold;
  34.     font-family: sans-serif;
  35.     letter-spacing: 10px;
  36. }
  37. .tv2{
  38.     font-size: 34px;
  39.     font-weight: bold;
  40.     font-family: sans-serif;
  41. }

 5.跳转页面后的视图层

    
 
 
 
  1. <div  class="pageview">
  2.     <swiper  class="swiperview"   id="swiper" index="0" >
  3.         <div class ="sw1">
  4.             <swiper class="swiper1" id="swiper1" autoplay="true" index="0" indicator="true"  loop="true" digital="false">
  5.                 <div class = "swiperContent1" >
  6.                     <text class = "text" value="轮播图1"></text>
  7.                 </div>
  8.                 <div class = "swiperContent1">
  9.                     <text class = "text" value="轮播图2"></text>
  10.                 </div>
  11.                 <div class = "swiperContent1">
  12.                     <text class = "text" value="轮播图3"></text>
  13.                 </div>
  14.             </swiper>
  15.             <swiper class="swiper2" loop="true" vertical="true" indicator="false" autoplay="true">
  16.                      <div class="lineview">
  17.                        <text>1.鸿蒙</text>
  18.                      </div>
  19.                      <div class="lineview">
  20.                          <text>2.苹果</text>
  21.                      </div>
  22.                      <div class="lineview">
  23.                          <text>3.安卓</text>
  24.                      </div>
  25.             </swiper>
  26.         </div>
  27.         <div class ="sw2">
  28.             <list class="todo-wraper">
  29.                 <list-item for="{{todolist}}" class="todo-item">
  30.                     <text class="todo-title">{{$item.title}}</text>
  31.                     <text class="todo-title">{{$item.date}}</text>
  32.                 </list-item>
  33.             </list>
  34.         </div>
  35.         <div class ="sw3">
  36.             <tabs class = "tabs" index="0" vertical="false" onchange="change">
  37.                 <tab-bar class="tab-bar" mode="fixed">
  38.                     <text class="tab-text">推荐</text>
  39.                     <text class="tab-text">视频</text>
  40.                     <text class="tab-text">本地</text>
  41.                     <text class="tab-text">内容</text>
  42.                 </tab-bar>
  43.                 <tab-content class="tabcontent" scrollable="true">
  44.                     <div class="item-content" >
  45.                         <div class="currentview">
  46.                                 <div  class="leftview"><text class="infot1">{{weatherInfo.city}}</text></div>
  47.                                  <div class="rightview1">
  48.                                     <div  class="cell"><text>{{winfo.info}}</text></div>
  49.                                      <div class="cell"><text>{{winfo.direct}}</text></div>
  50.                                      <div class="cell"><text>{{winfo.power}}</text></div>
  51.                                  </div>
  52.                         </div>
  53.                         <div class="nextview">
  54.                         </div>
  55.                     </div>
  56.                     <div class="item-content" >
  57.                         <text class="item-title">第二个</text>
  58.                     </div>
  59.                     <div class="item-content" >
  60.                         <text class="item-title">第三个</text>
  61.                     </div>
  62.                     <div class="item-content" >
  63.                         <text class="item-title">第四个</text>
  64.                     </div>
  65.                 </tab-content>
  66.             </tabs>
  67.         </div>
  68.         <div class ="sw4">
  69.             <text>第四幅</text>
  70.         </div>
  71.     </swiper>
  72.     <div  class="bottommenu">
  73.         <div  for="{{menus}}"  class="menubox"  onclick="changemenu({{$idx}})">
  74.             <image  src="{{currentdata==$idx?$item.path:$item.path1}}" class="cimg"></image>
  75.            <text  class="menutitle">{{$item.menu}}</text>
  76.         </div>
  77.     </div>
  78. </div>

 6.js业务逻辑部分

 
 
 
 
  1. import   fetch  from '@system.fetch';
  2. export default {
  3.     data: {
  4.         weatherInfo:{},
  5.         winfo:{},
  6.         nextInfo:[],
  7.         currentdata:0,
  8.         title: "",
  9.         menus:[{menu:"首页","path":"./common/ones.png","path1":"./common/oneu.png"},
  10.                {menu:"分类","path":"./common/cs.png","path1":"./common/cu.png"},
  11.                {menu:"内容","path":"./common/cons.png","path1":"./common/conu.png"},
  12.                {menu:"我的","path":"./common/mys.png","path1":"./common/myu.png"}],
  13.        todolist: [{
  14.       title: '刷leetcode',
  15.       date: '2020-06-25 10:00:00',
  16.     }, {
  17.       title: '看电影',
  18.       date: '2020-06-27 20:00:00',
  19.     },
  20.                   {
  21.                       title: '刷leetcode',
  22.                       date: '2020-06-25 10:00:00',
  23.                   }, {
  24.                       title: '看电影',
  25.                       date: '2020-06-27 20:00:00',
  26.                   },{
  27.                       title: '刷leetcode',
  28.                       date: '2020-06-25 10:00:00',
  29.                   }, {
  30.                       title: '看电影',
  31.                       date: '2020-06-27 20:00:00',
  32.                   },{
  33.                       title: '刷leetcode',
  34.                       date: '2020-06-25 10:00:00',
  35.                   }, {
  36.                       title: '看电影',
  37.                       date: '2020-06-27 20:00:00',
  38.                   },
  39.                   {
  40.                       title: '刷leetcode',
  41.                       date: '2020-06-25 10:00:00',
  42.                   }, {
  43.                       title: '看电影',
  44.                       date: '2020-06-27 20:00:00',
  45.                   },
  46.                   {
  47.                       title: '刷leetcode',
  48.                       date: '2020-06-25 10:00:00',
  49.                   }, {
  50.                       title: '看电影',
  51.                       date: '2020-06-27 20:00:00',
  52.                   },{
  53.                       title: '刷leetcode',
  54.                       date: '2020-06-25 10:00:00',
  55.                   }, {
  56.                       title: '看电影',
  57.                       date: '2020-06-27 20:00:00',
  58.                   },{
  59.                       title: '刷leetcode',
  60.                       date: '2020-06-25 10:00:00',
  61.                   }, {
  62.                       title: '看电影',
  63.                       date: '2020-06-27 20:00:00',
  64.                   },{
  65.                       title: '刷leetcode',
  66.                       date: '2020-06-25 10:00:00',
  67.                   }, {
  68.                       title: '看电影',
  69.                       date: '2020-06-27 20:00:00',
  70.                   },
  71.                   {
  72.                       title: '刷leetcode',
  73.                       date: '2020-06-25 10:00:00',
  74.                   }, {
  75.                       title: '看电影',
  76.                       date: '2020-06-27 20:00:00',
  77.                   },{
  78.                       title: '刷leetcode',
  79.                       date: '2020-06-25 10:00:00',
  80.                   }, {
  81.                       title: '看电影',
  82.                       date: '2020-06-27 20:00:00',
  83.                   },{
  84.                       title: '刷leetcode',
  85.                       date: '2020-06-25 10:00:00',
  86.                   }, {
  87.                       title: '看电影',
  88.                       date: '2020-06-27 20:00:00',
  89.                   }
  90.        ]
  91.     },
  92.     onInit() {
  93.        // this.title = this.$t('strings.world');
  94.         let  that  =this;
  95.         fetch.fetch({
  96.             url:"http://apis.juhe.cn/simpleWeather/query?city=南京&key=3dc98f3428c44424088015738a070554",
  97.             responseType:"json",
  98.             success:function(resp)
  99.             {
  100.                 let  currentValue=JSON.parse(resp.data);
  101.                 that.weatherInfo=currentValue.result;
  102.                 that.winfo=currentValue.result.realtime;
  103.                // that.nextInfo=currentValue.future;
  104.             }
  105.         })
  106.     },
  107.     changemenu(index)
  108.     {
  109.         this.currentdata=index;
  110.         this.$element('swiper').swipeTo({index: index});
  111.     }
  112. }

 7.样式代码

 
 
 
 
  1. .pageview{
  2.     width: 100%;
  3.     height: 1600px;
  4.     background-color: azure;
  5. }
  6. .bottommenu{
  7.     width: 100%;
  8.     height: 140px;
  9.     background-color: snow;
  10.     border-top: 10px  solid  black;
  11.     z-index:999;
  12.     position: fixed;
  13.     left: 0px;
  14.     bottom: 0px;
  15.     display: flex;
  16.     justify-content: center;
  17.     align-items: center;
  18. }
  19. .menubox{
  20.     width: 22%;
  21.     height: 90%;
  22.     /**border:9px  solid  #ccff6a;**/
  23.     margin-left: 20px;
  24.     display: flex;
  25.     flex-direction: column;
  26.     justify-content: center;
  27.     align-items: center;
  28. }
  29. .menutitle{
  30.     color: black;
  31.     font-weight: bold;
  32.     letter-spacing: 4px;
  33. }
  34. .cimg{
  35.     width: 40px;
  36.     height: 40px;
  37. }
  38. .swiperview{
  39.     width: 100%;
  40.     height: 100%;
  41. }
  42. .sw1{
  43.     width: 100%;
  44.     height: 100%;
  45.     display: flex;
  46.     flex-direction: column;
  47. }
  48. .sw2{
  49.     width: 100%;
  50.     height: 100%;
  51.     background-color: cornflowerblue;
  52. }
  53. .sw3{
  54.     width: 100%;
  55.     height: 100%;
  56.     background-color: #ccff6a;
  57. }
  58. .sw4{
  59.     width: 100%;
  60.     height: 100%;
  61.     background-color: #009865;
  62. }
  63. .swiper1 {
  64.     width: 100%;
  65.     height: 330px;
  66.     border: 1px solid #000000;
  67.     indicator-color: #cf2411;
  68.     indicator-size: 14px;
  69.     indicator-bottom: 20px;
  70.     indicator-right: 30px;
  71.     margin-top: 100px;
  72. }
  73. .swiperContent1 {
  74.     width: 800px;
  75.     height: 100%;
  76.     justify-content: center;
  77. }
  78. .button {
  79.     width: 70%;
  80.     margin: 10px;
  81. }
  82. .text {
  83.     font-size: 40px;
  84. }
  85. .swiper2{
  86.     width: 100%;
  87.     height: 100px;
  88.     background-color: powderblue;
  89. }
  90. .lineview{
  91.     width: 100%;
  92.     height: 100%;
  93. }
  94. .todo-wraper {
  95.     width: 100%;
  96.     height: 100%;
  97. }
  98. .todo-item {
  99.     width: 100%;
  100.     height: 80px;
  101.     flex-direction: row;
  102.     display: flex;
  103. }
  104. .todo-title {
  105.     width: 454px;
  106.     height: 40px;
  107.     text-align: center;
  108. }
  109. .tabs {
  110.     width: 100%;
  111. }
  112. .tab-bar {
  113.     margin: 10px;
  114.     height: 60px;
  115.     border-color: #007dff;
  116.     border-width: 1px;
  117. }
  118. .tab-text {
  119.     width: 300px;
  120.     text-align: center;
  121. }
  122. .tabcontent {
  123.     width: 100%;
  124.     height: 80%;
  125.     justify-content: center;
  126. }
  127. .item-content {
  128.     height: 100%;
  129.     justify-content: center;
  130.     display: flex;
  131.     flex-direction: column;
  132. }
  133. .item-title {
  134.     font-size: 60px;
  135. }
  136. .currentview{
  137.     width: 100%;
  138.     height: 30%;
  139.     border-bottom: 4px  solid  peru;
  140.     display: flex;
  141. }
  142. .nextview{
  143.     width: 100%;
  144.     height: 70%;
  145. }
  146. .leftview{
  147.     width: 30%;
  148.     height: 100%;
  149.     border-right