forked from wangziqi/gongxue-base
refactor: remove sync and mark-staff buttons from Users page
This commit is contained in:
@@ -10,9 +10,8 @@ import {
|
||||
Tag,
|
||||
Popconfirm,
|
||||
message,
|
||||
TreeSelect,
|
||||
} from 'antd';
|
||||
import { PlusOutlined, EditOutlined, DeleteOutlined, KeyOutlined, IdcardOutlined, CloudDownloadOutlined, InboxOutlined } from '@ant-design/icons';
|
||||
import { PlusOutlined, EditOutlined, DeleteOutlined, KeyOutlined, IdcardOutlined, InboxOutlined } from '@ant-design/icons';
|
||||
import dayjs from 'dayjs';
|
||||
import api from '../../api';
|
||||
import PermissionButton from '../../components/PermissionButton';
|
||||
@@ -30,27 +29,9 @@ const UsersPage: React.FC = () => {
|
||||
const [profileForm] = Form.useForm();
|
||||
const [form] = Form.useForm();
|
||||
const [pwdForm] = Form.useForm();
|
||||
const [syncing, setSyncing] = useState(false);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [showArchived, setShowArchived] = useState(false);
|
||||
// 组织树同步
|
||||
const [syncDeptId, setSyncDeptId] = useState<number | undefined>(undefined);
|
||||
const [orgTree, setOrgTree] = useState<Array<{ title: string; value: number; children?: Array<{ title: string; value: number; children?: unknown[] }> }>>([]);
|
||||
|
||||
const loadOrgTree = async () => {
|
||||
try {
|
||||
const res = await api.get<{ success: boolean; data: Array<{ id: number; name: string; children: Array<{ id: number; name: string; children: unknown[] }> }> }>('/sync/dingtalk/org-tree');
|
||||
const toTreeNode = (nodes: Array<{ id: number; name: string; children: unknown[] }>): Array<{ title: string; value: number; children?: unknown[] }> =>
|
||||
nodes.map((n) => ({
|
||||
title: n.name,
|
||||
value: n.id,
|
||||
children: n.children?.length > 0 ? toTreeNode(n.children as Array<{ id: number; name: string; children: unknown[] }>) : undefined,
|
||||
}));
|
||||
setOrgTree(toTreeNode(res.data));
|
||||
} catch {
|
||||
// org tree may not be available
|
||||
}
|
||||
};
|
||||
|
||||
const handleOpenProfile = async (record: any) => {
|
||||
setProfileUser(record);
|
||||
@@ -93,24 +74,6 @@ const UsersPage: React.FC = () => {
|
||||
setLoading(false);
|
||||
}, [showArchived]);
|
||||
|
||||
const handleSyncDingTalk = async () => {
|
||||
setSyncing(true);
|
||||
try {
|
||||
const params: Record<string, string> = {};
|
||||
if (syncDeptId) params.rootDeptId = String(syncDeptId);
|
||||
const res = await api.post('/sync/trigger?platform=dingtalk', undefined as unknown as null, { params }) as {
|
||||
synced: number; logs: Array<{ recordsCount?: number }>;
|
||||
};
|
||||
const log = res.logs?.[0];
|
||||
message.success(`同步完成:${log?.recordsCount || 0} 条记录`);
|
||||
fetchData();
|
||||
} catch (e: unknown) {
|
||||
const err = e as { message?: string };
|
||||
message.error(err?.message || '同步失败');
|
||||
} finally {
|
||||
setSyncing(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
@@ -184,16 +147,6 @@ const UsersPage: React.FC = () => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleMarkStaff = async (id: number, toStaff: boolean) => {
|
||||
try {
|
||||
await api.put(`/rbac/users/${id}/${toStaff ? 'mark-staff' : 'mark-student'}`);
|
||||
message.success(toStaff ? '已标记为教职工' : '已恢复为学员');
|
||||
fetchData();
|
||||
} catch (e: unknown) {
|
||||
const err = e as { message?: string };
|
||||
message.error(err?.message || '操作失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleResetPwd = (record: any) => {
|
||||
setResetTarget(record);
|
||||
@@ -255,7 +208,7 @@ const UsersPage: React.FC = () => {
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 320,
|
||||
width: 240,
|
||||
fixed: 'right' as const,
|
||||
render: (_: unknown, record: any) => (
|
||||
<Space>
|
||||
@@ -295,16 +248,6 @@ const UsersPage: React.FC = () => {
|
||||
<PermissionButton permission="user:edit" type="link" size="small">归档</PermissionButton>
|
||||
</Popconfirm>
|
||||
)}
|
||||
{record.studentStatus === 'active' && (
|
||||
<Popconfirm title="确认标记为教职工?" onConfirm={() => handleMarkStaff(record.id, true)}>
|
||||
<PermissionButton permission="user:edit" type="link" size="small">标记教职工</PermissionButton>
|
||||
</Popconfirm>
|
||||
)}
|
||||
{record.studentStatus === 'staff' && (
|
||||
<Popconfirm title="确认恢复为学员?" onConfirm={() => handleMarkStaff(record.id, false)}>
|
||||
<PermissionButton permission="user:edit" type="link" size="small">恢复学员</PermissionButton>
|
||||
</Popconfirm>
|
||||
)}
|
||||
{record.username !== 'admin' && (
|
||||
<Popconfirm title="确认删除?需先归档" onConfirm={() => handleDelete(record.id)}>
|
||||
<PermissionButton permission="user:delete" type="link" size="small" danger icon={<DeleteOutlined />}>
|
||||
@@ -330,16 +273,6 @@ const UsersPage: React.FC = () => {
|
||||
}}>
|
||||
<h2 style={{ margin: 0 }}>账号管理</h2>
|
||||
<Space wrap>
|
||||
<TreeSelect
|
||||
treeData={orgTree}
|
||||
value={syncDeptId}
|
||||
onChange={(v) => setSyncDeptId(v)}
|
||||
placeholder="选择同步部门(不选=全部)"
|
||||
allowClear
|
||||
treeDefaultExpandAll
|
||||
style={{ minWidth: 260 }}
|
||||
onDropdownVisibleChange={(open) => { if (open) loadOrgTree(); }}
|
||||
/>
|
||||
<PermissionButton
|
||||
permission="user:create"
|
||||
type="primary"
|
||||
@@ -348,14 +281,6 @@ const UsersPage: React.FC = () => {
|
||||
>
|
||||
新增账号
|
||||
</PermissionButton>
|
||||
<PermissionButton
|
||||
permission="sync:trigger"
|
||||
icon={<CloudDownloadOutlined />}
|
||||
loading={syncing}
|
||||
onClick={handleSyncDingTalk}
|
||||
>
|
||||
同步钉钉用户
|
||||
</PermissionButton>
|
||||
<span style={{ marginLeft: 8 }}>
|
||||
<InboxOutlined style={{ marginRight: 4 }} />
|
||||
归档
|
||||
|
||||
Reference in New Issue
Block a user