diff --git a/web/src/admin/pages/Agents/BatchVisibilityModal.tsx b/web/src/admin/pages/Agents/BatchVisibilityModal.tsx new file mode 100644 index 0000000..dffcf85 --- /dev/null +++ b/web/src/admin/pages/Agents/BatchVisibilityModal.tsx @@ -0,0 +1,90 @@ +import {useState} from 'react'; +import {App, Form, Modal, Radio} from 'antd'; +import {useMutation, useQueryClient} from '@tanstack/react-query'; +import {batchUpdateAgentVisibility} from '@/api/agent.ts'; +import {getErrorMessage} from '@/lib/utils'; + +interface BatchVisibilityModalProps { + open: boolean; + agentIds: string[]; + onCancel: () => void; + onSuccess: () => void; +} + +const BatchVisibilityModal = ({open, agentIds, onCancel, onSuccess}: BatchVisibilityModalProps) => { + const {message: messageApi} = App.useApp(); + const queryClient = useQueryClient(); + const [form] = Form.useForm(); + const [loading, setLoading] = useState(false); + + const updateMutation = useMutation({ + mutationFn: (data: { agentIds: string[]; visibility: string }) => + batchUpdateAgentVisibility(data.agentIds, data.visibility), + onSuccess: () => { + messageApi.success('批量修改可见性成功'); + queryClient.invalidateQueries({queryKey: ['admin', 'agents']}); + form.resetFields(); + onSuccess(); + }, + onError: (error: unknown) => { + messageApi.error(getErrorMessage(error, '批量修改可见性失败')); + }, + }); + + const handleOk = async () => { + try { + setLoading(true); + const values = await form.validateFields(); + await updateMutation.mutateAsync({ + agentIds, + visibility: values.visibility, + }); + } catch (error) { + console.error('表单验证失败:', error); + } finally { + setLoading(false); + } + }; + + const handleCancel = () => { + form.resetFields(); + onCancel(); + }; + + return ( + +
+ + + 匿名可见 + 登录可见 + + +
+

• 匿名可见:未登录用户也可以查看探针信息

+

• 登录可见:仅登录用户可以查看探针信息

+
+
+
+ ); +}; + +export default BatchVisibilityModal;