一直用百度的ueditor,可是阿里云这种"wo chuo"的云上部署的beego做的服务,总是出现ueditor.all.min.js语法错误,清理浏览器缓存后又会好起来。本地调试也没问题。反复无常。

用froala也是因为体验了官方的demo,带图片的word直接粘贴,不像ueditor那样需要word图片转存。

还有就是少了好多配置。什么ueditor.config.js,config.json,还有什么// 服务器统一请求接口路径URL +, serverUrl:  "/controller",光写这个controller就折腾你了,因为golang语言它官方不提供啊。

开始以为froala也像ueditor那样,有语言上的障碍,用后果然如别人说的,跟语言毫无关系,只有一个上传图片的服务就好了。

所以,早点脱离苦海吧。

1.上传图片

网络上都是写这个的,我开始纳闷,难道这个编辑器只有这个吗?用了后确实,就只要这个有了,然后,就没有了,不用其他的了。

配置里:

<script>
// $(function(){
// $('#edit').froalaEditor()
// });
$(function (){
//超大屏幕
var toolbarButtons = ['fullscreen', 'bold', 'italic', 'underline', 'strikeThrough', 'subscript', 'superscript', 'fontFamily', 'fontSize', '|', 'color', 'emoticons', 'inlineStyle', 'paragraphStyle', '|', 'paragraphFormat', 'align', 'formatOL', 'formatUL', 'outdent', 'indent', 'quote', 'insertHR', '-', 'insertLink', 'insertImage', 'insertVideo', 'insertFile', 'insertTable', 'undo', 'redo', 'clearFormatting', 'selectAll', 'html'];
//大屏幕
var toolbarButtonsMD = ['fullscreen', 'bold', 'italic', 'underline', 'fontFamily', 'fontSize', 'color', 'paragraphStyle', 'paragraphFormat', 'align', 'formatOL', 'formatUL', 'outdent', 'indent', 'quote', 'insertHR', 'insertLink', 'insertImage', 'insertVideo', 'insertFile', 'insertTable', 'undo', 'redo', 'clearFormatting'];
//小屏幕
var toolbarButtonsSM = ['fullscreen', 'bold', 'italic', 'underline', 'fontFamily', 'fontSize', 'insertLink', 'insertImage', 'insertTable', 'undo', 'redo'];
//手机
var toolbarButtonsXS = ['bold', 'italic', 'fontFamily', 'fontSize', 'undo', 'redo'];
var pid = $('#pid').val();
//编辑器初始化并赋值
$('#edit').froalaEditor({
placeholderText: '请输入内容',
charCounterCount : true,//默认
// charCounterMax : -1,//默认
saveInterval : 0,//不自动保存,默认10000
// theme : "red",
height : "300px",
toolbarBottom : false,//默认
toolbarButtonsMD : toolbarButtonsMD,
toolbarButtonsSM : toolbarButtonsSM,
toolbarButtonsXS : toolbarButtonsXS,
toolbarInline : false,//true选中设置样式,默认false
imageUploadMethod : 'POST',
heightMin: 450,
charCounterMax: 3000,
// imageUploadURL: "uploadImgEditor",
imageParams: { postId: "123" },
params: {
acl: '01',
AWSAccessKeyId: '02',
policy: '03',
signature: '04',
},
autosave: true,
autosaveInterval: 2500,
saveURL: 'hander/FroalaHandler.ashx',
saveParams: { postId: '1'},
spellcheck: false,
imageUploadURL: '/uploadimg',//上传到本地服务器
imageUploadParams: {pid: '{{.Id}}'},
imageDeleteURL: 'lib/delete_image.php',//删除图片
imagesLoadURL: 'lib/load_images.php',//管理图片
enter: $.FroalaEditor.ENTER_BR,
language: 'zh_cn',
// toolbarButtons: ['bold', 'italic', 'underline', 'paragraphFormat', 'align','color','fontSize','insertImage','insertTable','undo', 'redo']
});
})
</script>

其实只有一句重点,带参数的图片上传,如下

imageUploadURL: '/uploadimg',//上传到本地服务器
imageUploadParams: {pid: '{{.Id}}'},

这样服务端就取到图片和pid参数了。

