pageNavigation.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  1. <template>
  2. <div class="navigate">
  3. <div class="partOne">
  4. <div class="inner">
  5. <ul class="navigationOne">
  6. <li>
  7. <NuxtLink href="/">
  8. 首页
  9. </NuxtLink>
  10. </li>
  11. <li v-for="(item, index) in navigation1" :key="index">
  12. <NuxtLink :href="getLinkPath(item)" :title="item.alias"
  13. :target="item.is_url == 1 ? '_blank' : '_self'">
  14. {{ item.alias }}
  15. </NuxtLink>
  16. </li>
  17. </ul>
  18. </div>
  19. </div>
  20. <div class="partTwo">
  21. <div class="inner">
  22. <ul class="partTwoNav">
  23. <li class="navList" v-for="(item, index) in navigation2" :key="index">
  24. <NuxtLink :href="getLinkPath(item)" :title="item.alias"
  25. :target="item.is_url == 1 ? '_blank' : '_self'">
  26. {{ item.alias }}
  27. </NuxtLink>
  28. </li>
  29. </ul>
  30. </div>
  31. </div>
  32. <div class="partThree">
  33. <div class="inner">
  34. <div class="title">
  35. 搜索职位 :
  36. </div>
  37. <div class="searchRole">
  38. <!--下拉框只在客户端渲染-->
  39. <client-only>
  40. <el-select v-model="searchInputValue1" placeholder="请选择..." size="large" style="width: 75px"
  41. :key="'select1'">
  42. <el-option v-for="item in selectOptions" :key="item.id" :label="item.name"
  43. :value="item.id" />
  44. </el-select>
  45. </client-only>
  46. <i></i>
  47. <input type="text" v-model="typeValue" placeholder="请输入职位/岗位名称" class="ipt">
  48. <em class="search" @click="goToSearch"></em>
  49. </div>
  50. <div class="box111"></div>
  51. <div class="title">搜索资讯 :</div>
  52. <div class="searchRole" v-if="provinceList.length > 0">
  53. <el-select v-model="province" placeholder="请选择省" size="large" style="width: 80px">
  54. <el-option v-for="item in provinceList" :key="item.id" :label="item.name"
  55. @click="change(item.id)" :value="item.id" />
  56. </el-select>
  57. <i></i>
  58. <el-select v-model="city" placeholder="请选择市" no-data-text="请先选择省份" size="large" style="width: 80px">
  59. <el-option v-for="(item, index) in cityList" :key="item.id" :label="item.name"
  60. @click="change1(item.id)" :value="item.id" />
  61. </el-select>
  62. <i></i>
  63. <el-select v-model="region" placeholder="请选择区/县" no-data-text="请先选择市" size="large"
  64. style="width: 100px">
  65. <el-option v-for="item in regionList" :key="item.id" :label="item.name" :value="item.id" />
  66. </el-select>
  67. <em class="searchbtn" @click="goToPrimary"></em>
  68. </div>
  69. </div>
  70. </div>
  71. <div class="phone_nav pc_none">
  72. <div class="phone_nav_in">
  73. <NuxtLink
  74. to="/"
  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. <NuxtLink
  88. v-for="(item, index) in navigation2" :key="index"
  89. :to="getLinkPath(item)"
  90. :target="item.is_url == 1 ? '_blank' : '_self'">
  91. {{ item.alias }}
  92. </NuxtLink>
  93. </div>
  94. </div>
  95. </div>
  96. </div>
  97. </template>
  98. <script setup>
  99. //1.获取导航菜单 start ---------------------------------------->
  100. //第一行导航菜单 10个
  101. const navigation1 = ref([]);
  102. //两行的导航菜单 20个
  103. const navigation2 = ref([]);
  104. //获取导航菜单1
  105. async function getNavigation1() {
  106. const mkdata = await requestDataPromise('/web/getWebsiteModelCategory', {
  107. method: 'GET',
  108. query: {
  109. 'pid': 0,
  110. 'num': 10,
  111. 'placeid': 1
  112. },
  113. });
  114. navigation1.value = mkdata.data;
  115. }
  116. getNavigation1();
  117. //获取导航菜单2
  118. async function getNavigation2() {
  119. const mkdata = await requestDataPromise('/web/getWebsiteModelCategory', {
  120. method: 'GET',
  121. query: {
  122. 'pid': 0,
  123. 'num': 10,
  124. 'placeid': 11
  125. },
  126. });
  127. navigation2.value = mkdata.data;
  128. }
  129. getNavigation2();
  130. //1.获取导航菜单 end ---------------------------------------->
  131. //2.搜索 start ---------------------------------------->
  132. import { ElSelect, ElOption, ElMessage } from 'element-plus'
  133. let selectOptions = [
  134. { name: '招聘', id: 4 },
  135. { name: '求职', id: 5 },
  136. ]
  137. //2.1跳转到搜索页面
  138. const searchInputValue1 = ref("")
  139. const typeValue = ref("")
  140. let goToSearch = async () => {
  141. if (searchInputValue1.value == "") {
  142. ElMessage.error('搜索项类型不能为空!')
  143. } else {
  144. const route = `/search/search?type=${searchInputValue1.value}&keyword=${typeValue.value}`;
  145. window.location.href = route;
  146. }
  147. }
  148. //2.搜索 end ---------------------------------------->
  149. //4.展示行政区划 start ---------------------------------------->
  150. //let areaList = ref("")
  151. //4.1 省
  152. let province = ref("")
  153. let provinceid = ref("")
  154. let provinceList = ref("")
  155. //4.2 市
  156. let city = ref("")
  157. let cityid = ref("")
  158. let cityList = ref("")
  159. //4.3 县
  160. let region = ref("")
  161. //let regionid = ref("")
  162. let regionList = ref("")
  163. //选择省
  164. let areaArrList = async () => {
  165. const mkdata = await requestDataPromise('/web/selectWebsiteArea', {
  166. method: 'GET',
  167. query: {},
  168. });
  169. if (mkdata.code == 200) {
  170. provinceList.value = mkdata.data;
  171. } else {
  172. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  173. // console.log("错误位置:获取行政区划")
  174. // console.log("后端错误反馈:", mkdata.message)
  175. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  176. }
  177. }
  178. //一开始只需要获取一下省
  179. areaArrList();
  180. //选择市
  181. let change = async (id) => {
  182. provinceid.value = id;
  183. const shengData = await requestDataPromise('/web/selectWebsiteArea', {
  184. method: 'GET',
  185. query: {
  186. 'pid': id,
  187. },
  188. });
  189. cityList.value = shengData.data;
  190. }
  191. //选择县
  192. let change1 = async (id) => {
  193. cityid.value = id;
  194. const xianData = await requestDataPromise('/web/selectWebsiteArea', {
  195. method: 'GET',
  196. query: {
  197. 'pid': id,
  198. },
  199. });
  200. regionList.value = xianData.data;
  201. }
  202. //4.展示行政区划 end ---------------------------------------->
  203. //5.执行搜索 start ---------------------------------------->
  204. const getcityid = ref("")
  205. //获得cityid和
  206. let goToPrimary = async () => {
  207. if (province.value != "") { getcityid.value = province.value }
  208. if (city.value != "") { getcityid.value = city.value }
  209. if (region.value != "") { getcityid.value = region.value }
  210. if (province.value == "" && city.value == "" && region.value == "") {
  211. ElMessage.error('请选择地区!')
  212. } else {
  213. const route = `/search/search?catids=${getcityid.value}&type=1`;
  214. window.location.href = route;
  215. }
  216. }
  217. //5.执行搜索 end ---------------------------------------->
  218. //获取当前url路径
  219. const route = useRoute();
  220. //获得当前的完整路径
  221. const fullPath = route.path;
  222. const segments = fullPath.split('/');
  223. const targetSegment = segments[1];
  224. const delayTimer_2 = ref(null);
  225. onMounted(() => {
  226. delayTimer_2.value = setTimeout(() => {
  227. const parentElement_a = document.querySelectorAll('.phone_nav_a_box>a');
  228. let nav1_length = navigation1.value.length;
  229. navigation2.value.forEach((item, index) => {
  230. if (item.aLIas_pinyin == targetSegment) {
  231. // 帮我写1下js添加class名active
  232. parentElement_a[index+nav1_length].classList.add('router-link-exact-active');
  233. }
  234. })
  235. },333)
  236. })
  237. const delayTimer = ref(null);
  238. onMounted(() => {
  239. delayTimer.value = setTimeout(() => {
  240. const parentElement = document.querySelector('.phone_nav_a_box');
  241. const targetElement = document.querySelector('.phone_nav_a_box .router-link-exact-active');
  242. if (targetElement) {
  243. const targetRect = targetElement.getBoundingClientRect();
  244. const parentRect = parentElement.getBoundingClientRect();
  245. const distanceToParentLeft = targetRect.left - parentRect.left;
  246. parentElement.scrollLeft = distanceToParentLeft;
  247. }
  248. }, 999);
  249. })
  250. </script>
  251. <style lang="less" scoped>
  252. @import url('@/assets/css/public/nav.less');
  253. </style>
  254. <style lang="less" scoped>
  255. @media screen and (min-width:801px){/*pc*/
  256. .pc_none{display:none;}
  257. }
  258. @media screen and (max-width:800px){/*ipad_phone*/
  259. .phone_nav{
  260. width:100%;margin:10px auto 0;
  261. height:44px;background:#489d97;
  262. }
  263. .phone_nav_in{height:44px;width:92%;margin:0px auto;}
  264. .phone_nav_index{height:44px;line-height:44px;font-size:16px;float:left;
  265. color:rgba(255, 255, 255,.6);;margin-right:20px;}
  266. .phone_nav_a_box{height:44px;
  267. overflow-x:auto;overflow-y:hidden;word-break: keep-all; white-space: nowrap;
  268. }
  269. .phone_nav_a_box::-webkit-scrollbar{height:0px;}
  270. .phone_nav_a_box a{display:inline-block;height:44px;line-height:44px;font-size:16px;margin:0 10px;
  271. color:rgba(255, 255, 255,.6);}
  272. .phone_nav_index_only{ color:#fff; font-weight:bold;}
  273. .phone_nav_a_box a.router-link-exact-active{color:#fff;font-weight:bold;}
  274. .partOne{display:none;}
  275. .partTwo{display:none;}
  276. .partThree{display:none;}
  277. .phone_none{display:none;}
  278. }
  279. </style>