pageNavigation.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. <template>
  2. <!-- 导航 -->
  3. <div class="navigate">
  4. <div class="partOne">
  5. <div class="inner">
  6. <!-- 导航一 -->
  7. <div class="navLeft">
  8. <div class="navIndex">
  9. <NuxtLink to="/" title="首页">
  10. 首页
  11. </NuxtLink>
  12. </div>
  13. <div class="navClass">
  14. <div>乡村资讯</div>
  15. <div>社会资讯</div>
  16. </div>
  17. </div>
  18. <ul class="navigationOne">
  19. <li v-for="(item, index) in navigation1" :key="index">
  20. <NuxtLink :to="getLinkPath(item)" :target="item.is_url == 1 ? '_blank' : '_self'">
  21. <span> {{ item.alias }}</span>
  22. </NuxtLink>
  23. </li>
  24. </ul>
  25. <div class="navRight">
  26. <div class="nav111" v-for="(item, index) in navigation2" :key="index">
  27. <NuxtLink :to="getLinkPath(item)" :target="item.is_url == 1 ? '_blank' : '_self'">
  28. <span>{{ item.alias }}</span>
  29. </NuxtLink>
  30. </div>
  31. </div>
  32. </div>
  33. </div>
  34. <div class="partTwo">
  35. <div class="inner">
  36. <h3>
  37. 深度服务
  38. </h3>
  39. <ul class="partTwoTitle">
  40. <li class="titleList" v-for="(item, index) in navigation3" :key="index">
  41. <NuxtLink :to="getLinkPath(item)" :target="item.is_url == 1 ? '_blank' : '_self'">
  42. <span>{{ item.alias }}</span>
  43. </NuxtLink>
  44. </li>
  45. </ul>
  46. <div class="searchBox">
  47. <input v-model="keywords" type="text" placeholder="请输入关键词" @keydown.enter="goToSearch">
  48. <img src="../../public/image/search.png" @keydown.enter="goToSearch" @click="goSearch">
  49. </div>
  50. </div>
  51. </div>
  52. <div class="littleNav">
  53. <div class="inner">
  54. <img src="../../public/index/hdpt.png" alt="">
  55. <ul class="leftPart">
  56. <li class="navList" v-for="item in navigation4" :key="index">
  57. <NuxtLink :to="getLinkPath(item)" :target="item.is_url == 1 ? '_blank' : '_self'">
  58. <span>{{ item.alias }}</span>
  59. </NuxtLink>
  60. </li>
  61. </ul>
  62. <ul class="rightPart">
  63. <li class="navList" v-for="item in navigation4data2" :key="index">
  64. <NuxtLink :to="getLinkPath(item)" :target="item.is_url == 1 ? '_blank' : '_self'">
  65. <span>{{ item.alias }}</span>
  66. </NuxtLink>
  67. </li>
  68. </ul>
  69. </div>
  70. </div>
  71. <div class="phone_nav pc_none">
  72. <div class="phone_nav_in">
  73. <NuxtLink
  74. to="/" title="首页"
  75. class="phone_nav_index"
  76. :class="{ 'phone_nav_index_only': $route.path === '/' }"
  77. >
  78. 首页
  79. </NuxtLink>
  80. <div class="phone_nav_a_box">
  81. <NuxtLink
  82. v-for="(item, index) in navigation1" :key="index"
  83. :to="getLinkPath(item)"
  84. :target="item.is_url == 1 ? '_blank' : '_self'">
  85. {{ item.alias }}
  86. </NuxtLink>
  87. </div>
  88. </div>
  89. </div>
  90. </div>
  91. </template>
  92. <script setup>
  93. import { ref, onMounted } from 'vue';
  94. import { useRoute } from 'vue-router';
  95. const $route = useRoute();
  96. //1.加载依赖 start ---------------------------------------->
  97. //1.加载依赖 end ---------------------------------------->
  98. //2.页面公用方法 start ---------------------------------------->
  99. //搜索跳转
  100. //点击搜索按钮
  101. let goSearch = () => {
  102. const route = `/search/search?keyword=${keywords.value}`;
  103. window.location.href = route;
  104. }
  105. //2.页面公用方法 end ---------------------------------------->
  106. //3.获取导航菜单 start ---------------------------------------->
  107. const navigation1 = ref([]);
  108. //2是那个独立的2个
  109. const navigation2 = ref([]);
  110. const navigation3 = ref([]);
  111. //下面一行是2边分开的 一边5个
  112. const navigation4 = ref([]);
  113. const navigation4data2 = ref([]);
  114. //获取导航菜单1
  115. async function getNavigation1() {
  116. const mkdata = await requestDataPromise('/web/getWebsiteModelCategory', {
  117. method: 'GET',
  118. query: {
  119. 'pid': 0,
  120. 'num': 20,
  121. 'placeid': 1
  122. },
  123. });
  124. navigation1.value = mkdata.data;
  125. }
  126. getNavigation1();
  127. //获取导航菜单2
  128. async function getNavigation2() {
  129. const mkdata = await requestDataPromise('/web/getWebsiteModelCategory', {
  130. method: 'GET',
  131. query: {
  132. 'pid': 0,
  133. 'num': 2,
  134. 'placeid': 21
  135. },
  136. });
  137. navigation2.value = mkdata.data;
  138. }
  139. getNavigation2();
  140. //获取导航菜单4
  141. async function getNavigation4() {
  142. const mkdata = await requestDataPromise('/web/getWebsiteModelCategory', {
  143. method: 'GET',
  144. query: {
  145. 'pid': 0,
  146. 'num': 10,
  147. 'placeid': 23
  148. },
  149. });
  150. for (let i in mkdata.data) {
  151. if (i < 5) {
  152. navigation4.value.push(mkdata.data[i]);
  153. } else {
  154. navigation4data2.value.push(mkdata.data[i]);
  155. }
  156. }
  157. //navigation4.value = mkdata.data;
  158. //navigation4data2.value = mkdata.data;
  159. }
  160. getNavigation4();
  161. //获取导航菜单3
  162. async function getNavigation3() {
  163. const mkdata = await requestDataPromise('/web/getWebsiteModelCategory', {
  164. method: 'GET',
  165. query: {
  166. 'pid': 0,
  167. 'num': 6,
  168. 'placeid': 33
  169. },
  170. });
  171. navigation3.value = mkdata.data;
  172. }
  173. getNavigation3();
  174. //3.获取导航菜单 end ---------------------------------------->
  175. //4.跳转到搜索页面 start ---------------------------------------->
  176. const keywords = ref("")
  177. let goToSearch = () => {
  178. const route = "/search/search?keyword=" + keywords.value;
  179. window.open(route, '_blank');
  180. }
  181. //4.跳转到搜索页面 end ---------------------------------------->
  182. const delayTimer = ref(null);
  183. onMounted(() => {
  184. delayTimer.value = setTimeout(() => {
  185. const parentElement = document.querySelector('.phone_nav_a_box');
  186. const targetElement = document.querySelector('.phone_nav_a_box .router-link-exact-active');
  187. if (targetElement) {
  188. const targetRect = targetElement.getBoundingClientRect();
  189. const parentRect = parentElement.getBoundingClientRect();
  190. const distanceToParentLeft = targetRect.left - parentRect.left;
  191. parentElement.scrollLeft = distanceToParentLeft;
  192. }
  193. }, 999);
  194. })
  195. </script>
  196. <style lang="less" scoped>
  197. // 导航部分
  198. .partOne .navigationOne,
  199. .partOne .navigationOne>li {
  200. float: left;
  201. }
  202. .partOne {
  203. width: 100%;
  204. height: 133px;
  205. // margin-bottom: 10px;
  206. background-color: #a01c0e;
  207. font-size: 20px;
  208. font-family: PingFang SC-Semibold;
  209. .inner {
  210. display: flex;
  211. justify-content: space-between;
  212. .navLeft {
  213. width: 160px;
  214. font-size: 16px;
  215. display: flex;
  216. }
  217. .navIndex {
  218. height: 100px;
  219. line-height: 130px;
  220. a {
  221. font-weight: bold;
  222. font-size: 16px;
  223. color: #F8ECD2;
  224. }
  225. }
  226. .navClass {
  227. padding-top: 35px;
  228. padding-left: 30px;
  229. font-weight: bold;
  230. color: #F8ECD2;
  231. div:nth-child(2) {
  232. padding-top: 17px;
  233. }
  234. }
  235. }
  236. .navigationOne {
  237. width: 1200px;
  238. color: #333;
  239. display: flex;
  240. flex-wrap: wrap;
  241. padding-top: 24px;
  242. li {
  243. width: 74px;
  244. font-family: PingFang SC;
  245. height: 42px;
  246. line-height: 42px;
  247. //font-weight: 600;
  248. font-size: 16px;
  249. text-align: left;
  250. font-style: normal;
  251. text-transform: none;
  252. margin: 0 10px;
  253. text-align: center;
  254. a {
  255. font-weight: 400;
  256. font-size: 16px;
  257. color: #FFFFFF;
  258. display: block;
  259. }
  260. }
  261. >li:hover a {
  262. color: #F8ECD2;
  263. }
  264. .active {
  265. color: #F8ECD2;
  266. }
  267. }
  268. .navRight {
  269. width: 135px;
  270. height: 75px;
  271. font-size: 16px;
  272. margin-top: 30px;
  273. background: url(https://img.bjzxtw.org.cn/master/www/xcw/nav_bg.png) no-repeat;
  274. .nav111 {
  275. width: 98px;
  276. height: 30px;
  277. line-height: 44px;
  278. text-align: center;
  279. font-family: Microsoft YaHei, Microsoft YaHei;
  280. font-weight: bold;
  281. font-size: 16px;
  282. a {
  283. font-weight: bold;
  284. background: linear-gradient(to bottom, #FFF6B1 0%, #F5BC38 100%);
  285. -webkit-background-clip: text;
  286. color: transparent;
  287. }
  288. }
  289. }
  290. }
  291. .partTwo {
  292. width: 100%;
  293. height: 60px;
  294. line-height: 60px;
  295. // border-bottom: 1px solid #e3e3e3;
  296. background-color: #fafafa;
  297. .inner {
  298. width: 1200px;
  299. height: 57px;
  300. display: flex;
  301. // justify-content: space-between;
  302. h3 {
  303. font-family: Microsoft YaHei, Microsoft YaHei;
  304. font-weight: bold;
  305. font-size: 16px;
  306. padding-left: 60px;
  307. a {
  308. color: #333333;
  309. }
  310. }
  311. .partTwoTitle {
  312. display: flex;
  313. justify-content: flex-start;
  314. width: 633px;
  315. padding-left: 30px;
  316. padding-right: 30px;
  317. .titleList {
  318. font-size: 16px;
  319. font-family: PingFang SC, PingFang SC;
  320. font-weight: 400;
  321. margin-right: 25px;
  322. a {
  323. color: #333333;
  324. }
  325. }
  326. .titleList:hover a {
  327. color: #A01C0E;
  328. }
  329. }
  330. .searchBox {
  331. width: 356px;
  332. height: 40px;
  333. line-height: 40px;
  334. background-color: #fff;
  335. margin-top: 10px;
  336. border-radius: 25px;
  337. border: 1px solid #ededed;
  338. input {
  339. width: 285px;
  340. height: 35px;
  341. line-height: 35px;
  342. margin-left: 20px;
  343. border: none;
  344. outline: none;
  345. }
  346. img {
  347. width: 32px;
  348. height: 32px;
  349. vertical-align: middle;
  350. cursor: pointer;
  351. }
  352. }
  353. }
  354. }
  355. //小导航
  356. .littleNav {
  357. width: 100%;
  358. height: 88px;
  359. margin-top: 15px;
  360. .inner {
  361. width: 1200px;
  362. height: 88px;
  363. line-height: 88px;
  364. margin: 0 auto;
  365. display: flex;
  366. border: 1px solid #D3D5D8;
  367. background-color: #fafafa;
  368. img {
  369. width: 138px;
  370. height: 28px;
  371. margin-top: 30px;
  372. margin-left: 25px;
  373. }
  374. .leftPart {
  375. margin-left: 40px;
  376. margin-right: 10px;
  377. }
  378. .leftPart,
  379. .rightPart {
  380. width: 470px;
  381. height: 78px;
  382. margin-top: 5px;
  383. display: flex;
  384. align-items: center;
  385. justify-content: space-between;
  386. padding: 0 10px;
  387. border-bottom: 3px solid #A01C0E;
  388. .navList {
  389. a {
  390. font-family: Microsoft YaHei, Microsoft YaHei;
  391. font-weight: bold;
  392. font-size: 16px;
  393. color: #333333;
  394. line-height: 19px;
  395. }
  396. }
  397. .navList:hover a {
  398. color: #A01C0E;
  399. }
  400. }
  401. }
  402. }
  403. </style>
  404. <style lang="less" scoped>
  405. @media screen and (min-width:801px){/*pc*/
  406. .pc_none{display:none;}
  407. }
  408. @media screen and (max-width:800px){/*ipad_phone*/
  409. .phone_nav{
  410. width:100%;margin:10px auto 0;
  411. height:44px;background:#A01C0E;
  412. }
  413. .phone_nav_in{height:44px;width:92%;margin:0px auto;}
  414. .phone_nav_index{height:44px;line-height:44px;font-size:16px;float:left;
  415. color:rgba(255, 255, 255,.6);;margin-right:20px;}
  416. .phone_nav_a_box{height:44px;
  417. overflow-x:auto;overflow-y:hidden;word-break: keep-all; white-space: nowrap;
  418. }
  419. .phone_nav_a_box::-webkit-scrollbar{height:0px;}
  420. .phone_nav_a_box a{display:inline-block;height:44px;line-height:44px;font-size:16px;margin:0 10px;
  421. color:rgba(255, 255, 255,.6);}
  422. .phone_nav_index_only{ color:#fff; font-weight:bold;}
  423. .phone_nav_a_box a.router-link-exact-active{color:#fff;font-weight:bold;}
  424. // .phone_nav_a_box::-webkit-scrollbar{height:0px;}
  425. .partOne{display:none;}
  426. .partTwo{display:none;}
  427. .littleNav{display:none;}
  428. .phone_none{display:none;}
  429. }
  430. </style>