diff --git a/src/components/Layout.tsx b/src/components/Layout.tsx index 920126a..effa38b 100644 --- a/src/components/Layout.tsx +++ b/src/components/Layout.tsx @@ -40,6 +40,7 @@ export default function AppLayout() { const { userInfo } = useSelector((state: RootState) => state.user); // 从 store 中同时取出 stationList(优先级最高,保证最新) const { currentStation, stationId, stationList: storeStationList } = useSelector((state: RootState) => state.station); + const { systemName } = useSelector((state: RootState) => state.basicSettings); // 真正用于展示和选择的列表:优先用 store 中的(StationManage 编辑后会同步),否则用本地接口的 @@ -213,7 +214,7 @@ export default function AppLayout() { Logo {!collapsed && ( - {t('layout.systemName')} + {systemName || t('layout.systemName')} )} diff --git a/src/components/SystemSetting/BasicSettings.tsx b/src/components/SystemSetting/BasicSettings.tsx index 756950a..7b59e92 100644 --- a/src/components/SystemSetting/BasicSettings.tsx +++ b/src/components/SystemSetting/BasicSettings.tsx @@ -67,7 +67,9 @@ import { getUser } from '@/api/user'; import { useAppDispatch } from '../../store'; import { setLocale, setTimezone, setUnitSystem, setDateFormat } from '../../store/preferencesSlice'; import { saveAllSettings, resetBasicSettings } from '../../store/basicSettingsSlice'; +import { setCurrentStation } from '../../store/stationSlice'; import { getTimezoneOptions, isDST, getTimezoneOffsetLabel } from '../../lib/dayjs'; +import utils from '../../lib/utils'; const { Text, Title } = Typography; @@ -76,7 +78,7 @@ const BasicSettings = () => { const [form] = Form.useForm(); const [roles, setRoles] = useState([]); const { userInfo } = useSelector((state: RootState) => state.user); - const { currentStation, stationId } = useSelector((state: RootState) => state.station); + const { currentStation, stationId, stationList } = useSelector((state: RootState) => state.station); const [userList, setUserList] = useState([]); const dispatch = useAppDispatch(); @@ -95,13 +97,26 @@ const BasicSettings = () => { const fontLarge = 'clamp(18px, 1.1vw, 22px)'; const handleSave = () => { + const defaultSite = form.getFieldValue('defaultSite') || basicSettings.defaultSite; dispatch(saveAllSettings({ systemName: form.getFieldValue('systemName') || basicSettings.systemName, - defaultSite: form.getFieldValue('defaultSite') || basicSettings.defaultSite, + defaultSite, defaultPage: form.getFieldValue('defaultPage') || basicSettings.defaultPage, refreshRate: form.getFieldValue('refreshRate') || basicSettings.refreshRate, })); - message.success(t('systemSetting.fixed2SettingsSaveFixed2')); + if (defaultSite && stationList && stationList.length > 0) { + const target = stationList.find((s: any) => s.id === defaultSite); + if (target) { + dispatch(setCurrentStation(target)); + } + } + if (defaultSite && stationList && stationList.length > 0) { + const target = stationList.find((s: any) => s.id === defaultSite); + if (target) { + dispatch(setCurrentStation(target)); + } + } + utils.message.success(t('systemSetting.fixed2SettingsSaveFixed2')); }; // 顶部统计卡片数据 @@ -250,6 +265,15 @@ const BasicSettings = () => { getUserData(); }, [stationId]) + useEffect(() => { + form.setFieldsValue({ + systemName: basicSettings.systemName, + defaultSite: basicSettings.defaultSite, + defaultPage: basicSettings.defaultPage, + refreshRate: basicSettings.refreshRate, + }); + }, [basicSettings]) + return (
@@ -295,13 +319,17 @@ const BasicSettings = () => { - dispatch(saveAllSettings({ systemName: e.target.value }))} /> + @@ -345,13 +373,13 @@ const BasicSettings = () => { - + {/* - + */}
@@ -372,7 +400,20 @@ const BasicSettings = () => {
- +
diff --git a/src/store/basicSettingsSlice.ts b/src/store/basicSettingsSlice.ts index 45d58e4..403d4d8 100644 --- a/src/store/basicSettingsSlice.ts +++ b/src/store/basicSettingsSlice.ts @@ -1,4 +1,4 @@ -import { createSlice, PayloadAction } from '@reduxjs/toolkit'; +import { createSlice, PayloadAction } from '@reduxjs/toolkit'; export interface BasicSettingsState { systemName: string; @@ -24,7 +24,7 @@ export interface BasicSettingsState { const STORAGE_KEY = 'basicSettings'; const defaultState: BasicSettingsState = { - systemName: '', + systemName: '光伏机器人环境感知服务平台', defaultSite: '', defaultPage: 'dashboard', refreshRate: '5min',