富文本編輯器vue2-editor實現全屏功能


vue2-editor非常不錯,可惜並未帶全屏功能,自己實現了一個,供大家參考。

實現思路:自定義模塊。

1. 定義全屏模塊Fullscreen

/**
 * 編輯器的全屏實現
 */
import noScroll from 'no-scroll'

export default class Fullscreen {
    constructor (quill, options = {}) {
        this.quill = quill
        this.options = options
        this.fullscreen = false
        this.editorContainer = this.quill.container.parentNode.parentNode
    }

    handle () {
        if (! this.fullscreen) {
            this.fullscreen = true
            this.editorContainer.className = 'ql-editor ql-blank editor-fullscreen'
            noScroll.on()
        }else{
            this.fullscreen = false
            this.editorContainer.className = 'ql-editor ql-blank'
            noScroll.off()
        }
    }
}
Fullscreen.js

2. 通過編輯器的選項注冊模塊,我是放在了全局的Global.vue中,其他頁面直接引用這個選項

const EDITOR_OPTIONS = {
   modules: {
        fullscreen: {},
        toolbar: {
            container: [
                [{ header: [false, 1, 2, 3, 4, 5, 6] }],
                ["bold", "italic", "underline", "strike"], // toggled buttons
                [
                    { align: "" },
                    { align: "center" },
                    { align: "right" },
                    { align: "justify" }
                ],
                ["blockquote", "code-block"],
                [{ list: "ordered" }, { list: "bullet" }, { list: "check" }],
                [{ indent: "-1" }, { indent: "+1" }], // outdent/indent
                [{ color: [] }, { background: [] }], // dropdown with defaults from theme
                ["link", "image", "video"],
                ["clean"], // remove formatting button
                ['fullscreen']
            ],
            handlers: {
                fullscreen() {
                    this.quill.getModule('fullscreen').handle()
                }
            }
        }
    }
}
Global.vue

3. 在頁面中引用

 <vue-editor
     useCustomImageHandler
    @imageAdded="handleImageAdded"
    v-model="entity.content"
    :editorOptions="$global.EDITOR_OPTIONS"
    class="editor">
</vue-editor>
                           
import {VueEditor, Quill} from "vue2-editor"
import Fullscreen from '../Fullscreen'

Quill.register('modules/fullscreen', Fullscreen)

4. 最后在全局樣式中加入全屏的樣式,我這個樣式中控制了編輯器的高度,默認是自適應高度的。

  .editor .ql-editor{
    height: 300px;
  }
  .editor-fullscreen{
      background: white;
      margin: 0 !important;
      position: fixed;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      z-index: 100000;
      .ql-editor{
          height: 100%;
      }
      .fullscreen-editor {
          border-radius: 0;
          border: none;
      }
      .ql-container {
          height: calc(100vh - 3rem - 24px) !important; 
          margin: 0 auto;
          overflow-y: auto;
      }
  }
  .ql-fullscreen{
    background:url('./assets/images/fullscreen.svg') no-repeat center!important;
  }
App.vue

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM