平臺(tái)自動(dòng)發(fā)送郵件的功能需要添加正文編輯,即需要提供在線編輯富文本,并將對(duì)應(yīng)html傳回后臺(tái)。
富文本編輯器使用quill.js
quill的風(fēng)格較為簡(jiǎn)潔美觀,提供了帶toolbar的snow和不帶toolbar的bubble兩種主題
Demo
snow
Quill引用
- npm下載:
npm install quill@1.2.0
; 或者release直接下載源文件 - 引用文件存放在/dist目錄下,復(fù)制到項(xiàng)目中
- html中添加
<!-- Include stylesheet -->
<link rel="stylesheet">
<!-- Create the editor container -->
<div id="editor">
</div>
<!-- Include the Quill library -->
<script src="https://cdn.quilljs.com/1.2.0/quill.js"></script>
<!-- Initialize Quill editor -->
<script>
var quill = new Quill('#editor', {
theme: 'snow'
});
</script>
ToolBar
toolbar的自定義:
var toolbarOptions = [
['bold', 'italic', 'underline', 'strike'], // toggled buttons
['blockquote', 'code-block'],
[{ 'header': 1 }, { 'header': 2 }], // custom button values
[{ 'list': 'ordered'}, { 'list': 'bullet' }],
[{ 'script': 'sub'}, { 'script': 'super' }], // superscript/subscript
[{ 'indent': '-1'}, { 'indent': '+1' }], // outdent/indent
[{ 'direction': 'rtl' }], // text direction
[{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown
[{ 'header': [1, 2, 3, 4, 5, 6, false] }],
[{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme
[{ 'font': [] }],
[{ 'align': [] }],
['clean'] // remove formatting button
];
var quill = new Quill('#editor', {
modules: {
toolbar: toolbarOptions
},
theme: 'snow'
});
文本對(duì)應(yīng)Html獲取
quill取消了getHtml()的API,getContents()返回的是Delta對(duì)象,一種JSON數(shù)組,getText()返回文本域里對(duì)應(yīng)字符串。
因平臺(tái)需將用戶(hù)編輯的格式傳回后臺(tái)生成郵件的正文,而郵件的正文是Html格式,通過(guò)查issue找到獲取Html的方法:quill.container.firstChild.innerHTML