pageNavigation.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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" v-if="provinceList.length > 0">
  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. <!-- 行政查询 -->
  36. <div class="select">
  37. <div class="inner">
  38. <div class="role left">
  39. <div class="title">行政职能查询</div>
  40. <div class="searchRole">
  41. <el-select v-model="depValue" placeholder="职能部门" filterable size="large" style="width: 330px">
  42. <el-option v-for="(item, index) in department" :key="index" :label="item.name" :value="item.id" />
  43. </el-select>
  44. <em @click="goToPrimary"></em>
  45. </div>
  46. </div>
  47. <div class="region left">
  48. <div class="title">行政区划查询</div>
  49. <div class="searchRole" v-if="provinceList.length > 0">
  50. <el-select v-model="province" placeholder="请选择省" size="large" style="width: 80px">
  51. <el-option v-for="item in provinceList" :key="item.id" :label="item.name" @click="change(item.id)" :value="item.id" />
  52. </el-select>
  53. <i></i>
  54. <el-select v-model="city" placeholder="请选择市" no-data-text="请先选择省份" size="large" style="width: 80px">
  55. <el-option v-for="(item, index) in cityList" :key="item.id" :label="item.name" @click="change1(item.id)" :value="item.id" />
  56. </el-select>
  57. <i></i>
  58. <el-select v-model="region" placeholder="请选择区/县" no-data-text="请先选择市" size="large" style="width: 100px">
  59. <el-option v-for="item in regionList" :key="item.id" :label="item.name" :value="item.id" />
  60. </el-select>
  61. <em @click="goToPrimary"></em>
  62. </div>
  63. </div>
  64. </div>
  65. </div>
  66. </div>
  67. </template>
  68. <script setup>
  69. //1.加载依赖 start ---------------------------------------->
  70. import { ElMessage } from 'element-plus'
  71. import { ref, onMounted } from 'vue';
  72. import { ElSelect, ElOption } from 'element-plus'
  73. const nuxtApp = useNuxtApp();
  74. const axios = nuxtApp.$axios;
  75. const route = useRoute();
  76. const routeId = route.params.id; //获得该页面的id
  77. //1.加载依赖 end ---------------------------------------->
  78. //2.加载模块数据 start ---------------------------------------->
  79. const navigation1 = ref("");
  80. async function getPageData2() {
  81. const mkdata = await requestDataPromise('/web/getWebsiteModelCategory', {
  82. method: 'GET',
  83. query: {
  84. 'placeid': 1,
  85. 'pid': 0,
  86. 'num': 35
  87. },
  88. });
  89. navigation1.value = mkdata.data;
  90. }
  91. getPageData2();
  92. //格式化跳转路径
  93. const getLinkPath = (item) => {
  94. if(item.is_url==1){
  95. return `${item.web_url}`;
  96. }else if(item.children_count == 0){
  97. //return `/${item.aLIas_pinyin}/1.html`;
  98. return `/newsList/${item.category_id}?page=1`;
  99. }else{
  100. //return `/${item.aLIas_pinyin}/`;
  101. return `/primaryNavigation/${item.category_id}`;
  102. }
  103. }
  104. //2.加载模块数据 end ---------------------------------------->
  105. //3.职能部门 start ---------------------------------------->
  106. let department = ref("")
  107. const depValue = ref("")
  108. const typeValue = ref("")
  109. // let departmentList = async () => {
  110. // const mkdata = await requestDataPromise('/web/selectWebsiteDepartment', {
  111. // method: 'GET',
  112. // query: {
  113. // 'keyword': department.value,
  114. // },
  115. // });
  116. // if(mkdata.code == 200){
  117. // department.value = mkdata.data;
  118. // }else{
  119. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  120. // console.log("错误位置:获取职能部门")
  121. // console.log("后端错误反馈:",mkdata.message)
  122. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  123. // }
  124. // }
  125. // //获得所有部门
  126. // departmentList();
  127. //3.职能部门 end ---------------------------------------->
  128. //4.展示行政区划 start ---------------------------------------->
  129. //let areaList = ref("")
  130. //4.1 省
  131. let province = ref("")
  132. let provinceid = ref("")
  133. let provinceList = ref("")
  134. //4.2 市
  135. let city = ref("")
  136. let cityid = ref("")
  137. let cityList = ref("")
  138. //4.3 县
  139. let region = ref("")
  140. //let regionid = ref("")
  141. let regionList = ref("")
  142. //选择省
  143. // let areaArrList = async () => {
  144. // const mkdata = await requestDataPromise('/web/selectWebsiteArea', {
  145. // method: 'GET',
  146. // query: {},
  147. // });
  148. // if(mkdata.code == 200){
  149. // provinceList.value = mkdata.data;
  150. // }else{
  151. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  152. // console.log("错误位置:获取行政区划")
  153. // console.log("后端错误反馈:",mkdata.message)
  154. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  155. // }
  156. // }
  157. // //一开始只需要获取一下省
  158. // areaArrList();
  159. //选择市
  160. let change = async (id) => {
  161. provinceid.value = id;
  162. const shengData = await requestDataPromise('/web/selectWebsiteArea', {
  163. method: 'GET',
  164. query: {
  165. 'pid': id,
  166. },
  167. });
  168. cityList.value = shengData.data;
  169. }
  170. //选择县
  171. let change1 = async (id) => {
  172. cityid.value = id;
  173. const xianData = await requestDataPromise('/web/selectWebsiteArea', {
  174. method: 'GET',
  175. query: {
  176. 'pid': id,
  177. },
  178. });
  179. regionList.value = xianData.data;
  180. }
  181. //4.展示行政区划 end ---------------------------------------->
  182. //5.执行搜索 start ---------------------------------------->
  183. const getcityid = ref("")
  184. //跳转到搜索页面
  185. // let goToSearch = (id) => {
  186. // console.log(id)
  187. // const route = `/search/search?catids=${id}`;
  188. // window.location.href = route;
  189. // }
  190. //获得cityid和
  191. let goToPrimary = async () => {
  192. if (province.value != "") { getcityid.value = province.value }
  193. if (city.value != "") { getcityid.value = city.value }
  194. if (region.value != "") { getcityid.value = region.value }
  195. if (province.value == ""&&city.value == ""&&region.value == ""&&depValue.value=="") {
  196. ElMessage.error('请选择行政区划或者职能部门!')
  197. }else{
  198. // const responseStatus = await requestDataPromise('/web/selectWebsiteCategory', {
  199. // method: 'GET',
  200. // query: {
  201. // 'cityid': getcityid.value,
  202. // 'department_id': depValue.value
  203. // },
  204. // });
  205. // if (responseStatus.data.catid && responseStatus.data.catid.length > 0) {
  206. // const catids = responseStatus.data.catid.join(',');
  207. // const route = `/search/search?catids=${catids}`;
  208. // window.location.href = route;
  209. // } else {
  210. // // 可以在这里处理数组为空的情况
  211. // console.log('没有可用的分类ID');
  212. // const route = `/search/search`;
  213. // window.location.href = route;
  214. // }
  215. const route = `/search/search?catids=${getcityid.value}&department_id=${depValue.value}`;
  216. window.location.href = route;
  217. }
  218. }
  219. //5.执行搜索 end ---------------------------------------->
  220. onMounted(async () => {
  221. //从客户端获取行政职能部门 加快打开速度
  222. try {
  223. const { $webUrl, $CwebUrl } = useNuxtApp();
  224. const response = await fetch($webUrl + '/web/selectWebsiteDepartment', {
  225. headers: {
  226. 'Content-Type': 'application/json',
  227. 'Userurl': $CwebUrl,
  228. 'Origin': $CwebUrl
  229. }
  230. });
  231. const result = await response.json();
  232. department.value = result.data;
  233. } catch (error) {
  234. console.error('获取部门数据失败:', error);
  235. }
  236. //从客户端获取行政区划
  237. try {
  238. const { $webUrl, $CwebUrl } = useNuxtApp();
  239. const response2 = await fetch($webUrl + '/web/selectWebsiteArea', {
  240. headers: {
  241. 'Content-Type': 'application/json',
  242. 'Userurl': $CwebUrl,
  243. 'Origin': $CwebUrl
  244. }
  245. });
  246. const result2 = await response2.json();
  247. provinceList.value = result2.data;
  248. } catch (error) {
  249. console.error('获取行政区划数据失败:', error);
  250. }
  251. })
  252. </script>
  253. <style lang="less" scoped>
  254. @import url('@/assets/css/nav.less');
  255. </style>