|
|
@@ -2,6 +2,7 @@ import React, { useState, useEffect, useRef } from 'react';
|
|
|
import { useNavigate } from 'react-router-dom';
|
|
|
import { useHomeData } from '../hooks/useHomeData';
|
|
|
import { useAuth } from '../hooks/AuthProvider';
|
|
|
+import { useHomeIcons } from '../hooks/useHomeIcons';
|
|
|
import { EnhancedCarousel } from '../components/EnhancedCarousel';
|
|
|
import { AdBannerCarousel } from '../components/AdBannerCarousel';
|
|
|
import { SkeletonLoader, BannerSkeleton, ListItemSkeleton } from '../components/SkeletonLoader';
|
|
|
@@ -112,16 +113,8 @@ const serviceCategories = [
|
|
|
}
|
|
|
];
|
|
|
|
|
|
-// 数据转换工具
|
|
|
-const transformPolicyNews = (news: any[]) =>
|
|
|
- news.map(item => ({
|
|
|
- id: item.id,
|
|
|
- title: item.newsTitle,
|
|
|
- description: item.summary || item.newsContent?.substring(0, 100) + '...' || '暂无描述',
|
|
|
- image: item.images?.split(',')[0] || unsplash.getPlaceholderImage('community', item.id),
|
|
|
- fallbackImage: '/images/placeholder-banner.jpg',
|
|
|
- link: `/policy-news/${item.id}`
|
|
|
- }));
|
|
|
+// 政策资讯转换工具(已迁移到HomeIcons模块)
|
|
|
+// 轮播图数据现在通过 useHomeIcons 获取
|
|
|
|
|
|
const transformJobs = (jobs: any[]) =>
|
|
|
jobs.map(job => ({
|
|
|
@@ -237,7 +230,10 @@ const NewHomePage: React.FC = () => {
|
|
|
const handlePullToRefresh = async () => {
|
|
|
setIsPulling(true);
|
|
|
try {
|
|
|
- await refetch();
|
|
|
+ await Promise.all([
|
|
|
+ refetch(),
|
|
|
+ // 这里可以添加图标数据的刷新
|
|
|
+ ]);
|
|
|
} finally {
|
|
|
setIsPulling(false);
|
|
|
}
|
|
|
@@ -256,8 +252,16 @@ const NewHomePage: React.FC = () => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ // 获取动态图标数据
|
|
|
+ const {
|
|
|
+ banners: dynamicBanners,
|
|
|
+ categories: dynamicCategories,
|
|
|
+ isLoading: isIconsLoading,
|
|
|
+ isError: isIconsError
|
|
|
+ } = useHomeIcons();
|
|
|
+
|
|
|
// 加载状态
|
|
|
- if (isLoading || !homeData) {
|
|
|
+ if (isLoading || !homeData || isIconsLoading) {
|
|
|
return (
|
|
|
<div className="min-h-screen" style={{ backgroundColor: COLORS.ink.light }}>
|
|
|
<HeaderSkeleton />
|
|
|
@@ -270,7 +274,6 @@ const NewHomePage: React.FC = () => {
|
|
|
}
|
|
|
|
|
|
// 数据转换与排序
|
|
|
- const banners = transformPolicyNews(homeData.banners || []);
|
|
|
const recommendedJobs = transformJobs(homeData.recommendedJobs || [])
|
|
|
.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime())
|
|
|
.slice(0, 3);
|
|
|
@@ -290,6 +293,64 @@ const NewHomePage: React.FC = () => {
|
|
|
|
|
|
const timeBankActivities = transformTimeBank(homeData.timeBankActivities || []);
|
|
|
|
|
|
+ // 转换轮播图数据(来自HomeIcons管理)
|
|
|
+ const banners = dynamicBanners.map(banner => ({
|
|
|
+ id: banner.id,
|
|
|
+ title: banner.title,
|
|
|
+ description: banner.description || '',
|
|
|
+ image: banner.file?.path || unsplash.getPlaceholderImage('banner', banner.id),
|
|
|
+ fallbackImage: '/images/placeholder-banner.jpg',
|
|
|
+ link: banner.linkUrl || '#'
|
|
|
+ }));
|
|
|
+
|
|
|
+ // 转换分类图标数据
|
|
|
+ const categories = dynamicCategories.length > 0
|
|
|
+ ? dynamicCategories.map(category => ({
|
|
|
+ name: category.title,
|
|
|
+ icon: BriefcaseIcon, // 默认图标,后续可根据需要扩展
|
|
|
+ path: category.linkUrl || '/',
|
|
|
+ color: COLORS.accent.blue,
|
|
|
+ image: category.file?.path
|
|
|
+ }))
|
|
|
+ : [
|
|
|
+ {
|
|
|
+ name: '银龄岗位',
|
|
|
+ icon: BriefcaseIcon,
|
|
|
+ path: '/silver-jobs',
|
|
|
+ color: COLORS.accent.blue
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '银龄人才',
|
|
|
+ icon: UserGroupIcon,
|
|
|
+ path: '/silver-talents',
|
|
|
+ color: COLORS.accent.green
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '银龄智库',
|
|
|
+ icon: BookOpenIcon,
|
|
|
+ path: '/silver-wisdom',
|
|
|
+ color: COLORS.accent.red
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '老年大学',
|
|
|
+ icon: AcademicCapIcon,
|
|
|
+ path: '/elderly-university',
|
|
|
+ color: COLORS.ink.dark
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '时间银行',
|
|
|
+ icon: ClockIcon,
|
|
|
+ path: '/time-bank',
|
|
|
+ color: '#7c5c4a'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: '政策资讯',
|
|
|
+ icon: NewspaperIcon,
|
|
|
+ path: '/policy-news',
|
|
|
+ color: COLORS.ink.deep
|
|
|
+ }
|
|
|
+ ];
|
|
|
+
|
|
|
return (
|
|
|
<div className="min-h-screen" style={{ backgroundColor: COLORS.ink.light }}>
|
|
|
{/* 顶部导航栏 */}
|