shadowsocks.tsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { useTranslation } from 'react-i18next';
  2. import { Button, Form, Input, Select, Space, Switch, type FormInstance } from 'antd';
  3. import { ReloadOutlined } from '@ant-design/icons';
  4. import { RandomUtil } from '@/utils';
  5. import { SSMethodSchema } from '@/schemas/protocols/shared/shadowsocks';
  6. import type { InboundFormValues } from '@/schemas/forms/inbound-form';
  7. interface ShadowsocksFieldsProps {
  8. form: FormInstance<InboundFormValues>;
  9. isSSWith2022: boolean;
  10. }
  11. export default function ShadowsocksFields({ form, isSSWith2022 }: ShadowsocksFieldsProps) {
  12. const { t } = useTranslation();
  13. return (
  14. <>
  15. <Form.Item name={['settings', 'method']} label={t('pages.inbounds.form.encryptionMethod')}>
  16. <Select
  17. onChange={(v) => {
  18. form.setFieldValue(
  19. ['settings', 'password'],
  20. RandomUtil.randomShadowsocksPassword(v as string),
  21. );
  22. }}
  23. options={SSMethodSchema.options.map((m) => ({ value: m, label: m }))}
  24. />
  25. </Form.Item>
  26. {isSSWith2022 && (
  27. <Form.Item label={t('password')}>
  28. <Space.Compact block>
  29. <Form.Item name={['settings', 'password']} noStyle>
  30. <Input style={{ width: 'calc(100% - 32px)' }} />
  31. </Form.Item>
  32. <Button
  33. icon={<ReloadOutlined />}
  34. onClick={() => {
  35. const method = form.getFieldValue(['settings', 'method']);
  36. form.setFieldValue(
  37. ['settings', 'password'],
  38. RandomUtil.randomShadowsocksPassword(method as string),
  39. );
  40. }}
  41. />
  42. </Space.Compact>
  43. </Form.Item>
  44. )}
  45. <Form.Item name={['settings', 'network']} label={t('pages.inbounds.network')}>
  46. <Select
  47. style={{ width: 120 }}
  48. options={[
  49. { value: 'tcp,udp', label: 'TCP, UDP' },
  50. { value: 'tcp', label: 'TCP' },
  51. { value: 'udp', label: 'UDP' },
  52. ]}
  53. />
  54. </Form.Item>
  55. <Form.Item
  56. name={['settings', 'ivCheck']}
  57. label="ivCheck"
  58. valuePropName="checked"
  59. >
  60. <Switch />
  61. </Form.Item>
  62. </>
  63. );
  64. }