RichText.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <quill-editor
  3. ref="myTextEditor"
  4. v-model="text"
  5. class="editor"
  6. :options="editorOption"
  7. @change="onEditorChange($event)"
  8. />
  9. </template>
  10. <script>
  11. const toolbar = [
  12. ['bold', 'italic', 'underline', 'strike'], // 加粗 斜体 下划线 删除线
  13. ['blockquote', 'code-block'], // 引用 代码块
  14. [{ header: 1 }, { header: 2 }], // 1、2 级标题
  15. [{ list: 'ordered' }, { list: 'bullet' }], // 有序、无序列表
  16. // [{ script: "sub" }, { script: "super" }], // 上标/下标
  17. // [{ indent: "-1" }, { indent: "+1" }], // 缩进
  18. // [{'direction': 'rtl'}], // 文本方向
  19. [{ size: ['small', false, 'large', 'huge'] }], // 字体大小
  20. [{ header: [1, 2, 3, 4, 5, 6, false] }], // 标题
  21. [{ color: [] }, { background: [] }], // 字体颜色、字体背景颜色
  22. [{ font: [] }], // 字体种类
  23. [{ align: [] }], // 对齐方式
  24. ['clean'], // 清除文本格式
  25. ['link', 'image', 'video'] // 链接、图片、视频
  26. ] // 工具菜单栏配置
  27. export default {
  28. name: 'RichText',
  29. props: {
  30. text: {
  31. type: String,
  32. default: ''
  33. }
  34. },
  35. data() {
  36. return {
  37. content: '', // 内容
  38. editorOption: {
  39. modules: {
  40. toolbar
  41. },
  42. placeholder: '', // 提示
  43. readyOnly: false, // 是否只读
  44. theme: 'snow', // 主题 snow/bubble
  45. syntax: true // 语法检测
  46. }
  47. }
  48. },
  49. methods: {
  50. // 值发生变化
  51. onEditorChange(editor) {
  52. this.content = editor.html
  53. this.$emit('content', editor.html)
  54. }
  55. }
  56. }
  57. </script>
  58. <style>
  59. .editor {
  60. line-height: normal !important;
  61. height: 480px;
  62. margin-bottom: 30px;
  63. }
  64. .ql-snow .ql-tooltip[data-mode="link"]::before {
  65. content: "请输入链接地址:";
  66. }
  67. .ql-snow .ql-tooltip.ql-editing a.ql-action::after {
  68. border-right: 0px;
  69. content: "保存";
  70. padding-right: 0px;
  71. }
  72. .ql-snow .ql-tooltip[data-mode="video"]::before {
  73. content: "请输入视频地址:";
  74. }
  75. .ql-snow .ql-picker.ql-size .ql-picker-label::before,
  76. .ql-snow .ql-picker.ql-size .ql-picker-item::before {
  77. content: "14px";
  78. }
  79. .ql-snow .ql-picker.ql-size .ql-picker-label[data-value="small"]::before,
  80. .ql-snow .ql-picker.ql-size .ql-picker-item[data-value="small"]::before {
  81. content: "10px";
  82. }
  83. .ql-snow .ql-picker.ql-size .ql-picker-label[data-value="large"]::before,
  84. .ql-snow .ql-picker.ql-size .ql-picker-item[data-value="large"]::before {
  85. content: "18px";
  86. }
  87. .ql-snow .ql-picker.ql-size .ql-picker-label[data-value="huge"]::before,
  88. .ql-snow .ql-picker.ql-size .ql-picker-item[data-value="huge"]::before {
  89. content: "32px";
  90. }
  91. .ql-snow .ql-picker.ql-header .ql-picker-label::before,
  92. .ql-snow .ql-picker.ql-header .ql-picker-item::before {
  93. content: "文本";
  94. }
  95. .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="1"]::before,
  96. .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="1"]::before {
  97. content: "标题1";
  98. }
  99. .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="2"]::before,
  100. .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="2"]::before {
  101. content: "标题2";
  102. }
  103. .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="3"]::before,
  104. .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="3"]::before {
  105. content: "标题3";
  106. }
  107. .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="4"]::before,
  108. .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="4"]::before {
  109. content: "标题4";
  110. }
  111. .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="5"]::before,
  112. .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="5"]::before {
  113. content: "标题5";
  114. }
  115. .ql-snow .ql-picker.ql-header .ql-picker-label[data-value="6"]::before,
  116. .ql-snow .ql-picker.ql-header .ql-picker-item[data-value="6"]::before {
  117. content: "标题6";
  118. }
  119. .ql-snow .ql-picker.ql-font .ql-picker-label::before,
  120. .ql-snow .ql-picker.ql-font .ql-picker-item::before {
  121. content: "标准字体";
  122. }
  123. .ql-snow .ql-picker.ql-font .ql-picker-label[data-value="serif"]::before,
  124. .ql-snow .ql-picker.ql-font .ql-picker-item[data-value="serif"]::before {
  125. content: "衬线字体";
  126. }
  127. .ql-snow .ql-picker.ql-font .ql-picker-label[data-value="monospace"]::before,
  128. .ql-snow .ql-picker.ql-font .ql-picker-item[data-value="monospace"]::before {
  129. content: "等宽字体";
  130. }
  131. </style>