当前位置:   article > 正文

鸿蒙页面菜单的选择_鸿蒙backgroundimage

鸿蒙backgroundimage

主要界面截图

 

所有未显示的代码均在前面发的文档中可找到

search.css代码

  1. .search-container {
  2. padding: 10px 15px;
  3. }
  4. .search-input {
  5. height: 40px;
  6. width: 100%;
  7. justify-content: center;
  8. align-items: center;
  9. border-radius: 6px;
  10. border: 0.5px solid #ee742f;
  11. }
  12. .search-input-image {
  13. width: 20px;
  14. height: 20px;
  15. }
  16. .search-input-text {
  17. font-size: 12px;
  18. font-weight: 100;
  19. }
  20. .index-inner-bg {
  21. background-color: #fff;
  22. }
  23. .cate-inner-bg {
  24. background-color: #f2f2f2;
  25. border-width: 0;
  26. }
  27. .index-outer-bg {
  28. background-color: #f2f2f2;
  29. }
  30. .cate-outer-bg {
  31. background-color: #fff;
  32. }

 search.hml代码

  1. <div class="search-container {{from==='cate' ?'cate-outer-bg':'index-outer-bg'}}">
  2. <div class="search-input {{from==='cate' ?'cate-inner-bg':'index-inner-bg'}}">
  3. <image src="/common/images/search.png"></image>
  4. <text>搜索</text>
  5. </div>
  6. </div>

 search.js代码

  1. export default{
  2. props:['from']
  3. }

 cookbook-category.json代码,其余两个在之前博客有

  1. {
  2. "data": {
  3. "category": {
  4. "热门": ["饮品", "清淡", "夏季菜谱", "下饭菜", "面食", "粥", "晚餐", "汤", "面条", "汤圆", "烤箱", "中餐", "西餐", "早餐", "蛋糕", "东北菜", "凉拌", "煲汤", "布丁", "寿司", "糕点", "糖水", "湘菜", "甜点"],
  5. "菜式": ["家常菜", "素菜", "凉菜", "下饭菜", "面试", "小吃", "粥", "汤"],
  6. "菜系": ["川菜", "东北菜", "粤菜", "湘菜", "西餐", "鲁菜", "韩式料理", "日式料理"],
  7. "特色": ["泡菜", "冰淇淋", "粽子", "沙拉", "油条", "豆浆", "零食", "布丁"],
  8. "烘焙": ["蛋糕", "披萨", "面包", "月饼", "吐司", "饼干", "杯子蛋糕", "蛋挞"],
  9. "主食": ["寿司", "饼", "炒饭", "馒头", "饺子", "炒面"],
  10. "器具": ["烤箱", "炒锅", "微波炉"],
  11. "烹饪方式": ["烘焙", "拌", "火锅", "蒸", "煮", "卤"],
  12. "口味": ["清淡", "咖喱", "麻辣", "香辣", "煮", "卤"],
  13. "场合": ["早餐", "晚餐", "中餐", "下午茶", "宵夜", "熬夜餐", "春季菜谱"],
  14. "节日": ["春节", "年夜饭", "中秋节", "元旦"]
  15. },
  16. "material": {
  17. "肉类": ["猪肉", "排骨", "猪蹄", "牛肉"],
  18. "蛋/奶": ["鸡蛋", "鸭蛋", "鹌鹑蛋", "咸鸭蛋", "松花蛋"],
  19. "鱼类": ["章鱼", "鲤鱼", "鲫鱼"],
  20. "水产": ["虾", "虾米", "龙虾", "河虾"],
  21. "蔬菜": ["白菜", "油菜", "芹菜", "菠菜", "茼蒿"],
  22. "豆类": ["绿豆芽", "黄豆芽", "黄豆"],
  23. "果品类": ["苹果", "香蕉"],
  24. "五谷杂粮": ["芥麦面", "麦芽", "小米"],
  25. "药食": ["燕窝", "人参"]
  26. }
  27. }
  28. }

index.css代码

  1. .container {
  2. flex-direction: column;
  3. justify-content: center;
  4. align-items: center;
  5. width: 100%;
  6. height: 100%;
  7. }
  8. .title {
  9. font-size: 40px;
  10. color: #000000;
  11. opacity: 0.9;
  12. }
  13. @media screen and (device-type: tablet) and (orientation: landscape) {
  14. .title {
  15. font-size: 100px;
  16. }
  17. }
  18. @media screen and (device-type: wearable) {
  19. .title {
  20. font-size: 28px;
  21. color: #FFFFFF;
  22. }
  23. }
  24. @media screen and (device-type: tv) {
  25. .container {
  26. background-image: url("/common/images/Wallpaper.png");
  27. background-size: cover;
  28. background-repeat: no-repeat;
  29. background-position: center;
  30. }
  31. .title {
  32. font-size: 100px;
  33. color: #FFFFFF;
  34. }
  35. }
  36. @media screen and (device-type: phone) and (orientation: landscape) {
  37. .title {
  38. font-size: 60px;
  39. }
  40. }

 index.hml代码

  1. <element name='comp' src='../../components/tabbar/tabbar.hml'></element>
  2. <div class="container">
  3. <!-- <text class="title">
  4. 关于我们
  5. </text>-->
  6. <div>
  7. <web src="https://map.baidu.com/search/%E5%A4%A9%E5%AE%89%E9%97%A8/@12957695.78455178,4825339.25645,17.33z?querytype=s&da_src=shareurl&wd=%E5%A4%A9%E5%AE%89%E9%97%A8&c=153&src=0&wd2=%E5%8C%97%E4%BA%AC%E5%B8%82%E4%B8%9C%E5%9F%8E%E5%8C%BA&pn=0&sug=1&l=12&b=(12469977.85,4064032.61;12568281.85,4112864.61)&from=webmap&biz_forward=%7B%22scaler%22:2,%22styles%22:%22pl%22%7D&sug_forward=65e1ee886c885190f60e77ff&device_ratio=2"></web>
  8. </div>
  9. <comp index="2"></comp>
  10. </div>

 index.js代码

  1. export default {
  2. data: {
  3. title: ""
  4. },
  5. onInit() {
  6. this.title = this.$t('strings.world');
  7. }
  8. }

menu.css代码

  1. .menu-container {
  2. flex: 1;
  3. border-top: 0.5px solid #CCC;
  4. }
  5. .menu-tab {
  6. width: 100px;
  7. background-color: #f3f3f3;
  8. flex-direction: column;
  9. }
  10. .menu-tab-item {
  11. height: 34px;
  12. justify-content: center;
  13. align-items: center;
  14. width: 100px;
  15. }
  16. .menu-tab-item-text {
  17. font-size: 12px;
  18. font-weight: 100;
  19. height: 100%;
  20. /* align-content: stretch;*/
  21. }
  22. .menu-tab-item-normal {
  23. background-color: #f3f3f3;
  24. }
  25. .menu-tab-item-text-normal {
  26. /* font-size: 12px;*/
  27. /* font-weight: 100;*/
  28. /* height: 100%;*/
  29. /* align-content: stretch;*/
  30. color: #000;
  31. border-bottom: 0;
  32. }
  33. .menu-tab-item-active {
  34. background-color: #FFF;
  35. }
  36. .menu-tab-item-text-active {
  37. font-size: 12px;
  38. font-weight: 100;
  39. height: 100%;
  40. /* align-content: stretch;*/
  41. /* color: #ee742f;*/
  42. /* border-bottom: 2px solid #ee742f;*/
  43. }
  44. .menu-list {
  45. flex: 1;
  46. flex-wrap: wrap;
  47. }
  48. .menu-list-item {
  49. width: 33.333333%;
  50. height: 40px;
  51. justify-content: center;
  52. align-items: center;
  53. }
  54. .menu-list-item-text {
  55. font-size: 12px;
  56. font-weight: bold;
  57. }

 menu.hml代码

  1. <div class="menu-container">
  2. <div class="menu-tab">
  3. <div class="menu-tab-item {{ $item === currentTab ?'active' :'normal' }}"
  4. for="{{tabs}}"
  5. @click="handleTabClick($item)"
  6. >
  7. <text>
  8. {{$item}}
  9. </text>
  10. </div>
  11. </div>
  12. <div class="menu-list">
  13. <div class="menu-list-item" for="{{lists}}">
  14. <text>
  15. <span>{{ $item }}</span>
  16. </text>
  17. </div>
  18. </div>
  19. </div>

 menu.js代码

  1. export default{
  2. props: ['menuData','firstItem'],
  3. data(){
  4. return{
  5. currentTab: this.firstItem
  6. }
  7. },
  8. computed:{
  9. tabs(){
  10. return Object.keys(this.menuData)
  11. },
  12. lists(){
  13. return this.menuData[this.currentTab]
  14. }
  15. },
  16. handleTabClick(currentTab){
  17. this.currentTab=currentTab
  18. },
  19. onReady(){
  20. this.$watch('firstItem',(newValue)=>{
  21. this.currentTab=newValue
  22. })
  23. }
  24. }

index.hml代码

  1. <element name='comp' src='../../components/tabbar/tabbar.hml'></element>
  2. <element src='../../components/child/child.hml'></element>
  3. <element src='../index/menu/menu.hml' name="cb-menu"></element>
  4. <element name="cb-search" src="../../common/components/components/search/search.hml"></element>
  5. <div class="cate-container">
  6. <div class="cate-header">
  7. <div class="cate-header-nav">
  8. <div class="cate-header-nav-item" @click="handleSliderClick('category')">
  9. <text>
  10. 分类
  11. </text>
  12. </div>
  13. <div class="cate-header-nav-item" @click="handleSliderClick('material')">
  14. <text>
  15. 食材
  16. </text>
  17. </div>
  18. <div if="{{type==='category'}}" class="cate-header-nav-slider">
  19. <text>
  20. 分类
  21. </text>
  22. </div>
  23. <div else class="cate-header-nav-slider move">
  24. <text>
  25. 食材
  26. </text>
  27. </div>
  28. </div>
  29. </div>
  30. <div>
  31. <cb-search> from="cate"</cb-search>
  32. </div>
  33. <div>
  34. <cb-menu menu-data="{{filteredMenuData}}"first-item="{{type==='category' ? '热门':'肉类'}}"></cb-menu>
  35. </div>
  36. <div>
  37. <comp index="0"></comp>
  38. </div>
  39. </div>
  40. <!--<div>
  41. <text>
  42. 信息页面
  43. </text>
  44. <text>{{num}}</text>
  45. <child @change-father-num="changeNum">
  46. <text>父组件slot内容</text>
  47. <text slot="other"></text>
  48. </child>
  49. <comp index="0"></comp>
  50. </div>-->

index.css代码

  1. .cate-container {
  2. flex-direction: column;
  3. }
  4. .cate-header {
  5. width: 100%;
  6. height: 44px;
  7. background-color: #ee742f;
  8. justify-content: center;
  9. align-items: center;
  10. }
  11. .cate-header-nav {
  12. width: 140px;
  13. height: 30px;
  14. border-radius: 30px;
  15. border: 0.5px solid #FFF;
  16. position: relative;
  17. z-index: 1;
  18. }
  19. .cate-header-nav-item {
  20. flex: 1;
  21. justify-content: center;
  22. align-items: center;
  23. height: 30px;
  24. }
  25. .item-text {
  26. font-size: 12px;
  27. color: #FFF;
  28. }
  29. .cate-header-nav-slider {
  30. position: absolute;
  31. left: 0;
  32. border-radius: 30px;
  33. width: 70px;
  34. height: 30px;
  35. background-color: #FFF;
  36. z-index: 0;
  37. justify-content: center;
  38. align-items: center;
  39. transition: left 200ms ease-in;
  40. }
  41. .slider-text {
  42. font-size: 12px;
  43. color: #ee742f;
  44. }
  45. .move {
  46. left: 70px;
  47. }

