富文本 图片上传

This commit is contained in:
xiexiangrui 2020-07-04 17:07:10 +08:00
parent d0bd515ed4
commit 879f46b984
2 changed files with 60 additions and 5 deletions

View File

@ -262,7 +262,34 @@
onChange: function (contents, $edittable) { onChange: function (contents, $edittable) {
// Xss 过滤掉了html 内容 所以用base64 保存 // Xss 过滤掉了html 内容 所以用base64 保存
$("input[name='" + this.id + "']").val(window.btoa(encodeURI(contents))); $("input[name='" + this.id + "']").val(window.btoa(encodeURI(contents)));
},
onImageUpload: function(files) {
var _self = this;
for(var i = 0; i < files.length; i++){
var formData = new FormData();
formData.append('file', files[i]);
var config = {
url: '/common/upload',
type: 'post',
data: formData,
contentType: false,
processData: false,
beforeSend: function () {
$.modal.loading("正在处理中,请稍后...");
},
success: function(result) {
if (result.code == web_status.SUCCESS) {
$('#'+ _self.id).summernote('insertImage',result.url);
} else if (result.code == web_status.WARNING) {
$.modal.alertWarning(result.msg)
} else {
$.modal.alertError(result.msg);
}
$.modal.closeLoading();
}
};
$.ajax(config)
}
} }
} }
}); });

View File

@ -265,18 +265,46 @@
#if($isSummernote) #if($isSummernote)
$(function () { $(function () {
$('.summernote').each(function (i) { $('.summernote').each(function (i) {
var content = $("input[name='" + this.id + "']").val() $('#'+this.id).summernote({
content = decodeURI(window.atob(content));
this.innerHTML = content;
$(this).summernote({
height: 100, height: 100,
lang: 'zh-CN', lang: 'zh-CN',
callbacks: { callbacks: {
onChange: function (contents, $edittable) { onChange: function (contents, $edittable) {
$("input[name='" + this.id + "']").val(window.btoa(encodeURI(contents))); $("input[name='" + this.id + "']").val(window.btoa(encodeURI(contents)));
},
onImageUpload: function(files) {
var _self = this;
for(var i = 0; i < files.length; i++){
var formData = new FormData();
formData.append('file', files[i]);
var config = {
url: '/common/upload',
type: 'post',
data: formData,
contentType: false,
processData: false,
beforeSend: function () {
$.modal.loading("正在处理中,请稍后...");
},
success: function(result) {
if (result.code == web_status.SUCCESS) {
$('#'+ _self.id).summernote('insertImage',result.url);
} else if (result.code == web_status.WARNING) {
$.modal.alertWarning(result.msg)
} else {
$.modal.alertError(result.msg);
}
$.modal.closeLoading();
}
};
$.ajax(config)
}
} }
} }
}); });
var content = $("input[name='" + this.id + "']").val()
content = decodeURI(window.atob(content));
$('#'+this.id).summernote('code',content);
}) })
}); });
#end #end