简体中文、英文、多语言框架、时区、夏令时、公制/英制和区域配置

This commit is contained in:
mmc
2026-10-09 13:30:55 +08:00
parent 0bc900cb5b
commit 5afaf1de75
14 changed files with 595 additions and 23 deletions

View File

@@ -3,9 +3,12 @@ import { Button, Dropdown } from 'antd';
import { GlobalOutlined } from '@ant-design/icons';
import { useTranslation } from 'react-i18next';
import type { MenuProps } from 'antd';
import { useAppDispatch } from '../store';
import { setLocale } from '../store/preferencesSlice';
export default function LanguageSwitcher() {
const { i18n ,t} = useTranslation();
const { i18n, t } = useTranslation();
const dispatch = useAppDispatch();
const currentLng = i18n.language?.startsWith('en') ? 'en' : 'zh';
const items: MenuProps['items'] = [
@@ -28,6 +31,7 @@ export default function LanguageSwitcher() {
const handleChange: MenuProps['onClick'] = ({ key }) => {
i18n.changeLanguage(key);
localStorage.setItem('i18nextLng', key);
dispatch(setLocale(key as 'zh' | 'en'));
};
return (

View File

@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect } from 'react';
import { Outlet, useNavigate, useLocation } from 'react-router-dom';
import {
Layout, Menu, Button, Space, Select, Avatar, Card, Tag
@@ -19,6 +19,7 @@ import { setCurrentStation, clearStation, setStationList as setStoreStationList
import { getMenuList } from '../api/mune';
import { getStationByUserId } from '../api/stationManage';
import LanguageSwitcher from './LanguageSwitcher';
import { nowInTz } from '../lib/dayjs';
import envConfig from '../../env';
const { Header, Sider, Content } = Layout;
@@ -27,6 +28,7 @@ export default function AppLayout() {
const { t } = useTranslation();
const [collapsed, setCollapsed] = useState(false);
const [time, setTime] = useState(new Date().toLocaleString());
const { timezone, dateFormat } = useSelector((state: RootState) => state.preferences);
const [menuList, setMenuList] = useState([]);
const [stationList, setStationList] = useState([]);
const [isFullScreen, setIsFullScreen] = useState(false);
@@ -163,11 +165,15 @@ export default function AppLayout() {
};
useEffect(() => {
const timer = setInterval(() => setTime(new Date().toLocaleString()), 1000);
const timer = setInterval(() => setTime(nowInTz(timezone, dateFormat)), 1000);
getMenu();
getStationData();
return () => clearInterval(timer);
}, [userInfo]);
}, [userInfo, timezone, dateFormat]);
useEffect(() => {
setTime(nowInTz(timezone, dateFormat));
}, [timezone, dateFormat]);
useEffect(() => {
const fullscreenChange = () => {

View File

@@ -15,6 +15,7 @@ import {
Space,
TimePicker,
Divider,
Radio,
} from 'antd';
import {
CloudOutlined,
@@ -58,12 +59,21 @@ import {
} from 'lucide-react';
import dayjs from 'dayjs';
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
import { useAppDispatch } from '../../store';
import { setLocale, setTimezone, setUnitSystem, setDateFormat } from '../../store/preferencesSlice';
import { getTimezoneOptions, isDST, getTimezoneOffsetLabel } from '../../lib/dayjs';
const { Text, Title } = Typography;
const BasicSettings = () => {
const { t } = useTranslation();
const { t, i18n } = useTranslation();
const [form] = Form.useForm();
const dispatch = useAppDispatch();
const { locale, timezone, unitSystem, dateFormat } = useSelector((state: any) => state.preferences);
const tzOptions = getTimezoneOptions();
const dstActive = isDST(timezone);
// 响应式字体大小
const fontNormal = 'clamp(12px, 0.75vw, 13px)';
@@ -224,17 +234,41 @@ const BasicSettings = () => {
</Form.Item>
</Col>
<Col xs={24} sm={12} md={8}>
<Form.Item label={t('systemSetting.defaultLanguage')} name="defaultLang" style={{ marginBottom: 12 }}>
<Select size="small" defaultValue="zh">
<Form.Item label={t('systemSetting.defaultLanguage')} style={{ marginBottom: 12 }}>
<Select size="small" value={locale} onChange={(v) => { dispatch(setLocale(v)); i18n.changeLanguage(v); }}>
<Select.Option value="zh">{t('users.chinese')}</Select.Option>
<Select.Option value="en">English</Select.Option>
</Select>
</Form.Item>
</Col>
<Col xs={24} sm={12} md={8}>
<Form.Item label={t('systemSetting.timezone')} name="timezone" style={{ marginBottom: 12 }}>
<Select size="small" defaultValue="UTC+08:00">
<Select.Option value="8">UTC+08:00</Select.Option>
<Form.Item label={t('systemSetting.timezoneSelect')} style={{ marginBottom: 12 }}>
<Select size="small" value={timezone} onChange={(v) => dispatch(setTimezone(v))} showSearch optionFilterProp="label">
{tzOptions.map(opt => <Select.Option key={opt.value} value={opt.value}>{opt.label}</Select.Option>)}
</Select>
</Form.Item>
</Col>
<Col xs={24} sm={12} md={8}>
<Form.Item label={t('systemSetting.daylightSavingTime')} style={{ marginBottom: 12 }}>
<Tag color={dstActive ? 'green' : 'default'}>
{dstActive ? t('systemSetting.dstActive') : t('systemSetting.dstInactive')} ({getTimezoneOffsetLabel(timezone)})
</Tag>
</Form.Item>
</Col>
<Col xs={24} sm={12} md={8}>
<Form.Item label={t('systemSetting.unitSystem')} style={{ marginBottom: 12 }}>
<Radio.Group size="small" value={unitSystem} onChange={(e) => dispatch(setUnitSystem(e.target.value))}>
<Radio value="metric" style={{ fontSize: fontSmall }}>{t('systemSetting.metric')}</Radio>
<Radio value="imperial" style={{ fontSize: fontSmall }}>{t('systemSetting.imperial')}</Radio>
</Radio.Group>
</Form.Item>
</Col>
<Col xs={24} sm={12} md={8}>
<Form.Item label={t('systemSetting.dateFormat')} style={{ marginBottom: 12 }}>
<Select size="small" value={dateFormat} onChange={(v) => dispatch(setDateFormat(v))}>
<Select.Option value="YYYY-MM-DD HH:mm:ss">YYYY-MM-DD HH:mm:ss</Select.Option>
<Select.Option value="YYYY-MM-DD HH:mm">YYYY-MM-DD HH:mm</Select.Option>
<Select.Option value="MM/DD/YYYY HH:mm:ss">MM/DD/YYYY HH:mm:ss</Select.Option>
</Select>
</Form.Item>
</Col>

View File

@@ -33,6 +33,7 @@ import { useSelector } from 'react-redux';
import { RootState } from '@/store';
import envConfig from '../../../env';
import utils from '@/lib/utils.ts';
import { useUnitFormatter } from '@/lib/units';
import { useTranslation } from 'react-i18next';
const { Content } = Layout;
@@ -44,6 +45,7 @@ export default function DeviceOverviewPage() {
const { t } = useTranslation();
const { userInfo } = useSelector((state: RootState) => state.user);
const { stationId, currentStation } = useSelector((state: RootState) => state.station);
const { formatTemperature } = useUnitFormatter();
const [zoomedVideo, setZoomedVideo] = useState(null);
const [mowerView, setMowerView] = useState('front');
@@ -784,7 +786,7 @@ export default function DeviceOverviewPage() {
{realtimeDevice?.environment_temperature && (
<div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
<span style={{ fontSize: 12 }}>{t('home.temperature')}</span>
<span style={{ color: '#faad14' }}>{fix2(realtimeDevice.environment_temperature || 25)}℃</span>
<span style={{ color: '#faad14' }}>{formatTemperature(Number(realtimeDevice.environment_temperature || 25), 1).label}</span>
</div>
)}
</div>
@@ -986,7 +988,7 @@ export default function DeviceOverviewPage() {
<div style={{ display: "flex", justifyContent: "space-between", gap: 12, alignItems: "center" }}>
<div style={{ display: "flex", border: "1px solid #e8e8e8", borderRadius: 12, overflow: "hidden", flex: 1 }}>
<div style={{ flex: 1, textAlign: 'center', whiteSpace: "nowrap", padding: "12px 4px", borderRight: "1px solid #e8e8e8" }}><div style={{ fontSize: 11, color: '#666', fontWeight: 600 }}>{t('devices.s44')}</div><div style={{ fontSize: 14, fontWeight: 700, color: '#222', marginTop: 2 }}>{fix2(realtimeDevice?.wind_speed)} m/s</div></div>
<div style={{ flex: 1, textAlign: 'center', whiteSpace: "nowrap", padding: "12px 4px", borderRight: "1px solid #e8e8e8" }}><div style={{ fontSize: 11, color: '#666', fontWeight: 600 }}>{t('home.temperature')}</div><div style={{ fontSize: 14, fontWeight: 700, color: '#222', marginTop: 2 }}>{fix2(realtimeDevice?.environment_temperature)}℃</div></div>
<div style={{ flex: 1, textAlign: 'center', whiteSpace: "nowrap", padding: "12px 4px", borderRight: "1px solid #e8e8e8" }}><div style={{ fontSize: 11, color: '#666', fontWeight: 600 }}>{t('home.temperature')}</div><div style={{ fontSize: 14, fontWeight: 700, color: '#222', marginTop: 2 }}>{formatTemperature(Number(realtimeDevice?.environment_temperature || 0), 1).label}</div></div>
<div style={{ flex: 1, textAlign: 'center', whiteSpace: "nowrap", padding: "12px 4px", borderRight: "1px solid #e8e8e8" }}><div style={{ fontSize: 11, color: '#666', fontWeight: 600 }}>{t('devices.rainfall')}</div><div style={{ fontSize: 14, fontWeight: 700, color: '#222', marginTop: 2 }}>{getVal(realtimeDevice?.rainfall)}</div></div>
<div style={{ flex: 1, textAlign: 'center', whiteSpace: "nowrap", padding: "12px 4px" }}><div style={{ fontSize: 11, color: '#666', fontWeight: 600 }}>RTK</div><div style={{ fontSize: 14, fontWeight: 700, color: '#52c41a', marginTop: 2 }}>{realtimeDevice?.position_state?.is_fixed === 'fixing_successful' ? '固定' : '未固定'}</div></div>
</div>

View File

@@ -61,6 +61,7 @@ import { MowerAllView } from './MowerAllView';
import { useMqtt } from '@/hooks/useMqtt';
import envConfig from '../../../env';
import { dataUrlToFile } from '@/lib/utils.ts';
import { useUnitFormatter } from '@/lib/units';
import { PauseOutlined, PlayCircleOutlined } from '@ant-design/icons';
import { useTranslation } from 'react-i18next';
const { RangePicker } = DatePicker;
@@ -72,6 +73,7 @@ export default function DeviceStatusPage() {
const { t } = useTranslation();
const { userInfo } = useSelector((state: RootState) => state.user);
const { stationId, currentStation } = useSelector((state: RootState) => state.station);
const { formatTemperature } = useUnitFormatter();
const [persistentDroneData, setPersistentDroneData] = useState(null); // 持久化无人机数据
const [persistentHostData, setPersistentHostData] = useState(null); // 持久化机场数据
const [devices, setDevices] = useState([]);
@@ -1188,11 +1190,11 @@ export default function DeviceStatusPage() {
<span>{t('devices.rtRightSpeed')}</span>
<span>{runningStatus?.rightMeasureSpeed !== undefined ? `${Number(runningStatus?.rightMeasureSpeed).toFixed(1)}rpm` : '-'}</span>
<span>{t('devices.rtLeftTemp')}</span>
<span>{runningStatus?.leftMotorTemp !== undefined ? `${Number(runningStatus?.leftMotorTemp).toFixed(1)}℃` : '-'}</span>
<span>{runningStatus?.leftMotorTemp !== undefined ? formatTemperature(Number(runningStatus?.leftMotorTemp), 1).label : '-'}</span>
<span>{t('devices.rtRightTemp')}</span>
<span>{runningStatus?.rightMotorTemp !== undefined ? `${Number(runningStatus?.rightMotorTemp).toFixed(1)}℃` : '-'}</span>
<span>{runningStatus?.rightMotorTemp !== undefined ? formatTemperature(Number(runningStatus?.rightMotorTemp), 1).label : '-'}</span>
<span>{t('devices.rtMainTemp')}</span>
<span>{runningStatus?.chipTemp !== undefined ? `${Number(runningStatus?.chipTemp).toFixed(1)}℃` : '-'}</span>
<span>{runningStatus?.chipTemp !== undefined ? formatTemperature(Number(runningStatus?.chipTemp), 1).label : '-'}</span>
<span>{t('devices.rtHeadingAngle')}</span>
<span>{runningStatus?.yaw !== undefined ? `${Number(runningStatus?.yaw).toFixed(1)}°` : '-'}</span>
<span>{t('devices.rtPitchAngle')}</span>
@@ -1307,11 +1309,11 @@ export default function DeviceStatusPage() {
<span>{t('devices.rtRightSpeed')}</span>
<span>{runningStatus?.rightMeasureSpeed !== undefined ? `${Number(runningStatus?.rightMeasureSpeed).toFixed(1)}rpm` : '-'}</span>
<span>{t('devices.rtLeftTemp')}</span>
<span>{runningStatus?.leftMotorTemp !== undefined ? `${Number(runningStatus?.leftMotorTemp).toFixed(1)}℃` : '-'}</span>
<span>{runningStatus?.leftMotorTemp !== undefined ? formatTemperature(Number(runningStatus?.leftMotorTemp), 1).label : '-'}</span>
<span>{t('devices.rtRightTemp')}</span>
<span>{runningStatus?.rightMotorTemp !== undefined ? `${Number(runningStatus?.rightMotorTemp).toFixed(1)}℃` : '-'}</span>
<span>{runningStatus?.rightMotorTemp !== undefined ? formatTemperature(Number(runningStatus?.rightMotorTemp), 1).label : '-'}</span>
<span>{t('devices.rtMainTemp')}</span>
<span>{runningStatus?.chipTemp !== undefined ? `${Number(runningStatus?.chipTemp).toFixed(1)}℃` : '-'}</span>
<span>{runningStatus?.chipTemp !== undefined ? formatTemperature(Number(runningStatus?.chipTemp), 1).label : '-'}</span>
<span>{t('devices.rtHeadingAngle')}</span>
<span>{runningStatus?.yaw !== undefined ? `${Number(runningStatus?.yaw).toFixed(1)}°` : '-'}</span>
<span>{t('devices.rtPitchAngle')}</span>

View File

@@ -38,6 +38,7 @@ const { RangePicker } = DatePicker;
export default function WayLinePage({ onRefresh }) {
const { t } = useTranslation();
const { userInfo } = useSelector((state: RootState) => state.user);
const { timezone } = useSelector((state: RootState) => state.preferences);
const { stationId } = useSelector((state: RootState) => state.station);
const { currentStation } = useSelector((state: RootState) => state.station);
@@ -325,7 +326,7 @@ export default function WayLinePage({ onRefresh }) {
days_of_month: [],
week_of_month: 1,
},
time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone,
time_zone: timezone,
recurring_task_start_time_list: [],
});
@@ -389,7 +390,7 @@ export default function WayLinePage({ onRefresh }) {
task_type: 'immediate',
repeat_type: 'nonrepeating',
repeat_option: { interval: 1 },
time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone,
time_zone: timezone,
begin_at: null,
end_at: null,
recurring_task_start_time_list: [],
@@ -687,7 +688,7 @@ export default function WayLinePage({ onRefresh }) {
resumable_status: 'auto',
min_battery_capacity: 50,
repeat_type: 'nonrepeating',
time_zone: Intl.DateTimeFormat().resolvedOptions().timeZone,
time_zone: timezone,
};
const res: any = await createWaylineTask(payload);