index.js代码

  1. // @ts-nocheck
  2. import menuData from '../../common/data/cookbook-category.json'
  3. export default {
  4. data: {
  5. type:'category',
  6. menuData:[]
  7. },
  8. handleSliderClick(type){
  9. this.type=type
  10. },
  11. computed:{
  12. filteredMenuData(){
  13. return this.menuData[this.type]
  14. }
  15. },
  16. onInit(){
  17. this.menuData=menuData.data
  18. }
  19. }

index.css代码

  1. /*@import "../../../common/scss/title.scss";*/
  2. .container {
  3. flex-direction: column;
  4. justify-content: center;
  5. align-items: center;
  6. width: 100%;
  7. height: 100%;
  8. }
  9. .title {
  10. font-size: 40px;
  11. color: #000000;
  12. opacity: 0.9;
  13. }
  14. @media screen and (device-type: tablet) and (orientation: landscape) {
  15. .title {
  16. font-size: 100px;
  17. }
  18. }
  19. @media screen and (device-type: wearable) {
  20. .title {
  21. font-size: 28px;
  22. color: #FFFFFF;
  23. }
  24. }
  25. @media screen and (device-type: tv) {
  26. .container {
  27. background-image: url("/common/images/Wallpaper.png");
  28. background-size: cover;
  29. background-repeat: no-repeat;
  30. background-position: center;
  31. }
  32. .title {
  33. font-size: 100px;
  34. color: #FFFFFF;
  35. }
  36. }
  37. @media screen and (device-type: phone) and (orientation: landscape) {
  38. .title {
  39. font-size: 60px;
  40. }
  41. }
  42. .more-container {
  43. flex-direction: column;
  44. }
  45. /*.cb-title {*/
  46. /* @extent %cb-title;*/
  47. /*}*/
  48. .cb-title {
  49. width: 100%;
  50. height: 44px;
  51. background-color: #ee742f;
  52. justify-content: center;
  53. align-items: center;
  54. }
  55. .cb-title-text {
  56. font-size: 16px;
  57. font-weight: normal;
  58. color: #FFF;
  59. }
  60. .camera-container {
  61. width: 100%;
  62. height: 270px;
  63. flex-direction: column;
  64. align-content: center;
  65. justify-content: center;
  66. }
  67. .camera {
  68. width: 100%;
  69. height: 240px;;
  70. }
  71. .btn-takePhoto {
  72. width: 90%;
  73. height: 30px;
  74. align-self: center;
  75. }
  76. .switch-container {
  77. padding-left: 20px;
  78. }
  79. .switch-container-text {
  80. font-size: 12px;
  81. }
  82. .image_camera {
  83. margin-top: 10px;
  84. width: 100%;
  85. object-fit: contain;
  86. height: 400px;
  87. }

 index.hml代码

  1. <element name='comp' src='../../components/tabbar/tabbar.hml'></element>
  2. <!--<div class="container">
  3. <text class="title">
  4. 个人中心
  5. </text>
  6. <comp index="3"></comp>
  7. </div>-->
  8. <div class="more-container">
  9. <div div="cb-title">
  10. <text>个人中心</text>
  11. </div>
  12. <div class="camera-container">
  13. <camera class="camera" ref="camera"></camera>
  14. <div>
  15. <text>
  16. </text>
  17. </div>
  18. <button @click="handleClick" class="btn-takePhoto">
  19. 拍照
  20. </button>
  21. </div>
  22. <div class="switch-container">
  23. <text>
  24. 是否滑动切换
  25. </text>
  26. <switch checked="{{checked}}" @chenge="handleChange"></switch>
  27. </div>
  28. <comp index="3"></comp>
  29. </div>

 index.js代码

  1. /*export default {
  2. data: {
  3. title: ""
  4. },
  5. onInit() {
  6. this.title = this.$t('strings.world');
  7. }
  8. }*/
  9. export default{
  10. data:{
  11. photoUri:'',
  12. checked:true
  13. },
  14. handleClick(){
  15. this.$refs.camera.takePhoto({
  16. success(uri){
  17. this.photoUri=uri
  18. },
  19. fail(error){
  20. }
  21. })
  22. },
  23. handleChange(obj){
  24. }
  25. }

