pageNavigation1.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. <template>
  2. <div class="navigate">
  3. <div class="partOne">
  4. <div class="inner">
  5. <div class="navLeft">
  6. <div class="navIndex">
  7. <NuxtLink :to="'/'">首页</NuxtLink>
  8. </div>
  9. <div class="navClass">
  10. <div>主题资讯</div>
  11. <div>互动资讯</div>
  12. </div>
  13. </div>
  14. <ul class="navigationOne">
  15. <div class="nav_in clearfix">
  16. <li v-for="(item, index) in navigation1" :key="index">
  17. <NuxtLink :href="getLinkPath(item)" :title="item.alias" v-if="index <= 23"
  18. :target="item.is_url == 1 ? '_blank' : '_self'">
  19. <span class="active" v-if="item.category_id == routeId">{{ item.alias }}</span>
  20. <span v-else>{{ item.alias }}</span>
  21. </NuxtLink>
  22. </li>
  23. </div>
  24. </ul>
  25. </div>
  26. </div>
  27. <!-- 展示地区 -->
  28. <div class="cityBox">
  29. <div class="cityMain">
  30. <div class="cityTitle">地方频道</div>
  31. <ul class="cityList">
  32. <li v-for="item in provinceList">
  33. <NuxtLink :to="{ path: `/search/${item.id}` }">{{ item.abbreviation }}</NuxtLink>
  34. </li>
  35. </ul>
  36. </div>
  37. </div>
  38. </div>
  39. </template>
  40. <script setup>
  41. //1.加载依赖 start ---------------------------------------->
  42. import { ElMessage } from 'element-plus'
  43. import { ref, onMounted } from 'vue';
  44. import { ElSelect, ElOption } from 'element-plus'
  45. const nuxtApp = useNuxtApp();
  46. const axios = nuxtApp.$axios;
  47. const route = useRoute();
  48. const routeId = route.params.id; //获得该页面的id
  49. //1.加载依赖 end ---------------------------------------->
  50. //2.加载模块数据 start ---------------------------------------->
  51. const navigation1 = ref("");
  52. async function getPageData2() {
  53. const mkdata = await requestDataPromise('/web/getWebsiteModelCategory', {
  54. method: 'GET',
  55. query: {
  56. 'placeid': 1,
  57. 'pid': 0,
  58. 'num': 35
  59. },
  60. });
  61. navigation1.value = mkdata.data;
  62. }
  63. getPageData2();
  64. //格式化跳转路径
  65. const getLinkPath = (item) => {
  66. if (item.is_url == 1) {
  67. return `${item.web_url}`;
  68. } else if (item.children_count == 0) {
  69. //return `/newsList/${item.category_id}?page=1`;
  70. return `/${item.aLIas_pinyin}/list-1.html`;
  71. } else {
  72. //return `/primaryNavigation/${item.aLIas_pinyin}/`;
  73. return `/${item.aLIas_pinyin}/index.html`;
  74. }
  75. }
  76. //2.加载模块数据 end ---------------------------------------->
  77. //3.职能部门 start ---------------------------------------->
  78. // let department = ref("")
  79. const depValue = ref("")
  80. const typeValue = ref("")
  81. // let departmentList = async () => {
  82. // const mkdata = await requestDataPromise('/web/selectWebsiteDepartment', {
  83. // method: 'GET',
  84. // query: {
  85. // 'keyword': department.value,
  86. // },
  87. // });
  88. // if(mkdata.code == 200){
  89. // department.value = mkdata.data;
  90. // }else{
  91. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  92. // console.log("错误位置:获取职能部门")
  93. // console.log("后端错误反馈:",mkdata.message)
  94. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  95. // }
  96. // }
  97. // //获得所有部门
  98. // departmentList();
  99. //3.职能部门 end ---------------------------------------->
  100. //4.展示行政区划 start ---------------------------------------->
  101. let areaList = ref("")
  102. //4.1 省
  103. let province = ref("")
  104. let provinceid = ref("")
  105. let provinceList = ref("")
  106. //4.2 市
  107. let city = ref("")
  108. let cityid = ref("")
  109. let cityList = ref("")
  110. //4.3 县
  111. let region = ref("")
  112. let regionid = ref("")
  113. let regionList = ref("")
  114. //选择省
  115. // let areaArrList = async () => {
  116. // const mkdata = await requestDataPromise('/web/selectWebsiteArea', {
  117. // method: 'GET',
  118. // query: {},
  119. // });
  120. // if(mkdata.code == 200){
  121. // provinceList.value = mkdata.data;
  122. // }else{
  123. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  124. // console.log("错误位置:获取行政区划")
  125. // console.log("后端错误反馈:",mkdata.message)
  126. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  127. // }
  128. // }
  129. // //一开始只需要获取一下省
  130. // areaArrList();
  131. onMounted(async () => {
  132. //从客户端获取行政区划
  133. try {
  134. const { $webUrl, $CwebUrl } = useNuxtApp();
  135. const response2 = await fetch($webUrl + '/web/selectWebsiteArea', {
  136. headers: {
  137. 'Content-Type': 'application/json',
  138. 'Userurl': $CwebUrl,
  139. 'Origin': $CwebUrl
  140. }
  141. });
  142. const result2 = await response2.json();
  143. provinceList.value = result2.data;
  144. } catch (error) {
  145. console.error('获取行政区划数据失败:', error);
  146. }
  147. // 设置滚动条初始位置
  148. const parentElement = document.querySelector('.nav_in');
  149. const targetElement = document.querySelector('.nav_in .router-link-exact-active');
  150. if (targetElement && parentElement) {
  151. const targetRect = targetElement.getBoundingClientRect();
  152. const parentRect = parentElement.getBoundingClientRect();
  153. const distanceToParentLeft = targetRect.left - parentRect.left;
  154. const navigationElement = document.querySelector('.partOne .navigationOne');
  155. if (navigationElement) {
  156. navigationElement.scrollLeft = distanceToParentLeft - 0;
  157. }
  158. }
  159. })
  160. //选择市
  161. let change = async (id) => {
  162. provinceid.value = id;
  163. const shengData = await requestDataPromise('/web/selectWebsiteArea', {
  164. method: 'GET',
  165. query: {
  166. 'province': id,
  167. 'city': 0
  168. },
  169. });
  170. cityList.value = shengData.data.city;
  171. }
  172. //选择县
  173. let change1 = async (id) => {
  174. cityid.value = id;
  175. const xianData = await requestDataPromise('/web/selectWebsiteArea', {
  176. method: 'GET',
  177. query: {
  178. 'province': provinceid.value,
  179. 'city': cityid.value
  180. },
  181. });
  182. regionList.value = xianData.data.region;
  183. }
  184. //4.展示行政区划 end ---------------------------------------->
  185. //5.执行搜索 start ---------------------------------------->
  186. const getcityid = ref("")
  187. //跳转到搜索页面
  188. let goToSearch = (id) => {
  189. console.log(id)
  190. const route = `/search/search?catids=${id}`;
  191. window.open(route, '_blank');
  192. }
  193. //获得cityid和
  194. let goToPrimary = async () => {
  195. if (province.value != "") { getcityid.value = province.value }
  196. if (city.value != "") { getcityid.value = city.value }
  197. if (region.value != "") { getcityid.value = region.value }
  198. if (province.value == "" && city.value == "" && region.value == "" && depValue.value == "") {
  199. ElMessage.error('请选择行政区划或者职能部门!')
  200. } else {
  201. const responseStatus = await requestDataPromise('/web/selectWebsiteCategory', {
  202. method: 'GET',
  203. query: {
  204. 'cityid': getcityid.value,
  205. 'department_id': depValue.value
  206. },
  207. });
  208. if (responseStatus.data.catid && responseStatus.data.catid.length > 0) {
  209. const catids = responseStatus.data.catid.join(',');
  210. const route = `/search/search?catids=${catids}`;
  211. window.open(route, '_blank');
  212. } else {
  213. // 可以在这里处理数组为空的情况
  214. console.log('没有可用的分类ID');
  215. const route = `/search/search`;
  216. window.open(route, '_blank');
  217. }
  218. }
  219. }
  220. let searchDepartment = () => {
  221. //搜索职能部门
  222. let status = false;
  223. for (let item of department.value) {
  224. if (item.name == typeValue.value) {
  225. //如果有就赋值过去
  226. depValue.value = item.id
  227. status = true; //说明有可用的结果
  228. }
  229. }
  230. if (status == true) {
  231. //弹出提示告诉用户不存在
  232. }
  233. }
  234. //5.执行搜索 end ---------------------------------------->
  235. </script>
  236. <style lang="less" scoped>
  237. @import url('@/assets/css/nav.less');
  238. </style>
  239. <style lang="less" scoped>
  240. @media screen and (min-width:801px){
  241. .nav_in{ display:flex;
  242. width:100%;
  243. flex-wrap: wrap;
  244. }
  245. .pc_none{display:none;}
  246. }
  247. @media screen and (max-width:800px){/*ipad_phone*/
  248. .partOne{height:33px;background:#49a769;margin-top:11px;padding:6px 0px;}
  249. .partOne .inner{ overflow: hidden;position:relative;box-sizing:border-box;}
  250. .partOne .inner .navLeft{display:flex;overflow:hidden;word-break: keep-all; white-space: nowrap;height:33px;text-align:left;
  251. width:auto;line-height:33px;margin-right:20px;
  252. }
  253. .partOne .inner .navIndex{ line-height:33px;height:33px;overflow:hidden;width:auto; }
  254. .partOne .inner .navClass{ line-height:33px;height:33px;padding:0px;word-break: keep-all; white-space: nowrap;overflow:hidden;
  255. display:none;}
  256. .partOne .inner .navClass div{margin-left:8px; float:left;}
  257. .partOne .inner .navClass div:nth-child(2){padding:0px;}
  258. .partOne .navigationOne{ height:33px; display:block; width:auto;
  259. line-height:33px;
  260. flex:1;
  261. padding:0;margin:0;
  262. float:right;box-sizing:border-box;
  263. overflow-y: hidden; // 改为 overlay 模式
  264. overflow-x: auto; // 改为 overlay 模式
  265. // 隐藏滚动条轨道
  266. &::-webkit-scrollbar-track {
  267. background: transparent;
  268. width: 0;
  269. height: 0;
  270. }
  271. // 隐藏滚动条滑块
  272. &::-webkit-scrollbar-thumb {
  273. background: transparent;
  274. }
  275. /* 新增滚动条样式 */
  276. &::-webkit-scrollbar {
  277. width: 0;
  278. height: 0;
  279. }
  280. }
  281. .nav_in{height:33px;word-break: keep-all; white-space: nowrap; box-sizing:border-box;line-height:33px;}
  282. .partOne .navigationOne li{width:auto;display:inline-block;font-size:16px;line-height:33px;height:33px; overflow:hidden;}
  283. .partOne .navigationOne li:nth-of-type(1){margin-left:0px;}
  284. .partOne .navigationOne li a{display:block;line-height:33px;height:33px; overflow:hidden;}
  285. .cityBox{display: block;overflow:hidden;height:auto;display:none;}
  286. .cityBox .cityMain{display: block;overflow:hidden;height:auto;width:100%;}
  287. .cityBox .cityMain .cityTitle{line-height: 22px;padding:0;margin:10px 0px 0px 10px;width:auto;}
  288. .cityList{overflow:hidden;}
  289. .cityBox .cityMain .cityList li{line-height:22px;margin:11px;}
  290. .select{overflow:hidden;height:auto;line-height:normal;}
  291. .select .inner{width:96%;margin:0px auto;overflow:hidden;height:auto; }
  292. .select .role{padding:0;height:auto;overflow:hidden;float:none;}
  293. .select .role .searchRole{box-sizing:border-box;width:333px; float:left;margin-left:0px;}
  294. .select .el-select{width:230px!important;}
  295. .select .role .searchRole em{margin:4px 10px;float:right;}
  296. .select .role > .title, .select .region > .title{float:none;font-size:18px;}
  297. .select .region{overflow:hidden;height:auto;float:none;}
  298. .select .region .searchRole{float:none;padding:10px 0;width:90%;margin:5px;height:auto;}
  299. .select .region .el-select{margin-left:17px;}
  300. .select .region em{margin-left:22px;}
  301. .navigate_phone{
  302. }
  303. .nav_select_btn_box{
  304. overflow:hidden;padding:5px 0px;
  305. border-bottom:1px solid #ededed;
  306. width:92%;margin:0px auto;
  307. }
  308. .nav_select_btn{
  309. height: 33px;
  310. line-height: 33px;
  311. color: #333;font-size:16px;
  312. padding:0px 20px 0px 6px;
  313. float:left;margin:0px 8px 5px 0px;
  314. // border:dashed 1px #000;
  315. background:url(../../public/image/Iconly.png) no-repeat right center;
  316. background-size:auto 20px;
  317. }
  318. .nav_select_panel{
  319. width:100%;background:teal;left:0px;top:0px;
  320. position:fixed;z-index:999;
  321. height:100%;
  322. }
  323. .partOne .inner .navIndex a{font-size:16px; height:33px;line-height:33px;display:block; }
  324. .partOne .navigationOne li a span{display:block;height:33px;line-height:33px;
  325. opacity:0.6;
  326. }
  327. .nav_in .router-link-exact-active span{font-size:16px;font-weight:bold;opacity:1!important;}
  328. .partOne .inner .navIndex a{font-weight:normal;opacity:.6;}
  329. .select{display:none;}
  330. .navigate_phone{display:none;}
  331. .phone_none{display:none;}
  332. }
  333. </style>