|
@@ -15,6 +15,7 @@
|
|
|
<div class="divide-line" v-if="showBrowseList && showHistoryList"></div>
|
|
|
<history-list
|
|
|
v-if="showBrowseList"
|
|
|
+ class="browse-history"
|
|
|
title="历史浏览"
|
|
|
:list="buyerBrowseHistory"
|
|
|
@click="goBrowseClick"
|
|
@@ -64,10 +65,18 @@ export default {
|
|
|
return this.topSearch.input.split(' ').filter((v) => v.trim())
|
|
|
},
|
|
|
showHistoryList() {
|
|
|
- return this.type === 'history' && this.buyerSearchHistory.length && this.isLogin
|
|
|
+ return (
|
|
|
+ this.type === 'history' &&
|
|
|
+ this.buyerSearchHistory.length &&
|
|
|
+ this.isLogin
|
|
|
+ )
|
|
|
},
|
|
|
showBrowseList() {
|
|
|
- return this.type === 'history' && this.buyerBrowseHistory.length && this.isLogin
|
|
|
+ return (
|
|
|
+ this.type === 'history' &&
|
|
|
+ this.buyerBrowseHistory.length &&
|
|
|
+ this.isLogin
|
|
|
+ )
|
|
|
}
|
|
|
},
|
|
|
created() {
|
|
@@ -82,13 +91,33 @@ export default {
|
|
|
methods: {
|
|
|
...mapActions('search', ['removeHistory', 'setHistory']),
|
|
|
// 历史搜索、历史浏览
|
|
|
- getHistoryInfo() {
|
|
|
- getHistoryQuery({ type: '4,5' }).then((res) => {
|
|
|
- if (res.success === true) {
|
|
|
- this.buyerSearchHistory = res?.search || []
|
|
|
- res?.browse.forEach((s) => {
|
|
|
- this.buyerBrowseHistory.push(s.name)
|
|
|
- })
|
|
|
+ async getHistoryInfo() {
|
|
|
+ try {
|
|
|
+ if (!this.isLogin) return
|
|
|
+ const res = await getHistoryQuery({ type: '4,5' })
|
|
|
+ if (res.success) {
|
|
|
+ this.processSearchHistory(res.search)
|
|
|
+ this.processBrowseHistory(res.browse)
|
|
|
+ } else {
|
|
|
+ // 处理success为false的情况,例如记录日志、提示用户等
|
|
|
+ console.log('获取历史信息失败')
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ // 错误处理,例如记录日志、提示用户等
|
|
|
+ console.error('获取历史信息时发生错误:', error)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ processSearchHistory(searchHistory) {
|
|
|
+ if (!searchHistory || !Array.isArray(searchHistory)) return
|
|
|
+ this.buyerSearchHistory = searchHistory.map((s) =>
|
|
|
+ s.length > 20 ? s.slice(0, 20) : s
|
|
|
+ )
|
|
|
+ },
|
|
|
+ processBrowseHistory(browseHistory) {
|
|
|
+ if (!browseHistory || !Array.isArray(browseHistory)) return
|
|
|
+ browseHistory.forEach((item) => {
|
|
|
+ if (item.name) {
|
|
|
+ this.buyerBrowseHistory.push(item.name)
|
|
|
}
|
|
|
})
|
|
|
},
|
|
@@ -142,12 +171,14 @@ export default {
|
|
|
},
|
|
|
goPage(data) {
|
|
|
// 历史记录新增
|
|
|
- saveViewHistoryQuery({
|
|
|
- type: 'buyer',
|
|
|
- name: data?.label,
|
|
|
- }).then((res) => {
|
|
|
- console.log(res, 'res')
|
|
|
- })
|
|
|
+ if (this.isLogin) {
|
|
|
+ saveViewHistoryQuery({
|
|
|
+ type: 'buyer',
|
|
|
+ name: data?.label,
|
|
|
+ }).then((res) => {
|
|
|
+ console.log(res, 'res')
|
|
|
+ })
|
|
|
+ }
|
|
|
// 缓存定位值用于产品落地页
|
|
|
sessionStorage.setItem(
|
|
|
'landinfo',
|
|
@@ -249,5 +280,17 @@ export default {
|
|
|
height: 12px;
|
|
|
background: #F7F9FA;
|
|
|
}
|
|
|
+ .browse-history{
|
|
|
+ ::v-deep {
|
|
|
+ .hover-css--slide{
|
|
|
+ max-width: 100%;
|
|
|
+ }
|
|
|
+ .content-text {
|
|
|
+ white-space: nowrap;
|
|
|
+ overflow: hidden;
|
|
|
+ text-overflow: ellipsis;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
</style>
|