2025-11-17 19:50:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
import React, {useEffect} from 'react';
|
|
|
|
|
import { Loader2 } from 'lucide-react';
|
2025-11-17 19:57:57 +08:00
|
|
|
import { WeatherCard } from '@/components/WeatherCard';
|
2025-11-17 19:50:08 +08:00
|
|
|
import { useWeatherStore } from '@/store/weatherStore';
|
|
|
|
|
import {toast} from "sonner";
|
|
|
|
|
|
2025-11-17 18:51:51 +08:00
|
|
|
export function meta() {
|
2025-11-17 19:50:08 +08:00
|
|
|
return [
|
|
|
|
|
{ title: '天气 - Apple风格设计' },
|
|
|
|
|
{ name: 'description', content: '优雅的天气查询应用' },
|
|
|
|
|
];
|
2025-11-17 18:51:51 +08:00
|
|
|
}
|
2025-11-17 19:50:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
export default function Weather() {
|
|
|
|
|
const { currentWeather, isLoading ,error,setError} = useWeatherStore();
|
|
|
|
|
// Show toast when error changes
|
2025-11-17 18:51:51 +08:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (error) {
|
2025-11-17 19:50:08 +08:00
|
|
|
toast.error(error);
|
|
|
|
|
// Clear error after showing toast
|
|
|
|
|
setError(null);
|
2025-11-17 18:51:51 +08:00
|
|
|
}
|
2025-11-17 19:50:08 +08:00
|
|
|
}, [error, setError]);
|
|
|
|
|
return (
|
|
|
|
|
<div className="min-h-screen bg-gradient-to-b from-slate-50 via-blue-50/30 to-slate-50 dark:from-slate-950 dark:via-slate-900 dark:to-slate-950 transition-colors duration-500">
|
|
|
|
|
<div className="max-w-4xl mx-auto px-4 py-8 md:px-6 md:py-12">
|
|
|
|
|
|
|
|
|
|
<header className="text-center mb-8 space-y-3">
|
|
|
|
|
<h1 className="text-5xl md:text-6xl font-semibold tracking-tight bg-gradient-to-br from-blue-600 via-sky-500 to-cyan-500 dark:from-blue-400 dark:via-sky-400 dark:to-cyan-400 bg-clip-text text-transparent animate-in fade-in slide-in-from-top-4 duration-700">
|
|
|
|
|
天气
|
|
|
|
|
</h1>
|
|
|
|
|
<p className="text-sm md:text-base text-slate-500 dark:text-slate-400 font-medium animate-in fade-in slide-in-from-top-5 duration-700">
|
|
|
|
|
实时天气信息
|
|
|
|
|
</p>
|
|
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{isLoading && !currentWeather && (
|
|
|
|
|
<div className="flex items-center justify-center py-20">
|
|
|
|
|
<div className="text-center space-y-6 animate-in fade-in zoom-in-95 duration-500">
|
|
|
|
|
<div className="relative w-16 h-16 mx-auto">
|
|
|
|
|
<div className="absolute inset-0 rounded-full bg-gradient-to-tr from-blue-500 to-cyan-400 opacity-20 animate-ping"></div>
|
|
|
|
|
<div className="relative w-16 h-16 rounded-full bg-gradient-to-tr from-blue-500 to-cyan-400 flex items-center justify-center">
|
|
|
|
|
<Loader2 className="w-8 h-8 text-white animate-spin" />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<p className="text-slate-600 dark:text-slate-300 font-medium">
|
|
|
|
|
正在获取天气数据
|
|
|
|
|
</p>
|
2025-11-17 18:51:51 +08:00
|
|
|
</div>
|
2025-11-17 19:50:08 +08:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{!isLoading || currentWeather ? (
|
|
|
|
|
<div className="animate-in fade-in slide-in-from-bottom-4 duration-700">
|
|
|
|
|
<WeatherCard />
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|