修正search页面僵尸历史记录tag
This commit is contained in:
@@ -372,11 +372,11 @@ function SearchPageClient() {
|
|||||||
const yearsSet = new Set<string>();
|
const yearsSet = new Set<string>();
|
||||||
|
|
||||||
searchResults.forEach((item) => {
|
searchResults.forEach((item) => {
|
||||||
if (item.source && item.source_name) {
|
if (item.source && item.source_name && item.source.trim() !== '' && item.source_name.trim() !== '') {
|
||||||
sourcesSet.set(item.source, item.source_name);
|
sourcesSet.set(item.source, item.source_name);
|
||||||
}
|
}
|
||||||
if (item.title) titlesSet.add(item.title);
|
if (item.title && item.title.trim() !== '') titlesSet.add(item.title);
|
||||||
if (item.year) yearsSet.add(item.year);
|
if (item.year && item.year.trim() !== '') yearsSet.add(item.year);
|
||||||
});
|
});
|
||||||
|
|
||||||
const sourceOptions: { label: string; value: string }[] = [
|
const sourceOptions: { label: string; value: string }[] = [
|
||||||
|
|||||||
+12
-7
@@ -860,13 +860,15 @@ export async function getSearchHistory(): Promise<string[]> {
|
|||||||
// 返回缓存数据,同时后台异步更新
|
// 返回缓存数据,同时后台异步更新
|
||||||
fetchFromApi<string[]>(`/api/searchhistory`)
|
fetchFromApi<string[]>(`/api/searchhistory`)
|
||||||
.then((freshData) => {
|
.then((freshData) => {
|
||||||
|
// 去重处理
|
||||||
|
const uniqueData = Array.from(new Set(freshData));
|
||||||
// 只有数据真正不同时才更新缓存
|
// 只有数据真正不同时才更新缓存
|
||||||
if (JSON.stringify(cachedData) !== JSON.stringify(freshData)) {
|
if (JSON.stringify(cachedData) !== JSON.stringify(uniqueData)) {
|
||||||
cacheManager.cacheSearchHistory(freshData);
|
cacheManager.cacheSearchHistory(uniqueData);
|
||||||
// 触发数据更新事件
|
// 触发数据更新事件
|
||||||
window.dispatchEvent(
|
window.dispatchEvent(
|
||||||
new CustomEvent('searchHistoryUpdated', {
|
new CustomEvent('searchHistoryUpdated', {
|
||||||
detail: freshData,
|
detail: uniqueData,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -881,8 +883,10 @@ export async function getSearchHistory(): Promise<string[]> {
|
|||||||
// 缓存为空,直接从 API 获取并缓存
|
// 缓存为空,直接从 API 获取并缓存
|
||||||
try {
|
try {
|
||||||
const freshData = await fetchFromApi<string[]>(`/api/searchhistory`);
|
const freshData = await fetchFromApi<string[]>(`/api/searchhistory`);
|
||||||
cacheManager.cacheSearchHistory(freshData);
|
// 去重处理
|
||||||
return freshData;
|
const uniqueData = Array.from(new Set(freshData));
|
||||||
|
cacheManager.cacheSearchHistory(uniqueData);
|
||||||
|
return uniqueData;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('获取搜索历史失败:', err);
|
console.error('获取搜索历史失败:', err);
|
||||||
triggerGlobalError('获取搜索历史失败');
|
triggerGlobalError('获取搜索历史失败');
|
||||||
@@ -896,8 +900,9 @@ export async function getSearchHistory(): Promise<string[]> {
|
|||||||
const raw = localStorage.getItem(SEARCH_HISTORY_KEY);
|
const raw = localStorage.getItem(SEARCH_HISTORY_KEY);
|
||||||
if (!raw) return [];
|
if (!raw) return [];
|
||||||
const arr = JSON.parse(raw) as string[];
|
const arr = JSON.parse(raw) as string[];
|
||||||
// 仅返回字符串数组
|
// 仅返回字符串数组,并去重
|
||||||
return Array.isArray(arr) ? arr : [];
|
const validArray = Array.isArray(arr) ? arr : [];
|
||||||
|
return Array.from(new Set(validArray));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('读取搜索历史失败:', err);
|
console.error('读取搜索历史失败:', err);
|
||||||
triggerGlobalError('读取搜索历史失败');
|
triggerGlobalError('读取搜索历史失败');
|
||||||
|
|||||||
Reference in New Issue
Block a user