瀏覽代碼

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

yangfeng 1 年之前
父節點
當前提交
4789316532

+ 9 - 0
data/data-models/modules/quick-search-history/api/search-history.js

@@ -20,3 +20,12 @@ export function ajaxClearSearchHistory(data) {
     data: qs.stringify(data)
   })
 }
+
+// 保存浏览记录(企业画像、采购单位画像)
+export function ajaxSaveViewHistory(data) {
+  return useRequest({
+    url: `/publicapply/history/savePortrait`,
+    method: 'post',
+    data: qs.stringify(data)
+  })
+}

+ 3 - 2
data/data-models/modules/quick-search-history/model/index.js

@@ -4,13 +4,14 @@ import SearchHistoryBaseApi from '../plugins/base'
 function useSearchHistoryModel(config) {
   const useApiModel = new SearchHistoryBaseApi(config)
 
-  const { getHistoryQuery, clearHistoryQuery } = useApiModel
+  const { getHistoryQuery, clearHistoryQuery, saveViewHistoryQuery } = useApiModel
   const { searchHistoryList } = toRefs(reactive(useApiModel))
 
   return {
     searchHistoryList,
     getHistoryQuery,
-    clearHistoryQuery
+    clearHistoryQuery,
+    saveViewHistoryQuery
   }
 }
 

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

@@ -1,18 +1,26 @@
-import { ajaxGetSearchHistory, ajaxClearSearchHistory } from '../api/search-history'
+import { ajaxGetSearchHistory, ajaxClearSearchHistory, ajaxSaveViewHistory  } from '../api/search-history'
 
 class SearchHistoryBaseApi {
   constructor(config = {}) {
+    // 搜索历史type
+    this.searchType = [1, 2, 4]
+    // 浏览历史type
+    this.browseType = [3, 5]
+    // 历史搜索列表
     this.searchHistoryList = []
+    // 历史浏览记录列表
+    this.browseHistoryList = []
     this._getParams = config.getParams || (() => {})
     // 函数 Hooks
     this.getHistoryQuery = this.runQuery.bind(this)
     this.clearHistoryQuery = this.ajaxClearQuery.bind(this)
+    this.saveViewHistoryQuery = this.ajaxSaveViewQuery.bind(this)
   }
 
   /**
    * 统一查询 API 入口
    * @param params - 请求参数
-   * @returns {Promise<{success: boolean, list: []}>}
+   * @returns {Promise<{success: boolean, search: [], browse: []}>}
    */
 
   async runQuery(params) {
@@ -20,9 +28,11 @@ class SearchHistoryBaseApi {
     const query = Object.assign({}, params, this._getParams(params))
     const result = await this.ajaxQuery(query)
     if (result.success) {
-      this.searchHistoryList = result.list
+      this.searchHistoryList = result.search
+      this.browseHistoryList = result.browse
     } else {
       this.searchHistoryList = []
+      this.browseHistoryList = []
     }
     return result
   }
@@ -34,7 +44,8 @@ class SearchHistoryBaseApi {
 
       return {
         success: success,
-        list: res.data.reverse() || []
+        search: res?.data?.search ? res.data.search.reverse() : [],
+        browse: res?.data?.browse ? res.data.browse.reverse() : []
       }
     })
   }
@@ -46,11 +57,23 @@ class SearchHistoryBaseApi {
       let success = res?.error_code === 0
 
       if (success && res.data) {
-        this.searchHistoryList = []
+        // 清除成功再次获取历史列表
+        this.getHistoryQuery(params)
       }
       return {
-        success: success,
-        list: []
+        success: success && res?.data
+      }
+    })
+  }
+
+  // 保存企业浏览记录
+  async ajaxSaveViewQuery(params) {
+    const query = Object.assign({}, params, this._getParams(params))
+    return ajaxSaveViewHistory(query).then((res) => {
+      let success = res?.error_code === 0
+
+      return {
+        success: success && res?.data
       }
     })
   }