2025-11-14 18:38:11 +08:00
|
|
|
import REACT, { use, useEffect } from 'react'
|
|
|
|
|
import { Loader2 } from 'lucide-react';
|
2025-11-14 18:51:33 +08:00
|
|
|
import { WeatherCard } from '@/components/weather/WeatherCard'
|
|
|
|
|
import { useWeatherStore } from '@/store/weatherStore'
|
2025-11-14 18:38:11 +08:00
|
|
|
import { toast } from 'sonner'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function meta() {
|
|
|
|
|
return [
|
|
|
|
|
{ title: "天气查询页面" },
|
|
|
|
|
{ name: "description", content: "查询天气信息" }
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function Weather() {
|
2025-11-14 19:18:12 +08:00
|
|
|
|
2025-11-14 18:51:33 +08:00
|
|
|
const { currentWeather, isLoading, error, setError } = useWeatherStore()
|
2025-11-14 18:38:11 +08:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (error) {
|
|
|
|
|
toast.error(error)
|
2025-11-14 18:51:33 +08:00
|
|
|
setError("")
|
2025-11-14 19:09:40 +08:00
|
|
|
setError("")
|
2025-11-14 18:38:11 +08:00
|
|
|
}
|
2025-11-14 18:51:33 +08:00
|
|
|
}, [error, setError])
|
2025-11-14 19:18:12 +08:00
|
|
|
|
2025-11-14 18:38:11 +08:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col items-center justify-center h-screen">
|
|
|
|
|
<div className="flex flex-col items-center justify-center">
|
|
|
|
|
<header className="flex flex-col items-center justify-center">
|
|
|
|
|
<h1 className="text-4xl font-bold">天气查询</h1>
|
|
|
|
|
<p className="text-sm">实时天气</p>
|
|
|
|
|
</header>
|
|
|
|
|
{isLoading && !currentWeather && (
|
|
|
|
|
<div className="flex flex-col items-center justify-center">
|
|
|
|
|
<div className="flex flex-col items-center justify-center">
|
|
|
|
|
<div className='flex flex-col items-center justify-center'>
|
|
|
|
|
<div className="animate-spin rounded-full h-20 w-20 border-t-2 border-b-2 border-gray-900">
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-gray-900 text-lg font-bold">
|
|
|
|
|
<Loader2 className="h-10 w-10 animate-spin" />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<p className="text-gray-900 text-lg font-bold"> 加载中...</p>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{!isLoading || currentWeather ? (
|
|
|
|
|
<div className="flex flex-col items-center justify-center">
|
|
|
|
|
<WeatherCard />
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|