feat(weibo): 支持管理员强制转入工作台且不影响原使用人
This commit is contained in:
@@ -826,6 +826,7 @@ export interface WeiboWorkbenchBatchImportItem {
|
||||
identifier: string;
|
||||
status:
|
||||
| 'added'
|
||||
| 'forced_added'
|
||||
| 'already_added'
|
||||
| 'not_found'
|
||||
| 'ambiguous'
|
||||
@@ -836,11 +837,14 @@ export interface WeiboWorkbenchBatchImportItem {
|
||||
account_id: number | null;
|
||||
uid: string;
|
||||
nickname: string;
|
||||
occupied_by_user_id: number | null;
|
||||
occupied_by_username: string;
|
||||
}
|
||||
|
||||
export interface WeiboWorkbenchBatchImportResult {
|
||||
requested: number;
|
||||
added: number;
|
||||
forced_added: number;
|
||||
already_added: number;
|
||||
failed: number;
|
||||
account_ids: number[];
|
||||
|
||||
@@ -124,10 +124,10 @@ export const weiboApi = {
|
||||
'/weibo/workbench/accounts',
|
||||
{ account_ids: accountIds },
|
||||
),
|
||||
batchImportWorkbenchAccounts: (text: string) =>
|
||||
batchImportWorkbenchAccounts: (text: string, forceAddOccupied = false) =>
|
||||
api.post<WeiboWorkbenchBatchImportResult, WeiboWorkbenchBatchImportResult>(
|
||||
'/weibo/workbench/accounts/batch-import',
|
||||
{ text },
|
||||
{ text, force_add_occupied: forceAddOccupied },
|
||||
),
|
||||
transferWorkbenchToCollab: (accountId: number) =>
|
||||
api.post<
|
||||
|
||||
@@ -83,6 +83,7 @@ const WORKBENCH_IMPORT_STATUS: Record<
|
||||
{ label: string; color: string }
|
||||
> = {
|
||||
added: { label: '已导入', color: 'success' },
|
||||
forced_added: { label: '强制转入', color: 'orange' },
|
||||
already_added: { label: '已存在', color: 'blue' },
|
||||
not_found: { label: '未找到', color: 'error' },
|
||||
ambiguous: { label: '重名', color: 'warning' },
|
||||
@@ -161,8 +162,9 @@ export default function WeiboAccountsPage({
|
||||
mode?: WeiboAccountsPageMode;
|
||||
}) {
|
||||
const { token } = theme.useToken();
|
||||
const { can } = usePermissions();
|
||||
const { can, user } = usePermissions();
|
||||
const navigate = useNavigate();
|
||||
const isSuperAdmin = user?.role === 'super_admin';
|
||||
const isWorkbench = mode === 'workbench';
|
||||
const canImport = can('weibo:import');
|
||||
const canManage = can('weibo:manage');
|
||||
@@ -206,6 +208,7 @@ export default function WeiboAccountsPage({
|
||||
'paste',
|
||||
);
|
||||
const [batchImportText, setBatchImportText] = useState('');
|
||||
const [forceAddOccupied, setForceAddOccupied] = useState(false);
|
||||
const [batchImportLoading, setBatchImportLoading] = useState(false);
|
||||
const [batchImportResult, setBatchImportResult] =
|
||||
useState<WeiboWorkbenchBatchImportResult | null>(null);
|
||||
@@ -400,6 +403,7 @@ export default function WeiboAccountsPage({
|
||||
setPoolSelectedIds([]);
|
||||
setWorkbenchImportTab('paste');
|
||||
setBatchImportText('');
|
||||
setForceAddOccupied(isSuperAdmin);
|
||||
setBatchImportResult(null);
|
||||
setPoolOpen(true);
|
||||
void loadWorkbenchPool(1, poolPageSize, '');
|
||||
@@ -414,17 +418,24 @@ export default function WeiboAccountsPage({
|
||||
setBatchImportLoading(true);
|
||||
setBatchImportResult(null);
|
||||
try {
|
||||
const result = await weiboApi.batchImportWorkbenchAccounts(text);
|
||||
const result = await weiboApi.batchImportWorkbenchAccounts(
|
||||
text,
|
||||
isSuperAdmin && forceAddOccupied,
|
||||
);
|
||||
setBatchImportResult(result);
|
||||
await loadAccounts();
|
||||
await loadKnownTags();
|
||||
const forceAddSummary =
|
||||
result.forced_added > 0
|
||||
? `,强制转入 ${result.forced_added} 个`
|
||||
: '';
|
||||
if (result.failed > 0) {
|
||||
message.warning(
|
||||
`批量导入完成:新增 ${result.added} 个,已存在 ${result.already_added} 个,失败 ${result.failed} 个`,
|
||||
`批量导入完成:新增 ${result.added} 个${forceAddSummary},已存在 ${result.already_added} 个,失败 ${result.failed} 个`,
|
||||
);
|
||||
} else {
|
||||
message.success(
|
||||
`批量导入完成:新增 ${result.added} 个,已存在 ${result.already_added} 个`,
|
||||
`批量导入完成:新增 ${result.added} 个${forceAddSummary},已存在 ${result.already_added} 个`,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -2589,6 +2600,16 @@ export default function WeiboAccountsPage({
|
||||
title="支持多行、空格、逗号分隔"
|
||||
description="优先按 UID 精确匹配;也支持微博用户名和角色名。重名时请改用 UID。"
|
||||
/>
|
||||
{isSuperAdmin && (
|
||||
<Checkbox
|
||||
checked={forceAddOccupied}
|
||||
onChange={(event) =>
|
||||
setForceAddOccupied(event.target.checked)
|
||||
}
|
||||
>
|
||||
其他人的工作台占用时,强制转入当前工作台(不影响原使用人)
|
||||
</Checkbox>
|
||||
)}
|
||||
<TextArea
|
||||
rows={8}
|
||||
value={batchImportText}
|
||||
@@ -2606,7 +2627,7 @@ export default function WeiboAccountsPage({
|
||||
<Alert
|
||||
type={batchImportResult.failed > 0 ? 'warning' : 'success'}
|
||||
showIcon
|
||||
title={`解析 ${batchImportResult.requested} 项:新增 ${batchImportResult.added},已存在 ${batchImportResult.already_added},失败 ${batchImportResult.failed}`}
|
||||
title={`解析 ${batchImportResult.requested} 项:新增 ${batchImportResult.added},强制转入 ${batchImportResult.forced_added},已存在 ${batchImportResult.already_added},失败 ${batchImportResult.failed}`}
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
|
||||
Reference in New Issue
Block a user