index.css代码

  1. .cb-container {
  2. flex-direction: column;
  3. }
  4. .cb-title {
  5. width: 100%;
  6. height: 44px;
  7. justify-content: center;
  8. align-items: center;
  9. background-color: #00ff00;
  10. }
  11. text {
  12. color: white;
  13. font-size: 16px;
  14. font-weight: normal;
  15. }
  16. .cb-body {
  17. flex: 1;
  18. }
  19. .cb-body-item {
  20. flex-direction: column;
  21. }

 index.hml代码

  1. <element name='cb-hotcake' src='./hotcake/hotcake'></element>
  2. <element name='cb-swiper' src='./swiper/swiper.hml'></element>
  3. <element name='cb-top' src='./top/top.hml'></element>
  4. <element name='comp' src='../../components/tabbar/tabbar.hml'></element>
  5. <element name="cb-search" src="../../common/components/components/search/search.hml"></element>
  6. <div class="cb-container" ><!--scrollable="{{pageScrollable}}"-->
  7. <div class="cb-title">
  8. <text>
  9. 美食大全
  10. </text>
  11. </div>
  12. <div class="cb-body">
  13. <list>
  14. <list-item class="cb-body-item">
  15. <!-- <cb-hotcake></cb-hotcake>-->
  16. <cb-swiper list="{{list}}"></cb-swiper>
  17. <!-- <cb-hotcake></cb-hotcake>-->
  18. </list-item>
  19. </list>
  20. </div>
  21. <div class="cb-body">
  22. <list>
  23. <list-item class="cb-body-item">
  24. <!-- <cb-hotcake></cb-hotcake>-->
  25. <cb-search from="index"></cb-search>
  26. <!-- <cb-hotcake></cb-hotcake>-->
  27. </list-item>
  28. </list>
  29. </div>
  30. <div class="cb-body">
  31. <list>
  32. <list-item class="cb-body-item">
  33. <cb-hotcake></cb-hotcake>
  34. <!-- <cb-hotcake></cb-hotcake>-->
  35. </list-item>
  36. </list>
  37. </div>
  38. <div class="cb-body">
  39. <list>
  40. <list-item class="cb-body-item">
  41. <cb-top list="{{list}}"></cb-top>
  42. </list-item>
  43. </list>
  44. <comp index="1"></comp>
  45. </div>
  46. </div>

 index.js代码

  1. // @ts-nocheck
  2. import list from '../../common/data/cookbook-list.json'
  3. import fetch from '@system.fetch';
  4. export default {
  5. data: {
  6. list:[]
  7. // title: ""
  8. },
  9. onInit() {
  10. this.list=list.data;
  11. // this.title = this.$t('strings.world');
  12. /* currentSelected:0,
  13. pageScrollable:true*/
  14. fetch.fetch({
  15. url:'http://securit.qfjava.cn/hm/cookbook-list.json',
  16. responseType:'json',
  17. success:res=>{
  18. const result=JSON.parse(res.data)
  19. this.list=result.data
  20. }
  21. })
  22. }
  23. }

config.json更改添加部分代码

此部分与js同级添加此部分代码

 

  1. "reqPermissions": [
  2. {
  3. "name": "ohos.permission.GET_NETWORK_INFO"
  4. },
  5. {
  6. "name": "ohos.permission.SET_NETWORK_INFO"
  7. },
  8. {
  9. "name": "ohos.permission.INTERNET"
  10. },
  11. {
  12. "name": "ohos.permission.CAMERA"
  13. }
  14. ]

更改此部分代码为截图所示 

 

  1. "deviceConfig": {
  2. "default": {
  3. "network": {
  4. "cleartextTraffic": true
  5. }
  6. }
  7. },

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/228832
推荐阅读
相关标签
  

闽ICP备14008679号