TextEdit.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <template>
  2. <div class="text-edit-wrap">
  3. <div style="font-size:16px;margin-bottom:20px">{{$t('ReportManage.ReportList.text_editing')}}</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", "13","14","15", "16", "18", "20", "24", "28", "32", "36", "40"],
  62. fontSizeDefaultSelection: "16",
  63. theme: "dark", //主题
  64. placeholderText: localStorage.getItem('i18n') == 'en' ? 'Please input content' : "请输入内容",
  65. language: localStorage.getItem('i18n') == 'en' ? 'en' : "zh_cn", //国际化
  66. imageDefaultWidth: false,
  67. quickInsertEnabled: false,
  68. toolbarVisibleWithoutSelection: true, //是否开启 不选中模式
  69. toolbarSticky: false, //操作栏是否自动吸顶
  70. saveInterval: 0,
  71. fontFamily:{
  72. 'Arial,Helvetica,sans-serif': 'Arial',
  73. 'Georgia,serif': 'Georgia',
  74. 'Impact,Charcoal,sans-serif': 'Impact',
  75. 'Tahoma,Geneva,sans-serif': 'Tahoma',
  76. 'Times New Roman,Times,serif': 'Times New Roman',
  77. 'Verdana,Geneva,sans-serif': 'Verdana',
  78. '思源宋体':'思源宋体',
  79. '思源黑体':'思源黑体',
  80. },
  81. events: {
  82. //this.editor 定义在vue data 中
  83. initialized: function () {
  84. // this.editor = editor;
  85. that.editor = this;
  86. // that.editor.html.set(that.value);
  87. // that.setHtml()
  88. },
  89. keyup: function (e, editor) {
  90. //添加事件,在每次按键按下时,都记录一下最后停留位置
  91. that.$nextTick(function () {
  92. that.lastEditRange = getSelection().getRangeAt(0);
  93. });
  94. },
  95. click: function (e, editor) {
  96. //添加事件,在每次鼠标点击时,都记录一下最后停留位置
  97. that.$nextTick(function () {
  98. that.lastEditRange = getSelection().getRangeAt(0);
  99. });
  100. },
  101. //内容改变事件
  102. contentChanged: function () {
  103. that.lastEditRange = getSelection().getRangeAt(0) || 0;
  104. // that.$emit('textChange', that.html)
  105. that.sendHtml()
  106. },
  107. },
  108. }
  109. }
  110. },
  111. methods: {
  112. sendHtml(){
  113. const str=this.html.replace(/<p data-f-id=\"pbf\".*?<\/p>/g, "")
  114. //如果富文本中有未上传完成的图片,去除这个dom
  115. $('.fr-element').find('img.fr-uploading').length&&$('.fr-element').find('img.fr-uploading').remove()
  116. this.$emit('textChange', str)
  117. }
  118. },
  119. components:{}
  120. }
  121. </script>
  122. <style lang="scss">
  123. .text-edit-wrap{
  124. .fr-box.fr-basic{
  125. flex: 1;
  126. overflow: hidden;
  127. display: flex;
  128. flex-direction: column;
  129. .fr-wrapper{
  130. flex: 1;
  131. overflow: auto;
  132. }
  133. }
  134. }
  135. </style>
  136. <style lang="scss" scoped>
  137. .text-edit-wrap{
  138. width:100%;
  139. height: 100%;
  140. overflow: hidden;
  141. display: flex;
  142. flex-direction: column;
  143. #froala-editor{
  144. flex:1;
  145. overflow: auto;
  146. }
  147. }
  148. </style>