|
@@ -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
|
|
|
}
|
|
|
})
|
|
|
}
|