基础设置界面 系统名称和默认电站的 显示和更新 ,完善恢复默认功能

This commit is contained in:
mmc
2026-10-09 14:59:17 +08:00
parent c2eb04b4a4
commit 7e4872e560
3 changed files with 53 additions and 11 deletions

View File

@@ -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() {
<img src={logo} alt="Logo" style={{ width: 24, height: 24 }} />
{!collapsed && (
<span style={{ fontWeight: 'bold', fontSize: 'clamp(14px, 1.2vw, 16px)', color: '#fff', whiteSpace: 'nowrap' }}>
{t('layout.systemName')}
{systemName || t('layout.systemName')}
</span>
)}
</div>

View File

@@ -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<any[]>([]);
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<any[]>([]);
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 (
<div className="normal-spacing" style={{ padding: '8px 0px', background: '#f5f7fa', minHeight: '100vh' }}>
@@ -295,13 +319,17 @@ const BasicSettings = () => {
<Row gutter={16}>
<Col xs={24} sm={12} md={8}>
<Form.Item label={t('systemSetting.systemName')} name="systemName" style={{ marginBottom: 12 }}>
<Input size="small" value={basicSettings.systemName} onChange={(e) => dispatch(saveAllSettings({ systemName: e.target.value }))} />
<Input size="small" value={basicSettings.systemName} />
</Form.Item>
</Col>
<Col xs={24} sm={12} md={8}>
<Form.Item label={t('systemSetting.fixed2Default2')} name="defaultSite" style={{ marginBottom: 12 }}>
<Select size="small" value={basicSettings.defaultSite} onChange={(v) => dispatch(saveAllSettings({ defaultSite: v }))}>
<Select.Option value="1MW">{t('layout.defaultStationName')}</Select.Option>
{(stationList || []).slice().sort((a, b) => (a.id || 0) - (b.id || 0)).map((s, idx) => (
<Select.Option key={s.id} value={s.id}>
{idx + 1}. {s.siteName || s.name || s.id}
</Select.Option>
))}
</Select>
</Form.Item>
</Col>
@@ -345,13 +373,13 @@ const BasicSettings = () => {
</Form.Item>
</Col>
<Col xs={24} sm={12} md={8}>
{/*<Col xs={24} sm={12} md={8}>
<Form.Item label={t('systemSetting.refreshFixed2FrequencyFixed2')} name="refreshRate" style={{ marginBottom: 12 }}>
<Select size="small" value={basicSettings.refreshRate} onChange={(v) => dispatch(saveAllSettings({ refreshRate: v }))}>
<Select.Option value="5min">{t('systemSetting.5')}</Select.Option>
</Select>
</Form.Item>
</Col>
</Col>*/}
<Col xs={24} md={16}>
<div style={{ display: 'flex', gap: 'clamp(8px, 1vw, 20px)', marginTop: 4, flexWrap: 'wrap' }}>
@@ -372,7 +400,20 @@ const BasicSettings = () => {
</Row>
<div style={{ marginTop: 12 }}>
<Button type="primary" size="small" onClick={handleSave} style={{ width: 100, borderRadius: 6 }}>{t('systemSetting.fixed2SaveFixed2SettingsFixed2')}</Button>
<Button size="small" style={{ marginLeft: 8, borderRadius: 6 }} onClick={() => { dispatch(resetBasicSettings()); form.resetFields(); }}>{t('systemSetting.fixed2ResumeFixed2DefaultFixed2')}</Button>
<Button size="small" style={{ marginLeft: 8, borderRadius: 6 }} onClick={() => {
dispatch(resetBasicSettings());
dispatch(setLocale('zh'));
i18n.changeLanguage('zh');
dispatch(setTimezone('Asia/Shanghai'));
dispatch(setUnitSystem('metric'));
dispatch(setDateFormat('YYYY-MM-DD HH:mm:ss'));
if (stationList && stationList.length > 0) {
const sorted = [...stationList].sort((a, b) => (a.id || 0) - (b.id || 0));
const first = sorted[0];
dispatch(saveAllSettings({ defaultSite: first.id }));
dispatch(setCurrentStation(first));
}
}}>{t('systemSetting.fixed2ResumeFixed2DefaultFixed2')}</Button>
</div>
</Form>
</AntdCard>