image.png

    1. import React, { useState } from 'react';
    2. import { PageContainer } from '@ant-design/pro-components';
    3. import { Alert, Card, Col, Row } from 'antd';
    4. import { FormGroup } from '@/components';
    5. import { generatePassword } from '@/utils'
    6. import List from './List'
    7. const initialValues = {
    8. ignore: 'iIl1o0O',
    9. length: 6,
    10. type: [1, 2, 3],
    11. total: 1,
    12. };
    13. const GeneratePassword: React.FC = () => {
    14. const [state, setState] = useState([]);
    15. const fields = [
    16. {
    17. name: 'type',
    18. label: '密码格式',
    19. component: 'CheckboxGroup',
    20. props: {
    21. options: [
    22. { label: '大写字母 [A-Z]', value: 1 },
    23. { label: '小写字母 [a-z]', value: 2 },
    24. { label: '数字 [0-9]', value: 3 },
    25. ],
    26. },
    27. },
    28. {
    29. name: 'ignore',
    30. label: '排除字符',
    31. component: 'Input',
    32. props: {},
    33. },
    34. {
    35. label: ' ',
    36. colon: false,
    37. component: 'Title',
    38. // noStyle: true,
    39. props: { children: '密码强度', level: 5 },
    40. },
    41. {
    42. name: 'length',
    43. label: '密码长度',
    44. component: 'Slider',
    45. props: {
    46. min: 4,
    47. max: 128,
    48. step: 2,
    49. marks: {
    50. 6: 6,
    51. 24: 24,
    52. 48: 48,
    53. 80: 80,
    54. 128: 128,
    55. }
    56. },
    57. },
    58. {
    59. name: 'total',
    60. label: '密码数量',
    61. component: 'InputNumber',
    62. props: {
    63. defaultValue: 1,
    64. },
    65. },
    66. ];
    67. function onFinish(values) {
    68. const passwords = generatePassword(values);
    69. setState(passwords);
    70. console.log(60, values);
    71. }
    72. return (
    73. <PageContainer>
    74. <Card bordered={false}>
    75. <FormGroup
    76. initialValues={initialValues}
    77. fields={fields}
    78. col={24}
    79. style={{ width: '50%' }}
    80. okButtonProps={{
    81. children: '生成密码',
    82. }}
    83. cancelButtonProps={{ danger: true }}
    84. confirmLoading={false}
    85. onFinish={onFinish}
    86. onReset={() => setState([])}
    87. mode='submit'
    88. />
    89. </Card>
    90. </PageContainer>
    91. );
    92. };
    93. export default GeneratePassword;