html富文本编辑器与nodejs,nodejs后台集成富文本编辑器(ueditor)

1 下载ueditor nodejs版本

2 复制public目录下面的文件

c7e8fc7a295e3c374f95bc549ab07b5f.png

到项目静态资源public文件夹下

17256ffe33e08ac1535275ed307f9396.png

3 在项目根目录创建ueditor文件夹

d5ce59de23dce1271778304a7891589a.png

要复制进来的内容为

5ed693a74ec4d94121738efa89028908.png

4 在根目录的 ueditor文件夹下执行 npm install 安装此目录下面package.json依赖的模块

5 项目根目录下创建 ue.js 代码部分来自于

a6379f7d233f554ea5a64eec8eee1503.png

ue.js 代码

const express = require('express'),

path= require('path'),

ueditor= require("./ueditor/"),

router=express.Router();

router.use("/",ueditor(path.join(process.cwd(),'public'),function(req,res,next){//客户端上传文件设置

//console.log(req.query.action);

let ActionType =req.query.action;if(ActionType === 'uploadimage' || ActionType === 'uploadfile' || ActionType === 'uploadvideo'){

let file_url= '/img/ueditor/';//默认图片上传地址

/*其他上传格式的地址*/

if(ActionType === 'uploadfile'){

file_url= '/file/ueditor/'; //附件

}if(ActionType === 'uploadvideo'){

file_url= '/video/ueditor/'; //视频

}

res.ue_up(file_url);//你只要输入要保存的地址 。保存操作交给ueditor来做

res.setHeader('Content-Type','text/html');

}//客户端发起图片列表请求

else if(req.query.action === 'listimage'){

let dir_url= '/img/ueditor/';

res.ue_list(dir_url);//客户端会列出 dir_url 目录下的所有图片

}else if(req.query.action === 'listfile'){

let dir_url= '/file/ueditor/';

res.ue_list(dir_url);//客户端会列出 dir_url 目录下的所有图片

}//客户端发起其它请求

else{//console.log('config.json')

res.setHeader('Content-Type','application/json');

res.redirect('/ueditor/nodejs/config.json');

}

}));

module.exports= router;

特别说明 默认ueditor上传的图片路径为 public/img/ueditor

6 路由设置 根目录下 app.js ---use()匹配的所有的路由/ueditor/ue,都会走 这个路由

5e4f55348bd646442277cb01fb854b99.png

7 后台模板使用富文本编辑器 --这里我后台主要发布文章的时候用到富文本编辑器

d0b5210dfd4cafc286634f5dd4138900.png

3791b2b0a26c21396f1cd871d5cc612a.png

特别注意:一定要实例化

a6662c49157754524ad5148abf18410e.png百度的这个富文本编辑器提供了很多种api 具体的请看

2ae6545173e349864a09672cdf252b22.png

8 由于我使用form(post)方式向mysql数据库添加数据,所以在点击提交的按钮的时候,将富文本编辑器里面的内容 添加到 form的一个input里面

$('button[type="submit"]').click(function() {var conData =getContent();

$('input.content').val(conData);

});

9 效果展示 --

d28b90e66badc1a22604d32567d8f4dc.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值