HeadBlock.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <script setup lang="ts">
  2. import { ref, watch } from 'vue'
  3. import { Search } from '@element-plus/icons-vue'
  4. // import type { TabsInstance } from 'element-plus'
  5. import { useRoute, useRouter } from 'vue-router'
  6. import { getNews, type NewsData, type NewsResponseData } from '@/api/home'
  7. import { getFileExtension } from '@/utils/getFileExtension'
  8. import { queryFieldMethod } from '@/utils/queryFieldMethod'
  9. import { useSearchStore } from '@/stores/searchStore'
  10. import homeBG from '/public/static/首页背景.png'
  11. const searchStore = useSearchStore();
  12. const input3 = ref('')
  13. const firstNewsList = ref<NewsData[]>();
  14. const tabs = ref([
  15. { title: '企业名称', placeholder: '请输入企业名称' },
  16. { title: '统一社会信用代码', placeholder: '请输入统一社会信用代码' },
  17. { title: '站内文章', placeholder: '请输入站内文章关键字' }
  18. ])
  19. const isHome = ref<boolean>(false);
  20. const route: any = useRoute()
  21. const router: any = useRouter()
  22. const BASE_URL = import.meta.env.VITE_APP_BASE_URL;
  23. const homeImgUrl = ref<string>('');
  24. const munTabs = ref([
  25. { title: '首页', route: 'home' },
  26. { title: '信用动态', route: 'creditDynamics' },
  27. { title: '信用惠企', route: 'creditWiseEnterprise' },
  28. { title: '信用红榜', route: 'creditEcaluationResults' },
  29. { title: '信用警示', route: 'creditWarning' },
  30. { title: '企业自主上报', route: 'creditServices' },
  31. { title: '园区通知公告', route: 'about' }
  32. ])
  33. const checkIndex = ()=>{
  34. const filter = munTabs.value.find(item=> item.title == route.meta.title );
  35. let index =null;
  36. if(filter){
  37. index = munTabs.value.indexOf(filter)
  38. }
  39. return index;
  40. }
  41. const activeTab = ref(0)
  42. const activeMun = ref(checkIndex())
  43. const staticNews = ref<NewsData>();
  44. watch(() => route.meta.title,()=>{
  45. activeMun.value = checkIndex();
  46. })
  47. const placeholder = ref('请输入企业名称')
  48. // const tabPosition = ref<TabsInstance['tabPosition']>('left')
  49. const setActiveTab = (index: any, value: any) => {
  50. if(!index){
  51. activeTab.value = 0
  52. }else {
  53. activeTab.value = index
  54. }
  55. if(!value){
  56. placeholder.value = '请输入企业名称'
  57. }else {
  58. placeholder.value = value?.placeholder
  59. }
  60. }
  61. setActiveTab(route.query.searchModule,tabs.value[route.query.searchModule])
  62. const munActiveTab = (index: any, tab: any) => {
  63. activeMun.value = index
  64. router.push({
  65. path: tab.route,
  66. query: {}
  67. })
  68. }
  69. const toSearch = (searchModule:number,value:string)=>{
  70. router.push({
  71. path:'/search',
  72. query:{
  73. searchModule,
  74. value
  75. }
  76. })
  77. }
  78. const toDetail = (id:number|undefined)=>{
  79. if(!id){
  80. return;
  81. }
  82. router.push({
  83. path:'/newsDetail',
  84. query:{
  85. id
  86. }
  87. })
  88. }
  89. const getData =async ()=>{
  90. const res:NewsResponseData = await getNews(queryFieldMethod('special_column','big_news'));
  91. // console.log(res)
  92. if(res.code == 200){
  93. firstNewsList.value = res.data.slice(0,5);
  94. }
  95. const res1:NewsResponseData = await getNews(queryFieldMethod('special_column','static_news'))
  96. if(res1.code == 200){
  97. staticNews.value = res1.data[0];
  98. }
  99. // const find = res.data.find(item=>{
  100. // return item.files.find(q=>{
  101. // return getFileExtension(q.fileOriginalName) == 'png'||getFileExtension(q.fileOriginalName) == 'jpg'
  102. // })
  103. // })
  104. // if(find){
  105. // firstNews.value = find;
  106. // }else {
  107. // firstNews.value = res.data[0];
  108. // }
  109. // homeImgUrl.value = BASE_URL + firstNews.value?.files.find(item=>{
  110. // return getFileExtension(item.fileOriginalName) == 'png'||getFileExtension(item.fileOriginalName) == 'jpg'
  111. // })?.fileUrl
  112. // console.log(homeImgUrl)
  113. // console.log(firstNews.value)
  114. };
  115. const computeImgUrl = (files:FileType[])=>{
  116. return BASE_URL + files.filter(item=>{
  117. return getFileExtension(item.fileUrl) == 'png'||getFileExtension(item.fileUrl) == 'jpg'
  118. })?.[0]?.fileUrl
  119. }
  120. const init = ()=>{
  121. getData()
  122. if(route.query.value){
  123. input3.value = route.query.value;
  124. }
  125. }
  126. const toManager = ()=>{
  127. window.open('https://gxq.huaihua.gov.cn/qyxyfjflgl/')
  128. }
  129. init()
  130. </script>
  131. <template>
  132. <div class="headContainer w-99vw" :style="{
  133. backgroundImage:`url(${homeBG})`,
  134. backgroundSize: '100% 100%',
  135. objectFit: 'fill'
  136. }">
  137. <!-- 标题部分登录跳转 -->
  138. <div class="headTitle">
  139. <text>欢迎来到怀化高新区企业信用分级分类网</text>
  140. <div>
  141. <el-button type="primary" @click="toManager">登录</el-button>
  142. </div>
  143. </div>
  144. <!-- 头部功能及其显示内容 -->
  145. <div class="headModule">
  146. <div class="h-238px">
  147. <h1>怀化高新区企业信用分级分类网</h1>
  148. <!-- <h3>www.aabbccd.com</h3>-->
  149. </div>
  150. <div class="headSearch">
  151. <!-- 搜索上方tab切换选择 -->
  152. <div class="headSTab">
  153. <div v-for="(tab, index) in tabs" :key="index" class="tab cursor-pointer hover:bg-#FF9900 hover:bg-op-80" :class="{ active: activeTab == index }"
  154. @click="setActiveTab(index, tab)">
  155. {{ tab.title }}
  156. </div>
  157. </div>
  158. <!-- 搜索框位置 -->
  159. <div>
  160. <el-input v-model="input3" style="width: 337px;height:33px" :placeholder=placeholder
  161. class="input-with-select">
  162. <template #append>
  163. <el-button :icon="Search" @click="toSearch(activeTab,input3)" />
  164. </template>
  165. </el-input>
  166. </div>
  167. </div>
  168. </div>
  169. <div class="D" style="display:flex;justify-content:center">
  170. <div style="width:100%;
  171. bottom: 0;
  172. display: flex;
  173. justify-content: center;
  174. background:rgba(255,255,255,.22);
  175. height:46px"
  176. >
  177. <div class="headMune bg-opacity-22">
  178. <div v-for="(tab, index) in munTabs" :key="index" class="tab cursor-pointer hover:bg-#FF9900 hover:bg-op-80" :class="{ activeMun: activeMun === index }"
  179. @click="munActiveTab(index,tab)">
  180. {{ tab.title }}
  181. </div>
  182. </div>
  183. </div>
  184. </div>
  185. <div v-if="route.meta.title == '首页'">
  186. <div class="h-100px" >
  187. <div class="w-1112px ml-auto mr-auto text-center mt-21px mb-20px bg-white bg-opacity-90 h-102px cursor-pointer" @click="toDetail(staticNews?.id)">
  188. <div class="text-26px font-600 color-black line-height-60px pt-21px pb-10px">{{staticNews?.title}}</div>
  189. <div class="mb-17px " ></div>
  190. </div>
  191. </div>
  192. <div class="w-1112px ml-auto mr-auto mt-20px pb-54px ">
  193. <el-carousel :interval="5000" arrow="always" indicator-position="none" height="367px">
  194. <el-carousel-item v-for="item in firstNewsList" :key="item">
  195. <div class="flex">
  196. <div class="w-685px h-351px">
  197. <img class="w-100% h-100%" :src="computeImgUrl(item.files)" />
  198. </div>
  199. <div class="w-427px h-351px p-22px bg-white bg-opacity-90">
  200. <div class="w-368px h-44px mb-12px bold text-22px line-height-22px line-clamp-2">{{item.title}}</div>
  201. <div class="w-368px h-206px mb-17px line-clamp-8 line-height-23px overflow-hidden text-13px" v-html="item.content"></div>
  202. <div class="color-006eff cursor-pointer text-right" @click="toDetail(item.id)" >了解更多 ></div>
  203. </div>
  204. </div>
  205. </el-carousel-item>
  206. </el-carousel>
  207. </div>
  208. </div>
  209. </div>
  210. </template>
  211. <style scoped lang="scss">
  212. $boxWidth: 1200px;
  213. .headContainer {
  214. background-size: 100% 100%;
  215. position: relative;
  216. //background-image: url(src/assets/img/首页背景.png);
  217. .headTitle {
  218. margin: 0 40px;
  219. height: 40px;
  220. display: flex;
  221. justify-content: space-between;
  222. align-items: center;
  223. text {
  224. font-weight: 400;
  225. font-size: 13px;
  226. color: #FFFFFF;
  227. }
  228. }
  229. .headModule {
  230. margin-top: 27px;
  231. width: $boxWidth;
  232. margin: 27px auto 0 auto;
  233. display: flex;
  234. justify-content: space-between;
  235. align-items: center;
  236. H1 {
  237. font-weight: bold;
  238. font-size: 26px;
  239. color: #FFFFFF;
  240. }
  241. H3 {
  242. font-weight: bold;
  243. font-size: 14px;
  244. color: #FFFFFF;
  245. margin: 16px 0 0 0;
  246. }
  247. .headSearch {
  248. .headSTab {
  249. display: flex;
  250. .tab {
  251. color: white;
  252. padding: 6px 6px;
  253. margin-bottom: 16px;
  254. border-radius: 6px;
  255. }
  256. .active {
  257. background-color: #FF9900;
  258. }
  259. }
  260. }
  261. }
  262. .headMune {
  263. width: 100%;
  264. bottom: 0;
  265. width: $boxWidth;
  266. display: flex;
  267. justify-content: space-between;
  268. align-items: center;
  269. height: 46px;
  270. .tab {
  271. color: white;
  272. width: 100%;
  273. height: 100%;
  274. display: flex;
  275. justify-content: center;
  276. align-items: center;
  277. }
  278. .activeMun {
  279. background-color: #FF9900;
  280. }
  281. }
  282. }
  283. </style>