pageNavigation.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <template>
  2. <!-- 导航 -->
  3. <div class="navigate">
  4. <div class="partOne">
  5. <div class="inner">
  6. <div class="home">
  7. <em></em>
  8. <NuxtLink :to="'/'">首页</NuxtLink>
  9. </div>
  10. <ul class="partOneTitle">
  11. <li class="titleList1">
  12. 深度服务
  13. </li>
  14. <li class="titleList111" v-for="(item, index) in navigation1" :key="index" >
  15. <NuxtLink :title="item.alias"
  16. :href="getLinkPath(item)"
  17. :target="item.is_url == 1 ? '_blank' : '_self'">
  18. {{ item.alias }}
  19. </NuxtLink>
  20. </li>
  21. </ul>
  22. </div>
  23. </div>
  24. <div class="partTwo">
  25. <div class="inner">
  26. <div class="navleft">
  27. <div> 互动版块 </div>
  28. <div> 推荐版块 </div>
  29. </div>
  30. <ul class="navlist">
  31. <li class="navListItem" v-for="(item, index) in navigation2" :key="index">
  32. <NuxtLink :href="getLinkPath(item)" :title="item.alias"
  33. :target="item.is_url == 1 ? '_blank' : '_self'">
  34. {{ item.alias }}
  35. </NuxtLink>
  36. </li>
  37. </ul>
  38. <div class="navright">
  39. <div class="nav111" v-for="(item, index) in navigation3" :key="index">
  40. <NuxtLink :href="getLinkPath(item)" :title="item.alias"
  41. :target="item.is_url == 1 ? '_blank' : '_self'">
  42. {{ item.alias }}
  43. </NuxtLink>
  44. </div>
  45. </div>
  46. </div>
  47. </div>
  48. <div class="phone_nav pc_none">
  49. <div class="phone_nav_in">
  50. <NuxtLink
  51. to="/" title="首页"
  52. class="phone_nav_index"
  53. :class="{ 'phone_nav_index_only': $route.path === '/' }"
  54. >
  55. 首页
  56. </NuxtLink>
  57. <div class="phone_nav_a_box">
  58. <NuxtLink
  59. v-for="(item, index) in navigation1" :key="index"
  60. :href="getLinkPath(item)"
  61. :title="item.alias"
  62. :target="item.is_url == 1 ? '_blank' : '_self'">
  63. {{ item.alias }}
  64. </NuxtLink>
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. </template>
  70. <script setup>
  71. //1.获取导航菜单 start ---------------------------------------->
  72. //第一行导航菜单 10个
  73. const navigation1 = ref([]);
  74. //两行的导航菜单 20个
  75. const navigation2 = ref([]);
  76. //边边上的导航菜单 2个
  77. const navigation3 = ref([]);
  78. //获取导航菜单1
  79. async function getNavigation1() {
  80. const mkdata = await requestDataPromise('/web/getWebsiteModelCategory', {
  81. method: 'GET',
  82. query: {
  83. 'pid': 0,
  84. 'num': 10,
  85. 'placeid': 1
  86. },
  87. });
  88. navigation1.value = mkdata.data;
  89. }
  90. getNavigation1();
  91. //获取导航菜单2
  92. async function getNavigation2() {
  93. const mkdata = await requestDataPromise('/web/getWebsiteModelCategory', {
  94. method: 'GET',
  95. query: {
  96. 'pid': 0,
  97. 'num': 20,
  98. 'placeid': 11
  99. },
  100. });
  101. navigation2.value = mkdata.data;
  102. }
  103. getNavigation2();
  104. //获取导航菜单3
  105. async function getNavigation3() {
  106. const mkdata = await requestDataPromise('/web/getWebsiteModelCategory', {
  107. method: 'GET',
  108. query: {
  109. 'pid': 0,
  110. 'num': 2,
  111. 'placeid': 31
  112. },
  113. });
  114. navigation3.value = mkdata.data;
  115. }
  116. getNavigation3();
  117. //1.获取导航菜单 end ---------------------------------------->
  118. //格式化跳转路径
  119. const getLinkPath = (item) => {
  120. if (item.is_url == 1) {
  121. return `${item.web_url}`;
  122. } else if (item.children_count == 0) {
  123. //return `/newsList/${item.category_id}?page=1`;
  124. return `/${item.aLIas_pinyin}/list-1.html`;
  125. } else {
  126. //return `/primaryNavigation/${item.aLIas_pinyin}/`;
  127. return `/${item.aLIas_pinyin}/index.html`;
  128. }
  129. }
  130. const delayTimer = ref(null);
  131. onMounted(() => {
  132. delayTimer.value = setTimeout(() => {
  133. const parentElement = document.querySelector('.phone_nav_a_box');
  134. const targetElement = document.querySelector('.phone_nav_a_box .router-link-exact-active');
  135. if (targetElement) {
  136. const targetRect = targetElement.getBoundingClientRect();
  137. const parentRect = parentElement.getBoundingClientRect();
  138. const distanceToParentLeft = targetRect.left - parentRect.left;
  139. parentElement.scrollLeft = distanceToParentLeft;
  140. }
  141. }, 999);
  142. })
  143. </script>
  144. <style lang="less" scoped>
  145. @import url('@/assets/css/public/nav.less');
  146. </style>
  147. <style lang="less" scoped>
  148. @media screen and (min-width:801px){/*pc*/
  149. .pc_none{display:none;}
  150. }
  151. @media screen and (max-width:800px){/*ipad_phone*/
  152. .phone_nav{
  153. width:100%;margin:10px auto 0;
  154. height:44px;background:#dd7d18;
  155. }
  156. .phone_nav_in{height:44px;width:92%;margin:0px auto;}
  157. .phone_nav_index{height:44px;line-height:44px;font-size:16px;float:left;
  158. color:rgba(255, 255, 255,.6);;margin-right:20px;}
  159. .phone_nav_a_box{height:44px;
  160. overflow-x:auto;overflow-y:hidden;word-break: keep-all; white-space: nowrap;
  161. }
  162. .phone_nav_a_box::-webkit-scrollbar{height:0px;}
  163. .phone_nav_a_box a{display:inline-block;height:44px;line-height:44px;font-size:16px;margin:0 10px;
  164. color:rgba(255, 255, 255,.6);}
  165. .phone_nav_a_box a:nth-of-type(1){margin-left:0px;}
  166. .phone_nav_index_only{ color:#fff; font-weight:bold;}
  167. .phone_nav_a_box a.router-link-exact-active{color:#fff;font-weight:bold;}
  168. .partOne{display:none;}
  169. .partTwo{display:none;}
  170. .littleNav{display:none;}
  171. .phone_none{display:none;}
  172. }
  173. </style>