index.jsx 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React from 'react';
  2. import { Button, Card, Popconfirm } from 'antd';
  3. import Page from '@/components/Page';
  4. import Wangeditor from '@/components/Wangeditor';
  5. import { getTaCheckStandById, putTaCheckStand } from '@/service/tacheckstand';
  6. export default (props) => {
  7. const [loading, setLoading] = React.useState(false);
  8. const [editable, setEditAble] = React.useState(false);
  9. const [detail, setDetail] = React.useState(false);
  10. const onChange = (e) => {
  11. setDetail({
  12. ...detail || {},
  13. content: e,
  14. })
  15. }
  16. const onSubmit = (e) => {
  17. setLoading(true);
  18. putTaCheckStand(1, detail).then(() => {
  19. setLoading(false);
  20. setEditAble(false);
  21. }).catch(() => {
  22. setLoading(false);
  23. })
  24. }
  25. React.useEffect(() => {
  26. setLoading(true);
  27. getTaCheckStandById(1).then((res) => {
  28. setDetail(res);
  29. setLoading(false);
  30. }).catch(() => {
  31. setLoading(false);
  32. })
  33. }, []);
  34. return (
  35. <Page>
  36. <Card loading={loading} extra={(
  37. editable ? <Button type="primary" onClick={onSubmit}>提交</Button>
  38. : <Button type="primary" onClick={() => setEditAble(true)}>编辑</Button>
  39. )}>
  40. {
  41. editable ? (
  42. <Wangeditor
  43. value={detail?.content}
  44. toolbarConfig={{
  45. toolbarKeys: [
  46. 'headerSelect',
  47. 'blockquote',
  48. '|',
  49. 'bold',
  50. 'underline',
  51. 'italic',
  52. 'color',
  53. 'fontSize',
  54. '|',
  55. 'bulletedList',
  56. 'numberedList',
  57. ]
  58. }}
  59. onChange={onChange}
  60. />
  61. ) : (
  62. <div dangerouslySetInnerHTML={{ __html: detail?.content }}></div>
  63. )
  64. }
  65. </Card>
  66. </Page>
  67. )
  68. }