浏览代码

Merge branch 'dev/v1.0.53_yf' of jianyu/web into feature/v1.0.53

yangfeng 1 年之前
父节点
当前提交
322c0e508b

+ 70 - 0
apps/bigmember_pc/src/components/history/BrowseHistory.vue

@@ -0,0 +1,70 @@
+<script setup>
+const props = defineProps({
+  list: {
+    type: Array,
+    default: () => []
+  }
+})
+
+const emit = defineEmits(['clear', 'select'])
+
+function onClickItem(item) {
+  emit('select', item)
+}
+
+function onClickClear() {
+  emit('clear')
+}
+
+</script>
+
+<template>
+  <div class="browse-history-card">
+    <div class="history-container">
+      <div class="history-header flex justify-between flex-items-center">
+        <span>历史浏览</span>
+        <i class="el-icon-delete" @click="onClickClear"></i>
+      </div>
+      <div class="history-main">
+        <div
+          class="list-item ellipsis"
+          v-for="(item, index) in list"
+          :data-id="item.id"
+          :key="index"
+          @click="onClickItem(item)"
+        >
+          {{ item.name }}
+        </div>
+      </div>
+    </div>
+    <slot></slot>
+  </div>
+</template>
+
+<style lang="scss" scoped>
+.browse-history-card {
+  .history-header{
+    padding: 0 20px;
+    font-size: 12px;
+    line-height: 18px;
+    color: #686868;
+    .el-icon-delete{
+      font-size: 15px;
+      cursor: pointer;
+    }
+  }
+  .history-main{
+    margin-top: 12px;
+    .list-item{
+      padding: 9px 20px;
+      font-size: 14px;
+      line-height: 22px;
+      cursor: pointer;
+      &:hover{
+        background: #EAF8FA;
+        color: #2ABED1;
+      }
+    }
+  }
+}
+</style>

+ 78 - 0
apps/bigmember_pc/src/components/history/SearchHistory.vue

@@ -0,0 +1,78 @@
+<script setup>
+const props = defineProps({
+  list: {
+    type: Array,
+    default: () => []
+  }
+})
+
+const emit = defineEmits(['clear', 'tag'])
+
+function onClickTag(item) {
+  emit('tag', item)
+}
+
+function onClickClear() {
+  emit('clear')
+}
+
+function formatTag(tag) {
+  if (!tag) return
+  return tag.length > 20? `${tag.slice(0, 20)}...` : tag
+}
+</script>
+
+<template>
+  <div class="search-history-card b-rd-8px">
+    <div class="history-container">
+      <div class="history-header flex justify-between flex-items-center">
+        <span>历史搜索</span>
+        <i class="el-icon-delete" @click="onClickClear"></i>
+      </div>
+      <div class="history-main">
+        <div class="tag-container flex flex-wrap">
+          <span
+            class="tag-item"
+            v-for="(item, index) in list"
+            :key="index"
+            @click.prevent="onClickTag(item)"
+          >
+            {{ formatTag(item) }}
+          </span>
+        </div>
+      </div>
+    </div>
+    <slot></slot>
+  </div>
+</template>
+
+<style lang="scss" scoped>
+.search-history-card {
+  .history-header{
+    padding: 0 20px;
+    font-size: 12px;
+    line-height: 18px;
+    color: #686868;
+    .el-icon-delete{
+      font-size: 15px;
+      cursor: pointer;
+    }
+  }
+  .history-main{
+    padding: 0 20px;
+    margin-top: 12px;
+    .tag-item{
+      display: inline-block;
+      padding: 1px 8px;
+      margin-right: 12px;
+      margin-bottom: 12px;
+      border-radius: 4px;
+      background: #F5F6F7;
+      font-size: 14px;
+      line-height: 22px;
+      border: 1px solid #ECECEC;
+      cursor: pointer;
+    }
+  }
+}
+</style>

+ 43 - 2
apps/bigmember_pc/src/components/search-input/SearchInput.vue

@@ -5,8 +5,8 @@
       :placeholder="placeholder"
       :value="value"
       :clearable="clearable"
-      @focus="preSearch.focus = true"
-      @blur="preSearch.focus = false"
+      @focus="focus"
+      @blur="blur"
       @input="input"
       @keyup.enter.native="onSearch"
     >
@@ -29,6 +29,12 @@
     >
       <slot name="preSearchContent"></slot>
     </div>
