1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| import "quill/dist/quill.core.css"; import "quill/dist/quill.snow.css"; import "quill/dist/quill.bubble.css";
import {quillEditor} from "vue-quill-editor/src"; import {addQuillTitle} from "../language/zh-CN"; import * as Quill from 'quill';
let fontSizeStyle = Quill.import('attributors/style/size') fontSizeStyle.whitelist = ['12px', false, '16px', '18px', '20px', '22px', '24px'] Quill.register(fontSizeStyle, true)
export default { name: "rich-text-editor", props: { totalWords: { type: Number, default: 10000 }, content: { type: String, default: '' }, showWordLimit: { type: Boolean, default: true } }, data() { return { content: "", currentWords: 0, option: { theme: 'snow', placeholder: '编辑文章内容', modules: { toolbar: [ ['bold', 'italic', 'underline', 'strike'], ['blockquote', 'code-block'], [{'header': 1}, {'header': 2}], [{'list': 'ordered'}, {'list': 'bullet'}], [{'script': 'sub'}, {'script': 'super'}], [{'indent': '-1'}, {'indent': '+1'}], [{'direction': 'rtl'}], [{'size': fontSizeStyle.whitelist}], [{'header': [1, 2, 3, 4, 5, 6, false]}], [{'color': []}, {'background': []}], [{'align': [false, 'center', 'right']}], ['clean'], ] } } } }, components: {quillEditor}, mounted() { addQuillTitle() }, methods: { onEditorReady(data) { this.wordLimit(data, 'ready'); }, onEditorBlur(data) { }, onEditorFocus(data) { }, onEditorChange(data) { this.wordLimit(data, 'change'); this.$emit('editChange', this.content) }, escapeStringHTML(str) { str = str.replace(/</g, '<'); str = str.replace(/>/g, '>'); return str; }, wordLimit(data, mode) { let opt = mode === 'ready' ? data : data.quill; let content = this.content opt.text; let total = this.totalWords + 2; opt.deleteText(total - 2, 4); if (content.length === 0) { this.currentWords = total; } else { this.currentWords = total - opt.getLength() - 1; } } }, computed: { editor() { return this.$refs.richTextEditor.quill; }, }
}
|