61294dc597
来源:luoguang/monkey-ai weiyuan@bfdfb339 的 web/(经 sync/main-weiyuan-web-bfdfb339 同步)
同步基准:总仓库 a2ca13cb = 本仓库初始导入 d8f3aee2
冲突处理原则:保留 ui-optimization 的 UI(样式/结构/组件),嫁接 weiyuan 的功能逻辑。
- i18n:按键三方合并;ours 的「令牌→密钥」改名键上移植 theirs 的术语修订
- task-logs / OrgLogs:ours 已手工移植同一功能(6ad95e2),保留 ours
- 删除:OrgCreate(theirs 下线 /org/create)、旧 image 组件与 VideoRegenerateModal(theirs 体验中心重写)、
OrgAvatarSection / PricingBentoPage / CommissionConsole(ours 重构中已移除)
- 测试:users-pagination 的 i18next mock 补 t();theirs 新增文件补 license header
1623 lines
56 KiB
React
1623 lines
56 KiB
React
/*
|
||
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 TableEmpty from '../../components/common/table/TableEmpty';
|
||
import TableToolbar from '../../components/common/table/TableToolbar';
|
||
import {
|
||
ConsoleCard,
|
||
ConsoleSearchBar,
|
||
} from '../../components/console/ConsolePrimitives';
|
||
import { ConsolePageActions } from '../../components/console/ConsolePageContainer';
|
||
import React, { useEffect, useState, useCallback, useRef } from 'react';
|
||
import { useTranslation } from 'react-i18next';
|
||
import { useNavigate } from 'react-router-dom';
|
||
import { Plus, Search, ExternalLink, BarChart3, Bell } from 'lucide-react';
|
||
import {
|
||
Table,
|
||
Button,
|
||
Input,
|
||
Tag,
|
||
Modal,
|
||
InputNumber,
|
||
Toast,
|
||
TextArea,
|
||
Select,
|
||
Switch,
|
||
Radio,
|
||
} from '@/components/ui';
|
||
import { API } from '../../helpers/api';
|
||
import { showError, isAdmin, isRoot } from '../../helpers';
|
||
import { renderQuota } from '../../helpers/render';
|
||
import QuotaInput from '../../components/common/ui/QuotaInput';
|
||
import OrgCredentialResult from '../../components/auth/OrgCredentialResult';
|
||
import { validateOrgOwnerLoginName } from '../../helpers/orgLoginName';
|
||
import OrgAlertSettingsModal from './OrgAlertSettingsModal';
|
||
import {
|
||
CLOUD_BRAIN_ORG_FEATURE_KEYS,
|
||
CLOUD_BRAIN_UI_ENABLED,
|
||
} from '../../config/cloudBrainUi';
|
||
|
||
// 企业功能开关(套餐能力,与后端 ValidOrgFeatureKeys 对齐,§28.8)
|
||
const ORG_FEATURE_KEYS = [
|
||
{ key: 'cloud_brain', label: '云端大脑(Beta)' },
|
||
{ key: 'expert', label: '专家能力' },
|
||
{ key: 'skill_market', label: 'Skill 市场' },
|
||
{ key: 'knowledge_base', label: '企业知识库' },
|
||
{ key: 'connector', label: '企业连接器' },
|
||
{ key: 'enterprise_knowledge', label: '企业知识能力' },
|
||
{ key: 'agent_effectiveness', label: 'Agent 效能分析' },
|
||
{ key: 'budget', label: '预算配置' },
|
||
{ key: 'budget_enforcement', label: '预算实时拦截' },
|
||
{ key: 'department_guardrail', label: '部门预算护栏(默认开启)' },
|
||
{ key: 'dept', label: '部门管理' },
|
||
{ key: 'project', label: '项目管理' },
|
||
{ key: 'approval', label: '审批中心' },
|
||
{ key: 'analytics', label: '用量分析' },
|
||
{ key: 'quality_monitor', label: '调用质量' },
|
||
{ key: 'enterprise_login', label: '企业登录入口' },
|
||
{ key: 'org_only_mode', label: '仅企业资源模式' },
|
||
{ key: 'content_moderation', label: '内容审核' },
|
||
{ key: 'no_training', label: '数据不用于训练' },
|
||
{ key: 'prompt_archive', label: '提示词采集' },
|
||
{ key: 'data_security', label: '数据安全自助配置' },
|
||
];
|
||
|
||
const VISIBLE_ORG_FEATURE_KEYS = CLOUD_BRAIN_UI_ENABLED
|
||
? ORG_FEATURE_KEYS
|
||
: ORG_FEATURE_KEYS.filter(
|
||
({ key }) => !CLOUD_BRAIN_ORG_FEATURE_KEYS.has(key),
|
||
);
|
||
|
||
import {
|
||
ConsoleFilterField,
|
||
ConsoleFilterActions,
|
||
} from '../../components/console/ConsoleModuleFilters';
|
||
|
||
const AdminOrganizations = () => {
|
||
const { t } = useTranslation();
|
||
const navigate = useNavigate();
|
||
const [orgs, setOrgs] = useState([]);
|
||
const [total, setTotal] = useState(0);
|
||
const [loading, setLoading] = useState(false);
|
||
const [page, setPage] = useState(1);
|
||
const [pageSize, setPageSize] = useState(20);
|
||
const [keyword, setKeyword] = useState('');
|
||
const [searchKeyword, setSearchKeyword] = useState('');
|
||
const [queryVersion, setQueryVersion] = useState(0);
|
||
const [quotaModalVisible, setQuotaModalVisible] = useState(false);
|
||
const [quotaOrgId, setQuotaOrgId] = useState(null);
|
||
const [quotaAmount, setQuotaAmount] = useState(0);
|
||
const [createModalVisible, setCreateModalVisible] = useState(false);
|
||
const [createLoading, setCreateLoading] = useState(false);
|
||
const [createForm, setCreateForm] = useState({
|
||
name: '',
|
||
owner_mode: 'managed',
|
||
owner_id: '',
|
||
owner_login_name: '',
|
||
owner_display_name: '',
|
||
quota: 0,
|
||
group: 'default',
|
||
groups: ['default'],
|
||
level: '',
|
||
max_members: 50,
|
||
max_tokens: 100,
|
||
cloud_brain_concurrency: 12,
|
||
sales_rep: '',
|
||
});
|
||
const [createCredentialResult, setCreateCredentialResult] = useState(null);
|
||
const [editModalVisible, setEditModalVisible] = useState(false);
|
||
const [editLoading, setEditLoading] = useState(false);
|
||
const [editForm, setEditForm] = useState({
|
||
id: null,
|
||
name: '',
|
||
group: '',
|
||
groups: [],
|
||
level: '',
|
||
max_members: 50,
|
||
max_tokens: 100,
|
||
cloud_brain_concurrency: 12,
|
||
default_member_quota: 0,
|
||
description: '',
|
||
contact_name: '',
|
||
contact_phone: '',
|
||
contact_email: '',
|
||
sales_rep: '',
|
||
});
|
||
const [groupOptions, setGroupOptions] = useState([]);
|
||
const [levelOptions, setLevelOptions] = useState([]);
|
||
const [featureModalOrg, setFeatureModalOrg] = useState(null);
|
||
const [featureFlags, setFeatureFlags] = useState({});
|
||
const [effectUsageVisible, setEffectUsageVisible] = useState(false);
|
||
const [effectUsage, setEffectUsage] = useState([]);
|
||
// 多维筛选 + 服务端排序(分页在服务端,排序/筛选必须一并下推,前端本地排序只会排当前页)
|
||
const [statusFilter, setStatusFilter] = useState(undefined);
|
||
const [levelFilter, setLevelFilter] = useState(undefined);
|
||
const [salesRepFilter, setSalesRepFilter] = useState(undefined);
|
||
// 用户ID筛选:输入框值与已应用值分离,回车才下推请求(与关键字框同一交互)
|
||
const [userIdInput, setUserIdInput] = useState('');
|
||
const [userIdFilter, setUserIdFilter] = useState('');
|
||
const [salesRepOptions, setSalesRepOptions] = useState([]);
|
||
const [sortBy, setSortBy] = useState('');
|
||
const [sortOrder, setSortOrder] = useState('');
|
||
// 企业预警通知(方案 11 号 §8):设置弹窗 + 行内屏蔽开关,均 root-only。
|
||
// 屏蔽状态的存储是 org_alert_setting.excluded_org_ids 这条 option(与设置弹窗同源),
|
||
// 行内切换走专用 CAS 接口防两个管理员并发覆盖。
|
||
const [alertSettingsVisible, setAlertSettingsVisible] = useState(false);
|
||
const [alertExcludedIds, setAlertExcludedIds] = useState(() => new Set());
|
||
const [alertToggleLoading, setAlertToggleLoading] = useState(null);
|
||
|
||
const fetchAlertExcluded = useCallback(async () => {
|
||
if (!isRoot()) return;
|
||
try {
|
||
const res = await API.get('/api/option/');
|
||
if (res?.data?.success) {
|
||
const row = (res.data.data || []).find(
|
||
(o) => o.key === 'org_alert_setting.excluded_org_ids',
|
||
);
|
||
setAlertExcludedIds(
|
||
new Set(
|
||
(row?.value || '')
|
||
.split(',')
|
||
.map((s) => parseInt(s.trim(), 10))
|
||
.filter((n) => Number.isFinite(n) && n > 0),
|
||
),
|
||
);
|
||
}
|
||
} catch (err) {
|
||
// 静默:屏蔽状态加载失败不阻塞页面,仅开关反显缺失
|
||
}
|
||
}, []);
|
||
|
||
const toggleAlertExclude = async (record) => {
|
||
const excluded = !alertExcludedIds.has(record.id);
|
||
setAlertToggleLoading(record.id);
|
||
try {
|
||
const res = await API.post('/api/org_alert/toggle_exclude', {
|
||
org_id: record.id,
|
||
excluded,
|
||
});
|
||
if (res.data?.success) {
|
||
Toast.success(
|
||
excluded ? t('已屏蔽该企业的预警') : t('已恢复该企业的预警'),
|
||
);
|
||
setAlertExcludedIds((prev) => {
|
||
const next = new Set(prev);
|
||
if (excluded) {
|
||
next.add(record.id);
|
||
} else {
|
||
next.delete(record.id);
|
||
}
|
||
return next;
|
||
});
|
||
} else {
|
||
showError(res.data?.message || t('操作失败'));
|
||
}
|
||
} catch (err) {
|
||
// 传对象而非 err.message,否则 showError 走不到中文翻译分支
|
||
showError(err);
|
||
} finally {
|
||
setAlertToggleLoading(null);
|
||
}
|
||
};
|
||
|
||
const openEffectUsage = async () => {
|
||
try {
|
||
const response = await API.get(
|
||
'/api/admin/organizations/effectiveness/usage',
|
||
);
|
||
if (!response.data?.success) {
|
||
showError(response.data?.message || t('企业使用统计加载失败'));
|
||
return;
|
||
}
|
||
setEffectUsage(response.data.data || []);
|
||
setEffectUsageVisible(true);
|
||
} catch (error) {
|
||
showError(error.message);
|
||
}
|
||
};
|
||
|
||
const fetchGroups = useCallback(async () => {
|
||
try {
|
||
const res = await API.get('/api/group/');
|
||
if (res?.data?.data) {
|
||
setGroupOptions(res.data.data.map((g) => ({ label: g, value: g })));
|
||
}
|
||
} catch (err) {
|
||
// 静默处理,分组加载失败不阻塞页面
|
||
}
|
||
}, []);
|
||
|
||
const fetchLevels = useCallback(async () => {
|
||
try {
|
||
const res = await API.get('/api/group/enterprise_levels');
|
||
const levels = res?.data?.data?.levels || [];
|
||
setLevelOptions(levels.map((l) => ({ label: l, value: l })));
|
||
} catch (err) {
|
||
// 静默处理,等级加载失败不阻塞页面
|
||
}
|
||
}, []);
|
||
|
||
const fetchSalesReps = useCallback(async () => {
|
||
try {
|
||
const res = await API.get('/api/admin/organizations/meta/sales-reps');
|
||
if (res?.data?.success) {
|
||
setSalesRepOptions(
|
||
(res.data.data || []).map((name) => ({ label: name, value: name })),
|
||
);
|
||
}
|
||
} catch (err) {
|
||
// 静默处理,商务人员选项加载失败不阻塞页面
|
||
}
|
||
}, []);
|
||
|
||
// 解析企业可用分组:兼容后端返回的 JSON 字符串 / 数组;为空时回退为 [group]
|
||
const parseOrgGroups = (record) => {
|
||
if (Array.isArray(record?.groups)) return record.groups;
|
||
if (typeof record?.groups === 'string' && record.groups.trim()) {
|
||
try {
|
||
const arr = JSON.parse(record.groups);
|
||
if (Array.isArray(arr) && arr.length) return arr;
|
||
} catch (e) {
|
||
// 解析失败回退
|
||
}
|
||
}
|
||
return record?.group ? [record.group] : [];
|
||
};
|
||
|
||
// 默认分组的可选项来自"已选可用分组"
|
||
const buildDefaultOptions = (groups) =>
|
||
(groups || []).map((g) => ({ label: g, value: g }));
|
||
|
||
const resetCreateForm = () => {
|
||
setCreateCredentialResult(null);
|
||
setCreateForm({
|
||
name: '',
|
||
owner_mode: 'managed',
|
||
owner_id: '',
|
||
owner_login_name: '',
|
||
owner_display_name: '',
|
||
quota: 0,
|
||
group: 'default',
|
||
groups: ['default'],
|
||
level: '',
|
||
max_members: 50,
|
||
max_tokens: 100,
|
||
cloud_brain_concurrency: 12,
|
||
sales_rep: '',
|
||
});
|
||
};
|
||
|
||
// 筛选/排序可高频连续触发请求,用递增序号丢弃过期响应,防止慢网下旧结果覆盖新筛选
|
||
const fetchSeqRef = useRef(0);
|
||
const fetchOrgs = useCallback(async () => {
|
||
const seq = ++fetchSeqRef.current;
|
||
setLoading(true);
|
||
try {
|
||
const params = { p: page, page_size: pageSize };
|
||
if (searchKeyword) params.keyword = searchKeyword;
|
||
if (statusFilter != null) params.status = statusFilter;
|
||
if (levelFilter) params.level = levelFilter;
|
||
if (salesRepFilter) params.sales_rep = salesRepFilter;
|
||
if (userIdFilter) params.user_id = userIdFilter;
|
||
if (sortBy) {
|
||
params.sort_by = sortBy;
|
||
params.sort_order = sortOrder || 'desc';
|
||
}
|
||
const res = await API.get('/api/admin/organizations/', { params });
|
||
if (seq !== fetchSeqRef.current) return;
|
||
if (res.data.success) {
|
||
setOrgs(res.data.data?.items || []);
|
||
setTotal(res.data.data?.total || 0);
|
||
} else {
|
||
showError(res.data.message || t('查询失败'));
|
||
}
|
||
} catch (err) {
|
||
if (seq === fetchSeqRef.current) showError(err.message);
|
||
} finally {
|
||
if (seq === fetchSeqRef.current) setLoading(false);
|
||
}
|
||
}, [
|
||
page,
|
||
pageSize,
|
||
searchKeyword,
|
||
statusFilter,
|
||
levelFilter,
|
||
salesRepFilter,
|
||
userIdFilter,
|
||
sortBy,
|
||
sortOrder,
|
||
t,
|
||
]);
|
||
|
||
useEffect(() => {
|
||
fetchOrgs();
|
||
}, [fetchOrgs, queryVersion]);
|
||
|
||
useEffect(() => {
|
||
fetchGroups();
|
||
fetchLevels();
|
||
fetchSalesReps();
|
||
fetchAlertExcluded();
|
||
}, [fetchGroups, fetchLevels, fetchSalesReps, fetchAlertExcluded]);
|
||
|
||
// 筛选变化统一回到第 1 页,避免停留在筛选后不存在的页码
|
||
const applyFilter = (setter) => (value) => {
|
||
setter(value);
|
||
setPage(1);
|
||
};
|
||
|
||
const handleSearch = () => {
|
||
setPage(1);
|
||
setSearchKeyword(keyword.trim());
|
||
setUserIdFilter(userIdInput);
|
||
setQueryVersion((version) => version + 1);
|
||
};
|
||
|
||
const resetFilters = () => {
|
||
setQueryVersion((version) => version + 1);
|
||
setKeyword('');
|
||
setSearchKeyword('');
|
||
setStatusFilter(undefined);
|
||
setLevelFilter(undefined);
|
||
setSalesRepFilter(undefined);
|
||
setUserIdInput('');
|
||
setUserIdFilter('');
|
||
setSortBy('');
|
||
setSortOrder('');
|
||
setPage(1);
|
||
};
|
||
|
||
// 服务端排序:列头点击 → 下推 sort_by/sort_order 重新拉取
|
||
const sortOrderFor = (key) =>
|
||
sortBy === key ? (sortOrder === 'asc' ? 'ascend' : 'descend') : null;
|
||
|
||
const handleTableChange = ({ sorter }) => {
|
||
// Ant Design clears both the field and order when sorting is cancelled.
|
||
if (!sorter || (sorter.sortOrder && !sorter.dataIndex)) return;
|
||
const nextBy = sorter.sortOrder ? sorter.dataIndex : '';
|
||
const nextOrder = sorter.sortOrder
|
||
? sorter.sortOrder === 'ascend'
|
||
? 'asc'
|
||
: 'desc'
|
||
: '';
|
||
// onChange 在翻页时也会带当前 sorter 触发;排序没变就不动,避免翻页被重置回第 1 页
|
||
if (nextBy === sortBy && nextOrder === sortOrder) return;
|
||
setSortBy(nextBy);
|
||
setSortOrder(nextOrder);
|
||
setPage(1);
|
||
};
|
||
|
||
const handleStatusChange = async (orgId, status) => {
|
||
try {
|
||
const res = await API.put(`/api/admin/organizations/${orgId}/status`, {
|
||
status,
|
||
});
|
||
if (res.data.success) {
|
||
Toast.success(t('状态已更新'));
|
||
fetchOrgs();
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
} catch (err) {
|
||
showError(err.message);
|
||
}
|
||
};
|
||
|
||
const openFeatureModal = (record) => {
|
||
let flags = {};
|
||
try {
|
||
flags = record.feature_flags ? JSON.parse(record.feature_flags) : {};
|
||
} catch {
|
||
flags = {};
|
||
}
|
||
setFeatureFlags(flags || {});
|
||
setFeatureModalOrg(record);
|
||
};
|
||
|
||
const saveFeatureFlags = async () => {
|
||
if (!featureModalOrg) return;
|
||
try {
|
||
const res = await API.put(
|
||
`/api/admin/organizations/${featureModalOrg.id}/feature-flags`,
|
||
{ flags: featureFlags },
|
||
);
|
||
if (res.data.success) {
|
||
Toast.success(t('功能开关已更新'));
|
||
setFeatureModalOrg(null);
|
||
fetchOrgs();
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
} catch (err) {
|
||
showError(err.message);
|
||
}
|
||
};
|
||
|
||
const handleActivate = async (orgId) => {
|
||
try {
|
||
const res = await API.put(`/api/admin/organizations/${orgId}/activate`);
|
||
if (res.data.success) {
|
||
Toast.success(t('企业已激活'));
|
||
fetchOrgs();
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
} catch (err) {
|
||
showError(err.message);
|
||
}
|
||
};
|
||
|
||
const handleQuotaAdjust = async () => {
|
||
if (!quotaOrgId || !quotaAmount) return;
|
||
try {
|
||
const res = await API.put(
|
||
`/api/admin/organizations/${quotaOrgId}/quota`,
|
||
{ quota: quotaAmount },
|
||
);
|
||
if (res.data.success) {
|
||
Toast.success(t('额度已调整'));
|
||
setQuotaModalVisible(false);
|
||
fetchOrgs();
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
} catch (err) {
|
||
showError(err.message);
|
||
}
|
||
};
|
||
|
||
const handleCreateOrg = async () => {
|
||
const orgName = (createForm.name || '').trim();
|
||
const ownerMode = createForm.owner_mode || 'managed';
|
||
if (!orgName) {
|
||
Toast.warning(t('请输入企业名称'));
|
||
return;
|
||
}
|
||
let ownerId = 0;
|
||
if (ownerMode === 'existing') {
|
||
if (!createForm.owner_id) {
|
||
Toast.warning(t('请输入所有者用户ID'));
|
||
return;
|
||
}
|
||
ownerId = parseInt(createForm.owner_id);
|
||
if (isNaN(ownerId) || ownerId <= 0) {
|
||
Toast.warning(t('所有者用户ID必须为正整数'));
|
||
return;
|
||
}
|
||
}
|
||
const ownerLoginName = (createForm.owner_login_name || '').trim();
|
||
if (ownerMode === 'managed') {
|
||
// 与后端 normalizeOrgOwnerLoginName 同口径:必填、格式受限、保留名一律拒绝
|
||
const loginNameError = validateOrgOwnerLoginName(ownerLoginName);
|
||
if (loginNameError) {
|
||
Toast.warning(t(loginNameError));
|
||
return;
|
||
}
|
||
}
|
||
if (!createForm.groups || !createForm.groups.length) {
|
||
Toast.warning(t('请至少选择一个企业可用分组'));
|
||
return;
|
||
}
|
||
if (!createForm.group || !createForm.groups.includes(createForm.group)) {
|
||
Toast.warning(t('默认分组必须属于企业可用分组'));
|
||
return;
|
||
}
|
||
setCreateLoading(true);
|
||
try {
|
||
const data = {
|
||
name: orgName,
|
||
};
|
||
if (ownerMode === 'existing') {
|
||
data.owner_id = ownerId;
|
||
} else {
|
||
data.owner_login_name = ownerLoginName;
|
||
data.owner_display_name = (createForm.owner_display_name || '').trim();
|
||
}
|
||
if (createForm.quota) data.quota = createForm.quota;
|
||
data.group = createForm.group;
|
||
data.groups = createForm.groups;
|
||
if (createForm.level) data.level = createForm.level;
|
||
if (createForm.max_members != null)
|
||
data.max_members = createForm.max_members;
|
||
if (createForm.max_tokens != null)
|
||
data.max_tokens = createForm.max_tokens;
|
||
if (createForm.cloud_brain_concurrency != null)
|
||
data.cloud_brain_concurrency = createForm.cloud_brain_concurrency;
|
||
if ((createForm.sales_rep || '').trim())
|
||
data.sales_rep = createForm.sales_rep.trim();
|
||
const res = await API.post('/api/admin/organizations/', data);
|
||
if (res.data.success) {
|
||
Toast.success(t('企业创建成功'));
|
||
if (res.data.data?.initial_password) {
|
||
setCreateCredentialResult(res.data.data);
|
||
} else {
|
||
setCreateModalVisible(false);
|
||
resetCreateForm();
|
||
}
|
||
fetchOrgs();
|
||
fetchSalesReps();
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
} catch (err) {
|
||
showError(err.message);
|
||
} finally {
|
||
setCreateLoading(false);
|
||
}
|
||
};
|
||
|
||
const openEditModal = (record) => {
|
||
setEditForm({
|
||
id: record.id,
|
||
name: record.name || '',
|
||
group: record.group || 'default',
|
||
groups: parseOrgGroups(record),
|
||
level: record.level || '',
|
||
max_members: record.max_members ?? 50,
|
||
max_tokens: record.max_tokens ?? 100,
|
||
cloud_brain_concurrency: record.cloud_brain_concurrency ?? 12,
|
||
default_member_quota: record.default_member_quota || 0,
|
||
description: record.description || '',
|
||
contact_name: record.contact_name || '',
|
||
contact_phone: record.contact_phone || '',
|
||
contact_email: record.contact_email || '',
|
||
sales_rep: record.sales_rep || '',
|
||
});
|
||
setEditModalVisible(true);
|
||
};
|
||
|
||
const handleEditOrg = async () => {
|
||
const orgName = (editForm.name || '').trim();
|
||
if (!orgName) {
|
||
Toast.warning(t('请输入企业名称'));
|
||
return;
|
||
}
|
||
if (!editForm.groups || !editForm.groups.length) {
|
||
Toast.warning(t('请至少选择一个企业可用分组'));
|
||
return;
|
||
}
|
||
if (!editForm.group || !editForm.groups.includes(editForm.group)) {
|
||
Toast.warning(t('默认分组必须属于企业可用分组'));
|
||
return;
|
||
}
|
||
setEditLoading(true);
|
||
try {
|
||
const data = {
|
||
name: orgName,
|
||
group: editForm.group,
|
||
groups: editForm.groups,
|
||
level: editForm.level || '',
|
||
max_members:
|
||
editForm.max_members != null ? editForm.max_members : undefined,
|
||
max_tokens:
|
||
editForm.max_tokens != null ? editForm.max_tokens : undefined,
|
||
cloud_brain_concurrency:
|
||
editForm.cloud_brain_concurrency != null
|
||
? editForm.cloud_brain_concurrency
|
||
: undefined,
|
||
default_member_quota:
|
||
editForm.default_member_quota != null
|
||
? Math.max(0, Number(editForm.default_member_quota) || 0)
|
||
: undefined,
|
||
description: editForm.description,
|
||
contact_name: editForm.contact_name,
|
||
contact_phone: editForm.contact_phone,
|
||
contact_email: editForm.contact_email,
|
||
// 始终传字符串:后端为指针字段,传空串即可清除商务人员分配
|
||
sales_rep: (editForm.sales_rep || '').trim(),
|
||
};
|
||
const res = await API.put(
|
||
`/api/admin/organizations/${editForm.id}`,
|
||
data,
|
||
);
|
||
if (res.data.success) {
|
||
Toast.success(t('企业信息已更新'));
|
||
setEditModalVisible(false);
|
||
fetchOrgs();
|
||
fetchSalesReps();
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
} catch (err) {
|
||
showError(err.message);
|
||
} finally {
|
||
setEditLoading(false);
|
||
}
|
||
};
|
||
|
||
const handleDelete = async (orgId) => {
|
||
Modal.confirm({
|
||
title: t('确认删除'),
|
||
content: t('删除企业将无法恢复,确定继续?'),
|
||
onOk: async () => {
|
||
try {
|
||
const res = await API.delete(`/api/admin/organizations/${orgId}`);
|
||
if (res.data.success) {
|
||
Toast.success(t('企业已删除'));
|
||
fetchOrgs();
|
||
// 被删企业可能是某商务唯一跟进的企业,同步刷新筛选下拉防残留失效姓名
|
||
fetchSalesReps();
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
} catch (err) {
|
||
showError(err.message);
|
||
}
|
||
},
|
||
});
|
||
};
|
||
|
||
const handleEnterOrg = (orgId) => {
|
||
localStorage.setItem('current_org_id', String(orgId));
|
||
navigate('/org/dashboard');
|
||
};
|
||
|
||
// 列宽合计 ~1400px(含商务人员列),必须给横向滚动,否则 390px 屏上只看得到
|
||
// ID+企业名称,编辑/调额/冻结/删除 全在视口外且无任何可拖动提示
|
||
const columns = [
|
||
{
|
||
title: 'ID',
|
||
dataIndex: 'id',
|
||
width: 70,
|
||
sorter: true,
|
||
sortOrder: sortOrderFor('id'),
|
||
},
|
||
{
|
||
title: t('企业名称'),
|
||
dataIndex: 'name',
|
||
width: 150,
|
||
ellipsis: true,
|
||
sorter: true,
|
||
sortOrder: sortOrderFor('name'),
|
||
render: (text, record) => {
|
||
if (isRoot()) {
|
||
return (
|
||
<button
|
||
className='inline-flex items-center gap-1 text-blue-600 dark:text-blue-400 hover:text-blue-700 dark:hover:text-blue-300 hover:underline cursor-pointer bg-transparent border-none p-0 font-inherit text-left'
|
||
onClick={() => handleEnterOrg(record.id)}
|
||
title={t('进入企业中心')}
|
||
>
|
||
<span className='truncate'>{text}</span>
|
||
<ExternalLink size={12} className='flex-shrink-0' />
|
||
</button>
|
||
);
|
||
}
|
||
return text;
|
||
},
|
||
},
|
||
{ title: t('企业代码'), dataIndex: 'code', width: 90 },
|
||
{
|
||
title: t('商务人员'),
|
||
dataIndex: 'sales_rep',
|
||
width: 100,
|
||
ellipsis: true,
|
||
render: (v) =>
|
||
v ? (
|
||
// maxWidth 约束住 Tag,超长姓名走 Tag 自带省略,不许溢出压过相邻列
|
||
<Tag size='small' color='cyan' style={{ maxWidth: '100%' }}>
|
||
{v}
|
||
</Tag>
|
||
) : (
|
||
<span className='text-xs text-gray-400 dark:text-gray-500'>
|
||
{t('未分配')}
|
||
</span>
|
||
),
|
||
},
|
||
{ title: t('所有者ID'), dataIndex: 'owner_id', width: 80 },
|
||
{
|
||
title: t('状态'),
|
||
dataIndex: 'status',
|
||
// 90 而非 70:root 视角下会在状态标签下方叠一枚"预警已屏蔽"(5 个 CJK 字符),70 会裁切
|
||
width: 90,
|
||
sorter: true,
|
||
sortOrder: sortOrderFor('status'),
|
||
render: (status, record) => (
|
||
<div className='flex flex-col items-start gap-0.5'>
|
||
<Tag
|
||
color={
|
||
status === 1
|
||
? 'green'
|
||
: status === 2
|
||
? 'red'
|
||
: status === 4
|
||
? 'blue'
|
||
: 'orange'
|
||
}
|
||
>
|
||
{status === 1
|
||
? t('正常')
|
||
: status === 2
|
||
? t('冻结')
|
||
: status === 4
|
||
? t('待激活')
|
||
: t('欠费')}
|
||
</Tag>
|
||
{isRoot() && alertExcludedIds.has(record.id) && (
|
||
<Tag size='small' color='grey'>
|
||
{t('预警已屏蔽')}
|
||
</Tag>
|
||
)}
|
||
</div>
|
||
),
|
||
},
|
||
{
|
||
title: t('额度'),
|
||
dataIndex: 'quota',
|
||
width: 100,
|
||
sorter: true,
|
||
sortOrder: sortOrderFor('quota'),
|
||
render: (v) => renderQuota(v, 2),
|
||
},
|
||
{
|
||
title: t('已用额度'),
|
||
dataIndex: 'used_quota',
|
||
width: 110,
|
||
sorter: true,
|
||
sortOrder: sortOrderFor('used_quota'),
|
||
render: (v) => renderQuota(v, 2),
|
||
},
|
||
{
|
||
title: t('分组'),
|
||
dataIndex: 'group',
|
||
width: 150,
|
||
render: (_, record) => {
|
||
const groups = parseOrgGroups(record);
|
||
if (!groups.length) return '-';
|
||
return (
|
||
<div className='flex flex-wrap gap-1'>
|
||
{groups.map((g) => (
|
||
<Tag
|
||
key={g}
|
||
size='small'
|
||
color={g === record.group ? 'blue' : 'grey'}
|
||
>
|
||
{g === record.group ? `${g} (${t('默认')})` : g}
|
||
</Tag>
|
||
))}
|
||
</div>
|
||
);
|
||
},
|
||
},
|
||
{
|
||
title: t('限额'),
|
||
width: 90,
|
||
render: (_, record) => (
|
||
<span
|
||
className='text-xs text-gray-600 dark:text-gray-400 whitespace-nowrap'
|
||
title={t('成员/Token限额')}
|
||
>
|
||
{record.max_members ?? '-'} / {record.max_tokens ?? '-'}
|
||
</span>
|
||
),
|
||
},
|
||
{
|
||
title: t('创建时间'),
|
||
dataIndex: 'created_at',
|
||
width: 110,
|
||
sorter: true,
|
||
sortOrder: sortOrderFor('created_at'),
|
||
render: (v) => (v ? new Date(v * 1000).toLocaleDateString() : '-'),
|
||
},
|
||
{
|
||
title: t('操作'),
|
||
width: 380,
|
||
render: (_, record) => (
|
||
<div className='console-module-row-actions'>
|
||
{isAdmin() && (
|
||
<>
|
||
<Button
|
||
type='link'
|
||
size='small'
|
||
onClick={() => openEditModal(record)}
|
||
>
|
||
{t('编辑')}
|
||
</Button>
|
||
<Button
|
||
type='link'
|
||
size='small'
|
||
onClick={() => {
|
||
setQuotaOrgId(record.id);
|
||
setQuotaAmount(0);
|
||
setQuotaModalVisible(true);
|
||
}}
|
||
>
|
||
{t('调额')}
|
||
</Button>
|
||
<Button
|
||
type='link'
|
||
size='small'
|
||
onClick={() => openFeatureModal(record)}
|
||
>
|
||
{t('功能开关')}
|
||
</Button>
|
||
{record.status === 4 ? (
|
||
<Button
|
||
size='small'
|
||
type='link'
|
||
onClick={() => handleActivate(record.id)}
|
||
>
|
||
{t('激活')}
|
||
</Button>
|
||
) : record.status === 1 ? (
|
||
<Button
|
||
size='small'
|
||
type='link'
|
||
onClick={() => handleStatusChange(record.id, 2)}
|
||
>
|
||
{t('冻结')}
|
||
</Button>
|
||
) : (
|
||
<Button
|
||
size='small'
|
||
type='link'
|
||
onClick={() => handleStatusChange(record.id, 1)}
|
||
>
|
||
{t('解冻')}
|
||
</Button>
|
||
)}
|
||
<Button
|
||
type='link'
|
||
size='small'
|
||
danger
|
||
onClick={() => handleDelete(record.id)}
|
||
>
|
||
{t('删除')}
|
||
</Button>
|
||
{isRoot() && (
|
||
<Button
|
||
size='small'
|
||
type='link'
|
||
loading={alertToggleLoading === record.id}
|
||
title={
|
||
alertExcludedIds.has(record.id)
|
||
? t('已屏蔽预警,点击恢复')
|
||
: t('屏蔽该企业的预警通知')
|
||
}
|
||
aria-label={
|
||
alertExcludedIds.has(record.id)
|
||
? t('恢复该企业的预警')
|
||
: t('屏蔽该企业的预警')
|
||
}
|
||
onClick={() => toggleAlertExclude(record)}
|
||
>
|
||
{alertExcludedIds.has(record.id)
|
||
? t('恢复通知')
|
||
: t('屏蔽通知')}
|
||
</Button>
|
||
)}
|
||
</>
|
||
)}
|
||
</div>
|
||
),
|
||
},
|
||
];
|
||
|
||
return (
|
||
<div className='console-content'>
|
||
<ConsoleSearchBar
|
||
formProps={{
|
||
layout: 'vertical',
|
||
onFinish: handleSearch,
|
||
className: 'console-module-filter-form',
|
||
}}
|
||
>
|
||
<div className='console-module-filter-grid'>
|
||
<ConsoleFilterField label={t('企业名称')}>
|
||
<Input
|
||
prefix={<Search size={16} />}
|
||
value={keyword}
|
||
onChange={(v) => {
|
||
setKeyword(v);
|
||
// 退格删空/点清除都会走到这里:输入框空了就同步解除过滤,
|
||
// 避免"框已空但表格仍按旧关键字过滤"的幽灵状态
|
||
if (v === '' && searchKeyword) {
|
||
setSearchKeyword('');
|
||
setPage(1);
|
||
}
|
||
}}
|
||
placeholder={t('搜索企业名称、代码、联系人、商务...')}
|
||
showClear
|
||
onEnterPress={() => {
|
||
setPage(1);
|
||
setSearchKeyword(keyword);
|
||
}}
|
||
/>
|
||
</ConsoleFilterField>
|
||
<ConsoleFilterField label={t('用户ID')}>
|
||
<Input
|
||
value={userIdInput}
|
||
onChange={(v) => {
|
||
// 只留数字并剥前导零:杜绝 "0"/"007" 这类后端会静默忽略的值,
|
||
// 否则 UI 显示筛选生效、实际返回全量列表(幽灵筛选态)
|
||
const digits = (v || '').replace(/\D/g, '').replace(/^0+/, '');
|
||
setUserIdInput(digits);
|
||
// 与关键字框同款:删空/点清除即解除过滤
|
||
if (digits === '' && userIdFilter) {
|
||
setUserIdFilter('');
|
||
setPage(1);
|
||
}
|
||
}}
|
||
placeholder={t('用户ID(owner或成员)')}
|
||
showClear
|
||
// 10 位封顶:真实用户ID 不会更长,且远离后端 Atoi 溢出边界(19 位)
|
||
maxLength={10}
|
||
aria-label={t('按用户ID筛选')}
|
||
onEnterPress={() => {
|
||
setPage(1);
|
||
setUserIdFilter(userIdInput);
|
||
}}
|
||
/>
|
||
</ConsoleFilterField>
|
||
<ConsoleFilterField label={t('状态')}>
|
||
<Select
|
||
value={statusFilter}
|
||
onChange={applyFilter(setStatusFilter)}
|
||
optionList={[
|
||
{ value: 1, label: t('正常') },
|
||
{ value: 2, label: t('冻结') },
|
||
{ value: 3, label: t('欠费') },
|
||
{ value: 4, label: t('待激活') },
|
||
]}
|
||
placeholder={t('全部状态')}
|
||
showClear
|
||
aria-label={t('按状态筛选')}
|
||
/>
|
||
</ConsoleFilterField>
|
||
<ConsoleFilterField label={t('企业等级')}>
|
||
<Select
|
||
value={levelFilter}
|
||
onChange={applyFilter(setLevelFilter)}
|
||
optionList={levelOptions}
|
||
placeholder={t('全部等级')}
|
||
showClear
|
||
filter
|
||
aria-label={t('按企业等级筛选')}
|
||
/>
|
||
</ConsoleFilterField>
|
||
<ConsoleFilterField label={t('商务人员')}>
|
||
<Select
|
||
value={salesRepFilter}
|
||
onChange={applyFilter(setSalesRepFilter)}
|
||
optionList={[
|
||
{ value: '__none__', label: t('未分配') },
|
||
...salesRepOptions,
|
||
]}
|
||
placeholder={t('全部商务')}
|
||
showClear
|
||
filter
|
||
aria-label={t('按商务人员筛选')}
|
||
/>
|
||
</ConsoleFilterField>
|
||
</div>
|
||
<ConsoleFilterActions
|
||
onReset={resetFilters}
|
||
onSearch={handleSearch}
|
||
loading={loading}
|
||
/>
|
||
{isAdmin() && (
|
||
<ConsolePageActions>
|
||
{CLOUD_BRAIN_UI_ENABLED && (
|
||
<Button icon={<BarChart3 size={16} />} onClick={openEffectUsage}>
|
||
{t('企业使用统计')}
|
||
</Button>
|
||
)}
|
||
{isRoot() && (
|
||
<Button
|
||
icon={<Bell size={16} />}
|
||
onClick={() => setAlertSettingsVisible(true)}
|
||
>
|
||
{t('通知设置')}
|
||
</Button>
|
||
)}
|
||
<Button
|
||
className='console-create-action'
|
||
type='primary'
|
||
icon={<Plus size={16} />}
|
||
onClick={() => {
|
||
resetCreateForm();
|
||
setCreateModalVisible(true);
|
||
}}
|
||
>
|
||
{t('创建企业')}
|
||
</Button>
|
||
</ConsolePageActions>
|
||
)}
|
||
</ConsoleSearchBar>
|
||
|
||
<ConsoleCard>
|
||
<TableToolbar title={t('企业列表')} />
|
||
<Table
|
||
empty={<TableEmpty />}
|
||
columns={columns}
|
||
dataSource={orgs}
|
||
loading={loading}
|
||
rowKey='id'
|
||
// 11 列且「操作」是最后一列(编辑/调额/功能开关/冻结/删除)。
|
||
// 不给 scroll 时表格会压缩到 min-content(~790px) 硬塞进 390px 视口,
|
||
// 操作列落在视口右侧 ~500px 处,iOS 上滚动条不可见、毫无可拖动提示。
|
||
scroll={{ x: 'max-content' }}
|
||
style={{ width: '100%' }}
|
||
onChange={handleTableChange}
|
||
pagination={{
|
||
currentPage: page,
|
||
pageSize,
|
||
total,
|
||
onPageChange: setPage,
|
||
onPageSizeChange: (size) => {
|
||
setPage(1);
|
||
setPageSize(size);
|
||
},
|
||
}}
|
||
/>
|
||
</ConsoleCard>
|
||
|
||
{CLOUD_BRAIN_UI_ENABLED && (
|
||
<Modal
|
||
title={t('企业 Agent / Skill 使用统计')}
|
||
visible={effectUsageVisible}
|
||
onCancel={() => setEffectUsageVisible(false)}
|
||
footer={null}
|
||
width={860}
|
||
>
|
||
<Table
|
||
pagination={false}
|
||
dataSource={effectUsage}
|
||
columns={[
|
||
{ title: t('企业 ID'), dataIndex: 'organization_id' },
|
||
{ title: t('企业名称'), dataIndex: 'organization_name' },
|
||
{ title: t('最新日期'), dataIndex: 'metric_date' },
|
||
{ title: t('任务量'), dataIndex: 'task_count' },
|
||
{ title: t('启用 Skill'), dataIndex: 'enabled_skill_count' },
|
||
{ title: t('调用 Skill'), dataIndex: 'skill_count' },
|
||
{ title: t('额度成本'), dataIndex: 'quota' },
|
||
{ title: t('节省分钟'), dataIndex: 'saved_minutes' },
|
||
]}
|
||
/>
|
||
</Modal>
|
||
)}
|
||
|
||
{/* 额度调整 Modal */}
|
||
<Modal
|
||
title={t('调整企业额度')}
|
||
visible={quotaModalVisible}
|
||
onOk={handleQuotaAdjust}
|
||
onCancel={() => setQuotaModalVisible(false)}
|
||
okText={t('确认')}
|
||
cancelText={t('取消')}
|
||
>
|
||
<div className='space-y-3'>
|
||
{quotaOrgId &&
|
||
(() => {
|
||
const currentOrg = orgs.find((o) => o.id === quotaOrgId);
|
||
return currentOrg ? (
|
||
<div className='p-3 rounded-lg bg-gray-50 dark:bg-neutral-800/50 text-sm'>
|
||
<div className='flex justify-between'>
|
||
<span className='text-gray-500 dark:text-gray-400'>
|
||
{t('当前额度')}
|
||
</span>
|
||
<span className='font-medium text-gray-900 dark:text-white'>
|
||
{renderQuota(currentOrg.quota, 2)}
|
||
</span>
|
||
</div>
|
||
<div className='flex justify-between mt-1'>
|
||
<span className='text-gray-500 dark:text-gray-400'>
|
||
{t('已用额度')}
|
||
</span>
|
||
<span className='font-medium text-gray-900 dark:text-white'>
|
||
{renderQuota(currentOrg.used_quota, 2)}
|
||
</span>
|
||
</div>
|
||
</div>
|
||
) : null;
|
||
})()}
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2'>
|
||
{t('调整额度(正数增加,负数减少)')}
|
||
</label>
|
||
<QuotaInput
|
||
value={quotaAmount}
|
||
onChange={setQuotaAmount}
|
||
style={{ width: '100%' }}
|
||
/>
|
||
</div>
|
||
</div>
|
||
</Modal>
|
||
|
||
{/* 企业预警通知设置 Modal(root-only,方案 11 号 §8-2) */}
|
||
<OrgAlertSettingsModal
|
||
visible={alertSettingsVisible}
|
||
onClose={() => setAlertSettingsVisible(false)}
|
||
onSaved={fetchAlertExcluded}
|
||
/>
|
||
|
||
{/* 创建企业 Modal */}
|
||
<Modal
|
||
title={createCredentialResult ? t('企业管理员凭证') : t('创建企业')}
|
||
visible={createModalVisible}
|
||
centered
|
||
onOk={handleCreateOrg}
|
||
onCancel={() => {
|
||
setCreateModalVisible(false);
|
||
resetCreateForm();
|
||
}}
|
||
okText={t('创建')}
|
||
cancelText={t('取消')}
|
||
confirmLoading={createLoading}
|
||
{...(createCredentialResult ? { footer: null } : {})}
|
||
bodyStyle={{
|
||
...(createCredentialResult ? { paddingBottom: 24 } : {}),
|
||
maxHeight: 'calc(100vh - 200px)',
|
||
overflowY: 'auto',
|
||
overscrollBehavior: 'contain',
|
||
scrollbarGutter: 'stable',
|
||
}}
|
||
>
|
||
{createCredentialResult ? (
|
||
<OrgCredentialResult creds={createCredentialResult} />
|
||
) : (
|
||
<div className='space-y-4'>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('企业名称')} <span className='text-red-500'>*</span>
|
||
</label>
|
||
<Input
|
||
value={createForm.name}
|
||
onChange={(v) => setCreateForm({ ...createForm, name: v })}
|
||
placeholder={t('请输入企业名称')}
|
||
/>
|
||
</div>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('所有者账号模式')} <span className='text-red-500'>*</span>
|
||
</label>
|
||
<Radio.Group
|
||
value={createForm.owner_mode}
|
||
onChange={(e) =>
|
||
setCreateForm({ ...createForm, owner_mode: e.target.value })
|
||
}
|
||
>
|
||
<Radio value='managed'>{t('自动生成 Owner')}</Radio>
|
||
<Radio value='existing'>{t('指定现有用户')}</Radio>
|
||
</Radio.Group>
|
||
<p className='text-xs text-gray-400 dark:text-gray-500 mt-1'>
|
||
{t(
|
||
'自动生成模式会返回一次性企业代码、登录名和初始密码,不依赖个人账号。',
|
||
)}
|
||
</p>
|
||
</div>
|
||
{createForm.owner_mode === 'existing' ? (
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('所有者用户ID')} <span className='text-red-500'>*</span>
|
||
</label>
|
||
<Input
|
||
value={createForm.owner_id}
|
||
onChange={(v) =>
|
||
setCreateForm({ ...createForm, owner_id: v })
|
||
}
|
||
placeholder={t('输入用户ID指定所有者')}
|
||
/>
|
||
</div>
|
||
) : (
|
||
<div className='grid grid-cols-1 sm:grid-cols-2 gap-4'>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('Owner 登录名')}
|
||
</label>
|
||
<Input
|
||
value={createForm.owner_login_name}
|
||
onChange={(v) =>
|
||
setCreateForm({ ...createForm, owner_login_name: v })
|
||
}
|
||
placeholder={t('请设置管理员登录名,如 zhang.san')}
|
||
/>
|
||
<div className='mt-1 text-xs text-gray-400'>
|
||
{t(
|
||
'3-32 位,字母开头;admin、root 等保留名不可用(创建后不可修改)',
|
||
)}
|
||
</div>
|
||
</div>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('Owner 显示名')}
|
||
</label>
|
||
<Input
|
||
value={createForm.owner_display_name}
|
||
onChange={(v) =>
|
||
setCreateForm({ ...createForm, owner_display_name: v })
|
||
}
|
||
placeholder={t('选填')}
|
||
/>
|
||
</div>
|
||
</div>
|
||
)}
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('可用分组 (Groups)')}
|
||
</label>
|
||
<Select
|
||
multiple
|
||
value={createForm.groups}
|
||
onChange={(v) => {
|
||
const next = { ...createForm, groups: v };
|
||
if (!v.includes(createForm.group)) next.group = v[0] || '';
|
||
setCreateForm(next);
|
||
}}
|
||
optionList={groupOptions}
|
||
placeholder={t('选择企业可用的分组,可多选')}
|
||
style={{ width: '100%' }}
|
||
filter
|
||
/>
|
||
<p className='text-xs text-gray-400 dark:text-gray-500 mt-1'>
|
||
{t('企业可调用的全部分组,员工可用分组从中分配')}
|
||
</p>
|
||
</div>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('默认分组')}
|
||
</label>
|
||
<Select
|
||
value={createForm.group}
|
||
onChange={(v) => setCreateForm({ ...createForm, group: v })}
|
||
optionList={buildDefaultOptions(createForm.groups)}
|
||
placeholder={t('默认 default')}
|
||
style={{ width: '100%' }}
|
||
filter
|
||
/>
|
||
<p className='text-xs text-gray-400 dark:text-gray-500 mt-1'>
|
||
{t('企业Token/员工未指定时使用的分组,必须属于可用分组')}
|
||
</p>
|
||
</div>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('企业等级')}
|
||
</label>
|
||
<Select
|
||
value={createForm.level}
|
||
onChange={(v) => setCreateForm({ ...createForm, level: v })}
|
||
optionList={levelOptions}
|
||
placeholder={t('默认(不打折)')}
|
||
style={{ width: '100%' }}
|
||
filter
|
||
showClear
|
||
/>
|
||
<p className='text-xs text-gray-400 dark:text-gray-500 mt-1'>
|
||
{t(
|
||
'不同等级在分组倍率基础上叠加折扣,等级与折扣在系统设置-等级与模型访问中配置',
|
||
)}
|
||
</p>
|
||
</div>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('商务人员')}
|
||
</label>
|
||
<Input
|
||
value={createForm.sales_rep}
|
||
onChange={(v) => setCreateForm({ ...createForm, sales_rep: v })}
|
||
placeholder={t('跟进该企业的商务/销售,选填')}
|
||
maxLength={64}
|
||
showClear
|
||
/>
|
||
<p className='text-xs text-gray-400 dark:text-gray-500 mt-1'>
|
||
{t('仅平台管理员可见,用于标记商机跟进人')}
|
||
</p>
|
||
</div>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('初始额度')}
|
||
</label>
|
||
<QuotaInput
|
||
value={createForm.quota}
|
||
onChange={(v) => setCreateForm({ ...createForm, quota: v })}
|
||
style={{ width: '100%' }}
|
||
minQuota={0}
|
||
/>
|
||
</div>
|
||
<div className='grid grid-cols-1 sm:grid-cols-2 gap-4'>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('最大成员数')}
|
||
</label>
|
||
<InputNumber
|
||
value={createForm.max_members}
|
||
onChange={(v) =>
|
||
setCreateForm({ ...createForm, max_members: v })
|
||
}
|
||
style={{ width: '100%' }}
|
||
min={1}
|
||
placeholder='50'
|
||
/>
|
||
</div>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('最大Token数')}
|
||
</label>
|
||
<InputNumber
|
||
value={createForm.max_tokens}
|
||
onChange={(v) =>
|
||
setCreateForm({ ...createForm, max_tokens: v })
|
||
}
|
||
style={{ width: '100%' }}
|
||
min={1}
|
||
placeholder='100'
|
||
/>
|
||
</div>
|
||
</div>
|
||
{CLOUD_BRAIN_UI_ENABLED && (
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('云端大脑企业总并发')}
|
||
</label>
|
||
<InputNumber
|
||
value={createForm.cloud_brain_concurrency}
|
||
onChange={(v) =>
|
||
setCreateForm({
|
||
...createForm,
|
||
cloud_brain_concurrency: v,
|
||
})
|
||
}
|
||
style={{ width: '100%' }}
|
||
min={1}
|
||
max={1000}
|
||
placeholder='12'
|
||
/>
|
||
</div>
|
||
)}
|
||
</div>
|
||
)}
|
||
</Modal>
|
||
|
||
{/* 编辑企业 Modal */}
|
||
<Modal
|
||
title={t('编辑企业')}
|
||
visible={editModalVisible}
|
||
onOk={handleEditOrg}
|
||
onCancel={() => setEditModalVisible(false)}
|
||
okText={t('保存')}
|
||
cancelText={t('取消')}
|
||
confirmLoading={editLoading}
|
||
>
|
||
<div className='space-y-4'>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('企业名称')} <span className='text-red-500'>*</span>
|
||
</label>
|
||
<Input
|
||
value={editForm.name}
|
||
onChange={(v) => setEditForm({ ...editForm, name: v })}
|
||
placeholder={t('请输入企业名称')}
|
||
/>
|
||
</div>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('可用分组 (Groups)')}
|
||
</label>
|
||
<Select
|
||
multiple
|
||
value={editForm.groups}
|
||
onChange={(v) => {
|
||
const next = { ...editForm, groups: v };
|
||
if (!v.includes(editForm.group)) next.group = v[0] || '';
|
||
setEditForm(next);
|
||
}}
|
||
optionList={groupOptions}
|
||
placeholder={t('选择企业可用的分组,可多选')}
|
||
style={{ width: '100%' }}
|
||
filter
|
||
/>
|
||
<p className='text-xs text-gray-400 dark:text-gray-500 mt-1'>
|
||
{t('企业可调用的全部分组,员工可用分组从中分配')}
|
||
</p>
|
||
</div>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('默认分组')}
|
||
</label>
|
||
<Select
|
||
value={editForm.group}
|
||
onChange={(v) => setEditForm({ ...editForm, group: v })}
|
||
optionList={buildDefaultOptions(editForm.groups)}
|
||
placeholder={t('选择分组')}
|
||
style={{ width: '100%' }}
|
||
filter
|
||
/>
|
||
<p className='text-xs text-gray-400 dark:text-gray-500 mt-1'>
|
||
{t('企业Token/员工未指定时使用的分组,必须属于可用分组')}
|
||
</p>
|
||
</div>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('企业等级')}
|
||
</label>
|
||
<Select
|
||
value={editForm.level}
|
||
onChange={(v) => setEditForm({ ...editForm, level: v })}
|
||
optionList={levelOptions}
|
||
placeholder={t('默认(不打折)')}
|
||
style={{ width: '100%' }}
|
||
filter
|
||
showClear
|
||
/>
|
||
<p className='text-xs text-gray-400 dark:text-gray-500 mt-1'>
|
||
{t(
|
||
'不同等级在分组倍率基础上叠加折扣,等级与折扣在系统设置-等级与模型访问中配置',
|
||
)}
|
||
</p>
|
||
</div>
|
||
<div className='grid grid-cols-2 gap-4'>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('最大成员数')}
|
||
</label>
|
||
<InputNumber
|
||
value={editForm.max_members}
|
||
onChange={(v) => setEditForm({ ...editForm, max_members: v })}
|
||
style={{ width: '100%' }}
|
||
min={1}
|
||
/>
|
||
</div>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('最大Token数')}
|
||
</label>
|
||
<InputNumber
|
||
value={editForm.max_tokens}
|
||
onChange={(v) => setEditForm({ ...editForm, max_tokens: v })}
|
||
style={{ width: '100%' }}
|
||
min={1}
|
||
/>
|
||
</div>
|
||
</div>
|
||
{CLOUD_BRAIN_UI_ENABLED && (
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('云端大脑企业总并发')}
|
||
</label>
|
||
<InputNumber
|
||
value={editForm.cloud_brain_concurrency}
|
||
onChange={(v) =>
|
||
setEditForm({
|
||
...editForm,
|
||
cloud_brain_concurrency: v,
|
||
})
|
||
}
|
||
style={{ width: '100%' }}
|
||
min={1}
|
||
max={1000}
|
||
/>
|
||
<p className='text-xs text-gray-500 mt-1'>
|
||
{t('成员个人并发上限仍独立生效,企业总并发用于保护共享资源。')}
|
||
</p>
|
||
</div>
|
||
)}
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('企业描述')}
|
||
</label>
|
||
<TextArea
|
||
value={editForm.description}
|
||
onChange={(v) => setEditForm({ ...editForm, description: v })}
|
||
placeholder={t('简要描述企业信息')}
|
||
rows={2}
|
||
/>
|
||
</div>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('商务人员')}
|
||
</label>
|
||
<Input
|
||
value={editForm.sales_rep}
|
||
onChange={(v) => setEditForm({ ...editForm, sales_rep: v })}
|
||
placeholder={t('跟进该企业的商务/销售,选填')}
|
||
maxLength={64}
|
||
showClear
|
||
/>
|
||
<p className='text-xs text-gray-400 dark:text-gray-500 mt-1'>
|
||
{t('仅平台管理员可见,用于标记商机跟进人')}
|
||
</p>
|
||
</div>
|
||
<div className='grid grid-cols-1 sm:grid-cols-2 gap-4'>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('联系人')}
|
||
</label>
|
||
<Input
|
||
value={editForm.contact_name}
|
||
onChange={(v) => setEditForm({ ...editForm, contact_name: v })}
|
||
placeholder={t('联系人姓名')}
|
||
/>
|
||
</div>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('联系电话')}
|
||
</label>
|
||
<Input
|
||
value={editForm.contact_phone}
|
||
onChange={(v) => setEditForm({ ...editForm, contact_phone: v })}
|
||
placeholder={t('联系电话')}
|
||
/>
|
||
</div>
|
||
</div>
|
||
<div>
|
||
<label className='block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1.5'>
|
||
{t('联系邮箱')}
|
||
</label>
|
||
<Input
|
||
value={editForm.contact_email}
|
||
onChange={(v) => setEditForm({ ...editForm, contact_email: v })}
|
||
placeholder={t('联系邮箱')}
|
||
/>
|
||
</div>
|
||
</div>
|
||
</Modal>
|
||
|
||
{/* 功能开关 / 套餐 Modal(平台控制企业可用能力,§28.8) */}
|
||
<Modal
|
||
title={`${t('功能开关')} - ${featureModalOrg?.name || ''}`}
|
||
visible={!!featureModalOrg}
|
||
centered
|
||
width='min(680px, calc(100vw - 32px))'
|
||
onOk={saveFeatureFlags}
|
||
onCancel={() => setFeatureModalOrg(null)}
|
||
okText={t('保存')}
|
||
cancelText={t('取消')}
|
||
bodyStyle={{
|
||
maxHeight: 'min(70vh, 560px)',
|
||
overflowX: 'hidden',
|
||
overflowY: 'auto',
|
||
overscrollBehavior: 'contain',
|
||
scrollbarGutter: 'stable',
|
||
}}
|
||
>
|
||
<div className='mb-4 text-xs leading-5 text-gray-500'>
|
||
{t(
|
||
'开启后企业方可使用对应能力;预算实时拦截需同时开启「预算配置」。',
|
||
)}
|
||
</div>
|
||
<div className='grid grid-cols-1 gap-2 sm:grid-cols-2'>
|
||
{VISIBLE_ORG_FEATURE_KEYS.map((f) => (
|
||
<div
|
||
key={f.key}
|
||
className='flex min-w-0 items-center justify-between gap-3 rounded-lg border border-[var(--border-subtle)] bg-[var(--surface-card)] px-3 py-2.5'
|
||
>
|
||
<span className='min-w-0 break-words text-sm leading-5'>
|
||
{t(f.label)}
|
||
</span>
|
||
<Switch
|
||
className='mr-0.5 flex-none'
|
||
aria-label={t(f.label)}
|
||
checked={
|
||
f.key === 'department_guardrail'
|
||
? featureFlags[f.key] !== false
|
||
: !!featureFlags[f.key]
|
||
}
|
||
onChange={(v) =>
|
||
setFeatureFlags((prev) => ({ ...prev, [f.key]: v }))
|
||
}
|
||
/>
|
||
</div>
|
||
))}
|
||
</div>
|
||
</Modal>
|
||
</div>
|
||
);
|
||
};
|
||
|
||
export default AdminOrganizations;
|