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

开发
文章由鸿蒙社区产出,想要了解更多内容请前往:51CTO和华为官方战略合作共建的鸿蒙技术社区https://harmonyos.51cto.com/#zz

[[378755]]

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

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

https://harmonyos.51cto.com/#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.  
  17.         if(itemvalue=="查询员工"
  18.         { 
  19.             this.$element("menu").show({ 
  20.                 x: 360, 
  21.                 y: 120 
  22.             }); 
  23.             //this.$element("menu").show(); 
  24.  
  25.         } 
  26.         prompt.showToast({ 
  27.             message:"点击了菜单"+itemvalue 
  28.  
  29.         }) 
  30.     }, 
  31.     menuSelected(e) { 
  32.         prompt.showToast({ 
  33.             message:"你选择查询的值是:"+e.value 
  34.         }) 
  35.  
  36.         router.push({ 
  37.             uri:"pages/index/index" 
  38.  
  39.         }) 
  40.  
  41.  
  42.     } 

 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.  
  22.  
  23.     <menu id="menu"  title="员工性别"  onselected="menuSelected"
  24.         <option value="男性员工"
  25.             男性员工 
  26.         </option
  27.         <option value="女性员工"
  28.             女性员工 
  29.         </option
  30.  
  31.     </menu> 
  32. </div> 

 4.样式代码

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

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

 6.js业务逻辑部分

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

 7.样式代码

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

 ©著作权归作者和HarmonyOS技术社区共同所有,如需转载,请注明出处,否则将追究法律责任.

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

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

https://harmonyos.51cto.com/#zz

 

责任编辑:jianghua 来源: 鸿蒙社区
相关推荐

2021-01-26 09:50:06

鸿蒙HarmonyOS远程调用

2009-06-19 08:29:36

Windows 7微软操作系统

2021-01-21 12:04:05

Windows 10UI界面微软

2021-02-22 14:56:55

鸿蒙HarmonyOS应用开发

2021-01-28 14:34:35

鸿蒙HarmonyOS应用开发

2012-03-07 15:13:07

PhoneGapmenu菜单

2021-08-05 15:06:30

鸿蒙HarmonyOS应用

2021-01-08 09:55:17

鸿蒙HarmonyOS组装列表

2014-04-08 17:35:24

iOS 7弹簧式列表

2009-11-10 09:00:50

2021-02-04 09:45:19

鸿蒙HarmonyOS应用开发

2009-07-15 13:31:51

Swing菜单和菜单项

2020-11-11 11:56:05

HarmonyOS

2011-04-22 19:29:57

Windows Emb嵌入式开发

2009-04-23 08:59:37

Windows 7微软操作系统

2009-04-15 08:54:19

Windows 7微软操作系统

2022-08-09 16:01:24

应用开发鸿蒙

2009-09-24 08:28:21

Windows 7新功能任务栏

2012-05-14 10:33:43

Coding4Fun

2009-12-11 09:07:59

点赞
收藏

51CTO技术栈公众号