Form1.jsx 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import React from "react";
  2. import Taro from "@tarojs/taro";
  3. import { View } from "@tarojs/components";
  4. import { Form, FormItem, Field, Button } from "@antmjs/vantui";
  5. import { useModel } from "@/store";
  6. import user from "@/assets/image/user.png";
  7. import password from "@/assets/image/password.png";
  8. import { warn } from "@/utils/message";
  9. import "./form.less";
  10. export default (props) => {
  11. const { onSuccess } = props;
  12. const { signin } = useModel("user");
  13. const form = Form.useForm();
  14. const [accErr, setAccErr] = React.useState();
  15. const [pwdErr, setPwdErr] = React.useState();
  16. const [loading, setLoading] = React.useState(false);
  17. const onFinish = (errs, res) => {
  18. console.log(11111111);
  19. if (!res.account) {
  20. setAccErr("账户不能为空");
  21. return;
  22. } else {
  23. setAccErr();
  24. }
  25. if (!res.password) {
  26. setPwdErr("密码不能为空");
  27. return;
  28. } else {
  29. setPwdErr();
  30. }
  31. setLoading(true);
  32. signin(res)
  33. .then(() => {
  34. onSuccess();
  35. setLoading(false);
  36. })
  37. .catch((err) => {
  38. setLoading(false);
  39. });
  40. };
  41. const onForgetPwd = () => {
  42. // Taro.navigateTo({
  43. // url: '/pages/reset-password/index'
  44. // });
  45. warn(true, "请联系管理人员");
  46. };
  47. const handleClick = () => {
  48. form.validateFields((err, res) => {
  49. if (!res.account) {
  50. setAccErr("账户不能为空");
  51. return;
  52. } else {
  53. setAccErr();
  54. }
  55. if (!res.password) {
  56. setPwdErr("密码不能为空");
  57. return;
  58. } else {
  59. setPwdErr();
  60. }
  61. setLoading(true);
  62. signin(res)
  63. .then(() => {
  64. onSuccess();
  65. setLoading(false);
  66. })
  67. .catch((err) => {
  68. setLoading(false);
  69. });
  70. });
  71. console.log(11111);
  72. };
  73. return (
  74. <View className="login-form">
  75. {/* onFinish={onFinish} */}
  76. <Form form={form} >
  77. <FormItem name="account" valueFormat={(e) => e.detail}>
  78. <Field
  79. border
  80. label="账号"
  81. leftIcon={user}
  82. errorMessage={accErr}
  83. placeholder="请输入您的登录账号"
  84. ></Field>
  85. </FormItem>
  86. <FormItem name="password" valueFormat={(e) => e.detail}>
  87. <Field
  88. password
  89. label="密码"
  90. leftIcon={password}
  91. errorMessage={pwdErr}
  92. placeholder="请输入您的登录密码"
  93. ></Field>
  94. </FormItem>
  95. <View className="forget-password" onClick={onForgetPwd}>
  96. 忘记密码?
  97. </View>
  98. <View>
  99. <Button
  100. block
  101. type="primary"
  102. // formType="submit"
  103. loading={loading}
  104. disabled={loading}
  105. onClick={handleClick}
  106. >
  107. 登录
  108. </Button>
  109. </View>
  110. </Form>
  111. </View>
  112. );
  113. };