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