@@ -998,15 +998,48 @@ export default defineComponent({
998998 };
999999
10001000 // 恢复滚动位置
1001- const restoreScrollPosition = () => {
1001+ const restoreScrollPosition = (retryCount = 0 ) => {
10021002 if (scrollPosition .value > 0 ) {
1003- nextTick (() => {
1003+ const maxRetries = 5 ;
1004+ const delay = Math .min (100 * Math .pow (2 , retryCount), 1000 ); // 指数退避,最大1秒
1005+
1006+ const attemptRestore = () => {
10041007 const scrollContainer = scrollbarRef .value ? .$el ? .querySelector (' .arco-scrollbar-container' );
10051008 if (scrollContainer) {
1006- scrollContainer .scrollTop = scrollPosition .value ;
1007- console .log (' 🔄 [滚动位置] 恢复滚动位置:' , scrollPosition .value );
1009+ // 检查容器是否有内容
1010+ const hasContent = scrollContainer .scrollHeight > scrollContainer .clientHeight ;
1011+ if (hasContent) {
1012+ scrollContainer .scrollTop = scrollPosition .value ;
1013+ console .log (' 🔄 [滚动位置] 恢复滚动位置:' , scrollPosition .value );
1014+ return true ;
1015+ } else if (retryCount < maxRetries) {
1016+ console .log (` 🔄 [滚动位置] 容器内容未完全加载,${ delay} ms后重试 (${ retryCount + 1 } /${ maxRetries} )` );
1017+ setTimeout (() => restoreScrollPosition (retryCount + 1 ), delay);
1018+ return false ;
1019+ }
1020+ } else if (retryCount < maxRetries) {
1021+ console .log (` 🔄 [滚动位置] 滚动容器未找到,${ delay} ms后重试 (${ retryCount + 1 } /${ maxRetries} )` );
1022+ setTimeout (() => restoreScrollPosition (retryCount + 1 ), delay);
1023+ return false ;
10081024 }
1009- });
1025+
1026+ if (retryCount >= maxRetries) {
1027+ console .warn (' 🔄 [滚动位置] 达到最大重试次数,滚动位置恢复失败' );
1028+ }
1029+ return false ;
1030+ };
1031+
1032+ if (retryCount === 0 ) {
1033+ // 首次尝试使用nextTick
1034+ nextTick (() => {
1035+ if (! attemptRestore ()) {
1036+ // 如果首次失败,开始重试机制
1037+ setTimeout (() => restoreScrollPosition (1 ), 100 );
1038+ }
1039+ });
1040+ } else {
1041+ attemptRestore ();
1042+ }
10101043 }
10111044 };
10121045
@@ -1085,11 +1118,12 @@ export default defineComponent({
10851118
10861119 // 延迟恢复滚动位置,确保DOM已渲染
10871120 if (scrollPosition .value > 0 ) {
1088- // 使用多重延迟确保搜索结果完全渲染
1121+ console .log (' 🔄 [滚动位置] 准备恢复滚动位置:' , scrollPosition .value );
1122+ // 使用更长的延迟确保搜索结果完全渲染,特别是从详情页返回时
10891123 nextTick (() => {
10901124 setTimeout (() => {
10911125 restoreScrollPosition ();
1092- }, 200 );
1126+ }, 300 ); // 增加延迟时间
10931127 });
10941128 }
10951129
@@ -1132,6 +1166,15 @@ export default defineComponent({
11321166 if (isReturnFromDetail) {
11331167 // 如果是从详情页返回,优先使用恢复的状态,不执行新搜索
11341168 console .log (' 🔄 [状态恢复] 从详情页返回,使用恢复的状态,不执行新搜索' );
1169+
1170+ // 从详情页返回时,需要额外确保滚动位置恢复
1171+ if (scrollPosition .value > 0 ) {
1172+ console .log (' 🔄 [滚动位置] 从详情页返回,额外确保滚动位置恢复:' , scrollPosition .value );
1173+ // 使用更长的延迟,确保页面完全渲染
1174+ setTimeout (() => {
1175+ restoreScrollPosition ();
1176+ }, 500 );
1177+ }
11351178 } else if (urlKeyword && urlKeyword === stateKeyword) {
11361179 // URL关键词与恢复状态匹配,使用恢复的状态
11371180 console .log (' 🔄 [状态恢复] URL关键词与恢复状态匹配,使用恢复的状态' );
0 commit comments