优化基础设置界面 完善角色权限概览和 用户权限概览 模块
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import React, { useState } from 'react';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import {
|
||||
Form,
|
||||
Input,
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
TimePicker,
|
||||
Divider,
|
||||
Radio,
|
||||
Pagination,
|
||||
} from 'antd';
|
||||
import {
|
||||
CloudOutlined,
|
||||
@@ -59,10 +60,13 @@ import {
|
||||
} from 'lucide-react';
|
||||
import dayjs from 'dayjs';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { getRoleList } from '@/api/role';
|
||||
import { useSelector } from 'react-redux';
|
||||
|
||||
import { RootState } from '@/src/store';
|
||||
import { getUser } from '@/api/user';
|
||||
import { useAppDispatch } from '../../store';
|
||||
import { setLocale, setTimezone, setUnitSystem, setDateFormat } from '../../store/preferencesSlice';
|
||||
import { saveAllSettings, resetBasicSettings } from '../../store/basicSettingsSlice';
|
||||
import { getTimezoneOptions, isDST, getTimezoneOffsetLabel } from '../../lib/dayjs';
|
||||
|
||||
const { Text, Title } = Typography;
|
||||
@@ -70,8 +74,17 @@ const { Text, Title } = Typography;
|
||||
const BasicSettings = () => {
|
||||
const { t, i18n } = useTranslation();
|
||||
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 [userList, setUserList] = useState<any[]>([]);
|
||||
|
||||
const dispatch = useAppDispatch();
|
||||
const { locale, timezone, unitSystem, dateFormat } = useSelector((state: any) => state.preferences);
|
||||
const basicSettings = useSelector((state: RootState) => state.basicSettings);
|
||||
const [userPage, setUserPage] = useState(1);
|
||||
const [rolePage, setRolePage] = useState(1);
|
||||
const [devicePage, setDevicePage] = useState(1);
|
||||
const tzOptions = getTimezoneOptions();
|
||||
const dstActive = isDST(timezone);
|
||||
|
||||
@@ -82,6 +95,12 @@ const BasicSettings = () => {
|
||||
const fontLarge = 'clamp(18px, 1.1vw, 22px)';
|
||||
|
||||
const handleSave = () => {
|
||||
dispatch(saveAllSettings({
|
||||
systemName: form.getFieldValue('systemName') || basicSettings.systemName,
|
||||
defaultSite: form.getFieldValue('defaultSite') || basicSettings.defaultSite,
|
||||
defaultPage: form.getFieldValue('defaultPage') || basicSettings.defaultPage,
|
||||
refreshRate: form.getFieldValue('refreshRate') || basicSettings.refreshRate,
|
||||
}));
|
||||
message.success(t('systemSetting.fixed2SettingsSaveFixed2'));
|
||||
};
|
||||
|
||||
@@ -129,6 +148,7 @@ const BasicSettings = () => {
|
||||
|
||||
// 角色权限概览
|
||||
const roleOverview = [
|
||||
//平台管理员
|
||||
{
|
||||
title: t('roles.superAdmin'),
|
||||
users: 2,
|
||||
@@ -138,6 +158,7 @@ const BasicSettings = () => {
|
||||
bg: '#e6f4ff',
|
||||
icon: <ShieldCheck size={20} color="#1677ff" />
|
||||
},
|
||||
//普通用户
|
||||
{
|
||||
title: t('systemSetting.fixed2OM'),
|
||||
users: 5,
|
||||
@@ -147,6 +168,7 @@ const BasicSettings = () => {
|
||||
bg: '#f6ffed',
|
||||
icon: <Wrench size={20} color="#52c41a" />
|
||||
},
|
||||
//机构管理员
|
||||
{
|
||||
title: t('systemSetting.fixed2Inspection2'),
|
||||
users: 8,
|
||||
@@ -156,6 +178,7 @@ const BasicSettings = () => {
|
||||
bg: '#fff7e6',
|
||||
icon: <Users size={20} color="#fa8c16" />
|
||||
},
|
||||
//场站管理员
|
||||
{
|
||||
title: t('systemSetting.s322'),
|
||||
users: 3,
|
||||
@@ -166,18 +189,67 @@ const BasicSettings = () => {
|
||||
icon: <LineChart size={20} color="#722ed1" />
|
||||
},
|
||||
];
|
||||
const matchRoleStyle = (roleName: string) => {
|
||||
const found = roleOverview.find(item => item.title === roleName);
|
||||
if (found) return found;
|
||||
// 兜底默认样式
|
||||
return {
|
||||
color: '#8c8c8c',
|
||||
bg: '#f5f5f5',
|
||||
icon: null,
|
||||
tags: []
|
||||
};
|
||||
};
|
||||
|
||||
const getUserData = () => {
|
||||
const params = {
|
||||
pageNum: 1,
|
||||
pageSize: 9999,
|
||||
orgId: userInfo?.roleKey == "manager" ? userInfo?.orgId : currentStation?.orgId,
|
||||
...(userInfo?.roleKey == "manager"
|
||||
? {}
|
||||
: { siteId: stationId }
|
||||
)
|
||||
};
|
||||
|
||||
getUser(params).then(res => {
|
||||
if (res.code === 200) {
|
||||
setUserList(res.rows || []);
|
||||
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// 设备状态
|
||||
const deviceStatuses = [
|
||||
{ name: t('home.inverter'), count: '5/5', status: t('roles.normal') },
|
||||
{ name: t('home.combinerBox'), count: '20/20', status: t('roles.normal') },
|
||||
{ name: t('home.WeatherStation'), count: '1/1', status: t('roles.normal') },
|
||||
{ name: t('home.weatherStation'), count: '1/1', status: t('roles.normal') },
|
||||
{ name: t('devices.camera'), count: '12/12', status: t('roles.normal') },
|
||||
{ name: t('constants.uav'), count: '2/2', status: t('roles.normal') },
|
||||
{ name: t('devices.robot'), count: '5/5', status: t('roles.normal') },
|
||||
{ name: t('systemSetting.api'), count: t('roles.normal'), status: t('roles.normal') },
|
||||
{ name: 'Modbus', count: t('roles.normal'), status: t('roles.normal') },
|
||||
];
|
||||
const getRoleData = () => {
|
||||
const params = { pageNum: 1, pageSize: 9999 };
|
||||
getRoleList(params).then(res => {
|
||||
if (res.code === 200) {
|
||||
let sortedRoles = (res.data || []).sort((a, b) => (a.roleSort || 999) - (b.roleSort || 999));
|
||||
setRoles(sortedRoles);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getRoleData();
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
getUserData();
|
||||
}, [stationId])
|
||||
|
||||
|
||||
return (
|
||||
<div className="normal-spacing" style={{ padding: '8px 0px', background: '#f5f7fa', minHeight: '100vh' }}>
|
||||
@@ -190,7 +262,7 @@ const BasicSettings = () => {
|
||||
<Row gutter={[8, 8]} style={{ marginBottom: 8 }}>
|
||||
{topCards.map((item, idx) => (
|
||||
<Col key={idx} style={{ minWidth: '168px', flex: '1 0 auto', maxWidth: "250px" }}>
|
||||
<AntdCard variant="borderless" styles={{ body: { padding: '12px 16px' } }} style={{ borderRadius: 10, boxShadow: '0 2px 8px rgba(0,0,0,0.04)' }}>
|
||||
<AntdCard bordered={false} bodyStyle={{ padding: '12px 16px' }} style={{ borderRadius: 10, boxShadow: '0 2px 8px rgba(0,0,0,0.04)' }}>
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: 10 }}>
|
||||
<div style={{ width: 40, height: 40, borderRadius: 10, background: item.bg, display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
||||
{React.cloneElement(item.icon as React.ReactElement, { size: 20, style: item.icon.props.style ? { ...item.icon.props.style, fontSize: 20 } : { fontSize: 20 } })}
|
||||
@@ -223,12 +295,12 @@ 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" defaultValue={t('login.systemName')} />
|
||||
<Input size="small" value={basicSettings.systemName} onChange={(e) => dispatch(saveAllSettings({ systemName: e.target.value }))} />
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col xs={24} sm={12} md={8}>
|
||||
<Form.Item label={t('systemSetting.fixed2Default2')} name="defaultSite" style={{ marginBottom: 12 }}>
|
||||
<Select size="small" defaultValue={t('layout.defaultStationName')}>
|
||||
<Select size="small" value={basicSettings.defaultSite} onChange={(v) => dispatch(saveAllSettings({ defaultSite: v }))}>
|
||||
<Select.Option value="1MW">{t('layout.defaultStationName')}</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
@@ -272,27 +344,15 @@ const BasicSettings = () => {
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
<Col xs={24} sm={12} md={8}>
|
||||
<Form.Item label={t('systemSetting.default')} name="defaultPage" style={{ marginBottom: 12 }}>
|
||||
<Select size="small" defaultValue="dashboard">
|
||||
<Select.Option value="dashboard">{t('router.overview')}</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={12} md={8}>
|
||||
<Form.Item label={t('systemSetting.refreshFixed2FrequencyFixed2')} name="refreshRate" style={{ marginBottom: 12 }}>
|
||||
<Select size="small" defaultValue="5min">
|
||||
<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 xs={24} sm={12} md={8}>
|
||||
<Form.Item label={t('systemSetting.s232')} name="mapService" style={{ marginBottom: 12 }}>
|
||||
<Select size="small" defaultValue="gaode">
|
||||
<Select.Option value="gaode">{t('systemSetting.s24')}</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} md={16}>
|
||||
<div style={{ display: 'flex', gap: 'clamp(8px, 1vw, 20px)', marginTop: 4, flexWrap: 'wrap' }}>
|
||||
<Space>
|
||||
@@ -312,7 +372,7 @@ 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 }}>{t('systemSetting.fixed2ResumeFixed2DefaultFixed2')}</Button>
|
||||
<Button size="small" style={{ marginLeft: 8, borderRadius: 6 }} onClick={() => { dispatch(resetBasicSettings()); form.resetFields(); }}>{t('systemSetting.fixed2ResumeFixed2DefaultFixed2')}</Button>
|
||||
</div>
|
||||
</Form>
|
||||
</AntdCard>
|
||||
@@ -362,7 +422,7 @@ const BasicSettings = () => {
|
||||
|
||||
{/* 用户与权限预览 */}
|
||||
<AntdCard
|
||||
title={<Space><Users size={16} style={{ color: '#1677ff' }} /><b>{t('systemSetting.fixed2RolePermissionFixed2OverviewFixed2')}</b></Space>}
|
||||
title={<Space><Users size={16} style={{ color: '#1677ff' }} /><b>{t('systemSetting.fixed2UserPermissionFixed2OverviewFixed2')}</b></Space>}
|
||||
variant="borderless"
|
||||
style={{ borderRadius: 10, boxShadow: '0 2px 8px rgba(0,0,0,0.04)', marginBottom: 0 }}
|
||||
styles={{ body: { padding: '12px' } }}
|
||||
@@ -375,41 +435,39 @@ const BasicSettings = () => {
|
||||
|
||||
|
||||
rowKey="name"
|
||||
pagination={{ size: 'small', total: 4, pageSize: 4, showTotal: (total) => `共 ${total} 条` }}
|
||||
pagination={{ size: 'small', total: userList.length, pageSize: 4, current: userPage, onChange: (page: number) => setUserPage(page), showTotal: (total) => `共 ${total} 条` }}
|
||||
columns={[
|
||||
{ title: t('systemSetting.s36'), dataIndex: 'name', key: 'name', fixed: 'left', width: 80 },
|
||||
{ title: t('systemSetting.s36'), dataIndex: 'userName', key: 'userName', fixed: 'left', },
|
||||
{
|
||||
title: t('users.role'),
|
||||
dataIndex: 'role',
|
||||
key: 'role',
|
||||
width: 100,
|
||||
render: (role) => {
|
||||
const config: any = {
|
||||
'超级管理员': { color: '#1677ff', bg: '#e6f4ff' },
|
||||
'运维工程师': { color: '#52c41a', bg: '#f6ffed' },
|
||||
'巡检主管': { color: '#fa8c16', bg: '#fff7e6' },
|
||||
'数据分析师': { color: '#722ed1', bg: '#f9f0ff' },
|
||||
};
|
||||
const s = config[role] || { color: '#8c8c8c', bg: '#f5f5f5' };
|
||||
return <Tag variant="borderless" style={{ color: s.color, background: s.bg, fontSize: 10, margin: 0 }}>{role}</Tag>;
|
||||
render: (_val, record) => {
|
||||
const roleList = record.roles || [];
|
||||
return <>
|
||||
{roleList.map((rItem: any) => {
|
||||
//const conf = getRoleConfByKey(rItem.roleKey);
|
||||
return <Tag key={rItem.roleId}>{rItem.roleKey == "manager" ? t('systemSetting.fixed2Inspection2') : rItem.roleKey == "siteManager" ? t('systemSetting.s322') : t('systemSetting.fixed2OM')}</Tag>
|
||||
})}
|
||||
</>
|
||||
}
|
||||
},
|
||||
{ title: t('users.phone'), dataIndex: 'phone', key: 'phone', width: 110 },
|
||||
{ title: t('users.phone'), dataIndex: 'phonenumber', key: 'phonenumber', },
|
||||
{ title: t('users.email'), dataIndex: 'email', key: 'email', ellipsis: true },
|
||||
{
|
||||
title: t('roles.status'),
|
||||
dataIndex: 'status',
|
||||
key: 'status',
|
||||
width: 70,
|
||||
render: (status) => (
|
||||
<Space size={4}>
|
||||
<div style={{ width: 6, height: 6, borderRadius: '50%', background: status === t('devices.online') ? '#52c41a' : '#bfbfbf' }} />
|
||||
<span style={{ fontSize: 10 }}>{status}</span>
|
||||
<span style={{ fontSize: 10 }}>{status == 1 ? "在线" : "离线"}</span>
|
||||
</Space>
|
||||
)
|
||||
},
|
||||
{
|
||||
title: t('roles.actions'), key: 'action', width: 60, render: () => <Button
|
||||
title: t('roles.actions'), key: 'action', render: () => <Button
|
||||
type="link"
|
||||
size="small"
|
||||
icon={<EyeOutlined />}
|
||||
@@ -417,12 +475,7 @@ const BasicSettings = () => {
|
||||
>{t('common.view')}</Button>, fixed: 'right'
|
||||
},
|
||||
]}
|
||||
dataSource={[
|
||||
{ name: '张运维', role: '超级管理员', phone: '138****0001', email: 'zhangyw@pvsmart.com', status: t('devices.online') },
|
||||
{ name: '李工程师', role: '运维工程师', phone: '139****0002', email: 'li.gongcheng@pvsmart.com', status: t('devices.online') },
|
||||
{ name: '王班长', role: '巡检主管', phone: '137****0003', email: 'wang.banzhang@pvsmart.com', status: t('devices.online') },
|
||||
{ name: '赵分析师', role: '数据分析师', phone: '136****0004', email: 'zhao.fx@pvsmart.com', status: t('devices.online') },
|
||||
]}
|
||||
dataSource={userList}
|
||||
/>
|
||||
</AntdCard>
|
||||
</Col>
|
||||
@@ -437,26 +490,52 @@ const BasicSettings = () => {
|
||||
styles={{ body: { padding: '10px' } }}
|
||||
>
|
||||
<Row gutter={[8, 8]}>
|
||||
{roleOverview.map((role, idx) => (
|
||||
<Col xs={24} sm={12} key={idx}>
|
||||
<div style={{ background: role.bg, borderRadius: 8, padding: 8, height: '100%' }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 4 }}>
|
||||
{React.cloneElement(role.icon as React.ReactElement, { size: 16 })}
|
||||
<RightOutlined style={{ fontSize: 9, color: role.color }} />
|
||||
{roles.slice((rolePage - 1) * 4, rolePage * 4).map((role, idx) => {
|
||||
const styleConf = matchRoleStyle(role.roleName);
|
||||
return (
|
||||
<Col xs={24} sm={12} key={idx}>
|
||||
<div style={{ background: styleConf.bg, borderRadius: 8, padding: 8, height: '100%' }}>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 4, alignItems: 'center' }}>
|
||||
{styleConf.icon}
|
||||
</div>
|
||||
<div style={{ fontWeight: 600, fontSize: 11, color: styleConf.color, marginBottom: 2 }}>
|
||||
{role.roleName}
|
||||
</div>
|
||||
<div style={{ fontSize: 9, color: '#8c8c8c', marginBottom: 6 }}>
|
||||
菜单权限 {role.menuIds?.length ?? 0}
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 4, flexWrap: 'wrap' }}>
|
||||
{styleConf.tags.map((tag, tidx) => (
|
||||
<span
|
||||
key={tidx}
|
||||
style={{
|
||||
fontSize: 8,
|
||||
padding: '0 4px',
|
||||
background: '#fff',
|
||||
color: styleConf.color,
|
||||
borderRadius: 2,
|
||||
border: `1px solid ${styleConf.color}20`
|
||||
}}
|
||||
>
|
||||
{tag}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ fontWeight: 600, fontSize: 11, color: role.color, marginBottom: 2 }}>{role.title}</div>
|
||||
<div style={{ fontSize: 9, color: '#8c8c8c', marginBottom: 6 }}>
|
||||
用户 {role.users} | 权限 {role.perms}
|
||||
</div>
|
||||
<div style={{ display: 'flex', gap: 4, flexWrap: 'wrap' }}>
|
||||
{role.tags.map((tag, tidx) => (
|
||||
<span key={tidx} style={{ fontSize: 8, padding: '0 4px', background: '#fff', color: role.color, borderRadius: 2, border: `1px solid ${role.color}20` }}>{tag}</span>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</Col>
|
||||
))}
|
||||
</Col>
|
||||
);
|
||||
})}
|
||||
</Row>
|
||||
{roles.length > 4 && (
|
||||
<Pagination
|
||||
size="small"
|
||||
current={rolePage}
|
||||
pageSize={4}
|
||||
total={roles.length}
|
||||
onChange={(page) => setRolePage(page)}
|
||||
style={{ textAlign: 'center', marginTop: 8 }}
|
||||
/>
|
||||
)}
|
||||
</AntdCard>
|
||||
|
||||
{/* 设备接入状态 */}
|
||||
@@ -469,7 +548,7 @@ const BasicSettings = () => {
|
||||
>
|
||||
<div style={{ display: 'flex', gap: 12 }}>
|
||||
<div style={{ flex: '0 0 90px' }}>
|
||||
{deviceStatuses.map((item, idx) => (
|
||||
{deviceStatuses.slice((devicePage - 1) * 4, devicePage * 4).map((item, idx) => (
|
||||
<div key={idx} style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 4 }}>
|
||||
<Space size={4}>
|
||||
<div style={{ width: 5, height: 5, borderRadius: '50%', background: '#52c41a' }} />
|
||||
@@ -517,6 +596,16 @@ const BasicSettings = () => {
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
{deviceStatuses.length > 4 && (
|
||||
<Pagination
|
||||
size="small"
|
||||
current={devicePage}
|
||||
pageSize={4}
|
||||
total={deviceStatuses.length}
|
||||
onChange={(page) => setDevicePage(page)}
|
||||
style={{ textAlign: 'center', marginTop: 4 }}
|
||||
/>
|
||||
)}
|
||||
</AntdCard>
|
||||
|
||||
{/* 数据与安全 */}
|
||||
|
||||
Reference in New Issue
Block a user