From 7e4872e560674500cb96facd90022e9ad0c0b5d8 Mon Sep 17 00:00:00 2001 From: mmc <1556375442@qq.com> Date: Fri, 9 Oct 2026 14:59:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E7=A1=80=E8=AE=BE=E7=BD=AE=E7=95=8C?= =?UTF-8?q?=E9=9D=A2=20=E7=B3=BB=E7=BB=9F=E5=90=8D=E7=A7=B0=E5=92=8C?= =?UTF-8?q?=E9=BB=98=E8=AE=A4=E7=94=B5=E7=AB=99=E7=9A=84=20=20=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=92=8C=E6=9B=B4=E6=96=B0=20=20=EF=BC=8C=E5=AE=8C?= =?UTF-8?q?=E5=96=84=E6=81=A2=E5=A4=8D=E9=BB=98=E8=AE=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Layout.tsx | 3 +- .../SystemSetting/BasicSettings.tsx | 57 ++++++++++++++++--- src/store/basicSettingsSlice.ts | 4 +- 3 files changed, 53 insertions(+), 11 deletions(-) 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',