pageNavigation1.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. <li v-for="(item, index) in navigation1" :key="index">
  16. <NuxtLink :href="getLinkPath(item)" :title="item.alias" v-if="index<=23" :target="item.is_url == 1 ? '_blank' : '_self'">
  17. <span class="active" v-if="item.category_id == routeId">{{ item.alias }}</span>
  18. <span v-else>{{ item.alias }}</span>
  19. </NuxtLink>
  20. </li>
  21. </ul>
  22. </div>
  23. </div>
  24. <!-- 展示地区 -->
  25. <div class="cityBox">
  26. <div class="cityMain">
  27. <div class="cityTitle">地方频道</div>
  28. <ul class="cityList">
  29. <li v-for="item in provinceList">
  30. <NuxtLink :to="{ path: `/search/${item.id}`}">{{item.abbreviation}}</NuxtLink>
  31. </li>
  32. </ul>
  33. </div>
  34. </div>
  35. </div>
  36. </template>
  37. <script setup>
  38. //1.加载依赖 start ---------------------------------------->
  39. import { ElMessage } from 'element-plus'
  40. import { ref,onMounted } from 'vue';
  41. import { ElSelect, ElOption } from 'element-plus'
  42. const nuxtApp = useNuxtApp();
  43. const axios = nuxtApp.$axios;
  44. const route = useRoute();
  45. const routeId = route.params.id; //获得该页面的id
  46. //1.加载依赖 end ---------------------------------------->
  47. //2.加载模块数据 start ---------------------------------------->
  48. const navigation1 = ref("");
  49. async function getPageData2() {
  50. const mkdata = await requestDataPromise('/web/getWebsiteModelCategory', {
  51. method: 'GET',
  52. query: {
  53. 'placeid': 1,
  54. 'pid': 0,
  55. 'num': 35
  56. },
  57. });
  58. navigation1.value = mkdata.data;
  59. }
  60. getPageData2();
  61. //格式化跳转路径
  62. const getLinkPath = (item) => {
  63. if(item.is_url==1){
  64. return `${item.web_url}`;
  65. }else if(item.children_count == 0){
  66. //return `/newsList/${item.category_id}?page=1`;
  67. return `/${item.aLIas_pinyin}/list-1.html`;
  68. }else{
  69. //return `/primaryNavigation/${item.aLIas_pinyin}/`;
  70. return `/${item.aLIas_pinyin}/index.html`;
  71. }
  72. }
  73. //2.加载模块数据 end ---------------------------------------->
  74. //3.职能部门 start ---------------------------------------->
  75. // let department = ref("")
  76. const depValue = ref("")
  77. const typeValue = ref("")
  78. // let departmentList = async () => {
  79. // const mkdata = await requestDataPromise('/web/selectWebsiteDepartment', {
  80. // method: 'GET',
  81. // query: {
  82. // 'keyword': department.value,
  83. // },
  84. // });
  85. // if(mkdata.code == 200){
  86. // department.value = mkdata.data;
  87. // }else{
  88. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  89. // console.log("错误位置:获取职能部门")
  90. // console.log("后端错误反馈:",mkdata.message)
  91. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  92. // }
  93. // }
  94. // //获得所有部门
  95. // departmentList();
  96. //3.职能部门 end ---------------------------------------->
  97. //4.展示行政区划 start ---------------------------------------->
  98. let areaList = ref("")
  99. //4.1 省
  100. let province = ref("")
  101. let provinceid = ref("")
  102. let provinceList = ref("")
  103. //4.2 市
  104. let city = ref("")
  105. let cityid = ref("")
  106. let cityList = ref("")
  107. //4.3 县
  108. let region = ref("")
  109. let regionid = ref("")
  110. let regionList = ref("")
  111. //选择省
  112. // let areaArrList = async () => {
  113. // const mkdata = await requestDataPromise('/web/selectWebsiteArea', {
  114. // method: 'GET',
  115. // query: {},
  116. // });
  117. // if(mkdata.code == 200){
  118. // provinceList.value = mkdata.data;
  119. // }else{
  120. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  121. // console.log("错误位置:获取行政区划")
  122. // console.log("后端错误反馈:",mkdata.message)
  123. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  124. // }
  125. // }
  126. // //一开始只需要获取一下省
  127. // areaArrList();
  128. onMounted(async () => {
  129. //从客户端获取行政区划
  130. try {
  131. const { $webUrl, $CwebUrl } = useNuxtApp();
  132. const response2 = await fetch($webUrl + '/web/selectWebsiteArea', {
  133. headers: {
  134. 'Content-Type': 'application/json',
  135. 'Userurl': $CwebUrl,
  136. 'Origin': $CwebUrl
  137. }
  138. });
  139. const result2 = await response2.json();
  140. provinceList.value = result2.data;
  141. } catch (error) {
  142. console.error('获取行政区划数据失败:', error);
  143. }
  144. })
  145. //选择市
  146. let change = async (id) => {
  147. provinceid.value = id;
  148. const shengData = await requestDataPromise('/web/selectWebsiteArea', {
  149. method: 'GET',
  150. query: {
  151. 'province': id,
  152. 'city': 0
  153. },
  154. });
  155. cityList.value = shengData.data.city;
  156. }
  157. //选择县
  158. let change1 = async (id) => {
  159. cityid.value = id;
  160. const xianData = await requestDataPromise('/web/selectWebsiteArea', {
  161. method: 'GET',
  162. query: {
  163. 'province': provinceid.value,
  164. 'city': cityid.value
  165. },
  166. });
  167. regionList.value = xianData.data.region;
  168. }
  169. //4.展示行政区划 end ---------------------------------------->
  170. //5.执行搜索 start ---------------------------------------->
  171. const getcityid = ref("")
  172. //跳转到搜索页面
  173. let goToSearch = (id) => {
  174. console.log(id)
  175. const route = `/search/search?catids=${id}`;
  176. window.open(route, '_blank');
  177. }
  178. //获得cityid和
  179. let goToPrimary = async () => {
  180. if (province.value != "") { getcityid.value = province.value }
  181. if (city.value != "") { getcityid.value = city.value }
  182. if (region.value != "") { getcityid.value = region.value }
  183. if (province.value == ""&&city.value == ""&&region.value == ""&&depValue.value=="") {
  184. ElMessage.error('请选择行政区划或者职能部门!')
  185. }else{
  186. const responseStatus = await requestDataPromise('/web/selectWebsiteCategory', {
  187. method: 'GET',
  188. query: {
  189. 'cityid': getcityid.value,
  190. 'department_id': depValue.value
  191. },
  192. });
  193. if (responseStatus.data.catid && responseStatus.data.catid.length > 0) {
  194. const catids = responseStatus.data.catid.join(',');
  195. const route = `/search/search?catids=${catids}`;
  196. window.open(route, '_blank');
  197. } else {
  198. // 可以在这里处理数组为空的情况
  199. console.log('没有可用的分类ID');
  200. const route = `/search/search`;
  201. window.open(route, '_blank');
  202. }
  203. }
  204. }
  205. let searchDepartment = () => {
  206. //搜索职能部门
  207. let status = false;
  208. for (let item of department.value) {
  209. if (item.name == typeValue.value) {
  210. //如果有就赋值过去
  211. depValue.value = item.id
  212. status = true; //说明有可用的结果
  213. }
  214. }
  215. if (status == true) {
  216. //弹出提示告诉用户不存在
  217. }
  218. }
  219. //5.执行搜索 end ---------------------------------------->
  220. </script>
  221. <style lang="less" scoped>
  222. @import url('@/assets/css/nav.less');
  223. </style>