feat: 同步权限管理、企业成员排行与消费计费明细
- 接入平台与企业角色权限,按权限展示菜单、页面及操作。 - 企业成员排行按需加载,翻页沿用同一榜单快照,保留连续名次与前三名样式。 - 更新消费日志的费用明细、超管指标和官方价格汇率设置,补齐翻译与回归测试。
This commit is contained in:
@@ -2,8 +2,11 @@ import { Plus as ActionPlus } from '@/components/common/icons/ActionIcons';
|
||||
import React from 'react';
|
||||
import { Button } from 'antd';
|
||||
import { isAdmin } from '../../../helpers';
|
||||
import { usePerm } from '../../../authz';
|
||||
|
||||
const UsersActions = ({ setShowAddUser, t }) => {
|
||||
// 已切换模块按权限点,未切换与原判断一致
|
||||
const canCreate = usePerm('platform.user.create', isAdmin());
|
||||
// Add new user
|
||||
const handleAddUser = () => {
|
||||
setShowAddUser(true);
|
||||
@@ -11,7 +14,7 @@ const UsersActions = ({ setShowAddUser, t }) => {
|
||||
|
||||
return (
|
||||
<div className='flex justify-end gap-2'>
|
||||
{isAdmin() && (
|
||||
{canCreate && (
|
||||
<Button
|
||||
className='console-create-action'
|
||||
type='primary'
|
||||
|
||||
@@ -16,9 +16,23 @@ import {
|
||||
renderNumber,
|
||||
renderQuota,
|
||||
getUserData,
|
||||
isAdmin,
|
||||
} from '../../../helpers';
|
||||
|
||||
/**
|
||||
* 当前登录人能否管理这一行(与后端 canManageUserOfRole 同口径,按钮权限另由 perms 决定)
|
||||
* - 超级管理员:全部可管理
|
||||
* - 用户管理已切到新体系:不能操作自己和超级管理员(目标权限是否被覆盖由后端校验)
|
||||
* - 未切换:只能管理角色低于自己的用户
|
||||
*/
|
||||
const canManageRow = (record, enforced) => {
|
||||
const me = getUserData();
|
||||
const currentRole = Number(me?.role || 0);
|
||||
const recordRole = Number(record.role || 0);
|
||||
if (currentRole >= 100) return true;
|
||||
if (enforced) return record.id !== me?.id && recordRole < 100;
|
||||
return recordRole < currentRole;
|
||||
};
|
||||
|
||||
/**
|
||||
* Render user role
|
||||
*/
|
||||
@@ -98,19 +112,21 @@ const renderUsername = (text, record) => {
|
||||
/**
|
||||
* Render user statistics
|
||||
*/
|
||||
const renderStatistics = (text, record, showEnableDisableModal, t) => {
|
||||
const renderStatistics = (text, record, showEnableDisableModal, perms, t) => {
|
||||
const isDeleted = record.DeletedAt !== null;
|
||||
|
||||
const currentRole = Number(getUserData()?.role || 0);
|
||||
const canManage =
|
||||
isAdmin() && (currentRole >= 100 || Number(record.role || 0) < 100);
|
||||
// 超级管理员是受保护对象,不可切换;其余按「禁用/启用」按钮权限与行级可管理性
|
||||
const canToggle =
|
||||
perms.canStatus &&
|
||||
Number(record.role || 0) < 100 &&
|
||||
canManageRow(record, perms.enforced);
|
||||
const content = isDeleted ? (
|
||||
<Tag color='red'>{t('已注销')}</Tag>
|
||||
) : (
|
||||
<TableStatusSwitch
|
||||
checked={record.status === 1}
|
||||
aria-label={t('状态')}
|
||||
disabled={!canManage}
|
||||
disabled={!canToggle}
|
||||
onChange={(checked, event) => {
|
||||
event.stopPropagation();
|
||||
showEnableDisableModal(record, checked ? 'enable' : 'disable');
|
||||
@@ -215,6 +231,9 @@ const renderOperations = (
|
||||
showResetPasskeyModal,
|
||||
showResetTwoFAModal,
|
||||
showInvitedUsersModal,
|
||||
showAssignRolesModal,
|
||||
showAddQuotaModal,
|
||||
perms,
|
||||
t,
|
||||
},
|
||||
) => {
|
||||
@@ -224,15 +243,23 @@ const renderOperations = (
|
||||
|
||||
const currentRole = Number(getUserData()?.role || 0);
|
||||
const recordRole = Number(record.role || 0);
|
||||
// 与后端 canManageUserOfRole 一致:非超级管理员只能管理角色低于自己的用户;提升/降级仅超级管理员
|
||||
const canManage =
|
||||
isAdmin() && (currentRole >= 100 || recordRole < currentRole);
|
||||
const canChangeRole = canManage && currentRole >= 100 && recordRole < 100;
|
||||
const manageable = canManageRow(record, perms.enforced);
|
||||
// 提升/降级仅超级管理员;用户管理切到新体系后冻结,改用「分配角色」
|
||||
const canChangeRole =
|
||||
!perms.enforced &&
|
||||
perms.canPromote &&
|
||||
manageable &&
|
||||
currentRole >= 100 &&
|
||||
recordRole < 100;
|
||||
const canEditRow = perms.canEdit && manageable;
|
||||
// 分配平台角色:超级管理员本身不参与角色授权
|
||||
const canAssignRow =
|
||||
perms.canAssignRole && recordRole < 100 && !!showAssignRolesModal;
|
||||
|
||||
// 低频动作全部收进「更多」下拉,操作列稳定为一行三个控件,避免跨行撑高行高
|
||||
const moreMenu = [];
|
||||
// 低频动作收进「更多」下拉;分组之间用分割线
|
||||
const groups = [];
|
||||
if (canChangeRole) {
|
||||
moreMenu.push(
|
||||
groups.push([
|
||||
{
|
||||
key: 'promote',
|
||||
label: t('提升'),
|
||||
@@ -243,51 +270,82 @@ const renderOperations = (
|
||||
label: t('降级'),
|
||||
onClick: () => showDemoteModal(record),
|
||||
},
|
||||
{ type: 'divider' },
|
||||
);
|
||||
]);
|
||||
}
|
||||
moreMenu.push({
|
||||
key: 'invitations',
|
||||
label: t('邀请记录'),
|
||||
onClick: () => showInvitedUsersModal(record),
|
||||
});
|
||||
if (canManage) {
|
||||
moreMenu.push(
|
||||
{ type: 'divider' },
|
||||
{
|
||||
key: 'reset-passkey',
|
||||
label: t('重置 Passkey'),
|
||||
onClick: () => showResetPasskeyModal(record),
|
||||
},
|
||||
{
|
||||
key: 'reset-2fa',
|
||||
label: t('重置 2FA'),
|
||||
onClick: () => showResetTwoFAModal(record),
|
||||
},
|
||||
{ type: 'divider' },
|
||||
groups.push([
|
||||
{
|
||||
key: 'invitations',
|
||||
label: t('邀请记录'),
|
||||
onClick: () => showInvitedUsersModal(record),
|
||||
},
|
||||
]);
|
||||
const resetItems = [];
|
||||
if (perms.canResetPasskey && manageable) {
|
||||
resetItems.push({
|
||||
key: 'reset-passkey',
|
||||
label: t('重置 Passkey'),
|
||||
onClick: () => showResetPasskeyModal(record),
|
||||
});
|
||||
}
|
||||
if (perms.canReset2FA && manageable) {
|
||||
resetItems.push({
|
||||
key: 'reset-2fa',
|
||||
label: t('重置 2FA'),
|
||||
onClick: () => showResetTwoFAModal(record),
|
||||
});
|
||||
}
|
||||
if (resetItems.length) groups.push(resetItems);
|
||||
// 超级管理员不可注销(后端同样拒绝)
|
||||
if (perms.canDelete && manageable && recordRole < 100) {
|
||||
groups.push([
|
||||
{
|
||||
key: 'delete',
|
||||
label: t('注销'),
|
||||
danger: true,
|
||||
onClick: () => showDeleteModal(record),
|
||||
},
|
||||
);
|
||||
]);
|
||||
}
|
||||
const moreMenu = groups.flatMap((group, index) =>
|
||||
index === 0
|
||||
? group
|
||||
: [{ type: 'divider', key: `divider-${index}` }, ...group],
|
||||
);
|
||||
|
||||
return (
|
||||
<TableRowActions items={moreMenu}>
|
||||
{canManage && (
|
||||
{(canEditRow || canAssignRow) && (
|
||||
<>
|
||||
<Button
|
||||
type='link'
|
||||
size='small'
|
||||
onClick={() => {
|
||||
setEditingUser(record);
|
||||
setShowEditUser(true);
|
||||
}}
|
||||
>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
{canEditRow && (
|
||||
<Button
|
||||
type='link'
|
||||
size='small'
|
||||
onClick={() => {
|
||||
setEditingUser(record);
|
||||
setShowEditUser(true);
|
||||
}}
|
||||
>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
)}
|
||||
{canEditRow && (
|
||||
<Button
|
||||
type='link'
|
||||
size='small'
|
||||
onClick={() => showAddQuotaModal(record)}
|
||||
>
|
||||
{t('添加额度')}
|
||||
</Button>
|
||||
)}
|
||||
{canAssignRow && (
|
||||
<Button
|
||||
type='link'
|
||||
size='small'
|
||||
onClick={() => showAssignRolesModal(record)}
|
||||
>
|
||||
{t('分配角色')}
|
||||
</Button>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</TableRowActions>
|
||||
@@ -308,6 +366,9 @@ export const getUsersColumns = ({
|
||||
showResetPasskeyModal,
|
||||
showResetTwoFAModal,
|
||||
showInvitedUsersModal,
|
||||
showAssignRolesModal,
|
||||
showAddQuotaModal,
|
||||
perms,
|
||||
}) => {
|
||||
return [
|
||||
{
|
||||
@@ -332,7 +393,7 @@ export const getUsersColumns = ({
|
||||
title: t('状态'),
|
||||
dataIndex: 'info',
|
||||
render: (text, record, index) =>
|
||||
renderStatistics(text, record, showEnableDisableModal, t),
|
||||
renderStatistics(text, record, showEnableDisableModal, perms, t),
|
||||
},
|
||||
{
|
||||
title: t('剩余额度/总额度'),
|
||||
@@ -363,7 +424,7 @@ export const getUsersColumns = ({
|
||||
title: t('操作'),
|
||||
dataIndex: 'operate',
|
||||
fixed: 'right',
|
||||
width: 135,
|
||||
width: 290,
|
||||
render: (text, record, index) =>
|
||||
renderOperations(text, record, {
|
||||
setEditingUser,
|
||||
@@ -375,6 +436,9 @@ export const getUsersColumns = ({
|
||||
showResetPasskeyModal,
|
||||
showResetTwoFAModal,
|
||||
showInvitedUsersModal,
|
||||
showAssignRolesModal,
|
||||
showAddQuotaModal,
|
||||
perms,
|
||||
t,
|
||||
}),
|
||||
},
|
||||
|
||||
@@ -7,7 +7,7 @@ import { IconSearch } from '@/components/ui/icons';
|
||||
const UsersFilters = ({
|
||||
formInitValues,
|
||||
setFormApi,
|
||||
searchUsers,
|
||||
refresh,
|
||||
loadUsers,
|
||||
activePage,
|
||||
pageSize,
|
||||
@@ -17,8 +17,7 @@ const UsersFilters = ({
|
||||
t,
|
||||
}) => {
|
||||
const { scheduleSearch, submitSearch, cancelPendingSearch } = useFilterSearch(
|
||||
(_, signal) =>
|
||||
searchUsers(Math.max(1, activePage), pageSize, null, null, signal),
|
||||
(_, signal) => refresh(activePage, pageSize, signal),
|
||||
);
|
||||
|
||||
const formApiRef = useRef(null);
|
||||
@@ -35,6 +34,7 @@ const UsersFilters = ({
|
||||
initValues={{
|
||||
...formInitValues,
|
||||
searchGroup: formInitValues.searchGroup || undefined,
|
||||
searchStatus: formInitValues.searchStatus || undefined,
|
||||
}}
|
||||
getFormApi={(api) => {
|
||||
setFormApi(api);
|
||||
@@ -71,6 +71,20 @@ const UsersFilters = ({
|
||||
size='small'
|
||||
/>
|
||||
</div>
|
||||
<div className='console-module-field'>
|
||||
<Form.Select
|
||||
label={t('状态')}
|
||||
field='searchStatus'
|
||||
placeholder={t('全部状态')}
|
||||
optionList={[
|
||||
{ value: 1, label: t('启用') },
|
||||
{ value: 2, label: t('禁用') },
|
||||
]}
|
||||
className='w-full'
|
||||
showClear
|
||||
size='small'
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<ConsoleFilterActions
|
||||
onReset={handleReset}
|
||||
|
||||
@@ -10,6 +10,10 @@ import DeleteUserModal from './modals/DeleteUserModal';
|
||||
import ResetPasskeyModal from './modals/ResetPasskeyModal';
|
||||
import ResetTwoFAModal from './modals/ResetTwoFAModal';
|
||||
import InvitedUsersModal from './modals/InvitedUsersModal';
|
||||
import AssignRolesModal from './modals/AssignRolesModal';
|
||||
import AddUserQuotaModal from './modals/AddUserQuotaModal';
|
||||
import { isAdmin, isRoot } from '../../../helpers';
|
||||
import { usePerm, useAuthzView } from '../../../authz';
|
||||
|
||||
const UsersTable = (usersData) => {
|
||||
const {
|
||||
@@ -25,6 +29,7 @@ const UsersTable = (usersData) => {
|
||||
setEditingUser,
|
||||
setShowEditUser,
|
||||
manageUser,
|
||||
adjustUserQuota,
|
||||
refresh,
|
||||
resetUserPasskey,
|
||||
resetUserTwoFA,
|
||||
@@ -41,6 +46,33 @@ const UsersTable = (usersData) => {
|
||||
const [showResetPasskeyModal, setShowResetPasskeyModal] = useState(false);
|
||||
const [showResetTwoFAModal, setShowResetTwoFAModal] = useState(false);
|
||||
const [showInvitedUsersModal, setShowInvitedUsersModal] = useState(false);
|
||||
const [showAssignRolesModal, setShowAssignRolesModal] = useState(false);
|
||||
const [showAddQuotaModal, setShowAddQuotaModal] = useState(false);
|
||||
|
||||
// 按钮权限:模块已切到新体系按权限点,未切换与原判断一致
|
||||
const canEdit = usePerm('platform.user.edit', isAdmin());
|
||||
const canStatus = usePerm('platform.user.status', isAdmin());
|
||||
const canDelete = usePerm('platform.user.delete', isAdmin());
|
||||
const canPromote = usePerm('platform.user.promote', isRoot());
|
||||
const canResetPasskey = usePerm('platform.user.reset_passkey', isAdmin());
|
||||
const canReset2FA = usePerm('platform.user.reset_2fa', isAdmin());
|
||||
// 分配平台角色:模块切换前仅 root 可用;弹窗要拉取角色列表,须同时持有 platform.authz.role.query
|
||||
const canAssignRoleOp = usePerm('platform.authz.role.assign', isRoot());
|
||||
const canQueryRole = usePerm('platform.authz.role.query', isRoot());
|
||||
// 用户管理模块是否已切到新体系:切换后提升/降级冻结,行级可管理性不再按 users.role 分层
|
||||
const platformView = useAuthzView('platform');
|
||||
const userModule = platformView?.moduleOf?.['platform.user.edit'];
|
||||
const enforced = !!userModule && platformView.enforcedSet.has(userModule);
|
||||
const perms = {
|
||||
canEdit,
|
||||
canStatus,
|
||||
canDelete,
|
||||
canPromote,
|
||||
canResetPasskey,
|
||||
canReset2FA,
|
||||
canAssignRole: canAssignRoleOp && canQueryRole,
|
||||
enforced,
|
||||
};
|
||||
|
||||
// Modal handlers
|
||||
const showPromoteUserModal = (user) => {
|
||||
@@ -79,6 +111,16 @@ const UsersTable = (usersData) => {
|
||||
setShowInvitedUsersModal(true);
|
||||
};
|
||||
|
||||
const showAssignRolesUserModal = (user) => {
|
||||
setModalUser(user);
|
||||
setShowAssignRolesModal(true);
|
||||
};
|
||||
|
||||
const showAddQuotaUserModal = (user) => {
|
||||
setModalUser(user);
|
||||
setShowAddQuotaModal(true);
|
||||
};
|
||||
|
||||
// Modal confirm handlers
|
||||
const handlePromoteConfirm = () => {
|
||||
manageUser(modalUser.id, 'promote', modalUser);
|
||||
@@ -90,6 +132,7 @@ const UsersTable = (usersData) => {
|
||||
setShowDemoteModal(false);
|
||||
};
|
||||
|
||||
// 状态 Switch 受控于 record.status:请求失败时 manageUser 已提示原因,列表保持原状态
|
||||
const handleEnableDisableConfirm = () => {
|
||||
manageUser(modalUser.id, enableDisableAction, modalUser);
|
||||
setShowEnableDisableModal(false);
|
||||
@@ -117,6 +160,9 @@ const UsersTable = (usersData) => {
|
||||
showResetPasskeyModal: showResetPasskeyUserModal,
|
||||
showResetTwoFAModal: showResetTwoFAUserModal,
|
||||
showInvitedUsersModal: showInvitedUsersUserModal,
|
||||
showAssignRolesModal: showAssignRolesUserModal,
|
||||
showAddQuotaModal: showAddQuotaUserModal,
|
||||
perms,
|
||||
});
|
||||
|
||||
// Handle compact mode by removing fixed positioning
|
||||
@@ -214,6 +260,25 @@ const UsersTable = (usersData) => {
|
||||
user={modalUser}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<AssignRolesModal
|
||||
visible={showAssignRolesModal}
|
||||
onCancel={() => setShowAssignRolesModal(false)}
|
||||
user={modalUser}
|
||||
t={t}
|
||||
/>
|
||||
|
||||
<AddUserQuotaModal
|
||||
visible={showAddQuotaModal}
|
||||
onCancel={() => setShowAddQuotaModal(false)}
|
||||
onSubmit={adjustUserQuota}
|
||||
user={
|
||||
modalUser
|
||||
? users.find((u) => u.id === modalUser.id) || modalUser
|
||||
: null
|
||||
}
|
||||
t={t}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -27,7 +27,6 @@ const UsersPage = () => {
|
||||
// Form state
|
||||
formInitValues,
|
||||
setFormApi,
|
||||
searchUsers,
|
||||
loadUsers,
|
||||
activePage,
|
||||
pageSize,
|
||||
@@ -64,7 +63,7 @@ const UsersPage = () => {
|
||||
<UsersFilters
|
||||
formInitValues={formInitValues}
|
||||
setFormApi={setFormApi}
|
||||
searchUsers={searchUsers}
|
||||
refresh={refresh}
|
||||
loadUsers={loadUsers}
|
||||
activePage={activePage}
|
||||
pageSize={pageSize}
|
||||
|
||||
@@ -1,7 +1,15 @@
|
||||
import React, { useState, useRef } from 'react';
|
||||
import { API, showError, showSuccess } from '../../../../helpers';
|
||||
import { useIsMobile } from '../../../../hooks/common/useIsMobile';
|
||||
import { Button, SideSheet, Spin, Form, Row, Col } from '@/components/ui';
|
||||
import {
|
||||
Button,
|
||||
SideSheet,
|
||||
Spin,
|
||||
Form,
|
||||
Row,
|
||||
Col,
|
||||
Typography,
|
||||
} from '@/components/ui';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
const AddUserModal = (props) => {
|
||||
@@ -70,6 +78,19 @@ const AddUserModal = (props) => {
|
||||
}}
|
||||
>
|
||||
<Row gutter={12}>
|
||||
<Col span={24}>
|
||||
{/* 账号类型用语统一为"个人账号"(PRD AC52);平台角色不在新建表单中选择(AC57) */}
|
||||
<Form.Slot label={t('账号类型')}>
|
||||
<Typography.Text>{t('个人账号')}</Typography.Text>
|
||||
<div>
|
||||
<Typography.Text type='secondary' className='text-xs'>
|
||||
{t(
|
||||
'创建后为启用状态;平台角色请在列表操作列通过「分配角色」设置',
|
||||
)}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
</Form.Slot>
|
||||
</Col>
|
||||
<Col span={24}>
|
||||
<Form.Input
|
||||
field='username'
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Typography } from 'antd';
|
||||
import { ConsoleModal } from '../../../console/ConsolePrimitives';
|
||||
import QuotaInput from '../../../common/ui/QuotaInput';
|
||||
import { renderQuota } from '../../../../helpers';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
// 添加额度弹窗(PRD §4.1、AC59):输入调整量(可正可负,不能为 0),实时展示
|
||||
// 「当前剩余额度 + 调整额度 = 新剩余额度」;新剩余额度不能小于 0。
|
||||
// QuotaInput 的 value/onChange 始终是内部额度单位,金额换算由它完成。
|
||||
const AddUserQuotaModal = ({ visible, onCancel, onSubmit, user, t }) => {
|
||||
const [delta, setDelta] = useState(null);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (visible) setDelta(null);
|
||||
}, [visible, user?.id]);
|
||||
|
||||
const current = parseInt(user?.quota) || 0;
|
||||
const amount = Number.isFinite(delta) ? delta : 0;
|
||||
const next = current + amount;
|
||||
const error =
|
||||
delta === null
|
||||
? ''
|
||||
: amount === 0
|
||||
? t('调整额度不能为 0')
|
||||
: next < 0
|
||||
? t('调整后的剩余额度不能小于 0')
|
||||
: '';
|
||||
const canSubmit = delta !== null && !error;
|
||||
|
||||
const handleOk = async () => {
|
||||
if (!canSubmit || submitting || !user?.id) return;
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const ok = await onSubmit(user.id, amount);
|
||||
if (ok) onCancel();
|
||||
} finally {
|
||||
setSubmitting(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<ConsoleModal
|
||||
title={`${t('添加额度')} - ${user?.display_name || user?.username || ''}`}
|
||||
open={visible}
|
||||
onOk={handleOk}
|
||||
onCancel={onCancel}
|
||||
okText={t('确定')}
|
||||
cancelText={t('取消')}
|
||||
confirmLoading={submitting}
|
||||
okButtonProps={{ disabled: !canSubmit }}
|
||||
centered
|
||||
destroyOnHidden
|
||||
>
|
||||
<div className='flex flex-col gap-3'>
|
||||
<div>
|
||||
<div className='mb-2'>
|
||||
<Text>{t('调整额度(正数增加,负数减少)')}</Text>
|
||||
</div>
|
||||
<QuotaInput
|
||||
value={delta}
|
||||
onChange={setDelta}
|
||||
placeholder={t('需要添加的金额(支持负数)')}
|
||||
style={{ width: '100%' }}
|
||||
status={error ? 'error' : undefined}
|
||||
aria-label={t('调整额度')}
|
||||
/>
|
||||
{error && (
|
||||
<div className='mt-1'>
|
||||
<Text type='danger' className='text-xs'>
|
||||
{error}
|
||||
</Text>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<Text type='secondary' className='tabular-nums'>
|
||||
{t(
|
||||
'当前剩余额度 {{current}} + 调整额度 {{delta}} = 新剩余额度 {{next}}',
|
||||
{
|
||||
current: renderQuota(current),
|
||||
delta: renderQuota(amount),
|
||||
next: renderQuota(next),
|
||||
},
|
||||
)}
|
||||
</Text>
|
||||
</div>
|
||||
</ConsoleModal>
|
||||
);
|
||||
};
|
||||
|
||||
export default AddUserQuotaModal;
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Select, Spin, Tag, Typography } from 'antd';
|
||||
import { ConsoleModal } from '../../../console/ConsolePrimitives';
|
||||
import { API, showError, showSuccess } from '../../../../helpers';
|
||||
|
||||
// 分配平台角色弹窗:读写 /api/user/:id/roles(整体替换)。
|
||||
// 角色列表来自 /api/authz/platform/roles,停用的角色仍可展示但标注"停用"。
|
||||
const AssignRolesModal = ({ visible, onCancel, user, t }) => {
|
||||
const [roles, setRoles] = useState([]);
|
||||
const [selected, setSelected] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [saving, setSaving] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (!visible || !user?.id) return;
|
||||
let alive = true;
|
||||
const load = async () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
const [rolesRes, mineRes] = await Promise.all([
|
||||
API.get('/api/authz/platform/roles'),
|
||||
API.get(`/api/user/${user.id}/roles`),
|
||||
]);
|
||||
if (!alive) return;
|
||||
if (rolesRes.data.success) {
|
||||
setRoles(rolesRes.data.data || []);
|
||||
} else {
|
||||
showError(rolesRes.data.message);
|
||||
}
|
||||
if (mineRes.data.success) {
|
||||
setSelected(mineRes.data.data || []);
|
||||
} else {
|
||||
showError(mineRes.data.message);
|
||||
}
|
||||
} catch (err) {
|
||||
showError(err);
|
||||
} finally {
|
||||
if (alive) setLoading(false);
|
||||
}
|
||||
};
|
||||
load();
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [visible, user?.id]);
|
||||
|
||||
const handleOk = async () => {
|
||||
if (!user?.id || saving) return;
|
||||
setSaving(true);
|
||||
try {
|
||||
const res = await API.put(`/api/user/${user.id}/roles`, {
|
||||
ids: selected,
|
||||
});
|
||||
if (res.data.success) {
|
||||
showSuccess(t('角色已更新'));
|
||||
onCancel();
|
||||
} else {
|
||||
showError(res.data.message);
|
||||
}
|
||||
} catch (err) {
|
||||
showError(err);
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<ConsoleModal
|
||||
title={`${t('分配角色')} - ${user?.display_name || user?.username || ''}`}
|
||||
open={visible}
|
||||
onOk={handleOk}
|
||||
onCancel={onCancel}
|
||||
confirmLoading={saving}
|
||||
okButtonProps={{ disabled: loading }}
|
||||
okText={t('保存')}
|
||||
cancelText={t('取消')}
|
||||
centered
|
||||
width='min(520px, calc(100vw - 32px))'
|
||||
>
|
||||
<Spin spinning={loading}>
|
||||
<Typography.Text type='secondary' className='text-xs'>
|
||||
{t('为该用户分配平台角色,保存后整体替换原有角色。')}
|
||||
</Typography.Text>
|
||||
<Select
|
||||
className='mt-3'
|
||||
style={{ width: '100%' }}
|
||||
mode='multiple'
|
||||
value={selected}
|
||||
onChange={setSelected}
|
||||
placeholder={t('选择平台角色')}
|
||||
aria-label={t('选择平台角色')}
|
||||
options={roles.map((r) => ({
|
||||
value: r.id,
|
||||
label: (
|
||||
<span className='inline-flex items-center gap-1'>
|
||||
<span>{r.name}</span>
|
||||
{r.status !== 1 ? (
|
||||
<Tag variant='filled'>{t('停用')}</Tag>
|
||||
) : null}
|
||||
</span>
|
||||
),
|
||||
searchText: `${r.name} ${r.code}`,
|
||||
}))}
|
||||
showSearch={{ optionFilterProp: 'searchText' }}
|
||||
notFoundContent={t('暂无角色')}
|
||||
/>
|
||||
</Spin>
|
||||
</ConsoleModal>
|
||||
);
|
||||
};
|
||||
|
||||
export default AssignRolesModal;
|
||||
@@ -30,6 +30,7 @@ const DeleteUserModal = ({
|
||||
onCancel={onCancel}
|
||||
onOk={handleConfirm}
|
||||
type='danger'
|
||||
okType='danger'
|
||||
>
|
||||
{t('相当于删除用户,此修改将不可逆')}
|
||||
</TableActionModal>
|
||||
|
||||
@@ -5,7 +5,6 @@ import { API, showError, showSuccess, renderQuota } from '../../../../helpers';
|
||||
import { useIsMobile } from '../../../../hooks/common/useIsMobile';
|
||||
import {
|
||||
Button,
|
||||
Modal,
|
||||
SideSheet,
|
||||
Spin,
|
||||
Typography,
|
||||
@@ -15,27 +14,28 @@ import {
|
||||
Row,
|
||||
Col,
|
||||
} from '@/components/ui';
|
||||
import QuotaInput, { FormQuotaInput } from '../../../common/ui/QuotaInput';
|
||||
import { FormQuotaInput } from '../../../common/ui/QuotaInput';
|
||||
import {
|
||||
User as ActionUser,
|
||||
Link as ActionLink,
|
||||
Users as ActionUsers,
|
||||
Plus as ActionPlus,
|
||||
} from '@/components/common/icons/ActionIcons';
|
||||
|
||||
import { toGroupList } from '@/helpers/groupList';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
// User.Group is a single lookup key. Preserve historical keys containing commas.
|
||||
const userGroupKey = (group) =>
|
||||
Array.isArray(group) ? group.join(',') : group;
|
||||
|
||||
const EditUserModal = (props) => {
|
||||
const { t } = useTranslation();
|
||||
const userId = props.editingUser.id;
|
||||
const [loading, setLoading] = useState(true);
|
||||
// 剩余额度只读展示(PRD AC56):调整额度走列表操作列的「添加额度」(按调整量累加)
|
||||
const [loadedQuota, setLoadedQuota] = useState(0);
|
||||
const [loadedUserId, setLoadedUserId] = useState(null);
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const pending = useRef(false);
|
||||
const [addQuotaModalOpen, setIsModalOpen] = useState(false);
|
||||
const [addQuotaLocal, setAddQuotaLocal] = useState('');
|
||||
const isMobile = useIsMobile();
|
||||
const [groupOptions, setGroupOptions] = useState([]);
|
||||
const [levelOptions, setLevelOptions] = useState([]);
|
||||
@@ -63,7 +63,9 @@ const EditUserModal = (props) => {
|
||||
const fetchGroups = async () => {
|
||||
try {
|
||||
let res = await API.get(`/api/group/`);
|
||||
setGroupOptions(res.data.data.map((g) => ({ label: g, value: g })));
|
||||
if (res.data.success && Array.isArray(res.data.data)) {
|
||||
setGroupOptions(res.data.data.map((g) => ({ label: g, value: g })));
|
||||
}
|
||||
} catch (e) {
|
||||
showError(e.message);
|
||||
}
|
||||
@@ -95,8 +97,6 @@ const EditUserModal = (props) => {
|
||||
|
||||
const handleCancel = () => {
|
||||
if (pending.current) return;
|
||||
setIsModalOpen(false);
|
||||
setAddQuotaLocal('');
|
||||
props.handleClose();
|
||||
};
|
||||
|
||||
@@ -112,11 +112,14 @@ const EditUserModal = (props) => {
|
||||
const { data: response } = await API.get(url);
|
||||
if (!isCurrent()) return;
|
||||
if (response.success) {
|
||||
setLoadedQuota(Number(response.data.quota) || 0);
|
||||
formApiRef.current?.setValues({
|
||||
...getInitValues(),
|
||||
...response.data,
|
||||
...(userId && {
|
||||
group: toGroupList(response.data.group ?? 'default'),
|
||||
group: [userGroupKey(response.data.group) ?? 'default'].filter(
|
||||
Boolean,
|
||||
),
|
||||
}),
|
||||
password: '',
|
||||
});
|
||||
@@ -147,13 +150,13 @@ const EditUserModal = (props) => {
|
||||
setSubmitting(true);
|
||||
try {
|
||||
const payload = { ...values };
|
||||
if (typeof payload.quota === 'string')
|
||||
payload.quota = parseInt(payload.quota) || 0;
|
||||
// 额度通过列表按增量调整;编辑资料时省略该字段,保留服务端当前余额。
|
||||
delete payload.quota;
|
||||
if (typeof payload.gift_quota === 'string')
|
||||
payload.gift_quota = parseInt(payload.gift_quota) || 0;
|
||||
if (userId) {
|
||||
payload.id = parseInt(userId);
|
||||
payload.group = toGroupList(values.group).join(',');
|
||||
payload.group = userGroupKey(values.group);
|
||||
}
|
||||
const url = userId ? '/api/user/' : '/api/user/self';
|
||||
const { data } = await API.put(url, payload);
|
||||
@@ -172,13 +175,6 @@ const EditUserModal = (props) => {
|
||||
}
|
||||
};
|
||||
|
||||
/* --------------------- quota helper -------------------- */
|
||||
const addLocalQuota = () => {
|
||||
const current = parseInt(formApiRef.current?.getValue('quota') || 0);
|
||||
const delta = parseInt(addQuotaLocal) || 0;
|
||||
formApiRef.current?.setValue('quota', current + delta);
|
||||
};
|
||||
|
||||
/* --------------------------- UI --------------------------- */
|
||||
return (
|
||||
<>
|
||||
@@ -298,6 +294,7 @@ const EditUserModal = (props) => {
|
||||
placeholder={t('请选择分组')}
|
||||
optionList={groupOptions}
|
||||
allowAdditions
|
||||
maxCount={1}
|
||||
search
|
||||
rules={[{ required: true, message: t('请选择分组') }]}
|
||||
/>
|
||||
@@ -318,12 +315,16 @@ const EditUserModal = (props) => {
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={12}>
|
||||
<FormQuotaInput
|
||||
field='quota'
|
||||
label={t('剩余额度')}
|
||||
rules={[{ required: true, message: t('请输入额度') }]}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
<Form.Slot label={t('剩余额度')}>
|
||||
<Text className='tabular-nums'>
|
||||
{renderQuota(loadedQuota)}
|
||||
</Text>
|
||||
<div>
|
||||
<Text type='secondary' className='text-xs'>
|
||||
{t('只读;调整请使用列表操作列的「添加额度」')}
|
||||
</Text>
|
||||
</div>
|
||||
</Form.Slot>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={12}>
|
||||
@@ -336,16 +337,6 @@ const EditUserModal = (props) => {
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
</Col>
|
||||
|
||||
<Col span={24}>
|
||||
<Form.Slot label={t('添加额度')}>
|
||||
<Button
|
||||
icon={<ActionPlus size={16} />}
|
||||
aria-label={t('添加额度')}
|
||||
onClick={() => setIsModalOpen(true)}
|
||||
/>
|
||||
</Form.Slot>
|
||||
</Col>
|
||||
</Row>
|
||||
</Card>
|
||||
)}
|
||||
@@ -395,42 +386,6 @@ const EditUserModal = (props) => {
|
||||
)}
|
||||
</Form>
|
||||
</SideSheet>
|
||||
|
||||
{/* 添加额度模态框 */}
|
||||
<Modal
|
||||
centered
|
||||
visible={addQuotaModalOpen}
|
||||
onOk={() => {
|
||||
addLocalQuota();
|
||||
setIsModalOpen(false);
|
||||
}}
|
||||
onCancel={() => setIsModalOpen(false)}
|
||||
closable={null}
|
||||
title={
|
||||
<div className='flex items-center'>
|
||||
<ActionPlus size={16} className='mr-2' />
|
||||
{t('添加额度')}
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className='mb-4'>
|
||||
{(() => {
|
||||
const current = formApiRef.current?.getValue('quota') || 0;
|
||||
return (
|
||||
<Text type='secondary' className='block mb-2'>
|
||||
{`${t('新额度:')}${renderQuota(current)} + ${renderQuota(addQuotaLocal || 0)} = ${renderQuota(current + parseInt(addQuotaLocal || 0))}`}
|
||||
</Text>
|
||||
);
|
||||
})()}
|
||||
</div>
|
||||
<QuotaInput
|
||||
placeholder={t('需要添加的金额(支持负数)')}
|
||||
value={addQuotaLocal}
|
||||
onChange={setAddQuotaLocal}
|
||||
style={{ width: '100%' }}
|
||||
showClear
|
||||
/>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user