setEarlyWarningsAccount.tsx 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { useAjax } from "@/Hook/useAjax"
  2. import { configRuleAccountApi } from "@/services/adMonitor/adMonitor"
  3. import { getSysWarningRuleListApi } from "@/services/adMonitor/earlyWarning"
  4. import { AlertOutlined } from "@ant-design/icons"
  5. import { Button, Form, message, Modal, Select } from "antd"
  6. import React, { useState } from "react"
  7. interface Props {
  8. accountIds: any
  9. onChange?: () => void
  10. }
  11. const SetEarlyWarningsAccount: React.FC<Props> = (props) => {
  12. /******************************/
  13. const { accountIds, onChange } = props
  14. const [visible, setVisible] = useState<boolean>(false)
  15. const [form] = Form.useForm();
  16. const getSysWarningRuleList = useAjax((params) => getSysWarningRuleListApi(params))
  17. const configRuleAccount = useAjax((params) => configRuleAccountApi(params), { formatResult: true })
  18. /******************************/
  19. const openModal = () => {
  20. setVisible(true)
  21. getSysWarningRuleList.run()
  22. }
  23. const handleOk = () => {
  24. form.validateFields().then(values => {
  25. configRuleAccount.run({ accountIds, ruleId: values.ruleId }).then(res => {
  26. console.log(res)
  27. if (res?.data) {
  28. message.success('设置成功')
  29. onChange?.()
  30. setVisible(false)
  31. }
  32. })
  33. })
  34. }
  35. return <>
  36. <Button icon={<AlertOutlined />} style={{ padding: 0, color: 'red' }} type="link" onClick={openModal}>设置预警</Button>
  37. {visible && <Modal
  38. open={visible}
  39. title="预警设置"
  40. onOk={handleOk}
  41. confirmLoading={configRuleAccount.loading}
  42. onCancel={() => setVisible(false)}
  43. >
  44. <Form
  45. form={form}
  46. labelCol={{ span: 5 }}
  47. colon={false}
  48. initialValues={{
  49. }}
  50. >
  51. <Form.Item name="ruleId" label={<strong>选择预警规则</strong>} rules={[{ required: true, message: '请选择预警规则' }]}>
  52. <Select
  53. showSearch
  54. allowClear
  55. placeholder="选择预警规则"
  56. filterOption={(input, option) =>
  57. ((option?.label ?? '') as any).toLowerCase().includes(input.toLowerCase())
  58. }
  59. >
  60. {getSysWarningRuleList?.data?.filter((item: any) => !item?.defaultRule)?.map((item: any) => <Select.Option value={item.id} key={item.id}>{item.ruleName}</Select.Option>)}
  61. </Select>
  62. </Form.Item>
  63. </Form>
  64. </Modal>}
  65. </>
  66. }
  67. export default React.memo(SetEarlyWarningsAccount)