7575
7676 <!-- 推荐分类内容 -->
7777 <div v-else-if =" activeKey === 'recommendTuijian404'" class =" tab-content" >
78+
7879 <!-- 分类数据获取loading -->
7980 <div v-if =" loadingCategory[activeKey]" class =" category-loading-container" >
8081 <a-spin :size =" 24" />
8182 <div class =" loading-text" >正在加载分类数据...</div >
8283 </div >
84+
8385 <VideoGrid
84- v-else
86+ v-if = " !loadingCategory[activeKey] "
8587 :videos =" listData[activeKey] || []"
8688 :loading =" loadingMore[activeKey] || false"
8789 :hasMore =" false"
@@ -422,7 +424,13 @@ const getListData = async (key, forceReload = false) => {
422424 console .log (` 分类 ${ key} 正在加载中,跳过重复请求` );
423425 return ;
424426 }
425-
427+
428+ console .log (' listData.hasOwnProperty(key):' , listData .hasOwnProperty (key));
429+ console .log (' forceReload:' , forceReload);
430+ console .log (' listData keys:' , Object .keys (listData));
431+ console .log (' listData[key]:' , listData[key]);
432+ console .log (' listData[key] length:' , listData[key]? .length );
433+
426434 if (! listData .hasOwnProperty (key) || forceReload) {
427435 // 设置分类数据获取loading状态
428436 loadingCategory[key] = true ;
@@ -433,9 +441,11 @@ const getListData = async (key, forceReload = false) => {
433441 let videoList, pagination;
434442 if (key === " recommendTuijian404" ) {
435443 // 使用传入的推荐视频数据 - 首页推荐数据不允许翻页
444+ console .log (' recommendTuijian404 recommendVideos:' ,props .recommendVideos );
436445 videoList = props .recommendVideos || [];
437446 // 推荐视频数据不允许翻页
438447 pagination = { page: 1 , hasNext: false };
448+
439449 } else {
440450 // 获取分类视频,包含筛选参数
441451 const filters = selectedFilters[key] || {};
@@ -460,10 +470,12 @@ const getListData = async (key, forceReload = false) => {
460470 }
461471 }
462472
463- // 使用批量更新,减少响应式触发次数
464- Object .assign (listData, { [key]: videoList });
465- Object .assign (pageData, { [key]: pagination });
466- Object .assign (loadingMore, { [key]: false });
473+ // 使用直接赋值确保响应式更新
474+ listData[key] = [... videoList];
475+ pageData[key] = pagination;
476+ loadingMore[key] = false ;
477+
478+
467479
468480 // 更新全局翻页统计信息
469481 if (key === activeKey .value ) {
@@ -682,41 +694,29 @@ const selectCategory = (categoryId) => {
682694 debouncedUpdateStats (getStatsText (categoryId, folderInfo), 100 );
683695};
684696
685- // 添加防护变量避免递归更新
686- let isWatchUpdating = false ;
687-
688697// 监听器
689698watch (() => props .recommendVideos , (newVideos ) => {
690- if (isWatchUpdating) return ; // 防止递归更新
699+ console . log ( ' [VideoList] recommendVideos watch triggered: ' , newVideos ? . length );
691700
692- isWatchUpdating = true ;
693- try {
694- if (newVideos && newVideos .length > 0 ) {
695- listData[" recommendTuijian404" ] = newVideos;
696- pageData[" recommendTuijian404" ] = { page: 1 , hasNext: false };
697- loadingMore[" recommendTuijian404" ] = false ;
698- console .log (" 推荐数据已更新:" , newVideos .length , " 条" );
699- } else {
700- listData[" recommendTuijian404" ] = [];
701- pageData[" recommendTuijian404" ] = { page: 1 , hasNext: false };
702- loadingMore[" recommendTuijian404" ] = false ;
703- }
704-
705- const newActiveKey = getDefaultActiveKey ();
706- if (activeKey .value !== newActiveKey) {
707- activeKey .value = newActiveKey;
708- // 延迟调用getListData,避免同步递归
709- setTimeout (() => {
710- if (! isWatchUpdating) return ;
711- getListData (newActiveKey);
712- emit (' activeKeyChange' , newActiveKey);
713- }, 50 );
714- }
715- } finally {
716- // 延迟重置防护变量
717- setTimeout (() => {
718- isWatchUpdating = false ;
719- }, 100 );
701+ if (newVideos && newVideos .length > 0 ) {
702+ // 直接赋值,确保响应式更新
703+ listData[" recommendTuijian404" ] = [... newVideos];
704+ pageData[" recommendTuijian404" ] = { page: 1 , hasNext: false };
705+ loadingMore[" recommendTuijian404" ] = false ;
706+ loadingCategory[" recommendTuijian404" ] = false ;
707+ console .log (" 推荐数据已更新:" , newVideos .length , " 条" );
708+ } else {
709+ listData[" recommendTuijian404" ] = [];
710+ pageData[" recommendTuijian404" ] = { page: 1 , hasNext: false };
711+ loadingMore[" recommendTuijian404" ] = false ;
712+ loadingCategory[" recommendTuijian404" ] = false ;
713+ }
714+
715+ // 如果当前activeKey是推荐分类,确保界面更新
716+ if (activeKey .value === " recommendTuijian404" ) {
717+ console .log (' [VideoList] 当前是推荐分类,强制更新界面' );
718+ // 触发响应式更新
719+ activeKey .value = " recommendTuijian404" ;
720720 }
721721}, { immediate: true });
722722
@@ -812,13 +812,36 @@ watch(() => props.sourceRoute?.query?.activeKey, (newActiveKey) => {
812812}, { immediate: true });
813813
814814onMounted (() => {
815- activeKey .value = getDefaultActiveKey ();
815+ // 优先使用父组件传递的activeKey,如果没有则使用默认值
816+ const parentActiveKey = props .sourceRoute ? .query ? .activeKey ;
817+ const targetActiveKey = parentActiveKey || getDefaultActiveKey ();
818+
819+ console .log (' [DEBUG] VideoList onMounted - parentActiveKey:' , parentActiveKey, ' targetActiveKey:' , targetActiveKey);
816820
817- // 始终加载数据,不管是否有returnToActiveKey参数
818- // 这样可以确保刷新页面时数据能正常显示
819- getListData (activeKey .value );
821+ activeKey .value = targetActiveKey;
820822
821- emit (' activeKeyChange' , activeKey .value );
823+ // 对于推荐分类,确保loading状态正确
824+ if (targetActiveKey === " recommendTuijian404" ) {
825+ loadingCategory[targetActiveKey] = false ;
826+ // 如果已有推荐数据,直接使用,不需要再调用getListData
827+ if (props .recommendVideos && props .recommendVideos .length > 0 ) {
828+ listData[targetActiveKey] = [... props .recommendVideos ];
829+ pageData[targetActiveKey] = { page: 1 , hasNext: false };
830+ loadingMore[targetActiveKey] = false ;
831+ console .log (' [DEBUG] 推荐数据已设置,跳过getListData调用' );
832+ } else {
833+ // 如果没有推荐数据,才调用getListData
834+ getListData (activeKey .value );
835+ }
836+ } else {
837+ // 非推荐分类,始终加载数据
838+ getListData (activeKey .value );
839+ }
840+
841+ // 只有当使用默认值时才emit,避免覆盖父组件的activeKey
842+ if (! parentActiveKey) {
843+ emit (' activeKeyChange' , activeKey .value );
844+ }
822845});
823846
824847onBeforeUnmount (() => {
0 commit comments