func (c *FroalaController) UploadImg() {
//解析表单
pid := c.Input().Get("pid")
// beego.Info(pid)
//pid转成64为
pidNum, err := strconv.ParseInt(pid, 10, 64)
if err != nil {
beego.Error(err)
}
//根据proj的parentIdpath
Url, DiskDirectory, err := GetUrlPath(pidNum)
if err != nil {
beego.Error(err)
}
beego.Info(DiskDirectory)
//获取上传的文件
_, h, err := c.GetFile("file")
if err != nil {
beego.Error(err)
}
// beego.Info(h.Filename)
fileSuffix := path.Ext(h.Filename)
// random_name
newname := strconv.FormatInt(time.Now().UnixNano(), 10) + fileSuffix // + "_" + filename
// err = ioutil.WriteFile(path1+newname+".jpg", ddd, 0666) //buffer输出到jpg文件中(不做处理,直接写到文件)
// if err != nil {
// beego.Error(err)
// }
year, month, _ := time.Now().Date()
err = os.MkdirAll(DiskDirectory+"\\"+strconv.Itoa(year)+month.String()+"\\", 0777) //..代表本当前exe文件目录的上级,.表示当前目录,没有.表示盘的根目录
if err != nil {
beego.Error(err)
}
var path string
var filesize int64
if h != nil {
//保存附件
path = DiskDirectory + "\\" + strconv.Itoa(year) + month.String() + "\\" + newname
Url = "/" + Url + "/" + strconv.Itoa(year) + month.String() + "/"
err = c.SaveToFile("file", path) //.Join("attachment", attachment)) //存文件 WaterMark(path) //给文件加水印
if err != nil {
beego.Error(err)
}
filesize, _ = FileSize(path)
filesize = filesize / 1000.0
c.Data["json"] = map[string]interface{}{"state": "SUCCESS", "link": Url + newname, "title": "111", "original": "demo.jpg"}
c.ServeJSON()
} else {
c.Data["json"] = map[string]interface{}{"state": "ERROR", "link": "", "title": "", "original": ""}
c.ServeJSON()
}
}

服务端返回{‘link’:图片的地址}就行了。

2.文章显示

官网有例子了。

<div class="fr-view">
{{str2html .article.Content}}
</div>

引入

<link rel="stylesheet" href="/static/froala/css/froala_style.css">

即可。比ueditor简单吧。

3.文章内容获得并提交服务端

function save2(){
var html = $('div#edit').froalaEditor('html.get');
$.ajax({
type:"post",
url:"/project/product/addarticle",
data: {content:html},
success:function(data,status){
alert("添加“"+data+"”成功!(status:"+status+".)");
},
});

var html = $('div#edit').froalaEditor('html.get');

就行了。

4.文章编辑

跟新建文章一样。

或者,如果是form表单提交,可能是按下列方法。官方的Textarea Editor例子不知道是不是想表达这个意思。

<div id="editor">
<h3>编辑文章</h3>
<form method="post" action="/project/product/updatearticle" enctype="multipart/form-data">
<label>文章内容:</label>
<textarea id='edit' style="margin-top: 30px;" placeholder="Type some text">
{{str2html .article.Content}}
</textarea>
<br />
<button type="submit" class="btn btn-primary" style="float:right">提交修改</button>
</form>
</div>
//编辑器初始化并赋值
$('#edit')
.on('froalaEditor.initialized', function (e, editor) {
$('#edit').parents('form').on('submit', function () {
// console.log($('#edit').val());
var articleid = {{.article.Id}};
var subtext = $('#subtext').val();
$.ajax({
type:"post",
url:"/project/product/updatearticle",
data: {aid:articleid,subtext:subtext,content:$('#edit').val()},
success:function(data,status){
alert("修改成功!");
window.location.reload();//刷新页面
},
});
// return false;
})
})
.froalaEditor({
// enter: $.FroalaEditor.ENTER_P,
placeholderText: '请输入内容',
charCounterCount : true,//默认
// charCounterMax : -1,//默认
saveInterval : 0,//不自动保存,默认10000
// theme : "red",
height : "550px",
toolbarBottom : false,//默认
toolbarButtonsMD : toolbarButtonsMD,
toolbarButtonsSM : toolbarButtonsSM,
toolbarButtonsXS : toolbarButtonsXS,
toolbarInline : false,//true选中设置样式,默认false
imageUploadMethod : 'POST',
heightMin: 450,
charCounterMax: 3000,
// imageUploadURL: "uploadImgEditor",
imageParams: { postId: "123" },
params: {
acl: '01',
AWSAccessKeyId: '02',
policy: '03',
signature: '04',
},
autosave: true,
autosaveInterval: 2500,
saveURL: 'hander/FroalaHandler.ashx',
saveParams: { postId: '1'},
spellcheck: false,
imageUploadURL: '/uploadimg',//上传到本地服务器
imageUploadParams: {pid: '{{.product.ProjectId}}'},
imageDeleteURL: 'lib/delete_image.php',//删除图片
imagesLoadURL: 'lib/load_images.php',//管理图片
enter: $.FroalaEditor.ENTER_BR,
language: 'zh_cn',
// toolbarButtons: ['bold', 'italic', 'underline', 'paragraphFormat', 'align','color','fontSize','insertImage','insertTable','undo', 'redo']
});
})

5.官方例子直接下载看

在github上下载的包,直接用浏览器打开index.html

一切都在,不过关于参数传递还真没找到例子。

