TextEdit.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <div class="text-edit-wrap">
  3. <div style="font-size:16px;margin-bottom:20px">文本编辑</div>
  4. <froala
  5. id="froala-editor"
  6. ref="froalaEditor"
  7. :tag="'textarea'"
  8. :config="froalaConfig"
  9. v-model="html"
  10. />
  11. </div>
  12. </template>
  13. <script>
  14. import VueFroala from 'vue-froala-wysiwyg';
  15. export default {
  16. name:'TextEdit',
  17. props:{
  18. content:''
  19. },
  20. data() {
  21. const that = this;
  22. return {
  23. html:this.content||'',
  24. editor: null,
  25. lastEditRange: null,
  26. froalaConfig:{
  27. imageUploadURL: process.env.VUE_APP_API_ROOT + "/report/uploadImg", //上传url
  28. videoUploadURL: process.env.VUE_APP_API_ROOT + "/report/uploadImg", //上传url
  29. fileUploadURL: process.env.VUE_APP_API_ROOT + "/report/uploadImg", //上传url 更多上传介绍 请访问https://www.froala.com/wysiwyg-editor/docs/options
  30. toolbarButtons: [
  31. "textColor",
  32. "bold",
  33. "italic",
  34. "underline",
  35. "strikeThrough",
  36. "subscript",
  37. "superscript",
  38. "fontFamily",
  39. "fontSize",
  40. "color",
  41. "inlineClass",
  42. "inlineStyle",
  43. "paragraphStyle",
  44. "lineHeight",
  45. "paragraphFormat",
  46. "align",
  47. "formatOL",
  48. "formatUL",
  49. "outdent",
  50. "indent",
  51. "quote",
  52. "specialCharacters",
  53. "insertHR",
  54. "selectAll",
  55. "clearFormatting",
  56. "html",
  57. "undo",
  58. "redo",
  59. ],
  60. height: 800,
  61. fontSize: ["12", "14", "16", "18", "20", "24", "28", "32", "36", "40"],
  62. fontSizeDefaultSelection: "16",
  63. theme: "dark", //主题
  64. placeholderText: "请输入内容",
  65. language: "zh_cn", //国际化
  66. imageDefaultWidth: false,
  67. quickInsertEnabled: false,
  68. toolbarVisibleWithoutSelection: true, //是否开启 不选中模式
  69. toolbarSticky: false, //操作栏是否自动吸顶
  70. saveInterval: 0,
  71. events: {
  72. //this.editor 定义在vue data 中
  73. initialized: function () {
  74. // this.editor = editor;
  75. that.editor = this;
  76. // that.editor.html.set(that.value);
  77. // that.setHtml()
  78. },
  79. keyup: function (e, editor) {
  80. //添加事件,在每次按键按下时,都记录一下最后停留位置
  81. that.$nextTick(function () {
  82. that.lastEditRange = getSelection().getRangeAt(0);
  83. });
  84. },
  85. click: function (e, editor) {
  86. //添加事件,在每次鼠标点击时,都记录一下最后停留位置
  87. that.$nextTick(function () {
  88. that.lastEditRange = getSelection().getRangeAt(0);
  89. });
  90. },
  91. //内容改变事件
  92. contentChanged: function () {
  93. that.lastEditRange = getSelection().getRangeAt(0) || 0;
  94. // that.$emit('textChange', that.html)
  95. that.sendHtml()
  96. },
  97. },
  98. }
  99. }
  100. },
  101. methods: {
  102. sendHtml(){
  103. const str=this.html.replace(/<p data-f-id=\"pbf\".*?<\/p>/g, "")
  104. //如果富文本中有未上传完成的图片,去除这个dom
  105. $('.fr-element').find('img.fr-uploading').length&&$('.fr-element').find('img.fr-uploading').remove()
  106. this.$emit('textChange', str)
  107. }
  108. },
  109. components:{}
  110. }
  111. </script>
  112. <style>
  113. </style>