@@ -333,6 +333,9 @@ export default defineComponent({
333333 const currentPages = ref ({}); // 每个源的当前页码
334334 const hasMorePages = ref ({}); // 每个源是否还有更多页面
335335
336+ // 搜索完成时间戳记录
337+ const searchCompletedTimes = ref ({}); // 记录每个源完成搜索的时间戳
338+
336339 // ActionRenderer相关
337340 const showActionRenderer = ref (false );
338341 const currentActionData = ref (null );
@@ -372,13 +375,28 @@ export default defineComponent({
372375 return hasMoreFromServer || hasMoreFromLocal;
373376 });
374377
375- // 过滤有结果的搜索源
378+ // 过滤有结果的搜索源,并按搜索完成时间排序
376379 const sourcesWithResults = computed (() => {
377- return searchSources .value .filter (source => {
380+ const sourcesWithData = searchSources .value .filter (source => {
378381 const results = searchResults .value [source .key ];
379382 // 严格只显示有结果的源
380383 return results && results .length > 0 ;
381384 });
385+
386+ // 按搜索完成时间排序,先完成的排在前面
387+ const sortedSources = sourcesWithData .sort ((a , b ) => {
388+ const timeA = searchCompletedTimes .value [a .key ] || 0 ;
389+ const timeB = searchCompletedTimes .value [b .key ] || 0 ;
390+ return timeA - timeB; // 升序排列,时间戳小的(先完成的)排在前面
391+ });
392+
393+ console .log (' 搜索源排序结果:' , sortedSources .map (s => ({
394+ name: s .name ,
395+ key: s .key ,
396+ completedTime: searchCompletedTimes .value [s .key ]
397+ })));
398+
399+ return sortedSources;
382400 });
383401
384402 // 搜索统计计算属性
@@ -481,6 +499,7 @@ export default defineComponent({
481499 errorStates .value = {};
482500 currentPages .value = {};
483501 hasMorePages .value = {};
502+ searchCompletedTimes .value = {}; // 清空搜索完成时间戳
484503 displayedCount .value = pageSize .value ;
485504
486505 // 重置活跃源,让自动激活逻辑来处理
@@ -555,6 +574,12 @@ export default defineComponent({
555574 // 更新分页状态
556575 hasMorePages .value [source .key ] = searchData .pagination ? .hasNext !== false ;
557576
577+ // 记录搜索完成时间戳(仅在第一页时记录)
578+ if (page === 1 ) {
579+ searchCompletedTimes .value [source .key ] = Date .now ();
580+ console .log (` 搜索源 ${ source .name } 完成搜索,时间戳: ${ searchCompletedTimes .value [source .key ]} ` );
581+ }
582+
558583 delete errorStates .value [source .key ];
559584 } catch (error) {
560585 console .error (` 搜索源 ${ source .name } 失败:` , error);
@@ -911,30 +936,28 @@ export default defineComponent({
911936 updateGlobalStats ();
912937 });
913938
914- // 监听搜索结果变化,自动激活第一个有结果的源
915- watch (searchResults, (newResults ) => {
916- // 只有在有搜索结果且当前没有活跃源或当前活跃源没有结果时才自动切换
917- if (Object .keys (newResults).length > 0 ) {
918- // 找到第一个有结果的源
919- const firstSourceWithResults = sourcesWithResults .value .find (source => {
920- const results = newResults[source .key ];
921- return results && results .length > 0 ;
922- });
939+ // 监听有结果的源列表变化,自动激活第一个有结果的源
940+ watch (sourcesWithResults, (newSourcesWithResults ) => {
941+ console .log (' sourcesWithResults 变化:' , newSourcesWithResults .map (s => s .name ));
942+ console .log (' 当前 activeSource:' , activeSource .value );
943+
944+ // 如果有结果的源列表不为空,且当前没有活跃源或当前活跃源没有结果
945+ if (newSourcesWithResults .length > 0 ) {
946+ const currentActiveHasResults = activeSource .value &&
947+ searchResults .value [activeSource .value ] &&
948+ searchResults .value [activeSource .value ].length > 0 ;
923949
924- // 如果找到有结果的源,且当前没有活跃源或当前活跃源没有结果,则自动切换
925- if (firstSourceWithResults) {
926- const currentActiveHasResults = activeSource .value &&
927- newResults[activeSource .value ] &&
928- newResults[activeSource .value ].length > 0 ;
929-
930- // 如果当前没有活跃源,或当前活跃源没有结果,则切换到第一个有结果的源
931- if (! activeSource .value || ! currentActiveHasResults) {
932- activeSource .value = firstSourceWithResults .key ;
933- console .log (` 自动激活第一个有结果的搜索源: ${ firstSourceWithResults .name } ` );
934- }
950+ console .log (' 当前活跃源是否有结果:' , currentActiveHasResults);
951+
952+ // 如果当前没有活跃源,或当前活跃源没有结果,则激活第一个有结果的源
953+ if (! activeSource .value || activeSource .value === ' ' || ! currentActiveHasResults) {
954+ const firstSourceWithResults = newSourcesWithResults[0 ];
955+ activeSource .value = firstSourceWithResults .key ;
956+ console .log (` 自动激活第一个有结果的搜索源: ${ firstSourceWithResults .name } (${ firstSourceWithResults .key } )` );
957+ console .log (' 激活后的 activeSource:' , activeSource .value );
935958 }
936959 }
937- }, { deep : true } );
960+ });
938961
939962 // 组件挂载时初始化
940963 onMounted (() => {
@@ -1221,8 +1244,17 @@ export default defineComponent({
12211244}
12221245
12231246.source - item .active {
1224- background: var (-- color- primary- 1 );
1225- border: 1px solid var (-- color- primary- 6 );
1247+ background: #1890ff ! important;
1248+ border: 1px solid #0050b3 ! important;
1249+ color: white ! important;
1250+ }
1251+
1252+ .source - item .active .source - name {
1253+ color: white ! important;
1254+ }
1255+
1256+ .source - item .active .source - count {
1257+ color: rgba (255 , 255 , 255 , 0.8 ) ! important;
12261258}
12271259
12281260.source - info {
0 commit comments