|
@@ -4,6 +4,7 @@ import { message } from 'antd';
|
|
|
import ReactQuill,{Quill} from 'react-quill';
|
|
|
import ajax from 'jquery/src/ajax/xhr.js';
|
|
|
import $ from 'jquery/src/ajax';
|
|
|
+import audioIcon from '../../image/audio.png';
|
|
|
|
|
|
|
|
|
let BlockEmbed = Quill.import('blots/block/embed');
|
|
@@ -41,7 +42,7 @@ var RichTextUploadUrl, RichTextUploadSign;
|
|
|
//上传图片
|
|
|
function uploadImg(s) {
|
|
|
let myform = new FormData()
|
|
|
- let file = document.getElementById("fileToUpload").files[0]
|
|
|
+ let file = document.getElementById("fileToUpload").files[0];
|
|
|
if (!file) { return; };
|
|
|
myform.append('file', file);
|
|
|
myform.append('sign', RichTextUploadSign);
|
|
@@ -55,20 +56,22 @@ function uploadImg(s) {
|
|
|
success: function (data) {
|
|
|
if (data.error && data.error.length) {
|
|
|
message.warning(data.error[0].message);
|
|
|
+ document.getElementById("fileToUpload").value = ''
|
|
|
} else {
|
|
|
const cursorPosition = s.quill.getSelection().index
|
|
|
- // s.quill.insertEmbed(
|
|
|
- // cursorPosition,
|
|
|
- // "image",
|
|
|
- // globalConfig.avatarUploadHost + data.data
|
|
|
- // );
|
|
|
s.quill.insertEmbed(
|
|
|
cursorPosition,
|
|
|
'AppPanelEmbed',
|
|
|
`<img style="width: 100%" src="${globalConfig.avatarUploadHost + data.data}"/>`
|
|
|
);
|
|
|
- s.quill.setSelection(cursorPosition + 1)
|
|
|
+ s.quill.setSelection(cursorPosition + 1);
|
|
|
+ document.getElementById("fileToUpload").value = ''
|
|
|
};
|
|
|
+ },
|
|
|
+ error: function(XMLHttpRequest, textStatus, errorThrown){
|
|
|
+ //查看错误信息
|
|
|
+ message("上传失败");
|
|
|
+ document.getElementById("fileToUpload").value = ''
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -109,6 +112,7 @@ function uploadAudio(s) {
|
|
|
success: function (data) {
|
|
|
if (data.error && data.error.length) {
|
|
|
message.warning(data.error[0].message);
|
|
|
+ document.getElementById("fileToUploadAudio").value = ''
|
|
|
} else {
|
|
|
const cursorPosition = s.quill.getSelection().index
|
|
|
s.quill.insertEmbed(
|
|
@@ -117,10 +121,12 @@ function uploadAudio(s) {
|
|
|
`<audio src="${globalConfig.avatarUploadHost + data.data}" controls="controls">Your browser does not support the audio element.</audio>`
|
|
|
);
|
|
|
s.quill.setSelection(cursorPosition + 1)
|
|
|
+ document.getElementById("fileToUploadAudio").value = ''
|
|
|
};
|
|
|
|
|
|
},
|
|
|
error: function(XMLHttpRequest, textStatus, errorThrown){
|
|
|
+ document.getElementById("fileToUploadAudio").value = ''
|
|
|
//查看错误信息
|
|
|
message("上传失败");
|
|
|
}
|
|
@@ -153,6 +159,7 @@ function uploadVideo(s) {
|
|
|
success: function (data) {
|
|
|
if (data.error && data.error.length) {
|
|
|
message.warning(data.error[0].message);
|
|
|
+ document.getElementById("fileToUploadVideo").value = ''
|
|
|
} else {
|
|
|
const cursorPosition = s.quill.getSelection().index
|
|
|
s.quill.insertEmbed(
|
|
@@ -162,13 +169,14 @@ function uploadVideo(s) {
|
|
|
<source src=${globalConfig.avatarUploadHost + data.data} type="video/mp4">
|
|
|
</video>`
|
|
|
);
|
|
|
- s.quill.setSelection(cursorPosition + 1)
|
|
|
+ s.quill.setSelection(cursorPosition + 1);
|
|
|
+ document.getElementById("fileToUploadVideo").value = ''
|
|
|
};
|
|
|
|
|
|
},
|
|
|
error: function(XMLHttpRequest, textStatus, errorThrown){
|
|
|
+ document.getElementById("fileToUploadVideo").value = ''
|
|
|
//查看错误信息
|
|
|
- message("上传失败");
|
|
|
}
|
|
|
})
|
|
|
}
|
|
@@ -186,7 +194,7 @@ const Editors = React.createClass({
|
|
|
// this.props.handleRichText(value.replace(/iframe/g, 'video'));
|
|
|
},
|
|
|
componentDidMount() {
|
|
|
- document.getElementsByClassName('ql-audio')[0].style = 'background: url("../../image/audio.png") no-repeat;background-size: contain;'
|
|
|
+ document.getElementsByClassName('ql-audio')[0].style = `background: url(${audioIcon}) no-repeat;background-size: contain;`
|
|
|
},
|
|
|
componentWillMount() {
|
|
|
RichTextUploadUrl = this.props.uploadUrl;
|