richText.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div class="richtext">
  3. <froala :id="'editor' + spareId" :tag="'textarea'" :config="froalaConfig" v-model="valueText" @input="inputHandler"></froala>
  4. </div>
  5. </template>
  6. <script>
  7. import VueFroala from "vue-froala-wysiwyg";
  8. export default {
  9. name: "",
  10. components: {},
  11. model: {
  12. prop: "valueText",
  13. event: "contentText",
  14. },
  15. props: {
  16. spareId: {
  17. type: String,
  18. required: true,
  19. },
  20. isText: {
  21. type: String,
  22. required: true,
  23. default: "",
  24. },
  25. valueText: {
  26. type: String,
  27. required: true,
  28. },
  29. },
  30. watch: {
  31. isText: {
  32. handler(newVal) {
  33. if (newVal) {
  34. this.froalaConfig.placeholderText = newVal;
  35. }
  36. },
  37. deep: true,
  38. immediate: true,
  39. },
  40. },
  41. data() {
  42. var that = this;
  43. return {
  44. editor: null,
  45. froalaConfig: {
  46. //More -> https://www.froala.com/wysiwyg-editor/docs/options
  47. // toolbarButtons: ['undo', 'redo', 'clearFormatting', '|', 'bold', 'italic', 'underline','strikeThrough','|', 'fontFamily', 'fontSize', 'color', '|','paragraphFormat', 'align', 'formatOL', 'formatUL', 'outdent', 'indent', 'quote', '-', 'insertLink', 'insertImage', 'insertVideo', 'embedly', 'insertFile', 'insertTable', '|', 'emoticons', 'specialCharacters', 'insertHR', 'selectAll', '|', 'print', 'spellChecker', 'help', '|', 'fullscreen'],//['fullscreen', 'bold', 'italic', 'underline', 'strikeThrough', 'subscript', 'superscript', '|', 'fontFamily', 'fontSize', 'color', 'inlineStyle', 'paragraphStyle', '|', 'paragraphFormat', 'align', 'formatOL', 'formatUL', 'outdent', 'indent', 'quote', '-', 'insertLink', 'insertImage', 'insertVideo', 'embedly', 'insertFile', 'insertTable', '|', 'emoticons', 'specialCharacters', 'insertHR', 'selectAll', 'clearFormatting', '|', 'print', 'spellChecker', 'help', 'html', '|', 'undo', 'redo'],//显示可操作项
  48. toolbarButtons: [
  49. "insertImage",
  50. "textColor",
  51. "bold",
  52. "italic",
  53. "underline",
  54. "strikeThrough",
  55. "fontFamily",
  56. "fontSize",
  57. "color",
  58. "paragraphStyle",
  59. "lineHeight",
  60. "paragraphFormat",
  61. "align",
  62. "insertHR",
  63. "undo",
  64. "redo",
  65. ],
  66. height: 400,
  67. fontSize: ["12", "14", "16", "18", "20", "24", "28", "32", "36", "40"],
  68. fontSizeDefaultSelection: "16",
  69. theme: "dark", //主题
  70. // placeholderText: this.isText,
  71. language: "zh_cn", //国际化
  72. imageUploadURL: import.meta.env.VITE_APP_API_ROOT + "/report/uploadImg", //上传url
  73. videoUploadURL: import.meta.env.VITE_APP_API_ROOT + "/report/uploadImg", //上传url
  74. fileUploadURL: import.meta.env.VITE_APP_API_ROOT + "/report/uploadImg", //上传url 更多上传介绍 请访问https://www.froala.com/wysiwyg-editor/docs/options
  75. imageDefaultWidth: false,
  76. // imageEditButtons:['imageAlign', 'imageCaption', 'imageRemove', '|', 'imageLink', 'linkOpen', 'linkEdit', 'linkRemove', '-', 'imageDisplay', 'imageStyle', 'imageAlt', 'imageSize'],
  77. quickInsertButtons: ["image", "table", "ul", "ol", "hr"], //快速插入项
  78. toolbarVisibleWithoutSelection: true, //是否开启 不选中模式
  79. // disableRightClick:true,//是否屏蔽右击
  80. // colorsHEXInput:false,//关闭16进制色值
  81. toolbarSticky: false, //操作栏是否自动吸顶
  82. // zIndex:99999,
  83. saveInterval: 0,
  84. events: {
  85. initialized: function () {
  86. // this.editor = editor;
  87. that.editor = this;
  88. // that.editor.html.set(that.value);
  89. // that.setHtml()
  90. },
  91. keyup: function (e, editor) {
  92. //添加事件,在每次按键按下时,都记录一下最后停留位置
  93. that.$nextTick(function () {
  94. that.lastEditRange = getSelection().getRangeAt(0);
  95. });
  96. },
  97. click: function (e, editor) {
  98. //添加事件,在每次鼠标点击时,都记录一下最后停留位置
  99. that.$nextTick(function () {
  100. that.lastEditRange = getSelection().getRangeAt(0);
  101. });
  102. },
  103. },
  104. charCounterCount: false,
  105. reportloadding: false,
  106. lastsavetime: "",
  107. isAddEnter: false, //是否已经添加过
  108. timer: null,
  109. ischange: false,
  110. isPublishloading: false,
  111. },
  112. value: "",
  113. };
  114. },
  115. methods: {
  116. inputHandler() {
  117. this.$emit("contentText", this.valueText);
  118. },
  119. },
  120. };
  121. </script>
  122. <style lang="scss">
  123. .richtext {
  124. .fr-placeholder {
  125. margin-top: 41px !important;
  126. }
  127. .fr-second-toolbar {
  128. display: none;
  129. }
  130. }
  131. </style>