登录表单

image.png

antd form

antd 组件实现的登录表单

  1. import React from 'react'
  2. import { Button, Checkbox, Form, Input } from 'antd';
  3. const { Item } = Form;
  4. function LoginForm(props) {
  5. const onFinish = (values) => {
  6. console.log('Success:', values);
  7. };
  8. const onFinishFailed = (errorInfo) => {
  9. console.log('Failed:', errorInfo);
  10. };
  11. return (
  12. <Form
  13. name="loginForm"
  14. labelCol={{ span: 8 }}
  15. wrapperCol={{ span: 16 }}
  16. initialValues={{ remember: true }}
  17. onFinish={onFinish}
  18. onFinishFailed={onFinishFailed}
  19. autoComplete="off"
  20. >
  21. <Item
  22. label="用户名"
  23. name="username"
  24. rules={[{ required: true, message: '请输入用户名!' }]}
  25. >
  26. <Input />
  27. </Item>
  28. <Item
  29. label="密码"
  30. name="password"
  31. rules={[{ required: true, message: '请输入密码!' }]}
  32. >
  33. <Input.Password />
  34. </Item>
  35. <Item
  36. name="remember"
  37. valuePropName="checked"
  38. wrapperCol={{ offset: 8, span: 16 }}
  39. >
  40. <Checkbox>一周内免登陆</Checkbox>
  41. </Item>
  42. <Item wrapperCol={{ offset: 8, span: 16 }}>
  43. <Button type="primary" htmlType="submit">
  44. 提交
  45. </Button>
  46. </Item>
  47. </Form>
  48. );
  49. }
  50. export default LoginForm;

antd form 渲染的 html

  1. <form
  2. id="basic"
  3. autocomplete="off"
  4. class="ant-form ant-form-horizontal"
  5. >
  6. <div class="ant-form-item">
  7. <div class="ant-row ant-form-item-row">
  8. <div class="ant-col ant-col-8 ant-form-item-label">
  9. <label
  10. for="basic_username"
  11. class="ant-form-item-required"
  12. title="Username"
  13. >用户名</label
  14. >
  15. </div>
  16. <div class="ant-col ant-col-16 ant-form-item-control">
  17. <div class="ant-form-item-control-input">
  18. <div class="ant-form-item-control-input-content">
  19. <input
  20. id="basic_username"
  21. aria-required="true"
  22. class="ant-input"
  23. type="text"
  24. value=""
  25. />
  26. </div>
  27. </div>
  28. </div>
  29. </div>
  30. </div>
  31. <div class="ant-form-item">
  32. <div class="ant-row ant-form-item-row">
  33. <div class="ant-col ant-col-8 ant-form-item-label">
  34. <label
  35. for="basic_password"
  36. class="ant-form-item-required"
  37. title="Password"
  38. >密码</label
  39. >
  40. </div>
  41. <div class="ant-col ant-col-16 ant-form-item-control">
  42. <div class="ant-form-item-control-input">
  43. <div class="ant-form-item-control-input-content">
  44. <span class="ant-input-affix-wrapper ant-input-password"
  45. ><input
  46. id="basic_password"
  47. aria-required="true"
  48. type="password"
  49. class="ant-input" /><span class="ant-input-suffix"
  50. ><span
  51. role="img"
  52. aria-label="eye-invisible"
  53. tabindex="-1"
  54. class="anticon anticon-eye-invisible ant-input-password-icon"
  55. ><svg
  56. viewBox="64 64 896 896"
  57. focusable="false"
  58. data-icon="eye-invisible"
  59. width="1em"
  60. height="1em"
  61. fill="currentColor"
  62. aria-hidden="true"
  63. >
  64. <path
  65. d="M942.2 486.2Q889.47 375.11 816.7 305l-50.88 50.88C807.31 395.53 843.45 447.4 874.7 512 791.5 684.2 673.4 766 512 766q-72.67 0-133.87-22.38L323 798.75Q408 838 512 838q288.3 0 430.2-300.3a60.29 60.29 0 000-51.5zm-63.57-320.64L836 122.88a8 8 0 00-11.32 0L715.31 232.2Q624.86 186 512 186q-288.3 0-430.2 300.3a60.3 60.3 0 000 51.5q56.69 119.4 136.5 191.41L112.48 835a8 8 0 000 11.31L155.17 889a8 8 0 0011.31 0l712.15-712.12a8 8 0 000-11.32zM149.3 512C232.6 339.8 350.7 258 512 258c54.54 0 104.13 9.36 149.12 28.39l-70.3 70.3a176 176 0 00-238.13 238.13l-83.42 83.42C223.1 637.49 183.3 582.28 149.3 512zm246.7 0a112.11 112.11 0 01146.2-106.69L401.31 546.2A112 112 0 01396 512z"
  66. ></path>
  67. <path
  68. d="M508 624c-3.46 0-6.87-.16-10.25-.47l-52.82 52.82a176.09 176.09 0 00227.42-227.42l-52.82 52.82c.31 3.38.47 6.79.47 10.25a111.94 111.94 0 01-112 112z"
  69. ></path></svg></span></span
  70. ></span>
  71. </div>
  72. </div>
  73. </div>
  74. </div>
  75. </div>
  76. <div class="ant-form-item">
  77. <div class="ant-row ant-form-item-row">
  78. <div class="ant-col ant-col-16 ant-col-offset-8 ant-form-item-control">
  79. <div class="ant-form-item-control-input">
  80. <div class="ant-form-item-control-input-content">
  81. <label
  82. class="ant-checkbox-wrapper ant-checkbox-wrapper-checked ant-checkbox-wrapper-in-form-item"
  83. ><span class="ant-checkbox ant-checkbox-checked"
  84. ><input
  85. id="basic_remember"
  86. type="checkbox"
  87. class="ant-checkbox-input"
  88. value=""
  89. checked="" /><span class="ant-checkbox-inner"></span></span
  90. ><span>一周内免登陆</span></label
  91. >
  92. </div>
  93. </div>
  94. </div>
  95. </div>
  96. </div>
  97. <div class="ant-form-item">
  98. <div class="ant-row ant-form-item-row">
  99. <div class="ant-col ant-col-16 ant-col-offset-8 ant-form-item-control">
  100. <div class="ant-form-item-control-input">
  101. <div class="ant-form-item-control-input-content">
  102. <button type="submit" class="ant-btn ant-btn-primary">
  103. <span>登录</span>
  104. </button>
  105. </div>
  106. </div>
  107. </div>
  108. </div>
  109. </div>
  110. </form>