+    <div
+      class="search-history-list"
+      v-show="historyShow"
+    >
+      <slot name="history"></slot>
+    </div>
   </div>
 </template>
 
@@ -51,6 +57,10 @@ export default {
     perSearchEnabled: {
       type: Boolean,
       default: false
+    },
+    historyEnabled: {
+      type: Boolean,
+      default: false
     }
   },
   model: {
@@ -72,6 +82,9 @@ export default {
         this.perSearchEnabled &&
         (this.preSearch.focus || this.preSearch.hover)
       )
+    },
+    historyShow() {
+      return !this.value && this.preSearch.focus && this.historyEnabled
     }
   },
   methods: {
@@ -80,6 +93,19 @@ export default {
     },
     onSearch() {
       this.$emit('onSearch', this.value)
+    },
+    focus(e) {
+      this.preSearch.focus = true
+      this.$emit('focus', e)
+    },
+    blur(e) {
+      // 由于JavaScript为单线程,同一时间只能执行处理一个事件,“blur优先于click执行”,下拉框内的click事件将会执行不了
+      // 解决方案1:对blur事件进行延迟,让click先执行
+      // 方案2:用mousedown事件替换click事件(鼠标事件优先于blur事件)
+      setTimeout(() => {
+        this.preSearch.focus = false
+        this.$emit('blur', e)
+      }, 300)
     }
   }
 }
@@ -162,4 +188,19 @@ export default {
     }
   }
 }
+.search-history-list{
+  padding: 20px 0;
+  position: absolute;
+  z-index: 6;
+  top: 42px;
+  width: 100%;
+  max-height: 520px;
+  background: #fff;
+  box-shadow: 0 0 20px rgb(0, 0, 0, 0.1);
+  border-radius: 8px;
+  overflow-y: auto;
+  &::-webkit-scrollbar{
+    width: 4px;
+  }
+}
 </style>

+ 12 - 12
data/data-models/modules/quick-search-history/plugins/base.js

@@ -2,15 +2,12 @@ import { ajaxGetSearchHistory, ajaxClearSearchHistory, ajaxSaveViewHistory  } fr
 
 class SearchHistoryBaseApi {
   constructor(config = {}) {
-    // 搜索历史type
-    this.searchType = [1, 2, 4]
-    // 浏览历史type
-    this.browseType = [3, 5]
+    // 初始化需要将type值传进来(标讯搜索:1  企业搜索:2,3 采购单位搜索: 4,5)
+    this._getParams = config || (() => {})
     // 历史搜索列表
     this.searchHistoryList = []
     // 历史浏览记录列表
     this.browseHistoryList = []
-    this._getParams = config.getParams || (() => {})
     // 函数 Hooks
     this.getHistoryQuery = this.runQuery.bind(this)
     this.clearHistoryQuery = this.ajaxClearQuery.bind(this)
@@ -24,9 +21,7 @@ class SearchHistoryBaseApi {
    */
 
   async runQuery(params) {
-    this.searchHistoryList = []
-    this.browseHistoryList = []
-    const query = Object.assign({}, params, this._getParams(params))
+    const query = Object.assign({}, params)
     const result = await this.ajaxQuery(query)
     if (result.success) {
       this.searchHistoryList = result.search
@@ -68,13 +63,14 @@ class SearchHistoryBaseApi {
 
   // 清除搜索历史
   async ajaxClearQuery(params) {
-    const query = Object.assign({}, params, this._getParams(params))
+    const query = Object.assign({}, params)
     return ajaxClearSearchHistory(query).then((res) => {
       let success = res?.error_code === 0
 
+      const { type } = this._getParams
       if (success && res.data) {
         // 清除成功再次获取历史列表
-        this.getHistoryQuery(params)
+        this.getHistoryQuery({ type: type })
       }
       return {
         success: success && res?.data
@@ -84,10 +80,14 @@ class SearchHistoryBaseApi {
 
   // 保存企业浏览记录
   async ajaxSaveViewQuery(params) {
-    const query = Object.assign({}, params, this._getParams(params))
+    const { type } = this._getParams
+    const query = Object.assign({}, params)
     return ajaxSaveViewHistory(query).then((res) => {
       let success = res?.error_code === 0
-
+      if (success && res.data &&  type) {
+        // 保存成功更新历史列表
+        this.getHistoryQuery({ type: type })
+      }
       return {
         success: success && res?.data
       }