Преглед изворни кода

更新 SearchIndex.vue 搜索页面

reghao пре 7 месеци
родитељ
комит
9169ef7294

+ 0 - 1
src/components/layout/NavBar.vue

@@ -171,7 +171,6 @@ export default {
   data() {
     return {
       user: null,
-      activeIndex: '1',
       restaurants: [],
       searchHint: '想要搜点神马呢',
       searchType: '1',

+ 0 - 37
src/components/layout/NavBarNoSearch.vue

@@ -10,38 +10,6 @@
         </li>
       </ul>
     </el-col>
-    <el-col :md="8">
-      <el-menu
-        mode="horizontal"
-      >
-        <el-menu-item index="1">
-          <a href="/video" style="text-decoration-line: none">
-            <span style="color: #007bff">分区</span>
-          </a>
-        </el-menu-item>
-        <el-menu-item index="2">
-          <a href="/shortvideo" style="text-decoration-line: none">
-            <span style="color: #007bff">短视频</span>
-          </a>
-        </el-menu-item>
-        <el-menu-item index="3">
-          <a href="/playlist" style="text-decoration-line: none">
-            <span style="color: #007bff">播放列表</span>
-          </a>
-        </el-menu-item>
-        <el-menu-item index="9">
-          <a href="/discover" style="text-decoration-line: none">
-            <span style="color: #007bff">发现</span>
-          </a>
-        </el-menu-item>
-      </el-menu>
-    </el-col>
-    <el-col :md="6">
-      <ul class="el-menu--horizontal el-menu">
-        <li class="el-menu-item">
-        </li>
-      </ul>
-    </el-col>
     <el-col :md="8">
       <ul class="el-menu--horizontal el-menu">
         <li class="el-menu-item">
@@ -96,9 +64,6 @@
             <span class="el-icon-bell" style="color: #007bff">消息</span>
           </el-badge>
         </li>
-        <li class="el-menu-item">
-          <el-button size="mini" type="upload" icon="el-icon-upload" @click="goToPublish">投稿</el-button>
-        </li>
       </ul>
     </el-col>
   </el-row>
@@ -106,7 +71,6 @@
 
 <script>
 import { userMixin } from 'assets/js/mixin'
-import { keywordSuggest } from '@/api/search'
 import { getAuthedUser } from '@/utils/auth'
 import { getUnreadCount } from '@/api/user'
 
@@ -118,7 +82,6 @@ export default {
       user: null,
       activeIndex: '1',
       restaurants: [],
-      searchHint: '想要搜点神马呢',
       searchType: '1',
       keyword: '',
       statusCount: 0,

+ 53 - 17
src/views/search/SearchIndex.vue

@@ -2,15 +2,16 @@
   <el-container>
     <el-main>
       <nav-bar-no-search />
-      <el-row class="center">
+      <el-row style="padding: 5px">
         <el-input
           v-model="keyword"
-          placeholder="想要搜点神马呢"
+          :fetch-suggestions="querySearchAsync"
+          :placeholder="searchHint"
           class="input-with-select"
           clearable
           @focus="focus"
           @blur="blur"
-          @keyup.enter.native="searchHandler"
+          @keyup.enter.native="handleOnSearch"
         >
           <el-select
             slot="prepend"
@@ -21,7 +22,7 @@
             <el-option label="视频" value="2" />
             <el-option label="文书" value="3" />
           </el-select>
-          <el-button slot="append" icon="el-icon-search" @click="searchHandler" />
+          <el-button slot="append" icon="el-icon-search" @click="handleOnSearch" />
         </el-input>
         <!---设置z-index优先级,防止被走马灯效果遮挡-->
         <el-card
@@ -45,17 +46,14 @@
               @close="closeHandler(search)"
             >{{ search.name }}</el-tag>
             <dt class="search-title">热门搜索</dt>
-            <dd v-for="search in hotSearchList" :key="search.id">{{ search }}</dd>
+            <dd v-for="search in hotSearchList" :key="search.rank">{{ search.keyword }}</dd>
           </dl>
           <dl v-if="isSearchList">
-            <dd v-for="search in searchList" :key="search.id">{{ search }}</dd>
+            <dd v-for="search in searchList" :key="search.rank">{{ search.keyword }}</dd>
           </dl>
         </el-card>
       </el-row>
-      <el-row>
-        <el-col :md="6" class="movie-list">
-          <hot-search :card-prop="cardProp" />
-        </el-col>
+      <el-row style="padding: 5px">
         <el-col v-loading="loading" :md="18">
           <el-row v-if="videoSearch" class="movie-list">
             <el-col v-for="(video,index) in dataList" :key="index" :md="6" :sm="8" :xs="12">
@@ -118,11 +116,11 @@
           </el-row>
         </el-col>
       </el-row>
-      <el-row v-if="showEmpty" class="not-result">
-        <el-col :span="12" :offset="6">
+      <el-row v-if="showEmpty" style="padding: 5px">
+        <div>
           <img src="@/assets/img/icon/not-result.png">
-          <div>没有结果</div>
-        </el-col>
+          <span>没有结果</span>
+        </div>
       </el-row>
     </el-main>
 
@@ -243,7 +241,7 @@ import SearchVideoCard from '@/components/card/SearchVideoCard'
 import HotSearch from '@/components/card/HotSearch'
 import RandomUtil from '@/utils/random-util'
 import Store from '@/utils/store'
-import { videoQuery, hotKeyword, getWenshuDetail, wenshuQuery } from '@/api/search'
+import { videoQuery, hotKeyword, getWenshuDetail, wenshuQuery, keywordSuggest } from '@/api/search'
 
 export default {
   name: 'SearchIndex',
@@ -260,6 +258,8 @@ export default {
       pageSize: 10,
       totalSize: 0,
       dataList: [],
+      restaurants: [],
+      searchHint: '想要搜点神马呢',
       showEmpty: false,
       cardProp: {
         title: '热搜排行',
@@ -293,13 +293,14 @@ export default {
     }
   },
   mounted() {
-    hotKeyword().then(resp => {
+    /* hotKeyword().then(resp => {
       if (resp.code === 0) {
         this.cardProp.title = '热搜排行'
         this.cardProp.type = 'hotSearch'
         this.cardProp.dataList = resp.data
+        this.hotSearchList = resp.data
       }
-    })
+    })*/
   },
   created() {
     this.keyword = this.$route.query.keyword
@@ -320,6 +321,41 @@ export default {
       })
       this.$router.go(0)
     },
+    handleOnSearch() {
+      this.$router.push({
+        path: '/search',
+        query: {
+          searchType: this.searchType,
+          keyword: this.keyword,
+          pn: 1
+        }
+      })
+      this.$router.go(0)
+    },
+    querySearchAsync(queryString, cb) {
+      if (queryString === '') {
+        return
+      }
+
+      setTimeout(() => {
+        keywordSuggest(queryString).then(res => {
+          if (res.code === 0) {
+            this.restaurants = res.data.map((item) => {
+              return {
+                value: item.keyword,
+                rank: 1
+              }
+            })
+
+            // 如果 cb 返回一个空数组, 那么模糊搜索输入建议的下拉选项会因为 length 为 0 而消失
+            // cb([])
+            cb(this.restaurants)
+            // eslint-disable-next-line no-empty
+          } else {
+          }
+        })
+      }, 500)
+    },
     focus() {
       // this.$message.info('input focus')
       this.isFocus = true