formily jsonSchema

预览状态
image.png

  1. const loginForm = {
  2. "form": {
  3. "labelCol": 6,
  4. "wrapperCol": 12
  5. },
  6. "schema": {
  7. "type": "object",
  8. "properties": {
  9. "username": {
  10. "type": "string",
  11. "title": "用户名",
  12. "required": true,
  13. "x-decorator": "FormItem",
  14. "x-component": "Input",
  15. "x-component-props": {
  16. "prefix": "{{icon('UserOutlined')}}"
  17. },
  18. "name": "username",
  19. "x-designable-id": "sl16zwpu6w6",
  20. "x-index": 0
  21. },
  22. "password": {
  23. "type": "string",
  24. "title": "密码",
  25. "required": true,
  26. "x-decorator": "FormItem",
  27. "x-component": "Password",
  28. "x-component-props": {
  29. "prefix": "{{icon('LockOutlined')}}"
  30. },
  31. "name": "password",
  32. "x-designable-id": "morbgl2l6op",
  33. "x-index": 1
  34. }
  35. },
  36. "x-designable-id": "g7o5nn4vyn0"
  37. }
  38. }

formily form 渲染的 html

  1. <form>
  2. <div
  3. class="ant-formily-item ant-formily-item-layout-horizontal ant-formily-item-feedback-layout-loose ant-formily-item-label-align-right ant-formily-item-control-align-left"
  4. >
  5. <div class="ant-formily-item-label ant-formily-item-item-col-6">
  6. <div class="ant-formily-item-label-content">
  7. <span
  8. ><span class="ant-formily-item-asterisk">*</span
  9. ><label>用户名</label></span
  10. >
  11. </div>
  12. <span class="ant-formily-item-colon">:</span>
  13. </div>
  14. <div class="ant-formily-item-control ant-formily-item-item-col-12">
  15. <div class="ant-formily-item-control-content">
  16. <div class="ant-formily-item-control-content-component">
  17. <span class="ant-input-affix-wrapper"
  18. ><input class="ant-input" type="text" value="" /><span
  19. class="ant-input-suffix"
  20. ><span></span></span
  21. ></span>
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. <div
  27. class="ant-formily-item ant-formily-item-layout-horizontal ant-formily-item-feedback-layout-loose ant-formily-item-label-align-right ant-formily-item-control-align-left"
  28. >
  29. <div class="ant-formily-item-label ant-formily-item-item-col-6">
  30. <div class="ant-formily-item-label-content">
  31. <span
  32. ><span class="ant-formily-item-asterisk">*</span
  33. ><label>密码</label></span
  34. >
  35. </div>
  36. <span class="ant-formily-item-colon">:</span>
  37. </div>
  38. <div class="ant-formily-item-control ant-formily-item-item-col-12">
  39. <div class="ant-formily-item-control-content">
  40. <div class="ant-formily-item-control-content-component">
  41. <span
  42. ><span class="ant-input-affix-wrapper ant-input-password"
  43. ><input type="password" class="ant-input" /><span
  44. class="ant-input-suffix"
  45. ><span
  46. role="img"
  47. aria-label="eye-invisible"
  48. tabindex="-1"
  49. class="anticon anticon-eye-invisible ant-input-password-icon"
  50. ><svg
  51. viewBox="64 64 896 896"
  52. focusable="false"
  53. data-icon="eye-invisible"
  54. width="1em"
  55. height="1em"
  56. fill="currentColor"
  57. aria-hidden="true"
  58. >
  59. <path
  60. d="M942.2 486.2Q889.47 375.11 816.7 305l-50.88 50.88C807.31 395.53 843.45 447.4 874.7 512 791.5 684.2 673.4 766 512 766q-72.67 0-133.87-22.38L323 798.75Q408 838 512 838q288.3 0 430.2-300.3a60.29 60.29 0 000-51.5zm-63.57-320.64L836 122.88a8 8 0 00-11.32 0L715.31 232.2Q624.86 186 512 186q-288.3 0-430.2 300.3a60.3 60.3 0 000 51.5q56.69 119.4 136.5 191.41L112.48 835a8 8 0 000 11.31L155.17 889a8 8 0 0011.31 0l712.15-712.12a8 8 0 000-11.32zM149.3 512C232.6 339.8 350.7 258 512 258c54.54 0 104.13 9.36 149.12 28.39l-70.3 70.3a176 176 0 00-238.13 238.13l-83.42 83.42C223.1 637.49 183.3 582.28 149.3 512zm246.7 0a112.11 112.11 0 01146.2-106.69L401.31 546.2A112 112 0 01396 512z"
  61. ></path>
  62. <path
  63. d="M508 624c-3.46 0-6.87-.16-10.25-.47l-52.82 52.82a176.09 176.09 0 00227.42-227.42l-52.82 52.82c.31 3.38.47 6.79.47 10.25a111.94 111.94 0 01-112 112z"
  64. ></path></svg></span></span></span
  65. ></span>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. </form>