ckeditor.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <div class="ckeditor">
  3. <textarea
  4. :id="id"
  5. :display="display"
  6. :value="value"
  7. class="el-textarea__inner"
  8. ></textarea>
  9. </div>
  10. </template>
  11. <script>
  12. let inc = 0;
  13. export default {
  14. props: {
  15. display: {
  16. type: String,
  17. default: "inline",
  18. },
  19. value: {
  20. type: String,
  21. default: "",
  22. },
  23. id: {
  24. type: String,
  25. default: () => `editor-${++inc}`,
  26. },
  27. height: {
  28. type: String,
  29. default: "300px",
  30. },
  31. width: {
  32. type: String,
  33. default: "500px",
  34. },
  35. language: {
  36. type: String,
  37. default: "zh-cn",
  38. },
  39. extraplugins: {
  40. type: String,
  41. default: "",
  42. },
  43. },
  44. computed: {
  45. instance() {
  46. return window.CKEDITOR.instances[this.id];
  47. },
  48. },
  49. beforeUpdate() {
  50. if (this.value !== this.instance.getData()) {
  51. this.instance.setData(this.value);
  52. }
  53. },
  54. mounted() {
  55. let config = {
  56. language: this.language,
  57. height: this.height,
  58. width: this.width,
  59. extraPlugins: this.extraplugins + ",base64image,pastebase64,image2",
  60. toolbarGroups: [
  61. { name: "clipboard", groups: ["clipboard", "undo"] },
  62. {
  63. name: "editing",
  64. groups: ["find", "selection", "spellchecker", "editing"],
  65. },
  66. { name: "links", groups: ["links"] },
  67. { name: "insert", groups: ["insert"] },
  68. { name: "forms", groups: ["forms"] },
  69. { name: "tools", groups: ["tools"] },
  70. { name: "document", groups: ["mode", "document", "doctools"] },
  71. { name: "others", groups: ["others"] },
  72. "/",
  73. { name: "basicstyles", groups: ["basicstyles", "cleanup"] },
  74. {
  75. name: "paragraph",
  76. groups: ["list", "indent", "blocks", "align", "bidi", "paragraph"],
  77. },
  78. { name: "styles", groups: ["styles"] },
  79. { name: "colors", groups: ["colors"] },
  80. { name: "about", groups: ["about"] },
  81. ],
  82. removePlugins: "bidi,colorbutton,image",
  83. removeButtons:
  84. "Font,FontSize,Styles,Format,ShowBlocks,Iframe,PageBreak,Smiley,Flash,Language,JustifyBlock,JustifyRight,JustifyCenter,JustifyLeft,CreateDiv,CopyFormatting,ImageButton,Button,HiddenField,Select,Textarea,TextField,Radio,Checkbox,Form,BGColor,SelectAll,Replace,Find,Templates,Print,Preview,NewPage,Save,Subscript,Superscript,HorizontalRule,Unlink,Link,Scayt,Cut,Copy,Paste,PasteText,PasteFromWord,Maximize,NumberedList,BulletedList,Indent,Outdent,Blockquote,About,RemoveFormat,Strike",
  85. };
  86. if (this.display !== "inline") {
  87. window.CKEDITOR.replace(this.id, config);
  88. } else {
  89. window.CKEDITOR.inline(this.id, config);
  90. }
  91. this.instance.on("change", () => {
  92. let html = this.instance.getData();
  93. if (html !== this.value) {
  94. this.$emit("input", html);
  95. }
  96. });
  97. },
  98. beforeDestroy() {
  99. if (this.instance) {
  100. this.instance.focusManager.blur(true);
  101. this.instance.destroy();
  102. }
  103. },
  104. };
  105. </script>
  106. <style>
  107. .ckeditor::after {
  108. content: "";
  109. display: table;
  110. clear: both;
  111. }
  112. .cke_button__image {
  113. display: none !important;
  114. }
  115. </style>