Merge branch 'main' of http://113.45.67.59:3003/lzq/test
This commit is contained in:
commit
39ac8592c3
|
|
@ -45,8 +45,6 @@ function WeatherIcon({ description, isDay, className = "w-16 h-16 md:w-20 md:h-2
|
||||||
}
|
}
|
||||||
return isDaytime ? <Sun className={className} /> : <Moon className={className} />;
|
return isDaytime ? <Sun className={className} /> : <Moon className={className} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export function WeatherDisplay(){
|
export function WeatherDisplay(){
|
||||||
const {currentWeather} = useWeatherStore();
|
const {currentWeather} = useWeatherStore();
|
||||||
if(!currentWeather) return null;
|
if(!currentWeather) return null;
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,8 @@ import { useWeatherStore } from '@/store/weatherStore';
|
||||||
|
|
||||||
export function WeatherSearchForm() {
|
export function WeatherSearchForm() {
|
||||||
const {isLoading, currentWeather, searchWeather, refreshWeather} = useWeatherStore();
|
const {isLoading, currentWeather, searchWeather, refreshWeather} = useWeatherStore();
|
||||||
|
|
||||||
const [city, setCity] = useState('');
|
const [city, setCity] = useState('');
|
||||||
const [inputError, setInputError] = useState('');
|
const [inputError, setInputError] = useState('');
|
||||||
|
|
||||||
const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
|
const handleInputChange = (e: ChangeEvent<HTMLInputElement>) => {
|
||||||
setCity(e.target.value);
|
setCity(e.target.value);
|
||||||
if (inputError) {
|
if (inputError) {
|
||||||
|
|
@ -19,13 +17,22 @@ export function WeatherSearchForm() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleFormSubmit = async (e: FormEvent<HTMLFormElement>) => {
|
const handleFormSubmit = async (e: FormEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const trimmedCity = city.trim();
|
const trimmedCity = city.trim();
|
||||||
if (!trimmedCity) {
|
if (!trimmedCity) {
|
||||||
setInputError('请输入城市名称');
|
setInputError('请输入城市名称');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (trimmedCity.length < 2) {
|
||||||
|
setInputError('请输入至少2个字符');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!/^[a-zA-Z\s]+$/.test(trimmedCity)) {
|
||||||
|
setInputError('请输入字母和空格');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await searchWeather(trimmedCity);
|
||||||
|
|
||||||
if (trimmedCity.length < 2) {
|
if (trimmedCity.length < 2) {
|
||||||
setInputError('请输入至少2个字符');
|
setInputError('请输入至少2个字符');
|
||||||
|
|
|
||||||
708
pnpm-lock.yaml
708
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue