From 465a52d36fbc1e8ddcfd645e05c1f504101e4d1a Mon Sep 17 00:00:00 2001 From: jinsir <874871581@qq.com> Date: Mon, 17 Nov 2025 19:29:59 +0800 Subject: [PATCH] =?UTF-8?q?form=20=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/components/WeatherSearchForm.tsx | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) 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