pageNavigation1.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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 `/${item.aLIas_pinyin}/1.html`;
  67. }else{
  68. return `/${item.aLIas_pinyin}/`;
  69. }
  70. }
  71. //2.加载模块数据 end ---------------------------------------->
  72. //3.职能部门 start ---------------------------------------->
  73. // let department = ref("")
  74. const depValue = ref("")
  75. const typeValue = ref("")
  76. // let departmentList = async () => {
  77. // const mkdata = await requestDataPromise('/web/selectWebsiteDepartment', {
  78. // method: 'GET',
  79. // query: {
  80. // 'keyword': department.value,
  81. // },
  82. // });
  83. // if(mkdata.code == 200){
  84. // department.value = mkdata.data;
  85. // }else{
  86. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  87. // console.log("错误位置:获取职能部门")
  88. // console.log("后端错误反馈:",mkdata.message)
  89. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  90. // }
  91. // }
  92. // //获得所有部门
  93. // departmentList();
  94. //3.职能部门 end ---------------------------------------->
  95. //4.展示行政区划 start ---------------------------------------->
  96. let areaList = ref("")
  97. //4.1 省
  98. let province = ref("")
  99. let provinceid = ref("")
  100. let provinceList = ref("")
  101. //4.2 市
  102. let city = ref("")
  103. let cityid = ref("")
  104. let cityList = ref("")
  105. //4.3 县
  106. let region = ref("")
  107. let regionid = ref("")
  108. let regionList = ref("")
  109. //选择省
  110. // let areaArrList = async () => {
  111. // const mkdata = await requestDataPromise('/web/selectWebsiteArea', {
  112. // method: 'GET',
  113. // query: {},
  114. // });
  115. // if(mkdata.code == 200){
  116. // provinceList.value = mkdata.data;
  117. // }else{
  118. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  119. // console.log("错误位置:获取行政区划")
  120. // console.log("后端错误反馈:",mkdata.message)
  121. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  122. // }
  123. // }
  124. // //一开始只需要获取一下省
  125. // areaArrList();
  126. onMounted(async () => {
  127. //从客户端获取行政区划
  128. try {
  129. const { $webUrl, $CwebUrl } = useNuxtApp();
  130. const response2 = await fetch($webUrl + '/web/selectWebsiteArea', {
  131. headers: {
  132. 'Content-Type': 'application/json',
  133. 'Userurl': $CwebUrl,
  134. 'Origin': $CwebUrl
  135. }
  136. });
  137. const result2 = await response2.json();
  138. provinceList.value = result2.data;
  139. } catch (error) {
  140. console.error('获取行政区划数据失败:', error);
  141. }
  142. })
  143. //选择市
  144. let change = async (id) => {
  145. provinceid.value = id;
  146. const shengData = await requestDataPromise('/web/selectWebsiteArea', {
  147. method: 'GET',
  148. query: {
  149. 'province': id,
  150. 'city': 0
  151. },
  152. });
  153. cityList.value = shengData.data.city;
  154. }
  155. //选择县
  156. let change1 = async (id) => {
  157. cityid.value = id;
  158. const xianData = await requestDataPromise('/web/selectWebsiteArea', {
  159. method: 'GET',
  160. query: {
  161. 'province': provinceid.value,
  162. 'city': cityid.value
  163. },
  164. });
  165. regionList.value = xianData.data.region;
  166. }
  167. //4.展示行政区划 end ---------------------------------------->
  168. //5.执行搜索 start ---------------------------------------->
  169. const getcityid = ref("")
  170. //跳转到搜索页面
  171. let goToSearch = (id) => {
  172. console.log(id)
  173. const route = `/search/search?catids=${id}`;
  174. window.open(route, '_blank');
  175. }
  176. //获得cityid和
  177. let goToPrimary = async () => {
  178. if (province.value != "") { getcityid.value = province.value }
  179. if (city.value != "") { getcityid.value = city.value }
  180. if (region.value != "") { getcityid.value = region.value }
  181. if (province.value == ""&&city.value == ""&&region.value == ""&&depValue.value=="") {
  182. ElMessage.error('请选择行政区划或者职能部门!')
  183. }else{
  184. const responseStatus = await requestDataPromise('/web/selectWebsiteCategory', {
  185. method: 'GET',
  186. query: {
  187. 'cityid': getcityid.value,
  188. 'department_id': depValue.value
  189. },
  190. });
  191. if (responseStatus.data.catid && responseStatus.data.catid.length > 0) {
  192. const catids = responseStatus.data.catid.join(',');
  193. const route = `/search/search?catids=${catids}`;
  194. window.open(route, '_blank');
  195. } else {
  196. // 可以在这里处理数组为空的情况
  197. console.log('没有可用的分类ID');
  198. const route = `/search/search`;
  199. window.open(route, '_blank');
  200. }
  201. }
  202. }
  203. let searchDepartment = () => {
  204. //搜索职能部门
  205. let status = false;
  206. for (let item of department.value) {
  207. if (item.name == typeValue.value) {
  208. //如果有就赋值过去
  209. depValue.value = item.id
  210. status = true; //说明有可用的结果
  211. }
  212. }
  213. if (status == true) {
  214. //弹出提示告诉用户不存在
  215. }
  216. }
  217. //5.执行搜索 end ---------------------------------------->
  218. </script>
  219. <style lang="less" scoped>
  220. @import url('@/assets/css/nav.less');
  221. </style>