635351f539
来源: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
746 lines
24 KiB
React
746 lines
24 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 React, { useCallback, useEffect, useMemo, useState } from 'react';
|
||
import { useTranslation } from 'react-i18next';
|
||
import {
|
||
Table,
|
||
Button,
|
||
Form,
|
||
Toast,
|
||
Tag,
|
||
Popconfirm,
|
||
Banner,
|
||
Typography,
|
||
Tooltip,
|
||
} from '@/components/ui';
|
||
import {
|
||
RefreshCw,
|
||
UserPlus,
|
||
Upload as UploadIcon,
|
||
IdCard,
|
||
} from 'lucide-react';
|
||
import { API } from '../../helpers/api';
|
||
import { showError, collectPagedItems } from '../../helpers';
|
||
import OrgPageHeader from './components/OrgPageHeader';
|
||
import OrgPanel from './components/OrgPanel';
|
||
import { OrgListCard, OrgRowActions } from './components/OrgListCard';
|
||
import OrgModal from './components/OrgModal';
|
||
import DeptTreeSelect from './components/DeptTreeSelect';
|
||
import {
|
||
buildDeptTreeData,
|
||
buildDeptFullNameMap,
|
||
hasChildDept,
|
||
} from './components/deptTree';
|
||
import { isOrgFeatureEnabled } from './orgFeatureFlags';
|
||
|
||
const { Text } = Typography;
|
||
const getOrgHeaders = (orgId) => ({ 'X-Org-Id': String(orgId) });
|
||
|
||
const formatImportError = (t, row) => {
|
||
const params = row?.error_params || {};
|
||
switch (row?.error_code) {
|
||
case 'login_name_required':
|
||
return t('企业内登录名必填');
|
||
case 'login_name_too_long':
|
||
return t(
|
||
'企业内登录名不能超过 {{max}} 个字符,当前 {{actual}} 个字符',
|
||
params,
|
||
);
|
||
case 'employee_no_too_long':
|
||
return t('工号不能超过 {{max}} 个字符', params);
|
||
case 'login_name_exists':
|
||
return t('企业内登录名已存在');
|
||
case 'login_name_reserved':
|
||
return t('该登录名为系统保留名称,请换一个登录名');
|
||
case 'email_exists':
|
||
return t('该邮箱已被平台用户使用,请更换邮箱或留空');
|
||
case 'member_limit_reached':
|
||
return t('企业成员数量已达到上限 {{max}}', params);
|
||
case 'password_generation_failed':
|
||
return t('初始密码生成失败,请重试');
|
||
case 'create_failed':
|
||
return t('账号创建失败,请检查数据后重试');
|
||
default:
|
||
return row?.error || t('导入失败');
|
||
}
|
||
};
|
||
|
||
// 状态色遵循 components/orgStatus.js 的统一口径:正常=green,停用/离职=grey(归档态,非错误态)
|
||
const statusTag = (t, s) =>
|
||
s === 1 ? (
|
||
<Tag color='green'>{t('正常')}</Tag>
|
||
) : (
|
||
<Tag color='grey'>{t('已停用/离职')}</Tag>
|
||
);
|
||
|
||
// 员工账号:企业托管账号生命周期(建号/CSV导入/重置密码/离职回收,PR6a)。
|
||
const OrgMemberAccounts = ({
|
||
orgId,
|
||
orgRole = null,
|
||
embedded = false,
|
||
featureFlags = null,
|
||
}) => {
|
||
const { t } = useTranslation();
|
||
// 企业管理员只能重置本企业托管账号;平台超管额外可重置个人账号(后端同口径校验)
|
||
const isSuperAdmin = orgRole === 'super_admin';
|
||
// dept 功能开关关闭时:不请求 /api/org/dept(后端 403),并隐藏部门列/分配入口/建号主部门字段
|
||
const deptEnabled = isOrgFeatureEnabled(featureFlags, 'dept');
|
||
const [members, setMembers] = useState([]);
|
||
const [membersTotal, setMembersTotal] = useState(0);
|
||
const [depts, setDepts] = useState([]);
|
||
const [loading, setLoading] = useState(false);
|
||
|
||
const [createVisible, setCreateVisible] = useState(false);
|
||
const [createFormApi, setCreateFormApi] = useState(null);
|
||
const [pwdResult, setPwdResult] = useState(null); // {username, login_name, initial_password}
|
||
|
||
const [importVisible, setImportVisible] = useState(false);
|
||
const [importResult, setImportResult] = useState(null);
|
||
const [importFile, setImportFile] = useState(null);
|
||
|
||
const [deptAssignFor, setDeptAssignFor] = useState(null); // 正在分配部门的成员
|
||
const [deptAssignVal, setDeptAssignVal] = useState(0);
|
||
|
||
const fetchAll = useCallback(async () => {
|
||
if (!orgId) return;
|
||
setLoading(true);
|
||
try {
|
||
const [m, d] = await Promise.all([
|
||
// 逐页取全:后端把 page_size 静默钳到 100。本页表格用的是**前端分页**
|
||
// (pageSize 15),单次只取 100 条会让管理员翻到最后一页、以为已看完
|
||
// 全部员工,而第 101 位之后的人根本不在表格里——total 也会与实际
|
||
// 行数对不上。
|
||
collectPagedItems((page, size) =>
|
||
API.get(`/api/org/members?p=${page}&page_size=${size}`, {
|
||
headers: getOrgHeaders(orgId),
|
||
}),
|
||
),
|
||
deptEnabled
|
||
? // 部门数据仅用于列展示与分配弹窗:网络失败兜底为 null,不连坐员工列表
|
||
API.get('/api/org/dept', { headers: getOrgHeaders(orgId) }).catch(
|
||
() => null,
|
||
)
|
||
: Promise.resolve(null),
|
||
]);
|
||
setMembers(m.items);
|
||
setMembersTotal(m.total);
|
||
if (m.message) showError(m.message);
|
||
// 触达 20 页上限(2000 人)时必须明说:本页顶部显示的是后端真实总数,
|
||
// 不提示的话又会变成"数字与表格行数对不上"的静默截断——正是本轮要消除的问题。
|
||
if (m.truncated)
|
||
showError(
|
||
t(
|
||
'员工数量超出单次加载上限,列表可能不完整,请用搜索或部门筛选缩小范围',
|
||
),
|
||
);
|
||
if (d) {
|
||
if (d.data.success) setDepts(d.data.data || []);
|
||
else showError(d.data.message);
|
||
}
|
||
} catch (err) {
|
||
showError(err.message);
|
||
} finally {
|
||
setLoading(false);
|
||
}
|
||
}, [orgId, deptEnabled, t]);
|
||
|
||
useEffect(() => {
|
||
fetchAll();
|
||
}, [fetchAll]);
|
||
|
||
// 建号弹窗主部门的树数据(与分配弹窗同规则:末级可选、停用置灰)
|
||
const deptTreeData = useMemo(
|
||
() => buildDeptTreeData(depts, { disabledLabel: t('已停用') }),
|
||
[depts, t],
|
||
);
|
||
const deptNameMap = useMemo(() => {
|
||
const m = {};
|
||
depts.forEach((d) => (m[d.id] = d.name));
|
||
return m;
|
||
}, [depts]);
|
||
const deptFullNameMap = useMemo(() => buildDeptFullNameMap(depts), [depts]);
|
||
// 当前归属部门如今已停用或有了下级(存量数据):仍正常回显,仅提示建议迁移
|
||
const assignCurrentDeptBlocked = useMemo(() => {
|
||
const deptId = deptAssignFor?.department_id;
|
||
if (!deptId) return false;
|
||
const dept = depts.find((d) => d.id === deptId);
|
||
if (!dept) return false;
|
||
return dept.status !== 1 || hasChildDept(depts, deptId);
|
||
}, [deptAssignFor, depts]);
|
||
|
||
const assignDept = async () => {
|
||
if (!deptAssignFor) return;
|
||
// 未变化直接关闭:存量归属可能已不满足「末级+启用」校验,原样提交会被后端拒绝
|
||
if ((deptAssignVal || 0) === (deptAssignFor.department_id || 0)) {
|
||
setDeptAssignFor(null);
|
||
return;
|
||
}
|
||
try {
|
||
const res = await API.put(
|
||
`/api/org/members/${deptAssignFor.id}/dept`,
|
||
{ department_id: deptAssignVal || 0 },
|
||
{ headers: getOrgHeaders(orgId) },
|
||
);
|
||
if (res.data.success) {
|
||
Toast.success(t('部门已分配'));
|
||
setDeptAssignFor(null);
|
||
fetchAll();
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
} catch (err) {
|
||
showError(err.message);
|
||
}
|
||
};
|
||
|
||
const submitCreate = async () => {
|
||
if (!createFormApi) return;
|
||
let v;
|
||
try {
|
||
v = await createFormApi.validate();
|
||
} catch {
|
||
return;
|
||
}
|
||
// 统一 trim 后再判空/提交:纯空格登录名在这里即被拦下,而不是到后端才报错。
|
||
// 后端建号硬性要求 login_name(登录只认登录名),提示与后端对齐,不再误导"填邮箱也行"。
|
||
const loginName = (v.login_name || '').trim();
|
||
const email = (v.email || '').trim();
|
||
if (!loginName) {
|
||
Toast.warning(t('请填写企业内登录名'));
|
||
return;
|
||
}
|
||
try {
|
||
const res = await API.post(
|
||
'/api/org/members/create-account',
|
||
{
|
||
login_name: loginName,
|
||
display_name: (v.display_name || '').trim(),
|
||
email,
|
||
employee_no: (v.employee_no || '').trim(),
|
||
department_id: v.department_id || 0,
|
||
},
|
||
{ headers: getOrgHeaders(orgId) },
|
||
);
|
||
if (res.data.success) {
|
||
setCreateVisible(false);
|
||
setPwdResult({
|
||
username: res.data.data.username,
|
||
login_name: res.data.data.login_name,
|
||
initial_password: res.data.data.initial_password,
|
||
login_name_global_collision:
|
||
res.data.data.login_name_global_collision,
|
||
});
|
||
fetchAll();
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
} catch (err) {
|
||
showError(err.message);
|
||
}
|
||
};
|
||
|
||
const submitImport = async () => {
|
||
if (!importFile) {
|
||
Toast.warning(t('请选择 CSV 文件'));
|
||
return;
|
||
}
|
||
const fd = new FormData();
|
||
fd.append('file', importFile);
|
||
try {
|
||
const res = await API.post('/api/org/members/import', fd, {
|
||
headers: getOrgHeaders(orgId),
|
||
});
|
||
if (res.data.success) {
|
||
setImportResult(res.data.data);
|
||
fetchAll();
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
} catch (err) {
|
||
showError(err.message);
|
||
}
|
||
};
|
||
|
||
const resetPassword = async (member) => {
|
||
try {
|
||
const res = await API.put(
|
||
`/api/org/members/${member.id}/reset-password`,
|
||
{},
|
||
{ headers: getOrgHeaders(orgId) },
|
||
);
|
||
if (res.data.success) {
|
||
// 回显被重置的账号:个人账号没有企业内登录名,只能凭系统用户名登录,不回显就无从告知本人。
|
||
// 托管账号只回显企业内登录名:其系统用户名是 o{orgId}_随机串,企业登录入口不认,
|
||
// 回显会被误读成“用户名被改了”并分发给员工,导致登录失败
|
||
const isManaged = member.created_by_org_id === member.organization_id;
|
||
setPwdResult({
|
||
username: isManaged && member.login_name ? '' : member.username || '',
|
||
login_name: member.login_name || '',
|
||
initial_password: res.data.data.temp_password,
|
||
reset: true,
|
||
});
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
} catch (err) {
|
||
showError(err.message);
|
||
}
|
||
};
|
||
|
||
const offboard = async (memberId) => {
|
||
try {
|
||
const res = await API.put(
|
||
`/api/org/members/${memberId}/offboard`,
|
||
{},
|
||
{ headers: getOrgHeaders(orgId) },
|
||
);
|
||
if (res.data.success) {
|
||
Toast.success(t('已离职回收'));
|
||
fetchAll();
|
||
} else {
|
||
showError(res.data.message);
|
||
}
|
||
} catch (err) {
|
||
showError(err.message);
|
||
}
|
||
};
|
||
|
||
const columns = [
|
||
{
|
||
title: t('成员'),
|
||
render: (_, r) => (
|
||
<div className='flex items-center gap-2'>
|
||
<span>{r.display_name || r.username || `#${r.user_id}`}</span>
|
||
{r.created_by_org_id !== r.organization_id && (
|
||
<Tooltip content={t('个人平台账号(非本企业托管)')}>
|
||
<Tag size='small' color='blue'>
|
||
{t('个人账号')}
|
||
</Tag>
|
||
</Tooltip>
|
||
)}
|
||
</div>
|
||
),
|
||
},
|
||
{
|
||
title: t('企业内登录名'),
|
||
dataIndex: 'login_name',
|
||
render: (v) => v || '-',
|
||
},
|
||
...(deptEnabled
|
||
? [
|
||
{
|
||
title: t('部门'),
|
||
dataIndex: 'department_id',
|
||
width: 120,
|
||
render: (v) =>
|
||
v ? (
|
||
<Tooltip content={deptFullNameMap[v] || `#${v}`}>
|
||
<span>{deptNameMap[v] || `#${v}`}</span>
|
||
</Tooltip>
|
||
) : (
|
||
<span className='text-gray-400'>{t('未分配')}</span>
|
||
),
|
||
},
|
||
]
|
||
: []),
|
||
{ title: t('工号'), dataIndex: 'employee_no', render: (v) => v || '-' },
|
||
{
|
||
title: t('角色'),
|
||
dataIndex: 'role',
|
||
width: 90,
|
||
render: (v) =>
|
||
v === 'owner'
|
||
? t('Owner')
|
||
: v === 'admin'
|
||
? t('Admin')
|
||
: v === 'dept_admin'
|
||
? t('Dept Admin')
|
||
: t('Member'),
|
||
},
|
||
{
|
||
title: t('状态'),
|
||
dataIndex: 'status',
|
||
width: 110,
|
||
render: (v) => statusTag(t, v),
|
||
},
|
||
{
|
||
title: t('操作'),
|
||
width: 260,
|
||
render: (_, r) => {
|
||
const managed = r.created_by_org_id === r.organization_id;
|
||
const canReset = managed || isSuperAdmin;
|
||
return (
|
||
<OrgRowActions>
|
||
{deptEnabled && (
|
||
<Button
|
||
type='link'
|
||
onClick={() => {
|
||
setDeptAssignFor(r);
|
||
setDeptAssignVal(r.department_id || 0);
|
||
}}
|
||
>
|
||
{t('分配部门')}
|
||
</Button>
|
||
)}
|
||
{canReset ? (
|
||
<Popconfirm
|
||
title={t('重置该账号密码?')}
|
||
content={
|
||
managed
|
||
? t('将生成一次性临时密码,并要求首次登录改密')
|
||
: t(
|
||
'该成员为个人平台账号,重置后其平台登录密码同步失效,请将临时密码安全告知本人',
|
||
)
|
||
}
|
||
onConfirm={() => resetPassword(r)}
|
||
>
|
||
<Button type='link'>{t('重置密码')}</Button>
|
||
</Popconfirm>
|
||
) : (
|
||
<Tooltip content={t('个人平台账号,请由本人通过找回密码修改')}>
|
||
<Button type='link' disabled>
|
||
{t('重置密码')}
|
||
</Button>
|
||
</Tooltip>
|
||
)}
|
||
{r.status === 1 && r.role !== 'owner' && (
|
||
<Popconfirm
|
||
title={t('确认离职回收该成员?')}
|
||
content={t(
|
||
'将禁用其企业成员身份与全部企业 Token,保留历史,不删除用户',
|
||
)}
|
||
onConfirm={() => offboard(r.id)}
|
||
>
|
||
<Button type='link' danger>
|
||
{t('离职回收')}
|
||
</Button>
|
||
</Popconfirm>
|
||
)}
|
||
</OrgRowActions>
|
||
);
|
||
},
|
||
},
|
||
];
|
||
|
||
// 原型员工列表工具区:刷新 / 新建员工(主按钮)/ CSV 导入;回调不变
|
||
const actions = (
|
||
<>
|
||
<Button icon={<RefreshCw size={16} />} onClick={fetchAll}>
|
||
{t('刷新')}
|
||
</Button>
|
||
<Button
|
||
theme='solid'
|
||
icon={<UserPlus size={16} />}
|
||
onClick={() => setCreateVisible(true)}
|
||
>
|
||
{t('创建员工账号')}
|
||
</Button>
|
||
<Button
|
||
icon={<UploadIcon size={16} />}
|
||
onClick={() => {
|
||
setImportResult(null);
|
||
setImportFile(null);
|
||
setImportVisible(true);
|
||
}}
|
||
>
|
||
{t('CSV 导入')}
|
||
</Button>
|
||
</>
|
||
);
|
||
|
||
return (
|
||
<div className={embedded ? 'oc-member-accounts' : 'uc-page'}>
|
||
{!embedded && (
|
||
<OrgPageHeader
|
||
icon={IdCard}
|
||
title={t('员工账号')}
|
||
subtitle={t('集中管理员工登录账号')}
|
||
actions={actions}
|
||
/>
|
||
)}
|
||
|
||
{membersTotal > members.length && (
|
||
<Banner
|
||
type='warning'
|
||
closeIcon={null}
|
||
className='mb-3'
|
||
description={t(
|
||
'员工账号数量已达 100 条上限,当前仅显示前 100 条,请使用搜索定位具体成员。',
|
||
)}
|
||
/>
|
||
)}
|
||
{embedded ? (
|
||
<OrgListCard title={t('员工账号')} tools={actions}>
|
||
<Table
|
||
empty={<TableEmpty />}
|
||
columns={columns}
|
||
dataSource={members}
|
||
loading={loading}
|
||
pagination={{
|
||
pageSize: 15,
|
||
showSizeChanger: false,
|
||
showTotal: (n) => t('共 {{total}} 条', { total: n }),
|
||
}}
|
||
rowKey='id'
|
||
/>
|
||
</OrgListCard>
|
||
) : (
|
||
<OrgPanel padding='p-2'>
|
||
<Table
|
||
columns={columns}
|
||
dataSource={members}
|
||
loading={loading}
|
||
pagination={{ pageSize: 15, showSizeChanger: false }}
|
||
rowKey='id'
|
||
/>
|
||
</OrgPanel>
|
||
)}
|
||
|
||
{/* 创建账号 */}
|
||
<OrgModal
|
||
title={t('创建员工账号')}
|
||
visible={createVisible}
|
||
onOk={submitCreate}
|
||
onCancel={() => setCreateVisible(false)}
|
||
okText={t('创建')}
|
||
cancelText={t('取消')}
|
||
>
|
||
<Form getFormApi={setCreateFormApi}>
|
||
<Form.Input
|
||
field='login_name'
|
||
label={t('企业内登录名')}
|
||
placeholder={t('企业内唯一,如 zhangsan')}
|
||
rules={[
|
||
{
|
||
// 与后端一致按码点计数;不用 maxLength 静默截断,让用户明确看到超长提醒
|
||
validator: (rule, value) =>
|
||
!value || Array.from(value.trim()).length <= 64,
|
||
message: t('登录名不能超过 64 个字符'),
|
||
},
|
||
]}
|
||
/>
|
||
<Form.Input field='display_name' label={t('姓名/显示名')} />
|
||
<Form.Input
|
||
field='email'
|
||
label={t('邮箱(可选)')}
|
||
placeholder={t('已被平台用户使用的邮箱不可填写,可留空')}
|
||
rules={[
|
||
{
|
||
pattern: /^[^\s@]+@[^\s@]+\.[^\s@]+$/,
|
||
message: t('邮箱格式不正确'),
|
||
},
|
||
]}
|
||
/>
|
||
<Form.Input
|
||
field='employee_no'
|
||
label={t('工号(可选)')}
|
||
rules={[
|
||
{
|
||
validator: (rule, value) =>
|
||
!value || Array.from(value.trim()).length <= 64,
|
||
message: t('工号不能超过 64 个字符'),
|
||
},
|
||
]}
|
||
/>
|
||
{deptEnabled && (
|
||
<Form.TreeSelect
|
||
field='department_id'
|
||
label={t('主部门')}
|
||
treeData={deptTreeData}
|
||
showClear
|
||
filterTreeNode
|
||
showFilteredOnly
|
||
expandAll
|
||
placeholder={t('未分配')}
|
||
style={{ width: '100%' }}
|
||
/>
|
||
)}
|
||
</Form>
|
||
</OrgModal>
|
||
|
||
{/* 一次性密码结果 */}
|
||
<OrgModal
|
||
title={pwdResult?.reset ? t('密码已重置') : t('账号已创建')}
|
||
visible={!!pwdResult}
|
||
onCancel={() => setPwdResult(null)}
|
||
footer={
|
||
<Button theme='solid' onClick={() => setPwdResult(null)}>
|
||
{t('我已记录')}
|
||
</Button>
|
||
}
|
||
>
|
||
<Banner
|
||
type='warning'
|
||
closeIcon={null}
|
||
description={t(
|
||
'初始密码仅显示这一次,请立即复制并安全分发给员工。关闭后无法再次查看。',
|
||
)}
|
||
className='mb-3'
|
||
/>
|
||
{pwdResult?.username ? (
|
||
<div className='mb-2'>
|
||
<Text type='tertiary'>{t('系统用户名')}: </Text>
|
||
<Text copyable>{pwdResult.username}</Text>
|
||
</div>
|
||
) : null}
|
||
{pwdResult?.login_name ? (
|
||
<div className='mb-2'>
|
||
<Text type='tertiary'>{t('企业内登录名')}: </Text>
|
||
<Text copyable>{pwdResult.login_name}</Text>
|
||
</div>
|
||
) : null}
|
||
{pwdResult?.login_name_global_collision ? (
|
||
<Banner
|
||
type='info'
|
||
closeIcon={null}
|
||
description={t(
|
||
'提示:该登录名在其他企业也存在。若已开启「免企业标识直接登录」,该员工登录时可能需要从多个企业中选择。可考虑使用更唯一的登录名(如加工号)。',
|
||
)}
|
||
className='mb-3'
|
||
/>
|
||
) : null}
|
||
<div>
|
||
<Text type='tertiary'>{t('初始密码')}: </Text>
|
||
<Text copyable strong>
|
||
{pwdResult?.initial_password}
|
||
</Text>
|
||
</div>
|
||
</OrgModal>
|
||
|
||
{/* 分配部门 */}
|
||
<OrgModal
|
||
title={`${t('分配部门')} - ${deptAssignFor?.display_name || deptAssignFor?.username || ''}`}
|
||
visible={!!deptAssignFor}
|
||
onOk={assignDept}
|
||
onCancel={() => setDeptAssignFor(null)}
|
||
okText={t('保存')}
|
||
cancelText={t('取消')}
|
||
>
|
||
{assignCurrentDeptBlocked && (
|
||
<Banner
|
||
type='info'
|
||
closeIcon={null}
|
||
className='mb-3'
|
||
description={t(
|
||
'该成员当前归属的部门已停用或已有下级部门,建议迁移到具体的末级部门。',
|
||
)}
|
||
/>
|
||
)}
|
||
<DeptTreeSelect
|
||
depts={depts}
|
||
value={deptAssignVal}
|
||
onChange={setDeptAssignVal}
|
||
/>
|
||
</OrgModal>
|
||
|
||
{/* CSV 导入 */}
|
||
<OrgModal
|
||
title={t('CSV 批量导入')}
|
||
visible={importVisible}
|
||
onOk={importResult ? () => setImportVisible(false) : submitImport}
|
||
onCancel={() => setImportVisible(false)}
|
||
okText={importResult ? t('完成') : t('开始导入')}
|
||
cancelText={t('取消')}
|
||
width={620}
|
||
>
|
||
{!importResult ? (
|
||
<>
|
||
<Banner
|
||
type='info'
|
||
closeIcon={null}
|
||
className='mb-3'
|
||
description={t(
|
||
'表头需含 login_name,display_name,email,employee_no(login_name 必填,不超过 64 个字符)。单次最多 500 行。每个账号返回一次性初始密码。',
|
||
)}
|
||
/>
|
||
<input
|
||
type='file'
|
||
accept='.csv'
|
||
onChange={(e) => setImportFile(e.target.files?.[0] || null)}
|
||
/>
|
||
</>
|
||
) : (
|
||
<>
|
||
<Banner
|
||
type={importResult.failed > 0 ? 'warning' : 'success'}
|
||
closeIcon={null}
|
||
className='mb-3'
|
||
description={t(
|
||
'成功 {{success}} · 失败 {{failed}} / 共 {{total}}',
|
||
{
|
||
success: importResult.success,
|
||
failed: importResult.failed,
|
||
total: importResult.total,
|
||
},
|
||
)}
|
||
/>
|
||
<Table
|
||
size='small'
|
||
pagination={false}
|
||
rowKey={(r) => `${r.row}`}
|
||
dataSource={importResult.details || []}
|
||
columns={[
|
||
{ title: t('行'), dataIndex: 'row', width: 50 },
|
||
{ title: t('登录名'), dataIndex: 'login_name' },
|
||
{
|
||
title: t('结果'),
|
||
render: (_, r) =>
|
||
r.success ? (
|
||
<span>
|
||
<Tag color='green' size='small'>
|
||
{t('成功')}
|
||
</Tag>{' '}
|
||
<Text
|
||
size='small'
|
||
copyable={{ text: r.initial_password }}
|
||
>
|
||
{t('初始密码')}
|
||
</Text>
|
||
</span>
|
||
) : (
|
||
<Tooltipless error={formatImportError(t, r)} t={t} />
|
||
),
|
||
},
|
||
]}
|
||
/>
|
||
<Text type='tertiary' size='small'>
|
||
{t('初始密码仅此一次,请及时导出/分发。')}
|
||
</Text>
|
||
</>
|
||
)}
|
||
</OrgModal>
|
||
</div>
|
||
);
|
||
};
|
||
|
||
// 简单错误展示(避免引入额外组件)
|
||
const Tooltipless = ({ error, t }) => (
|
||
<span>
|
||
<Tag color='red' size='small'>
|
||
{t('失败')}
|
||
</Tag>{' '}
|
||
<Text type='danger' size='small'>
|
||
{error}
|
||
</Text>
|
||
</span>
|
||
);
|
||
|
||
export default OrgMemberAccounts;
|