Browse Source

fix:页面首次搜索优化

zhangsiya 1 year ago
parent
commit
3bcd763463

+ 1 - 1
apps/bigmember_pc/src/components/article-item/ArticleItem.vue

@@ -417,7 +417,7 @@ export default {
       const keywords = this.getMatchKeys
       const keywords = this.getMatchKeys
       if (inFile) {
       if (inFile) {
         const keyword = keywords[0]
         const keyword = keywords[0]
-        if (keyword.length > 3) {
+        if (keyword?.length > 3) {
           return `(<span class="highlight-text">${keyword.substring(0, 3)}</span>...在附件中)`
           return `(<span class="highlight-text">${keyword.substring(0, 3)}</span>...在附件中)`
         } else {
         } else {
           return `(<span class="highlight-text">${keyword}</span>在附件中)`
           return `(<span class="highlight-text">${keyword}</span>在附件中)`

+ 1 - 0
apps/bigmember_pc/src/views/search/bidding/components/search-bid-header.vue

@@ -82,6 +82,7 @@ const showNewPublish = computed(() => {
       :show-workspace-button="isLogin && !isInApp"
       :show-workspace-button="isLogin && !isInApp"
       :showTab="!inBIPropertyIframe"
       :showTab="!inBIPropertyIframe"
       @goWorkSpace="goWorkSpace"
       @goWorkSpace="goWorkSpace"
+      :immediateSearch="false"
     >
     >
       <div class="flex flex-(row items-center)">
       <div class="flex flex-(row items-center)">
         <div class="flex flex-(row items-center)">
         <div class="flex flex-(row items-center)">

+ 21 - 15
apps/bigmember_pc/src/views/search/bidding/model/base.js

@@ -557,7 +557,7 @@ export default function () {
   // 条件:1.精准搜索模式 2.返回无数据 3.有主关键词或附加词
   // 条件:1.精准搜索模式 2.返回无数据 3.有主关键词或附加词
   let autoSwitchModel = false
   let autoSwitchModel = false
   const { goback } = useRoute().query
   const { goback } = useRoute().query
-  function changeSearchMode () {
+  function changeSearchMode (searchType) {
     const total = listState.total
     const total = listState.total
     const { searchMode, additionalWords,  input } = inputKeywordsState.value
     const { searchMode, additionalWords,  input } = inputKeywordsState.value
     const jzModel = searchMode === '0' && (additionalWords || input)
     const jzModel = searchMode === '0' && (additionalWords || input)
@@ -565,7 +565,7 @@ export default function () {
     if(!autoSwitchModel && jzModel && total === 0) {
     if(!autoSwitchModel && jzModel && total === 0) {
       autoSwitchModel = true
       autoSwitchModel = true
       inputKeywordsState.value.searchMode = '1'
       inputKeywordsState.value.searchMode = '1'
-      doQuery()
+      doQuery({}, searchType)
     }
     }
     if(mhModel && autoSwitchModel) {
     if(mhModel && autoSwitchModel) {
       if( total > 0) {
       if( total > 0) {
@@ -616,12 +616,6 @@ export default function () {
     if (!onTheWhiteList.value) {
     if (!onTheWhiteList.value) {
       const searchKeywords = inputKeywordsState.value.input
       const searchKeywords = inputKeywordsState.value.input
       const hasOneKey = (filterState.value.buyer?.length || filterState.value.winner?.length ||  filterState.value.agency?.length) > 0
       const hasOneKey = (filterState.value.buyer?.length || filterState.value.winner?.length ||  filterState.value.agency?.length) > 0
-      // 切换三种筛选类型时候判断(切换tab时不弹窗)
-      // if (!searchKeywords && !hasOneKey) {
-      //   if (from.indexOf('tab-') !== -1) {
-      //     return false
-      //   }
-      // }
       // 关键词去两边空格后为空
       // 关键词去两边空格后为空
       if (!searchKeywords && inputKeywordsState.value.additionalWords.length === 0) {
       if (!searchKeywords && inputKeywordsState.value.additionalWords.length === 0) {
         if (!hasOneKey) {
         if (!hasOneKey) {
@@ -640,7 +634,7 @@ export default function () {
     return true
     return true
   }
   }
   // 搜索前 处理一些事情
   // 搜索前 处理一些事情
-  function beforeSearch (pageNum) {
+  function beforeSearchSomthing (pageNum) {
     // 列表清空
     // 列表清空
     list.value = []
     list.value = []
     listState.total = 0
     listState.total = 0
@@ -681,16 +675,16 @@ export default function () {
     if(!bSearch) {
     if(!bSearch) {
       return
       return
     }
     }
-    beforeSearch (pageNum)
+    beforeSearchSomthing (pageNum)
     // Ajax请求
     // Ajax请求
     return doRunQuery(getParams(params)).then((res) => {
     return doRunQuery(getParams(params)).then((res) => {
-      afterQueryAjax(res)
+      afterQueryAjax(res, searchType)
     })
     })
   }
   }
   // 处理查询请求后的数据以及其他业务
   // 处理查询请求后的数据以及其他业务
-  function afterQueryAjax (res) {
+  function afterQueryAjax (res, searchType) {
     // 变更搜索模式
     // 变更搜索模式
-    changeSearchMode()
+    changeSearchMode(searchType)
 
 
     const { origin } = res
     const { origin } = res
 
 
@@ -1214,8 +1208,8 @@ export default function () {
     const originParams = packageFilter()
     const originParams = packageFilter()
     _storage.setItem(key, JSON.stringify(originParams))
     _storage.setItem(key, JSON.stringify(originParams))
 
 
-    // window.location.replace('/swordfish/page_big_pc/search/bidding?goback=true')
-    window.location.replace(`/page_workDesktop/work-bench/page?link=${encodeURIComponent(goHref_ + '?goback=true')}`)
+    window.location.replace('/swordfish/page_big_pc/search/bidding?goback=true')
+    // window.location.replace(`/page_workDesktop/work-bench/page?link=${encodeURIComponent(goHref_ + '?goback=true')}`)
   }
   }
 
 
   // 监听路由事件
   // 监听路由事件
@@ -1319,6 +1313,10 @@ export default function () {
           restoreSearchGroupFromLocal()
           restoreSearchGroupFromLocal()
           const defaultSelectType = ['title', 'content']
           const defaultSelectType = ['title', 'content']
           filterState.value.selectType = defaultSelectType
           filterState.value.selectType = defaultSelectType
+          if(!goback) {
+            // 非工作台外跳转进入则默认搜索
+            firstSearch()
+          }
         }
         }
 
 
         // vip 或者 桌面跳转回显筛选条件
         // vip 或者 桌面跳转回显筛选条件
@@ -1335,9 +1333,17 @@ export default function () {
             }
             }
           }
           }
         })
         })
+      } else {
+        firstSearch()
       }
       }
+    } else {
+      firstSearch()
     }
     }
   }
   }
+
+  function firstSearch () {
+    return doQuery({}, 'firstSearch')
+  }
   /**
   /**
    * 检查是否需要切换模糊搜索、是否展示提示
    * 检查是否需要切换模糊搜索、是否展示提示
    * 1. 精准搜索无数据 (自动切换模糊搜索)
    * 1. 精准搜索无数据 (自动切换模糊搜索)

+ 6 - 0
apps/bigmember_pc/src/views/search/components/search-header-card.vue

@@ -29,6 +29,11 @@ const props = defineProps({
   showTab: {
   showTab: {
     type: Boolean,
     type: Boolean,
     default: true
     default: true
+  },
+  // 立即搜索
+  immediateSearch: {
+    type: Boolean,
+    default: true
   }
   }
 })
 })
 
 
@@ -65,6 +70,7 @@ function goWorkSpaceCustom() {
       :show-wx-qr="showWxQr"
       :show-wx-qr="showWxQr"
       @input="$emit('input', $event)"
       @input="$emit('input', $event)"
       @search="$emit('search', $event)"
       @search="$emit('search', $event)"
+      :immediateSearch="immediateSearch"
     >
     >
       <div class="tab-switch" slot="tab-switch">
       <div class="tab-switch" slot="tab-switch">
         <slot name="tab-switch-content"></slot>
         <slot name="tab-switch-content"></slot>