diff --git a/src/components/SystemSetting/BasicSettings.tsx b/src/components/SystemSetting/BasicSettings.tsx index 5ff9322..756950a 100644 --- a/src/components/SystemSetting/BasicSettings.tsx +++ b/src/components/SystemSetting/BasicSettings.tsx @@ -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([]); + const { userInfo } = useSelector((state: RootState) => state.user); + const { currentStation, stationId } = useSelector((state: RootState) => state.station); + const [userList, setUserList] = useState([]); + 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: }, + //普通用户 { title: t('systemSetting.fixed2OM'), users: 5, @@ -147,6 +168,7 @@ const BasicSettings = () => { bg: '#f6ffed', icon: }, + //机构管理员 { title: t('systemSetting.fixed2Inspection2'), users: 8, @@ -156,6 +178,7 @@ const BasicSettings = () => { bg: '#fff7e6', icon: }, + //场站管理员 { title: t('systemSetting.s322'), users: 3, @@ -166,18 +189,67 @@ const BasicSettings = () => { icon: }, ]; + 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 (
@@ -190,7 +262,7 @@ const BasicSettings = () => { {topCards.map((item, idx) => ( - +
{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 = () => { - + dispatch(saveAllSettings({ systemName: e.target.value }))} /> - dispatch(saveAllSettings({ defaultSite: v }))}> {t('layout.defaultStationName')} @@ -272,27 +344,15 @@ const BasicSettings = () => { - - - - - + - dispatch(saveAllSettings({ refreshRate: v }))}> {t('systemSetting.5')} - - - - - +
@@ -312,7 +372,7 @@ const BasicSettings = () => {
- +
@@ -362,7 +422,7 @@ const BasicSettings = () => { {/* 用户与权限预览 */} {t('systemSetting.fixed2RolePermissionFixed2OverviewFixed2')}
} + title={{t('systemSetting.fixed2UserPermissionFixed2OverviewFixed2')}} 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 {role}; + render: (_val, record) => { + const roleList = record.roles || []; + return <> + {roleList.map((rItem: any) => { + //const conf = getRoleConfByKey(rItem.roleKey); + return {rItem.roleKey == "manager" ? t('systemSetting.fixed2Inspection2') : rItem.roleKey == "siteManager" ? t('systemSetting.s322') : t('systemSetting.fixed2OM')} + })} + } }, - { 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) => (
- {status} + {status == 1 ? "在线" : "离线"} ) }, { - title: t('roles.actions'), key: 'action', width: 60, render: () => , 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} /> @@ -437,26 +490,52 @@ const BasicSettings = () => { styles={{ body: { padding: '10px' } }} > - {roleOverview.map((role, idx) => ( - -
-
- {React.cloneElement(role.icon as React.ReactElement, { size: 16 })} - + {roles.slice((rolePage - 1) * 4, rolePage * 4).map((role, idx) => { + const styleConf = matchRoleStyle(role.roleName); + return ( + +
+
+ {styleConf.icon} +
+
+ {role.roleName} +
+
+ 菜单权限 {role.menuIds?.length ?? 0} +
+
+ {styleConf.tags.map((tag, tidx) => ( + + {tag} + + ))} +
-
{role.title}
-
- 用户 {role.users} | 权限 {role.perms} -
-
- {role.tags.map((tag, tidx) => ( - {tag} - ))} -
-
- - ))} + + ); + })} + {roles.length > 4 && ( + setRolePage(page)} + style={{ textAlign: 'center', marginTop: 8 }} + /> + )} {/* 设备接入状态 */} @@ -469,7 +548,7 @@ const BasicSettings = () => { >
- {deviceStatuses.map((item, idx) => ( + {deviceStatuses.slice((devicePage - 1) * 4, devicePage * 4).map((item, idx) => (
@@ -517,6 +596,16 @@ const BasicSettings = () => {
+ {deviceStatuses.length > 4 && ( + setDevicePage(page)} + style={{ textAlign: 'center', marginTop: 4 }} + /> + )} {/* 数据与安全 */} diff --git a/src/locales/en/index.ts b/src/locales/en/index.ts index b381f72..1d8e46b 100644 --- a/src/locales/en/index.ts +++ b/src/locales/en/index.ts @@ -2731,6 +2731,7 @@ s14: 'Address', fixed2RolePermissionFixed2OverviewFixed2: 'Role Permission Overview', + fixed2UserPermissionFixed2OverviewFixed2: 'User Permission Overview', fixed2DeviceAccessFixed2StatusFixed2: 'Device Access Status', diff --git a/src/locales/zh/index.ts b/src/locales/zh/index.ts index 7b2517f..045c5ad 100644 --- a/src/locales/zh/index.ts +++ b/src/locales/zh/index.ts @@ -2771,6 +2771,8 @@ const zh = { s14: '地址', fixed2RolePermissionFixed2OverviewFixed2: '角色权限概览', + fixed2UserPermissionFixed2OverviewFixed2: '用户权限概览', + fixed2DeviceAccessFixed2StatusFixed2: '设备接入状态', @@ -2794,7 +2796,7 @@ const zh = { s28: '开启钉钉推送时必须填写加密密钥', - fixed2OM: '运维工程师', + fixed2OM: '普通用户', fixed2Inspection: '巡检区', @@ -3237,9 +3239,9 @@ const zh = { s282: '最近更新', - fixed2Inspection2: '巡检主管', + fixed2Inspection2: '机构管理员', - s322: '数据分析师', + s322: '场站管理员', fixed2Login2: '登录审计', @@ -3581,7 +3583,7 @@ const zh = { roleNamePlaceholder: '角色名称占位', rolePermission: '角色权限', roleSortLabel: '角色排序标签', - superAdmin: '超级管理员', + superAdmin: '平台管理员', }, constants: { // 工单类型 diff --git a/src/store/basicSettingsSlice.ts b/src/store/basicSettingsSlice.ts new file mode 100644 index 0000000..45d58e4 --- /dev/null +++ b/src/store/basicSettingsSlice.ts @@ -0,0 +1,115 @@ +import { createSlice, PayloadAction } from '@reduxjs/toolkit'; + +export interface BasicSettingsState { + systemName: string; + defaultSite: string; + defaultPage: string; + refreshRate: string; + enableNotification: boolean; + enableAi: boolean; + enableAutoRefresh: boolean; + enableSms: boolean; + enableEmail: boolean; + enableTelegram: boolean; + enableSystemNotification: boolean; + enableCriticalAlert: boolean; + enableGenerationDescend: boolean; + enableCommunication: boolean; + enableEverydayPush: boolean; + nightModeStart: string; + nightModeEnd: string; + enableNightMode: boolean; +} + +const STORAGE_KEY = 'basicSettings'; + +const defaultState: BasicSettingsState = { + systemName: '', + defaultSite: '', + defaultPage: 'dashboard', + refreshRate: '5min', + enableNotification: true, + enableAi: true, + enableAutoRefresh: true, + enableSms: true, + enableEmail: true, + enableTelegram: true, + enableSystemNotification: true, + enableCriticalAlert: true, + enableGenerationDescend: true, + enableCommunication: true, + enableEverydayPush: true, + nightModeStart: '23:00', + nightModeEnd: '07:00', + enableNightMode: false, +}; + +const loadFromStorage = (): BasicSettingsState => { + try { + const raw = localStorage.getItem(STORAGE_KEY); + if (raw) { + return { ...defaultState, ...JSON.parse(raw) }; + } + } catch { + // ignore + } + return { ...defaultState }; +}; + +const persist = (state: BasicSettingsState) => { + try { + localStorage.setItem(STORAGE_KEY, JSON.stringify(state)); + } catch { + // ignore + } +}; + +const initialState: BasicSettingsState = loadFromStorage(); +persist(initialState); + +const basicSettingsSlice = createSlice({ + name: 'basicSettings', + initialState, + reducers: { + setSystemName: (state, action: PayloadAction) => { + state.systemName = action.payload; + persist(state); + }, + setDefaultSite: (state, action: PayloadAction) => { + state.defaultSite = action.payload; + persist(state); + }, + setDefaultPage: (state, action: PayloadAction) => { + state.defaultPage = action.payload; + persist(state); + }, + setRefreshRate: (state, action: PayloadAction) => { + state.refreshRate = action.payload; + persist(state); + }, + setSettingField: (state, action: PayloadAction>) => { + Object.assign(state, action.payload); + persist(state); + }, + saveAllSettings: (state, action: PayloadAction>) => { + Object.assign(state, action.payload); + persist(state); + }, + resetBasicSettings: (state) => { + Object.assign(state, defaultState); + persist(state); + }, + }, +}); + +export const { + setSystemName, + setDefaultSite, + setDefaultPage, + setRefreshRate, + setSettingField, + saveAllSettings, + resetBasicSettings, +} = basicSettingsSlice.actions; + +export default basicSettingsSlice.reducer; diff --git a/src/store/index.ts b/src/store/index.ts index 1afb030..50009c2 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1,16 +1,18 @@ -import { configureStore } from '@reduxjs/toolkit'; +import { configureStore } from '@reduxjs/toolkit'; import { useDispatch } from 'react-redux'; // 👇 保留 import,但是把类型定义放到 store 后面 import userReducer from './userSlice'; import stationReducer from './stationSlice'; // 👈 加这个 import preferencesReducer from './preferencesSlice'; +import basicSettingsReducer from './basicSettingsSlice'; export const store = configureStore({ reducer: { user: userReducer, station: stationReducer, // 👈 加这个 preferences: preferencesReducer, + basicSettings: basicSettingsReducer, }, });