Merge branch 'dev_aliyun' of http://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

newyslclassrooms
cxt 5 years ago
commit c11f9260c0

@ -10,11 +10,9 @@ import './index.scss';
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Form, Button, Input } from 'antd'; import { Form, Button, Input } from 'antd';
import QuillForEditor from '../../quillForEditor'; import QuillForEditor from '../../quillForEditor';
// import { QuillDeltaToHtmlConverter } from 'quill-delta-to-html'
// import {formatDelta} from './util';
const FormItem = Form.Item; const FormItem = Form.Item;
function CommentForm (props) { function CommentForm(props) {
const { const {
onCancel, onCancel,
@ -28,9 +26,6 @@ function CommentForm (props) {
const [focus, setFocus] = useState(false); const [focus, setFocus] = useState(false);
const options = [ const options = [
// ['bold', 'italic', 'underline'],
// [{header: [1,2,3,false]}],
'code-block',
'link', 'link',
'image', 'image',
'formula' 'formula'
@ -52,12 +47,10 @@ function CommentForm (props) {
// 编辑器内容变化时 // 编辑器内容变化时
const handleContentChange = (content) => { const handleContentChange = (content) => {
console.log('编辑器内容', content);
setCtx(content); setCtx(content);
try { try {
// const _html = new QuillDeltaToHtmlConverter(content.ops, {}).convert(); // const _html = new QuillDeltaToHtmlConverter(content.ops, {}).convert();
// props.form.setFieldsValue({'comment': _html.replace(/<\/?[^>]*>/g, '')}); props.form.setFieldsValue({ 'comment': content });
props.form.setFieldsValue({'comment': content});
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
@ -69,7 +62,7 @@ function CommentForm (props) {
if (!err) { if (!err) {
setShowQuill(false); setShowQuill(false);
const content = ctx; const content = ctx;
props.form.setFieldsValue({'comment': ''}); props.form.setFieldsValue({ 'comment': '' });
setCtx(''); setCtx('');
// const _html = formatDelta(content.ops); // const _html = formatDelta(content.ops);
// console.log('保存的内容=====》》》》', content); // console.log('保存的内容=====》》》》', content);
@ -95,7 +88,7 @@ function CommentForm (props) {
{ {
getFieldDecorator('comment', { getFieldDecorator('comment', {
rules: [ rules: [
{ required: true, message: '评论内容不能为空'} { required: true, message: '评论内容不能为空' }
], ],
})( })(
<Input <Input
@ -112,7 +105,7 @@ function CommentForm (props) {
} }
<QuillForEditor <QuillForEditor
imgAttrs={{width: '60px', height: '30px'}} imgAttrs={{ width: '60px', height: '30px' }}
wrapStyle={{ wrapStyle={{
height: showQuill ? 'auto' : '0px', height: showQuill ? 'auto' : '0px',
opacity: showQuill ? 1 : 0, opacity: showQuill ? 1 : 0,
@ -130,7 +123,7 @@ function CommentForm (props) {
</FormItem> </FormItem>
<FormItem style={{ textAlign: 'right', display: showQuill ? 'block' : 'none' }}> <FormItem style={{ textAlign: 'right', display: showQuill ? 'block' : 'none' }}>
<Button onClick={handleCancle}>取消</Button> <Button onClick={handleCancle}>取消</Button>
<Button onClick={handleSubmit} type="primary" style={{ marginLeft: '10px'}}>发送</Button> <Button onClick={handleSubmit} type="primary" style={{ marginLeft: '10px' }}>发送</Button>
</FormItem> </FormItem>
</Form> </Form>
); );

@ -237,7 +237,6 @@ function CommentItem({
/> />
</div> </div>
{/* 显示上传的图片信息 */}
<div className="show_upload_image" style={{ display: url ? 'block' : 'none' }}> <div className="show_upload_image" style={{ display: url ? 'block' : 'none' }}>
<Icon type="close" className="image_close" onClick={handleClose} /> <Icon type="close" className="image_close" onClick={handleClose} />
<div className="image_info"> <div className="image_info">

@ -8,19 +8,15 @@
*/ */
import Quill from 'quill'; import Quill from 'quill';
let Inline = Quill.import('blots/inline'); let Inline = Quill.import('blots/inline');
// const BlockEmbed = Quill.import('blots/embed');
class FillBlot extends Inline { class FillBlot extends Inline {
static create (value) { static create(value) {
const node = super.cerate(value); const node = super.cerate(value);
// node.classList.add('icon icon-bianji2');
// node.setAttribute('data-fill', 'fill');
console.log('编辑器值===》》》》》', value);
node.setAttribute('data_index', value.data_index); node.setAttribute('data_index', value.data_index);
node.nodeValue = value.text; node.nodeValue = value.text;
return node; return node;
} }
static value (node) { static value(node) {
return { return {
// dataSet: node.getAttribute('data-fill'), // dataSet: node.getAttribute('data-fill'),
data_index: node.getAttribute('data_index') data_index: node.getAttribute('data_index')

@ -17,7 +17,6 @@ export default class ImageBlot extends BlockEmbed {
const node = super.create(); const node = super.create();
node.setAttribute('alt', value.alt); node.setAttribute('alt', value.alt);
node.setAttribute('src', value.url); node.setAttribute('src', value.url);
// console.log('~~~~~~~~~~~', node, value);
node.addEventListener('click', function () { node.addEventListener('click', function () {
value.onclick(value.url); value.onclick(value.url);
}, false); }, false);
@ -33,25 +32,14 @@ export default class ImageBlot extends BlockEmbed {
} }
// 宽度和高度都不存在时, // 宽度和高度都不存在时,
if (!value.width && !value.height) { if (!value.width && !value.height) {
// node.setAttribute('display', 'block');
node.setAttribute('width', '100%'); node.setAttribute('width', '100%');
} }
// node.setAttribute('style', { cursor: 'pointer' });
// if (node.onclick) {
// console.log('image 有图片点击事件======》》》》》》');
// // node.setAttribute('onclick', node.onCLick);
// }
// 给图片添加点击事件
// node.onclick = () => {
// value.onClick && value.onClick(value.url);
// }
return node; return node;
} }
// 获取节点值 // 获取节点值
static value (node) { static value(node) {
return { return {
alt: node.getAttribute('alt'), alt: node.getAttribute('alt'),
@ -61,7 +49,6 @@ export default class ImageBlot extends BlockEmbed {
height: node.height, height: node.height,
display: node.getAttribute('display'), display: node.getAttribute('display'),
id: node.id, id: node.id,
// style: node.style
}; };
} }
} }

@ -20,16 +20,17 @@ import { fetchUploadImage } from '../../services/ojService.js';
import { getImageUrl } from 'educoder' import { getImageUrl } from 'educoder'
import ImageBlot from './ImageBlot'; import ImageBlot from './ImageBlot';
import FillBlot from './FillBlot'; import FillBlot from './FillBlot';
import LinkBlot from './link-blot'
var Size = Quill.import('attributors/style/size'); var Size = Quill.import('attributors/style/size');
// const Color = Quill.import('attributes/style/color');
Size.whitelist = ['14px', '16px', '18px', '20px', false]; Size.whitelist = ['14px', '16px', '18px', '20px', false];
var fonts = ['Microsoft-YaHei','SimSun', 'SimHei','KaiTi','FangSong']; var fonts = ['Microsoft-YaHei', 'SimSun', 'SimHei', 'KaiTi', 'FangSong'];
var Font = Quill.import('formats/font'); var Font = Quill.import('formats/font');
Font.whitelist = fonts; //将字体加入到白名单 Font.whitelist = fonts; //将字体加入到白名单
window.Quill = Quill; window.Quill = Quill;
window.katex = katex; window.katex = katex;
Quill.register(ImageBlot); Quill.register(ImageBlot);
Quill.register(Size); Quill.register(Size);
Quill.register(LinkBlot);
Quill.register(Font, true); Quill.register(Font, true);
// Quill.register({'modules/toolbar': Toolbar}); // Quill.register({'modules/toolbar': Toolbar});
Quill.register({ Quill.register({
@ -38,7 +39,7 @@ Quill.register({
// Quill.register(Color); // Quill.register(Color);
function QuillForEditor ({ function QuillForEditor({
placeholder, placeholder,
readOnly, readOnly,
autoFocus = false, autoFocus = false,
@ -51,17 +52,16 @@ function QuillForEditor ({
onContentChange, onContentChange,
addFill, // 点击填空成功的回调 addFill, // 点击填空成功的回调
deleteFill // 删除填空,返回删除的下标 deleteFill // 删除填空,返回删除的下标
// getQuillContent
}) { }) {
// toolbar 默认值 // toolbar 默认值
const defaultConfig = [ const defaultConfig = [
'bold', 'italic', 'underline', 'bold', 'italic', 'underline',
{size: ['14px', '16px', '18px', '20px']}, { size: ['14px', '16px', '18px', '20px'] },
{align: []}, {list: 'ordered'}, {list: 'bullet'}, // 列表 { align: [] }, { list: 'ordered' }, { list: 'bullet' }, // 列表
{script: 'sub'}, {script: 'super'}, { script: 'sub' }, { script: 'super' },
{ 'color': [] }, { 'background': [] }, { 'color': [] }, { 'background': [] },
{ 'font': []}, { 'font': [] },
{header: [1,2,3,4,5,false]}, { header: [1, 2, 3, 4, 5, false] },
'blockquote', 'code-block', 'blockquote', 'code-block',
'link', 'image', 'video', 'link', 'image', 'video',
'formula', 'formula',
@ -77,7 +77,6 @@ function QuillForEditor ({
// 文本内容变化时 // 文本内容变化时
const handleOnChange = content => { const handleOnChange = content => {
// getQuillContent && getQuillContent(quill);
onContentChange && onContentChange(content, quill); onContentChange && onContentChange(content, quill);
}; };
@ -86,9 +85,7 @@ function QuillForEditor ({
const bindings = { const bindings = {
tab: { tab: {
key: 9, key: 9,
handler: function () { handler: function () { }
console.log('调用了tab=====>>>>');
}
}, },
backspace: { backspace: {
key: 'Backspace', key: 'Backspace',
@ -104,11 +101,10 @@ function QuillForEditor ({
* index: 删除元素的位置 * index: 删除元素的位置
* length: 删除元素的个数 * length: 删除元素的个数
*/ */
const {index, length} = range; const { index, length } = range;
const _start = length === 0 ? index - 1 : index; const _start = length === 0 ? index - 1 : index;
const _length = length || 1; const _length = length || 1;
let delCtx = this.quill.getText(_start, _length); // 删除的元素 let delCtx = this.quill.getText(_start, _length); // 删除的元素
// aa
const reg = /▁/g; const reg = /▁/g;
const delArrs = delCtx.match(reg); const delArrs = delCtx.match(reg);
if (delArrs) { if (delArrs) {
@ -216,7 +212,7 @@ function QuillForEditor ({
const ops = value.ops || []; const ops = value.ops || [];
ops.forEach((item, i) => { ops.forEach((item, i) => {
if (item.insert['image']) { if (item.insert['image']) {
item.insert['image'] = Object.assign({}, item.insert['image'], {style: { cursor: 'pointer' }, onclick: (url) => showUploadImage(url)}); item.insert['image'] = Object.assign({}, item.insert['image'], { style: { cursor: 'pointer' }, onclick: (url) => showUploadImage(url) });
} }
}); });
} }
@ -225,7 +221,7 @@ function QuillForEditor ({
if (!deepEqual(previous, current)) { if (!deepEqual(previous, current)) {
setSelection(quill.getSelection()) setSelection(quill.getSelection())
if (typeof value === 'string' && value) { if (typeof value === 'string' && value) {
// debugger // debugger
quill.clipboard.dangerouslyPasteHTML(value, 'api'); quill.clipboard.dangerouslyPasteHTML(value, 'api');
if (autoFocus) { if (autoFocus) {
quill.focus(); quill.focus();
@ -273,9 +269,9 @@ function QuillForEditor ({
// 返回结果 // 返回结果
return ( return (
<div className='quill_editor_for_react_area' style={wrapStyle}> <div className='quill_editor_for_react_area' style={wrapStyle}>
<div ref={editorRef} style={style}></div> <div ref={editorRef} style={style}></div>
</div> </div>
); );
} }

@ -0,0 +1,21 @@
import Quill from "quill";
const Inline = Quill.import('blots/inline');
export default class LinkBlot extends Inline {
static create(value) {
let node = super.create()
let rs = value
if (rs.indexOf('http://') < 0) {
rs = 'http://' + rs
}
node.setAttribute('href', rs)
node.setAttribute('target', '_blank')
return node;
}
static formats(node) {
return node.getAttribute('href');
}
}
LinkBlot.blotName = 'link'
LinkBlot.tagName = 'a'
Loading…
Cancel
Save