pageNavigation.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 `/newsList/${item.category_id}`;
  98. }else{
  99. return `/${item.aLIas_pinyin}/`;
  100. }
  101. }
  102. //2.加载模块数据 end ---------------------------------------->
  103. //3.职能部门 start ---------------------------------------->
  104. let department = ref("")
  105. const depValue = ref("")
  106. const typeValue = ref("")
  107. // let departmentList = async () => {
  108. // const mkdata = await requestDataPromise('/web/selectWebsiteDepartment', {
  109. // method: 'GET',
  110. // query: {
  111. // 'keyword': department.value,
  112. // },
  113. // });
  114. // if(mkdata.code == 200){
  115. // department.value = mkdata.data;
  116. // }else{
  117. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  118. // console.log("错误位置:获取职能部门")
  119. // console.log("后端错误反馈:",mkdata.message)
  120. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  121. // }
  122. // }
  123. // //获得所有部门
  124. // departmentList();
  125. //3.职能部门 end ---------------------------------------->
  126. //4.展示行政区划 start ---------------------------------------->
  127. //let areaList = ref("")
  128. //4.1 省
  129. let province = ref("")
  130. let provinceid = ref("")
  131. let provinceList = ref("")
  132. //4.2 市
  133. let city = ref("")
  134. let cityid = ref("")
  135. let cityList = ref("")
  136. //4.3 县
  137. let region = ref("")
  138. //let regionid = ref("")
  139. let regionList = ref("")
  140. //选择省
  141. // let areaArrList = async () => {
  142. // const mkdata = await requestDataPromise('/web/selectWebsiteArea', {
  143. // method: 'GET',
  144. // query: {},
  145. // });
  146. // if(mkdata.code == 200){
  147. // provinceList.value = mkdata.data;
  148. // }else{
  149. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  150. // console.log("错误位置:获取行政区划")
  151. // console.log("后端错误反馈:",mkdata.message)
  152. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  153. // }
  154. // }
  155. // //一开始只需要获取一下省
  156. // areaArrList();
  157. //选择市
  158. let change = async (id) => {
  159. provinceid.value = id;
  160. const shengData = await requestDataPromise('/web/selectWebsiteArea', {
  161. method: 'GET',
  162. query: {
  163. 'pid': id,
  164. },
  165. });
  166. cityList.value = shengData.data;
  167. }
  168. //选择县
  169. let change1 = async (id) => {
  170. cityid.value = id;
  171. const xianData = await requestDataPromise('/web/selectWebsiteArea', {
  172. method: 'GET',
  173. query: {
  174. 'pid': id,
  175. },
  176. });
  177. regionList.value = xianData.data;
  178. }
  179. //4.展示行政区划 end ---------------------------------------->
  180. //5.执行搜索 start ---------------------------------------->
  181. const getcityid = ref("")
  182. //跳转到搜索页面
  183. // let goToSearch = (id) => {
  184. // console.log(id)
  185. // const route = `/search/search?catids=${id}`;
  186. // window.location.href = route;
  187. // }
  188. //获得cityid和
  189. let goToPrimary = async () => {
  190. if (province.value != "") { getcityid.value = province.value }
  191. if (city.value != "") { getcityid.value = city.value }
  192. if (region.value != "") { getcityid.value = region.value }
  193. if (province.value == ""&&city.value == ""&&region.value == ""&&depValue.value=="") {
  194. ElMessage.error('请选择行政区划或者职能部门!')
  195. }else{
  196. // const responseStatus = await requestDataPromise('/web/selectWebsiteCategory', {
  197. // method: 'GET',
  198. // query: {
  199. // 'cityid': getcityid.value,
  200. // 'department_id': depValue.value
  201. // },
  202. // });
  203. // if (responseStatus.data.catid && responseStatus.data.catid.length > 0) {
  204. // const catids = responseStatus.data.catid.join(',');
  205. // const route = `/search/search?catids=${catids}`;
  206. // window.location.href = route;
  207. // } else {
  208. // // 可以在这里处理数组为空的情况
  209. // console.log('没有可用的分类ID');
  210. // const route = `/search/search`;
  211. // window.location.href = route;
  212. // }
  213. const route = `/search/search?catids=${getcityid.value}&department_id=${depValue.value}`;
  214. window.location.href = route;
  215. }
  216. }
  217. //5.执行搜索 end ---------------------------------------->
  218. onMounted(async () => {
  219. //从客户端获取行政职能部门 加快打开速度
  220. try {
  221. const { $webUrl, $CwebUrl } = useNuxtApp();
  222. const response = await fetch($webUrl + '/web/selectWebsiteDepartment', {
  223. headers: {
  224. 'Content-Type': 'application/json',
  225. 'Userurl': $CwebUrl,
  226. 'Origin': $CwebUrl
  227. }
  228. });
  229. const result = await response.json();
  230. department.value = result.data;
  231. } catch (error) {
  232. console.error('获取部门数据失败:', error);
  233. }
  234. //从客户端获取行政区划
  235. try {
  236. const { $webUrl, $CwebUrl } = useNuxtApp();
  237. const response2 = await fetch($webUrl + '/web/selectWebsiteArea', {
  238. headers: {
  239. 'Content-Type': 'application/json',
  240. 'Userurl': $CwebUrl,
  241. 'Origin': $CwebUrl
  242. }
  243. });
  244. const result2 = await response2.json();
  245. provinceList.value = result2.data;
  246. } catch (error) {
  247. console.error('获取行政区划数据失败:', error);
  248. }
  249. })
  250. </script>
  251. <style lang="less" scoped>
  252. @import url('@/assets/css/nav.less');
  253. </style>