Merge remote-tracking branch 'origin/dev_aliyun' into dev_aliyun

dev_static
杨树明 5 years ago
commit 89bf3cd9f2

@ -4,7 +4,7 @@
* @Github: * @Github:
* @Date: 2020-01-06 16:20:03 * @Date: 2020-01-06 16:20:03
* @LastEditors : tangjiang * @LastEditors : tangjiang
* @LastEditTime : 2020-01-06 17:13:19 * @LastEditTime : 2020-01-09 09:45:29
--> -->
## QuillForEditor 使用 [https://quilljs.com/] ## QuillForEditor 使用 [https://quilljs.com/]
@ -21,7 +21,7 @@
| autoFocus | 自动获得焦点 | | autoFocus | 自动获得焦点 |
| options | 配置参数, 指定工具栏内容 | | options | 配置参数, 指定工具栏内容 |
| value | 文本编辑器内容 | | value | 文本编辑器内容 |
| imgAttrs | 指定上传图片的尺寸 | | imgAttrs | 指定上传图片的尺寸 { width: 'xxpx}, height: 'xxpx'|
| style | 指定quill容器样式 | | style | 指定quill容器样式 |
| wrapStyle | 指定包裹quill容器的样式| | wrapStyle | 指定包裹quill容器的样式|
| onContentChange | 当编辑器内容变化时调用此回调函数(注: 此时返回的内容为对象,提交到后台时需要格式成 JSON 字符串: JSON.stringify(xx)) | | onContentChange | 当编辑器内容变化时调用此回调函数(注: 此时返回的内容为对象,提交到后台时需要格式成 JSON 字符串: JSON.stringify(xx)) |

@ -4,7 +4,7 @@
* @Github: * @Github:
* @Date: 2019-12-18 08:49:30 * @Date: 2019-12-18 08:49:30
* @LastEditors : tangjiang * @LastEditors : tangjiang
* @LastEditTime : 2020-01-06 16:45:50 * @LastEditTime : 2020-01-09 11:01:51
*/ */
import './index.scss'; import './index.scss';
import 'quill/dist/quill.core.css'; // 核心样式 import 'quill/dist/quill.core.css'; // 核心样式
@ -18,11 +18,12 @@ import deepEqual from './deepEqual.js'
import { fetchUploadImage } from '../../services/ojService.js'; import { fetchUploadImage } from '../../services/ojService.js';
import { getImageUrl } from 'educoder' import { getImageUrl } from 'educoder'
import ImageBlot from './ImageBlot'; import ImageBlot from './ImageBlot';
import { Modal } from 'antd';
// import Toolbar from 'quill/modules/toolbar'; // import Toolbar from 'quill/modules/toolbar';
import FillBlot from './FillBlot'; import FillBlot from './FillBlot';
const Size = Quill.import('attributors/style/size'); const Size = Quill.import('attributors/style/size');
const Font = Quill.import('formats/font'); const Font = Quill.import('formats/font');
const { confirm } = Modal;
// const Color = Quill.import('attributes/style/color'); // const Color = Quill.import('attributes/style/color');
Size.whitelist = ['12px', '14px', '16px', '18px', '20px', false]; Size.whitelist = ['12px', '14px', '16px', '18px', '20px', false];
Font.whitelist = ['SimSun', 'SimHei','Microsoft-YaHei','KaiTi','FangSong','Arial','Times-New-Roman','sans-serif']; Font.whitelist = ['SimSun', 'SimHei','Microsoft-YaHei','KaiTi','FangSong','Arial','Times-New-Roman','sans-serif'];
@ -36,6 +37,7 @@ Quill.register(Font, true);
Quill.register(FillBlot); Quill.register(FillBlot);
// Quill.register(Color); // Quill.register(Color);
function QuillForEditor ({ function QuillForEditor ({
placeholder, placeholder,
readOnly, readOnly,
@ -79,10 +81,44 @@ function QuillForEditor ({
const renderOptions = options || defaultConfig; const renderOptions = options || defaultConfig;
const bindings = {
tab: {
key: 9,
handler: function () {
console.log('调用了tab=====>>>>');
}
},
enter: {
key: 'Enter',
handler: function () {
console.log('enter====>>>>>>');
}
},
backspace: {
key: 'Backspace',
handler: function (range, context) {
console.log('调用了删除按钮', range, context);
// 1. 获取删除的文件
// 2. 判断删除的文件中包含空格的个数
// 3. 循环调用删除方法
const r = window.confirm('确定要删除吗?')
console.log('+++++', quill);
if (r) {
// 调用传入的删除事件
return true
} else {
return false;
}
}
}
};
// quill 配置信息 // quill 配置信息
const quillOption = { const quillOption = {
modules: { modules: {
toolbar: renderOptions toolbar: renderOptions,
keyboard: {
bindings: bindings
}
// toolbar: { // toolbar: {
// container: renderOptions // container: renderOptions
// } // }
@ -98,8 +134,14 @@ function QuillForEditor ({
const quillNode = document.createElement('div'); const quillNode = document.createElement('div');
editorRef.current.appendChild(quillNode); editorRef.current.appendChild(quillNode);
const _quill = new Quill(editorRef.current, quillOption); const _quill = new Quill(editorRef.current, quillOption);
setQuill(_quill);
// _quill.keyboard.addBinding({
// key: 'tab'
// }, function (range, context) {
// console.log('点击了键盘的删除按钮: ', range, context);
// });
setQuill(_quill);
// 处理图片上传功能 // 处理图片上传功能
_quill.getModule('toolbar').addHandler('image', (e) => { _quill.getModule('toolbar').addHandler('image', (e) => {
const input = document.createElement('input'); const input = document.createElement('input');
@ -142,6 +184,12 @@ function QuillForEditor ({
// 点击填空图标时,插入一个下划线 // 点击填空图标时,插入一个下划线
// 1. 获取编辑器内容 // 1. 获取编辑器内容
}); });
// TODO
/**
* 1.获取键盘删除事件
* 2.点击时获取删除的叶子节点 getLeaf(range.index)
*/
}, []); }, []);
// 设置值 // 设置值
@ -232,6 +280,7 @@ function QuillForEditor ({
}, [quill, handleOnChange]); }, [quill, handleOnChange]);
useEffect(() => { useEffect(() => {
if (!quill) return;
if (autoFocus) { if (autoFocus) {
quill.focus(); quill.focus();
} }

@ -4,7 +4,7 @@
* @Github: * @Github:
* @Date: 2019-11-20 10:35:40 * @Date: 2019-11-20 10:35:40
* @LastEditors : tangjiang * @LastEditors : tangjiang
* @LastEditTime : 2020-01-07 15:29:18 * @LastEditTime : 2020-01-09 11:04:44
*/ */
import './index.scss'; import './index.scss';
// import 'katex/dist/katex.css'; // import 'katex/dist/katex.css';
@ -291,6 +291,7 @@ class EditTab extends React.Component {
// {font: []}, // {font: []},
'image', 'formula', // 数学公式、图片、视频 'image', 'formula', // 数学公式、图片、视频
'clean', // 清除格式 'clean', // 清除格式
// 'fill',
]; ];
const renderCourseQuestion = (arrs) => { const renderCourseQuestion = (arrs) => {
@ -452,6 +453,7 @@ class EditTab extends React.Component {
colon={ false } colon={ false }
> >
<QuillForEditor <QuillForEditor
autoFocus={true}
style={{ height: '200px' }} style={{ height: '200px' }}
placeholder="请输入描述信息" placeholder="请输入描述信息"
onContentChange={handleContentChange} onContentChange={handleContentChange}

Loading…
Cancel
Save