index.tsx 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import { Input, InputNumber } from 'antd';
  2. import { useEffect, useState } from 'react';
  3. interface SipComponentProps {
  4. onChange?: (data: any) => void;
  5. value?: {
  6. host?: string;
  7. port?: number;
  8. };
  9. }
  10. const SipComponent = (props: SipComponentProps) => {
  11. const { value, onChange } = props;
  12. const [data, setData] = useState<{ host?: string; port?: number } | undefined>(value);
  13. useEffect(() => {
  14. setData(value);
  15. }, [value]);
  16. return (
  17. <div style={{ display: 'flex', alignItems: 'center' }}>
  18. <Input
  19. onChange={(e) => {
  20. if (onChange) {
  21. const item = {
  22. ...data,
  23. host: e.target.value,
  24. };
  25. setData(item);
  26. onChange(item);
  27. }
  28. }}
  29. value={data?.host}
  30. style={{ marginRight: 10 }}
  31. placeholder="请输入IP地址"
  32. />
  33. <InputNumber
  34. style={{ minWidth: 100 }}
  35. value={data?.port}
  36. placeholder="请输入端口"
  37. min={1}
  38. max={65535}
  39. onChange={(e: number) => {
  40. if (onChange) {
  41. const item = {
  42. ...data,
  43. port: e,
  44. };
  45. setData(item);
  46. onChange(item);
  47. }
  48. }}
  49. />
  50. </div>
  51. );
  52. };
  53. export default SipComponent;