diff --git a/app/components/WeatherSearchForm.tsx b/app/components/WeatherSearchForm.tsx index 04dff4f..ab0ac03 100644 --- a/app/components/WeatherSearchForm.tsx +++ b/app/components/WeatherSearchForm.tsx @@ -7,7 +7,7 @@ import { useWeatherStore } from '@/store/weatherStore'; export function WeatherSearchForm() { - const [isLoading, currentWeather, searchWeather, refreshWeather] = useWeatherStore(); + const {isLoading, currentWeather, searchWeather, refreshWeather} = useWeatherStore(); const [city, setCity] = useState(''); const [inputError, setInputError] = useState(''); @@ -25,11 +25,7 @@ export function WeatherSearchForm() { setInputError('请输入城市名称'); return; } - if (!trimmedCity) { - setInputError('请输入有效的城市名称'); - return; - } - + if (trimmedCity.length < 2) { setInputError('请输入至少2个字符'); return; @@ -40,10 +36,9 @@ export function WeatherSearchForm() { return; } await searchWeather(trimmedCity); - } - + return ( -
+
@@ -52,16 +47,16 @@ export function WeatherSearchForm() { setCity(e.target.value)} + onChange={handleInputChange} placeholder="请输入城市名称" disabled={isLoading} - className={cn('pl-10 pr-4 py-2 w-full', inputError && 'border-red-500')} + className={cn('pl-10 pr-4 py-2 w-full text-base rounded-xl bg-slate-50/50 focus:bg-white transition-all', inputError && 'border-red-500') } />
{inputError && ( -
- -

{inputError}

+
+ +

{inputError}

@@ -99,4 +94,5 @@ export function WeatherSearchForm() { ) } +} } \ No newline at end of file