基础设置界面 系统名称和默认电站的 显示和更新 ,完善恢复默认功能
This commit is contained in:
@@ -40,6 +40,7 @@ export default function AppLayout() {
|
|||||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
const { userInfo } = useSelector((state: RootState) => state.user);
|
||||||
// 从 store 中同时取出 stationList(优先级最高,保证最新)
|
// 从 store 中同时取出 stationList(优先级最高,保证最新)
|
||||||
const { currentStation, stationId, stationList: storeStationList } = useSelector((state: RootState) => state.station);
|
const { currentStation, stationId, stationList: storeStationList } = useSelector((state: RootState) => state.station);
|
||||||
|
const { systemName } = useSelector((state: RootState) => state.basicSettings);
|
||||||
|
|
||||||
|
|
||||||
// 真正用于展示和选择的列表:优先用 store 中的(StationManage 编辑后会同步),否则用本地接口的
|
// 真正用于展示和选择的列表:优先用 store 中的(StationManage 编辑后会同步),否则用本地接口的
|
||||||
@@ -213,7 +214,7 @@ export default function AppLayout() {
|
|||||||
<img src={logo} alt="Logo" style={{ width: 24, height: 24 }} />
|
<img src={logo} alt="Logo" style={{ width: 24, height: 24 }} />
|
||||||
{!collapsed && (
|
{!collapsed && (
|
||||||
<span style={{ fontWeight: 'bold', fontSize: 'clamp(14px, 1.2vw, 16px)', color: '#fff', whiteSpace: 'nowrap' }}>
|
<span style={{ fontWeight: 'bold', fontSize: 'clamp(14px, 1.2vw, 16px)', color: '#fff', whiteSpace: 'nowrap' }}>
|
||||||
{t('layout.systemName')}
|
{systemName || t('layout.systemName')}
|
||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -67,7 +67,9 @@ import { getUser } from '@/api/user';
|
|||||||
import { useAppDispatch } from '../../store';
|
import { useAppDispatch } from '../../store';
|
||||||
import { setLocale, setTimezone, setUnitSystem, setDateFormat } from '../../store/preferencesSlice';
|
import { setLocale, setTimezone, setUnitSystem, setDateFormat } from '../../store/preferencesSlice';
|
||||||
import { saveAllSettings, resetBasicSettings } from '../../store/basicSettingsSlice';
|
import { saveAllSettings, resetBasicSettings } from '../../store/basicSettingsSlice';
|
||||||
|
import { setCurrentStation } from '../../store/stationSlice';
|
||||||
import { getTimezoneOptions, isDST, getTimezoneOffsetLabel } from '../../lib/dayjs';
|
import { getTimezoneOptions, isDST, getTimezoneOffsetLabel } from '../../lib/dayjs';
|
||||||
|
import utils from '../../lib/utils';
|
||||||
|
|
||||||
const { Text, Title } = Typography;
|
const { Text, Title } = Typography;
|
||||||
|
|
||||||
@@ -76,7 +78,7 @@ const BasicSettings = () => {
|
|||||||
const [form] = Form.useForm();
|
const [form] = Form.useForm();
|
||||||
const [roles, setRoles] = useState<any[]>([]);
|
const [roles, setRoles] = useState<any[]>([]);
|
||||||
const { userInfo } = useSelector((state: RootState) => state.user);
|
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 [userList, setUserList] = useState<any[]>([]);
|
||||||
|
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
@@ -95,13 +97,26 @@ const BasicSettings = () => {
|
|||||||
const fontLarge = 'clamp(18px, 1.1vw, 22px)';
|
const fontLarge = 'clamp(18px, 1.1vw, 22px)';
|
||||||
|
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
|
const defaultSite = form.getFieldValue('defaultSite') || basicSettings.defaultSite;
|
||||||
dispatch(saveAllSettings({
|
dispatch(saveAllSettings({
|
||||||
systemName: form.getFieldValue('systemName') || basicSettings.systemName,
|
systemName: form.getFieldValue('systemName') || basicSettings.systemName,
|
||||||
defaultSite: form.getFieldValue('defaultSite') || basicSettings.defaultSite,
|
defaultSite,
|
||||||
defaultPage: form.getFieldValue('defaultPage') || basicSettings.defaultPage,
|
defaultPage: form.getFieldValue('defaultPage') || basicSettings.defaultPage,
|
||||||
refreshRate: form.getFieldValue('refreshRate') || basicSettings.refreshRate,
|
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();
|
getUserData();
|
||||||
}, [stationId])
|
}, [stationId])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
form.setFieldsValue({
|
||||||
|
systemName: basicSettings.systemName,
|
||||||
|
defaultSite: basicSettings.defaultSite,
|
||||||
|
defaultPage: basicSettings.defaultPage,
|
||||||
|
refreshRate: basicSettings.refreshRate,
|
||||||
|
});
|
||||||
|
}, [basicSettings])
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="normal-spacing" style={{ padding: '8px 0px', background: '#f5f7fa', minHeight: '100vh' }}>
|
<div className="normal-spacing" style={{ padding: '8px 0px', background: '#f5f7fa', minHeight: '100vh' }}>
|
||||||
@@ -295,13 +319,17 @@ const BasicSettings = () => {
|
|||||||
<Row gutter={16}>
|
<Row gutter={16}>
|
||||||
<Col xs={24} sm={12} md={8}>
|
<Col xs={24} sm={12} md={8}>
|
||||||
<Form.Item label={t('systemSetting.systemName')} name="systemName" style={{ marginBottom: 12 }}>
|
<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>
|
</Form.Item>
|
||||||
</Col>
|
</Col>
|
||||||
<Col xs={24} sm={12} md={8}>
|
<Col xs={24} sm={12} md={8}>
|
||||||
<Form.Item label={t('systemSetting.fixed2Default2')} name="defaultSite" style={{ marginBottom: 12 }}>
|
<Form.Item label={t('systemSetting.fixed2Default2')} name="defaultSite" style={{ marginBottom: 12 }}>
|
||||||
<Select size="small" value={basicSettings.defaultSite} onChange={(v) => dispatch(saveAllSettings({ defaultSite: v }))}>
|
<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>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col>
|
||||||
@@ -345,13 +373,13 @@ const BasicSettings = () => {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</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 }}>
|
<Form.Item label={t('systemSetting.refreshFixed2FrequencyFixed2')} name="refreshRate" style={{ marginBottom: 12 }}>
|
||||||
<Select size="small" value={basicSettings.refreshRate} onChange={(v) => dispatch(saveAllSettings({ refreshRate: v }))}>
|
<Select size="small" value={basicSettings.refreshRate} onChange={(v) => dispatch(saveAllSettings({ refreshRate: v }))}>
|
||||||
<Select.Option value="5min">{t('systemSetting.5')}</Select.Option>
|
<Select.Option value="5min">{t('systemSetting.5')}</Select.Option>
|
||||||
</Select>
|
</Select>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Col>
|
</Col>*/}
|
||||||
|
|
||||||
<Col xs={24} md={16}>
|
<Col xs={24} md={16}>
|
||||||
<div style={{ display: 'flex', gap: 'clamp(8px, 1vw, 20px)', marginTop: 4, flexWrap: 'wrap' }}>
|
<div style={{ display: 'flex', gap: 'clamp(8px, 1vw, 20px)', marginTop: 4, flexWrap: 'wrap' }}>
|
||||||
@@ -372,7 +400,20 @@ const BasicSettings = () => {
|
|||||||
</Row>
|
</Row>
|
||||||
<div style={{ marginTop: 12 }}>
|
<div style={{ marginTop: 12 }}>
|
||||||
<Button type="primary" size="small" onClick={handleSave} style={{ width: 100, borderRadius: 6 }}>{t('systemSetting.fixed2SaveFixed2SettingsFixed2')}</Button>
|
<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>
|
</div>
|
||||||
</Form>
|
</Form>
|
||||||
</AntdCard>
|
</AntdCard>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||||
|
|
||||||
export interface BasicSettingsState {
|
export interface BasicSettingsState {
|
||||||
systemName: string;
|
systemName: string;
|
||||||
@@ -24,7 +24,7 @@ export interface BasicSettingsState {
|
|||||||
const STORAGE_KEY = 'basicSettings';
|
const STORAGE_KEY = 'basicSettings';
|
||||||
|
|
||||||
const defaultState: BasicSettingsState = {
|
const defaultState: BasicSettingsState = {
|
||||||
systemName: '',
|
systemName: '光伏机器人环境感知服务平台',
|
||||||
defaultSite: '',
|
defaultSite: '',
|
||||||
defaultPage: 'dashboard',
|
defaultPage: 'dashboard',
|
||||||
refreshRate: '5min',
|
refreshRate: '5min',
|
||||||
|
|||||||
Reference in New Issue
Block a user