index.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. import {Button, Card, Form, Input, message} from 'antd';
  2. import React, { useEffect, useState} from 'react';
  3. import {PageHeaderWrapper} from '@ant-design/pro-layout';
  4. import service from './service';
  5. import {connect} from "umi";
  6. import {ConnectState} from "@/models/connect";
  7. import { Dispatch, AnyAction } from 'redux';
  8. interface PasswordChange {
  9. newPassword: string;
  10. oldPassword: string;
  11. }
  12. interface PushChange {
  13. userId: number;
  14. noteUrl: string;
  15. }
  16. enum InputState {
  17. default = '',
  18. success = 'success',
  19. error = 'error'
  20. }
  21. const layout = {
  22. labelCol: {span: 4},
  23. wrapperCol: {span: 18},
  24. };
  25. const tailLayout = {
  26. wrapperCol: {offset: 4, span: 18},
  27. };
  28. interface Props {
  29. dispatch: Dispatch<AnyAction>;
  30. }
  31. /**
  32. * 更新节点
  33. * @param fields
  34. */
  35. const handleUpdate = async (fields: PasswordChange) => {
  36. const hide = message.loading('正在发送');
  37. try {
  38. const data = await service.updatePassword(fields);
  39. if (data.success) {
  40. hide();
  41. message.success('修改成功');
  42. } else {
  43. message.error('修改失败!');
  44. }
  45. } catch (e) {
  46. console.log(e);
  47. }
  48. };
  49. const TableList: React.FC<Props> = (props) => {
  50. const [success, setSuccess] = useState<InputState>(InputState.default);
  51. const [form2] = Form.useForm();
  52. const [noteForm] = Form.useForm();
  53. const logOutHandle=()=>{
  54. const { dispatch } = props;
  55. if (dispatch) {
  56. dispatch({
  57. type: 'login/logout',
  58. });
  59. }
  60. return;
  61. }
  62. const nameExist = async () => {
  63. const userName = form2.getFieldValue("userName");
  64. if (userName == null || userName.length <= 6) {
  65. message.error("密码长度不够6位");
  66. return false;
  67. }
  68. const res = await service.nameExist({userName: form2.getFieldValue("userName")});
  69. if (res.success) {
  70. setSuccess(InputState.success);
  71. return true;
  72. }
  73. setSuccess(InputState.error);
  74. return false;
  75. }
  76. /**
  77. * 密码更新
  78. * @param values
  79. */
  80. const onFinish = (values: any) => {
  81. handleUpdate(values);
  82. };
  83. const updatePushUrl = (values: PushChange) => {
  84. values["noteUrl"] = values["noteUrl"];
  85. service.updatePushUrl(values).then(res => {
  86. if (res.success) {
  87. message.success("更新成功");
  88. } else {
  89. message.error('获取url失败!');
  90. }
  91. });
  92. };
  93. /**
  94. * 用户名更新
  95. * @param value
  96. */
  97. const onFinishUserName = async (value: any) => {
  98. const res = await service.updateAccountName(value);
  99. if (res.success) {
  100. message.success('修改成功');
  101. window.history.go(0);
  102. } else {
  103. message.error('修改失败!');
  104. }
  105. }
  106. useEffect(() => {
  107. service.queryPushUrl({}).then(res => {
  108. if (res.success) {
  109. noteForm.setFieldsValue({"noteUrl": res.data});
  110. } else {
  111. message.error('获取url失败!');
  112. }
  113. })
  114. }, [])
  115. // const onFinishFailed = errorInfo => {
  116. // console.log('Failed:', errorInfo);
  117. // };
  118. return (
  119. <PageHeaderWrapper title={false}>
  120. <Card title="修改用户名" style={{width: '100%'}}>
  121. <Form
  122. {...layout}
  123. name="basic"
  124. form={form2}
  125. initialValues={{remember: true}}
  126. onFinish={onFinishUserName}
  127. // onFinishFailed={onFinishFailed}
  128. >
  129. <Form.Item
  130. label="新用户名"
  131. name="userName"
  132. hasFeedback
  133. validateStatus={success}
  134. rules={[{required: true, message: '请输入用户名!'}]}
  135. >
  136. <Input/>
  137. </Form.Item>
  138. <Form.Item {...tailLayout}>
  139. <Button type="primary" htmlType="button" onClick={nameExist}>
  140. 校验
  141. </Button>
  142. <span> </span>
  143. <Button type="primary" htmlType="submit">
  144. 提交
  145. </Button>
  146. </Form.Item>
  147. </Form>
  148. </Card>
  149. <Card title="重置密码" style={{width: '100%'}}>
  150. <Form
  151. {...layout}
  152. name="basic"
  153. initialValues={{remember: true}}
  154. onFinish={onFinish}
  155. // onFinishFailed={onFinishFailed}
  156. >
  157. <Form.Item
  158. label="旧密码"
  159. name="oldPassword"
  160. rules={[{required: true, message: '请输入旧密码!'}]}
  161. >
  162. <Input.Password/>
  163. </Form.Item>
  164. <Form.Item
  165. label="新密码"
  166. name="newPassword"
  167. rules={[{required: true, message: '请输入旧密码'}]}
  168. >
  169. <Input.Password/>
  170. </Form.Item>
  171. <Form.Item {...tailLayout}>
  172. <Button type="primary" htmlType="submit">
  173. 提交
  174. </Button>
  175. </Form.Item>
  176. </Form>
  177. </Card>
  178. <Card title="消息提醒地址" style={{width: '100%'}}>
  179. <Form
  180. {...layout}
  181. name="basic"
  182. initialValues={{}}
  183. onFinish={updatePushUrl}
  184. form={noteForm}
  185. // onFinishFailed={onFinishFailed}
  186. >
  187. <Form.Item
  188. label="提醒地址"
  189. name="noteUrl"
  190. >
  191. <Input/>
  192. </Form.Item>
  193. <Form.Item {...tailLayout}>
  194. <Button type="primary" htmlType="submit">
  195. 提交
  196. </Button>
  197. </Form.Item>
  198. </Form>
  199. </Card>
  200. <Card title="刷新页面" style={{width: '100%'}}>
  201. <Form
  202. {...layout}
  203. name="basic"
  204. >
  205. <Form.Item {...tailLayout}>
  206. <Button type="primary" htmlType="button" onClick={() => {
  207. window.location.reload();
  208. }}>
  209. 刷新页面
  210. </Button>
  211. </Form.Item>
  212. </Form>
  213. </Card>
  214. <Card title="退出登录" style={{width: '100%'}}>
  215. <Form
  216. {...layout}
  217. name="basic"
  218. >
  219. <Form.Item {...tailLayout}>
  220. <Button type="primary" htmlType="button" onClick={() => {
  221. logOutHandle();
  222. }}>
  223. 退出登录
  224. </Button>
  225. </Form.Item>
  226. </Form>
  227. </Card>
  228. </PageHeaderWrapper>
  229. );
  230. };
  231. export default connect(({ }: ConnectState) => ({
  232. }))(TableList);