froala富文本编辑器与golang、beego,脱离ueditor苦海的更多相关文章

  1. angular-froala-wysiwyg 富文本编辑器使用及遇到的坑

    介绍: angular-froala-wysiwyg: froala editor 的angular版本,支持Angular 2, Angular 4, Angular 5, Angular 6 an ...

  2. python 全栈开发,Day83(博客系统子评论,后台管理,富文本编辑器kindeditor,bs4模块)

    一.子评论 必须点击回复,才是子评论!否则是根评论点击回复之后,定位到输入框,同时加入@评论者的用户名 定位输入框 focus focus:获取对象焦点触发事件 先做样式.点击回复之后,定位到输入框, ...

  3. vue-froala-wysiwyg 富文本编辑器

    近期需要在vue3项目上做一个富文本编辑器,找了很多插件组件,最终决定用 froala.虽然不是免费的,但是功能实在是太强大了. froala 文档:https://www.froala.com/wy ...

  4. 富文本编辑器-SpringBoot

    目录 简介 Editor.md 基础工程搭建 数据库设计 基础项目搭建 文章编辑整合(重点) 图片上传问题 表情包问题 文章展示 简介 项目地址:https://gitee.com/zwtgit/ri ...

  5. 富文本编辑器Simditor的简易使用

    最近打算自己做一个博客系统,并不打算使用帝国cms或者wordpress之类的做后台管理!自己处于学习阶段也就想把从前台到后台一起谢了.好了,废话不多说了,先来看看富文本编辑器SimDitor,这里是 ...

  6. 个人网站对xss跨站脚本攻击(重点是富文本编辑器情况)和sql注入攻击的防范

    昨天本博客受到了xss跨站脚本注入攻击,3分钟攻陷--其实攻击者进攻的手法很简单,没啥技术含量.只能感叹自己之前竟然完全没防范. 这是数据库里留下的一些记录.最后那人弄了一个无限循环弹出框的脚本,估计 ...

  7. UEditor百度富文本编辑器--让编辑器自适应宽度的解决方案

    UEditor百度富文本编辑器的initialFrameWidth属性,默认值是1000. 不能够自适应屏幕宽度.如图1: 刚开始的时候,我是直接设置initialFrameWidth=null的.效 ...

  8. PHP Ueditor 富文本编辑器

    2016年12月11日 08:46:59 星期日 百度的简版富文本编辑器umeditor很久没更新了 全功能版本的配置项跟umeditor还是有区别的, 这里说下ueditor怎么对接到项目中去, 主 ...

  9. JavaScript 富文本编辑器

    WEB项目中使用UEditor(富文本编辑器) UEditor - 完整示例 http://ueditor.baidu.com/website/onlinedemo.html UEditor注意事项: ...

随机推荐

  1. xamarin 遇到的奇葩问题

    未能找到路径“E:\platforms”的一部分. xamarin 安卓存档出现这样的错误 建议检查下ndk是否配置完整

  2. Bash数组

    1. 数组申明 declare -a array 2. 数组赋值 #法1 array=(var1 var2 var3 ... varN) #法2 array=([]=var1 []=var2 []=v ...

  3. JavaSE-异常

    1.try catch finally 异常捕获 public class ExceptionTest { public static void main(String[] args) { int a ...

  4. Mac 下使用 brew 安装软件

    官网:http://brew.sh/安装 ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/m ...

  5. Android 开发工具类 37_ ContactInfoProvider

    Android 手机中的联系人信息保存在  data\data\com.android.providers.contacts\databases\contacts2.db 中.主要有 raw_cont ...

  6. 全网最详细的hive-site.xml配置文件里添加<name>hive.cli.print.header</name>和<name>hive.cli.print.current.db</name>前后的变化(图文详解)

    不多说,直接上干货! 比如,你是从hive-default.xml.template,复制一份,改名为hive-site.xml 一般是 <configuration> <prope ...

  7. 【JAVA SPRING】IOC与AOP

    IOC(注入)有三种类型: 构造函数注入: 属性注入: 接口注入: JAVA反射: JAVA反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法: 对于任意一个对象,都能够调用它的 ...

  8. apache 的 配置项

    一.主服务器部分 1.ServerName 指令 定义Apache默认主机名,(默认注释掉的),后面跟站点名,或是IP 例如:ServerName www.jone.com  或者 ServerNam ...

  9. 使用显式的Lock对象取代synchronized关键字进行同步

    Java SE5的java.util.concurrent类库还包含有定义在java.util.concurrent.locks中的显式的互斥机制.Lock对象必须被显式地创建.锁定和释放.因此,它与 ...

  10. 【JS】input输入框只能输入数字

    一.实现思路 input只能输入纯数字的思路其实很简单,监听输入框值的变化,每次输入检索输入框的值,将非数字的字段替换成空,再将此值赋予给输入框. 关键代码: \d:匹配数字 ^/d:全文匹配非数字 ...