ckeditor.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. },
  22. id: {
  23. type: String,
  24. default: () => `editor-${++inc}`
  25. },
  26. height: {
  27. type: String,
  28. default: "300px"
  29. },
  30. width: {
  31. type: String,
  32. default: "500px"
  33. },
  34. language: {
  35. type: String,
  36. default: "zh-cn"
  37. },
  38. extraplugins: {
  39. type: String,
  40. default: ""
  41. }
  42. },
  43. computed: {
  44. instance() {
  45. return window.CKEDITOR.instances[this.id];
  46. }
  47. },
  48. beforeUpdate() {
  49. if (this.value !== this.instance.getData()) {
  50. this.instance.setData(this.value);
  51. }
  52. },
  53. mounted() {
  54. let config = {
  55. language: this.language,
  56. height: this.height,
  57. width: this.width,
  58. extraPlugins: this.extraplugins + ",base64image,pastebase64",
  59. toolbarGroups: [
  60. { name: "clipboard", groups: ["clipboard", "undo"] },
  61. {
  62. name: "editing",
  63. groups: ["find", "selection", "spellchecker", "editing"]
  64. },
  65. { name: "links", groups: ["links"] },
  66. { name: "insert", groups: ["insert"] },
  67. { name: "forms", groups: ["forms"] },
  68. { name: "tools", groups: ["tools"] },
  69. { name: "document", groups: ["mode", "document", "doctools"] },
  70. { name: "others", groups: ["others"] },
  71. "/",
  72. { name: "basicstyles", groups: ["basicstyles", "cleanup"] },
  73. {
  74. name: "paragraph",
  75. groups: ["list", "indent", "blocks", "align", "bidi", "paragraph"]
  76. },
  77. { name: "styles", groups: ["styles"] },
  78. { name: "colors", groups: ["colors"] },
  79. { name: "about", groups: ["about"] }
  80. ],
  81. removePlugins: "bidi,colorbutton",
  82. removeButtons:
  83. "Font,FontSize,Image,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"
  84. };
  85. if (this.display !== "inline") {
  86. window.CKEDITOR.replace(this.id, config);
  87. } else {
  88. window.CKEDITOR.inline(this.id, config);
  89. }
  90. this.instance.on("change", () => {
  91. let html = this.instance.getData();
  92. if (html !== this.value) {
  93. this.$emit("input", html);
  94. }
  95. });
  96. },
  97. beforeDestroy() {
  98. if (this.instance) {
  99. this.instance.focusManager.blur(true);
  100. this.instance.destroy();
  101. }
  102. }
  103. };
  104. </script>
  105. <style>
  106. .ckeditor::after {
  107. content: "";
  108. display: table;
  109. clear: both;
  110. }
  111. </style>