Skip to content

Commit 1b6f3f0

Browse files
author
Taois
committed
feat:搜索触发机制
1 parent 7dae6fc commit 1b6f3f0

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

dashboard/src/views/SearchAggregation.vue

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -995,24 +995,43 @@ export default defineComponent({
995995
watch(() => route.query, (newQuery, oldQuery) => {
996996
const keyword = newQuery.keyword;
997997
const oldKeyword = oldQuery?.keyword;
998+
const isReturnFromDetail = newQuery._returnFromDetail === 'true';
999+
const newTimestamp = newQuery._t;
1000+
const oldTimestamp = oldQuery?._t;
1001+
1002+
// 检查是否只是时间戳参数变化(用于强制重新搜索)
1003+
const isTimestampOnlyChange = keyword === oldKeyword && newTimestamp !== oldTimestamp;
9981004
9991005
console.log('🔄 [路由监听] query变化:', {
10001006
newQuery,
10011007
oldQuery,
10021008
keyword,
10031009
oldKeyword,
1004-
currentKeyword: searchKeyword.value
1010+
currentKeyword: searchKeyword.value,
1011+
isReturnFromDetail,
1012+
isTimestampOnlyChange,
1013+
newTimestamp,
1014+
oldTimestamp
10051015
});
10061016
console.log('🔄 [路由监听] keyword类型:', typeof keyword, '值:', keyword);
10071017
console.log('🔄 [路由监听] 条件判断 keyword存在:', !!keyword);
10081018
10091019
if (keyword) {
1010-
// 只要有keyword参数,就执行搜索(用户点击搜索按钮时应该重新搜索)
1011-
console.log('🔄 [路由监听] 准备执行搜索:', keyword);
1012-
searchKeyword.value = keyword;
1013-
console.log('🔄 [路由监听] 即将调用performSearch');
1014-
performSearch(keyword);
1015-
console.log('🔄 [路由监听] performSearch调用完成');
1020+
if (isReturnFromDetail) {
1021+
// 从详情页返回时,不立即执行搜索,让状态恢复逻辑处理
1022+
console.log('🔄 [路由监听] 从详情页返回,跳过路由监听器的搜索,等待状态恢复逻辑处理');
1023+
searchKeyword.value = keyword; // 只更新关键词,不执行搜索
1024+
} else if (isTimestampOnlyChange || keyword !== searchKeyword.value) {
1025+
// 时间戳变化(强制重新搜索)或关键词变化时才执行搜索
1026+
console.log('🔄 [路由监听] 准备执行搜索:', keyword, isTimestampOnlyChange ? '(时间戳强制)' : '(关键词变化)');
1027+
searchKeyword.value = keyword;
1028+
console.log('🔄 [路由监听] 即将调用performSearch');
1029+
performSearch(keyword);
1030+
console.log('🔄 [路由监听] performSearch调用完成');
1031+
} else {
1032+
// 关键词相同且不是时间戳强制更新,跳过搜索
1033+
console.log('🔄 [路由监听] 关键词相同且无时间戳强制更新,跳过搜索');
1034+
}
10161035
} else {
10171036
// 当没有keyword参数时,重置搜索状态
10181037
console.log('🔄 [路由监听] 清空搜索状态');

dashboard/src/views/VideoDetail.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,11 @@ const goBack = () => {
950950
// 返回聚合搜索页面,添加返回标识
951951
console.log('从聚合搜索页面返回,添加返回标识');
952952
query._returnFromDetail = 'true';
953+
// 清除时间戳参数,避免触发重新搜索
954+
if (query._t) {
955+
delete query._t;
956+
console.log('清除时间戳参数 _t,避免触发重新搜索');
957+
}
953958
} else if (sourceRouteName === 'Home') {
954959
// 返回Home页面,检查搜索状态
955960
const savedSearchState = pageStateStore.getPageState('search');

0 commit comments

Comments
 (0)