stream.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /**
  2. * 必须要兼容,手动输入,以及选择负载均衡名字
  3. * @author tuonian
  4. * @date 2023/7/4
  5. */
  6. import {AutoTypeInputProps, AdvanceInputConfigs} from "auto-antd";
  7. import {Button, Input, Popover, Select} from "antd";
  8. import {useAppSelector} from "../../../../store";
  9. import {ChangeEvent, useEffect, useMemo, useState} from "react";
  10. import {EditOutlined} from "@ant-design/icons";
  11. import './index.less'
  12. export const StreamProxyPassInput = ({value, onChange}: AutoTypeInputProps)=>{
  13. const upstreamServer = useAppSelector(state => state.nginx.streamUpstream);
  14. const [data,setData] = useState<string>()
  15. const options = useMemo(()=>{
  16. let list:any[] = []
  17. if (upstreamServer?.upstreams){
  18. list = upstreamServer.upstreams.map(item=>{
  19. return {
  20. label: item.name,
  21. value: item.name
  22. }
  23. })
  24. }
  25. return list
  26. },[upstreamServer])
  27. useEffect(()=>{
  28. setData(value)
  29. },[value])
  30. const onSelectUpstream = (v?:string)=>{
  31. if (v){
  32. setData(v)
  33. onChange?.(v)
  34. }
  35. }
  36. const onUserInput = (e:ChangeEvent<any>)=>{
  37. setData(e.currentTarget.value)
  38. onChange?.(e.currentTarget.value)
  39. }
  40. const renderInput = ()=>{
  41. return (<div className="proxy-pass-popover">
  42. <Input placeholder="输入后端服务的IP:PORT或者复制均衡名称" value={data} onChange={onUserInput} />
  43. <Select onChange={onSelectUpstream}
  44. placeholder="选择负载均衡"
  45. allowClear
  46. className="upstream-select"
  47. options={options} />
  48. </div>)
  49. }
  50. return (<>
  51. {data}
  52. <Popover trigger="click" destroyTooltipOnHide content={renderInput}>
  53. <Button type="link" icon={<EditOutlined />} />
  54. </Popover>
  55. </>)
  56. }
  57. AdvanceInputConfigs['stream_proxy_pass'] = StreamProxyPassInput