|
@@ -2,7 +2,7 @@ import { ajaxGetSearchHistory, ajaxClearSearchHistory, ajaxSaveViewHistory } fr
|
|
|
|
|
|
class SearchHistoryBaseApi {
|
|
|
constructor(config = {}) {
|
|
|
- // 初始化需要将type值传进来(标讯搜索:1 企业搜索:2,3 采购单位搜索: 4,5)
|
|
|
+ // 初始化需要将type值传进来(标讯搜索:1 企业搜索:2,3 采购单位搜索: 4,5)必传
|
|
|
this._getParams = config || (() => {})
|
|
|
// 历史搜索列表
|
|
|
this.searchHistoryList = []
|
|
@@ -15,13 +15,13 @@ class SearchHistoryBaseApi {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 统一查询 API 入口
|
|
|
- * @param params - 请求参数
|
|
|
+ * 历史搜索、历史浏览查询 API 入口
|
|
|
+ * @param params - 请求参数(可传可不传,不传会从this._getParams中取 传了会合并)
|
|
|
* @returns {Promise<{success: boolean, search: [], browse: []}>}
|
|
|
*/
|
|
|
|
|
|
async runQuery(params) {
|
|
|
- const query = Object.assign({}, params)
|
|
|
+ const query = Object.assign({}, params, this._getParams)
|
|
|
const result = await this.ajaxQuery(query)
|
|
|
if (result.success) {
|
|
|
this.searchHistoryList = result.search
|
|
@@ -38,7 +38,7 @@ class SearchHistoryBaseApi {
|
|
|
return ajaxGetSearchHistory(params).then((res) => {
|
|
|
let success = res?.error_code === 0
|
|
|
if (res?.data?.browse) {
|
|
|
- // 格式化浏览历史数据(企业画像浏览记录跳转需要企业id, 存历史记录的时候保存格式为“企业名称_企业id”)
|
|
|
+ // 格式化浏览历史数据(企业画像浏览记录跳转需要企业id, 存历史记录的时候保存格式为“企业名称_企业id”, 取的时候要分割开)
|
|
|
res.data.browse = res.data.browse.map((item) => {
|
|
|
if (item.indexOf('_') > -1) {
|
|
|
const [name, id] = item.split('_')
|
|
@@ -61,15 +61,17 @@ class SearchHistoryBaseApi {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- // 清除搜索历史
|
|
|
+ /**
|
|
|
+ * 清除搜索历史
|
|
|
+ * @param params - 请求参数必传
|
|
|
+ */
|
|
|
async ajaxClearQuery(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) {
|
|
|
- // 清除成功再次获取历史列表
|
|
|
+ if (success && res.data && type) {
|
|
|
+ // 清除成功更新取历史列表
|
|
|
this.getHistoryQuery({ type: type })
|
|
|
}
|
|
|
return {
|
|
@@ -78,13 +80,16 @@ class SearchHistoryBaseApi {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- // 保存企业浏览记录
|
|
|
+ /**
|
|
|
+ * 保存画像浏览记录
|
|
|
+ * @param params - {type: buyer-采购单位画像 ent-企业画像, name: 采购单位画像时传名称,企业画像传 名称_企业id}
|
|
|
+ */
|
|
|
async ajaxSaveViewQuery(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) {
|
|
|
+ if (success && res.data && type) {
|
|
|
// 保存成功更新历史列表
|
|
|
this.getHistoryQuery({ type: type })
|
|
|
}
|