CkEditor.tsx 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { useEditor } from "@/modules/editor";
  2. import { Bold, Italic } from "@ckeditor/ckeditor5-basic-styles";
  3. import { InlineEditor } from "@ckeditor/ckeditor5-editor-inline";
  4. import { Essentials } from "@ckeditor/ckeditor5-essentials";
  5. import { Alignment } from "@ckeditor/ckeditor5-alignment";
  6. import { FontFamily, FontSize } from "@ckeditor/ckeditor5-font";
  7. import { Link } from "@ckeditor/ckeditor5-link";
  8. import { Paragraph } from "@ckeditor/ckeditor5-paragraph";
  9. import { defineComponent } from "vue";
  10. import { string } from "vue-types";
  11. export const CkEditor = defineComponent({
  12. props: {
  13. value: string().def("请输入文本"),
  14. },
  15. emits: ["change"],
  16. setup(props, { emit }) {
  17. const { store } = useEditor();
  18. const config = {
  19. plugins: [
  20. Essentials,
  21. Bold,
  22. Italic,
  23. Link,
  24. Paragraph,
  25. FontSize,
  26. FontFamily,
  27. Alignment,
  28. ],
  29. fontSize: {
  30. options: [9, 11, 13, "default", 17, 19, 21],
  31. },
  32. toolbar: {
  33. items: [
  34. "undo",
  35. "redo",
  36. "|",
  37. "fontFamily",
  38. "fontsize",
  39. "bold",
  40. "italic",
  41. "|",
  42. "alignment",
  43. "|",
  44. "link",
  45. ],
  46. },
  47. };
  48. return () => (
  49. <ckeditor
  50. editor={InlineEditor}
  51. onBlur={(e: any, editor: InlineEditor) =>
  52. emit("change", editor.getData())
  53. }
  54. onReady={(editor: InlineEditor) => {
  55. editor.setData(props.value);
  56. if (!store.isEditMode) {
  57. editor.enableReadOnlyMode("editor");
  58. }
  59. }}
  60. config={config}
  61. />
  62. );
  63. },
  64. });