Search.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <script setup>
  2. import {reactive} from 'vue'
  3. import { Search } from '@element-plus/icons-vue'
  4. import { apiReportSearch } from '@/api/report'
  5. import { useRouter } from 'vue-router'
  6. const router=useRouter()
  7. let listState=reactive({
  8. keywords:'',
  9. page:1,
  10. pageSize:20,
  11. list:[],
  12. loading:false,
  13. finished:false
  14. })
  15. async function getReportList(){
  16. if(!listState.keywords) return
  17. listState.loading=true
  18. const res=await apiReportSearch({
  19. key_word:listState.keywords,
  20. page_size:listState.pageSize,
  21. current:listState.page
  22. })
  23. setTimeout(() => {
  24. listState.loading=false
  25. }, 100);
  26. if(res.code===200){
  27. const arr=res.data.list||[]
  28. listState.list=[...listState.list,...arr]
  29. if(arr.length<listState.pageSize){
  30. listState.finished=true
  31. }
  32. }
  33. }
  34. function handleSearch(){
  35. listState.list=[]
  36. listState.page=1
  37. listState.finished=false
  38. getReportList()
  39. }
  40. //跳转详情
  41. function goReportDetail(item){
  42. const url=router.resolve({
  43. path:'/report/detail',
  44. query:{
  45. code:item.report_code
  46. }
  47. })
  48. window.open(url.href,'_blank')
  49. }
  50. </script>
  51. <template>
  52. <div class="report-search-page">
  53. <div class="header-wrap" @click="$router.replace('/')">
  54. <span>HORIZON INSIGHTS</span>
  55. </div>
  56. <div class="search-box">
  57. <el-input
  58. v-model="listState.keywords"
  59. class="self-input"
  60. placeholder="Please Input Keywords"
  61. :suffix-icon="Search"
  62. @change="handleSearch"
  63. />
  64. </div>
  65. <div v-if="listState.list.length===0" class="empty">no results</div>
  66. <div class="report-list-wrap" v-else>
  67. <div class="item" v-for="item in listState.list" :key="item.id" @click="goReportDetail(item)">
  68. <div class="title" v-html="item.title"></div>
  69. <div class="intro" v-html="item.content_sub"></div>
  70. <div class="time">{{item.publish_time}}</div>
  71. </div>
  72. </div>
  73. </div>
  74. </template>
  75. <style lang="scss" scoped>
  76. .header-wrap{
  77. text-align: center;
  78. font-size: 40px;
  79. font-weight: bold;
  80. color: var(--el-color-primary);
  81. padding: 40px 0;
  82. border-bottom: 1px solid#E6E6E6;
  83. position: sticky;
  84. top: 0;
  85. background-color: #fff;
  86. z-index: 99;
  87. cursor: pointer;
  88. }
  89. @media (max-width: 768px){
  90. .header-wrap{
  91. border: none;
  92. font-size: 17px;
  93. box-shadow: 0px 4px 20px rgba(180, 180, 180, 0.16);
  94. padding: 15px 0;
  95. }
  96. }
  97. .search-box{
  98. width: 640px;
  99. margin: 60px auto 0 auto;
  100. .self-input{
  101. :deep(.el-input__wrapper){
  102. border-radius: 24px;
  103. border: 1px solid #000000;
  104. height: 48px;
  105. }
  106. }
  107. }
  108. @media (max-width: 768px){
  109. .search-box{
  110. width: calc(100vw - 34px);
  111. margin: 30px auto 0 auto;
  112. .self-input{
  113. :deep(.el-input__wrapper){
  114. height: 40px;
  115. }
  116. }
  117. }
  118. }
  119. .empty{
  120. padding: 50px 0 ;
  121. text-align: center;
  122. color: #666;
  123. }
  124. .report-list-wrap{
  125. width: 600px;
  126. margin: 50px auto;
  127. .item{
  128. border-bottom: 1px solid #E6E6E6;
  129. padding: 20px 0;
  130. .title{
  131. font-size: 20px;
  132. font-weight: 600;
  133. }
  134. .intro{
  135. font-size: 14px;
  136. color: #666;
  137. line-height: 17px;
  138. margin: 10px 0;
  139. }
  140. .time{
  141. font-size: 14px;
  142. color: #999;
  143. }
  144. }
  145. }
  146. @media (max-width: 768px){
  147. .report-list-wrap{
  148. width: 100%;
  149. padding: 0 17px;
  150. margin: 25px 0;
  151. .item{
  152. padding: 10px 0;
  153. .title{
  154. font-size: 14px;
  155. }
  156. .time{
  157. font-size: 12px;
  158. }
  159. }
  160. }
  161. }
  162. </style>