mock平台

Editor.js 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import React, { Component } from 'react';
  2. import PropTypes from 'prop-types';
  3. import { Button, Checkbox } from 'antd';
  4. import Editor from 'common/tui-editor/dist/tui-editor-Editor-all.min.js';
  5. require('common/tui-editor/dist/tui-editor.min.css'); // editor ui
  6. require('common/tui-editor/dist/tui-editor-contents.min.css'); // editor content
  7. class WikiEditor extends Component {
  8. constructor(props) {
  9. super(props);
  10. }
  11. static propTypes = {
  12. isConflict: PropTypes.bool,
  13. onUpload: PropTypes.func,
  14. onCancel: PropTypes.func,
  15. notice: PropTypes.bool,
  16. onEmailNotice: PropTypes.func,
  17. desc: PropTypes.string
  18. };
  19. componentDidMount() {
  20. this.editor = new Editor({
  21. el: document.querySelector('#desc'),
  22. initialEditType: 'wysiwyg',
  23. height: '500px',
  24. initialValue: this.props.desc
  25. });
  26. }
  27. onUpload = () => {
  28. let desc = this.editor.getHtml();
  29. let markdown = this.editor.getMarkdown();
  30. this.props.onUpload(desc, markdown);
  31. };
  32. render() {
  33. const { isConflict, onCancel, notice, onEmailNotice } = this.props;
  34. return (
  35. <div>
  36. <div
  37. id="desc"
  38. className="wiki-editor"
  39. style={{ display: !isConflict ? 'block' : 'none' }}
  40. />
  41. <div className="wiki-title wiki-up">
  42. <Button
  43. icon="upload"
  44. type="primary"
  45. className="upload-btn"
  46. disabled={isConflict}
  47. onClick={this.onUpload}
  48. >
  49. 更新
  50. </Button>
  51. <Button onClick={onCancel} className="upload-btn">
  52. 取消
  53. </Button>
  54. <Checkbox checked={notice} onChange={onEmailNotice}>
  55. 通知相关人员
  56. </Checkbox>
  57. </div>
  58. </div>
  59. );
  60. }
  61. }
  62. export default WikiEditor;