|
|
@ -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-09 11:01:51
|
|
|
|
* @LastEditTime : 2020-01-09 11:56:10
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
import './index.scss';
|
|
|
|
import './index.scss';
|
|
|
|
import 'quill/dist/quill.core.css'; // 核心样式
|
|
|
|
import 'quill/dist/quill.core.css'; // 核心样式
|
|
|
@ -18,12 +18,9 @@ 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 FillBlot from './FillBlot';
|
|
|
|
// import Toolbar from 'quill/modules/toolbar';
|
|
|
|
|
|
|
|
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'];
|
|
|
@ -96,19 +93,38 @@ function QuillForEditor ({
|
|
|
|
},
|
|
|
|
},
|
|
|
|
backspace: {
|
|
|
|
backspace: {
|
|
|
|
key: 'Backspace',
|
|
|
|
key: 'Backspace',
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @param {*} range
|
|
|
|
|
|
|
|
* { index, // 删除元素的位置
|
|
|
|
|
|
|
|
* length // 删除元素的个数, 当删除一个时, length=0, 其它等于删除的元素的个数
|
|
|
|
|
|
|
|
* }
|
|
|
|
|
|
|
|
* @param {*} context 上下文
|
|
|
|
|
|
|
|
*/
|
|
|
|
handler: function (range, context) {
|
|
|
|
handler: function (range, context) {
|
|
|
|
console.log('调用了删除按钮', range, context);
|
|
|
|
console.log('调用了删除按钮', range, context);
|
|
|
|
// 1. 获取删除的文件
|
|
|
|
/**
|
|
|
|
// 2. 判断删除的文件中包含空格的个数
|
|
|
|
* 1. 根据range中的index及length值获取删除的起始位置
|
|
|
|
// 3. 循环调用删除方法
|
|
|
|
* length === 0 -> start = index - 1;
|
|
|
|
const r = window.confirm('确定要删除吗?')
|
|
|
|
* length !== 0 -> start = index
|
|
|
|
console.log('+++++', quill);
|
|
|
|
* 2. 获取删除的元素内容
|
|
|
|
if (r) {
|
|
|
|
* ctx = this.quill.getText(start, length === 0 ? 1 : length);
|
|
|
|
// 调用传入的删除事件
|
|
|
|
* 3. 判断当前删除的下划线是第几个
|
|
|
|
return true
|
|
|
|
*/
|
|
|
|
} else {
|
|
|
|
const {index, length} = range;
|
|
|
|
return false;
|
|
|
|
const _start = length === 0 ? index - 1 : index;
|
|
|
|
}
|
|
|
|
const _length = length || 1;
|
|
|
|
|
|
|
|
let delCtx = this.quill.getText(_start, _length);
|
|
|
|
|
|
|
|
// aa
|
|
|
|
|
|
|
|
console.log(delCtx.match(/▁/g));
|
|
|
|
|
|
|
|
console.log('删除的文本信息=====>>>>', delCtx);
|
|
|
|
|
|
|
|
// const r = window.confirm('确定要删除吗?')
|
|
|
|
|
|
|
|
// if (r) {
|
|
|
|
|
|
|
|
// // 调用传入的删除事件
|
|
|
|
|
|
|
|
// return true
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// return false;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
@ -180,7 +196,11 @@ function QuillForEditor ({
|
|
|
|
_quill.getModule('toolbar').addHandler('fill', (e) => {
|
|
|
|
_quill.getModule('toolbar').addHandler('fill', (e) => {
|
|
|
|
setFillCount(fillCount + 1);
|
|
|
|
setFillCount(fillCount + 1);
|
|
|
|
const range = _quill.getSelection(true);
|
|
|
|
const range = _quill.getSelection(true);
|
|
|
|
_quill.insertText(range.index, '▁');
|
|
|
|
// _quill.insertText(range.index, '▁', { 'data_index': fillCount });
|
|
|
|
|
|
|
|
_quill.insertEmbed(range.index, 'span', {
|
|
|
|
|
|
|
|
text: '▁',
|
|
|
|
|
|
|
|
'data_index': fillCount
|
|
|
|
|
|
|
|
});
|
|
|
|
// 点击填空图标时,插入一个下划线
|
|
|
|
// 点击填空图标时,插入一个下划线
|
|
|
|
// 1. 获取编辑器内容
|
|
|
|
// 1. 获取编辑器内容
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -242,33 +262,6 @@ function QuillForEditor ({
|
|
|
|
quill.on(
|
|
|
|
quill.on(
|
|
|
|
'text-change',
|
|
|
|
'text-change',
|
|
|
|
(handler = (delta, oldDelta, source) => {
|
|
|
|
(handler = (delta, oldDelta, source) => {
|
|
|
|
// let del = false;
|
|
|
|
|
|
|
|
// let delLen = 1;
|
|
|
|
|
|
|
|
// delta.ops.forEach(o => {
|
|
|
|
|
|
|
|
// // 存在删除并且只删除一个
|
|
|
|
|
|
|
|
// if (o.delete) {
|
|
|
|
|
|
|
|
// del = true;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
// 删除编辑器内容
|
|
|
|
|
|
|
|
// if (del) {
|
|
|
|
|
|
|
|
// delLen = delta.ops[0].retain || 1; // 删除数组的长度
|
|
|
|
|
|
|
|
// // 获取删除的内容并判断其它是否有填空内容
|
|
|
|
|
|
|
|
// console.log('原编辑器内容', oldDelta);
|
|
|
|
|
|
|
|
// console.log('编辑器内容', quillCtx);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// 获取删除的内容
|
|
|
|
|
|
|
|
// oldDelta
|
|
|
|
|
|
|
|
// if (del) {
|
|
|
|
|
|
|
|
// const ops = oldDelta.ops;
|
|
|
|
|
|
|
|
// const len = ops.length;
|
|
|
|
|
|
|
|
// // if (ops[len - 1] && ops[len - 1].insert) {
|
|
|
|
|
|
|
|
// // const str = ops[len - 1].insert;
|
|
|
|
|
|
|
|
// // const _len = str.length;
|
|
|
|
|
|
|
|
// // const _last = str.substr(_len - 1);
|
|
|
|
|
|
|
|
// // console.log('删除的一项', _last);
|
|
|
|
|
|
|
|
// // }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
const _ctx = quill.getContents();
|
|
|
|
const _ctx = quill.getContents();
|
|
|
|
setQuillCtx(_ctx);
|
|
|
|
setQuillCtx(_ctx);
|
|
|
|
handleOnChange(quill.getContents()); // getContents: 检索编辑器内容
|
|
|
|
handleOnChange(quill.getContents()); // getContents: 检索编辑器内容
|
|
|
|