BRAFT EDITOR富文本编辑器
https://braft.margox.cn/demos/basic 官方文档
import React from 'react'
import Uploading from '../Upload/index'
// import FuWenBen from '../fuwenben/index'
import { Form, Input, Button, AutoComplete, Radio, Card, Dropdown, Menu, Icon, message } from 'antd';
import Axios from 'axios'
import './index.scss'
import { Link } from 'react-router-dom'
import { rule } from 'postcss';
import { inject, observer } from 'mobx-react'
// 引入编辑器以及EditorState子模块
import BraftEditor from 'braft-editor'
// 引入编辑器样式
import 'braft-editor/dist/index.css'
import { getArticleContentById } from '@/api/content'
import { router } from 'sw-toolbox';
const { TextArea } = Input;
const FormItem = Form.Item;
const RadioGroup = Radio.Group;
let timer;
@inject('editStore') @observer
class EditForm extends React.Component {
constructor(props) {
super(props)
this.state = {
searchParams: {},
editorState: '', // 设置编辑器初始内容
outputHTML: '<p></p>',
imageUrl: '',
biaoqian: '',
isShow: false,
id:''
}
}
changeImg = (url) => {
this.setState({
imageUrl: url,
isShow: false
})
}
handleSubmit = (e) => {
e.preventDefault();
const { editorState } = this.state;
let submitData = {}
this.props.form.validateFields((err, values) => {
if (!this.state.imageUrl.length) {
this.setState({
isShow: true
})
return
}
if (!err) {
submitData = {
title: values.title,
zhaiyao: values.zhaiyao,
image: this.state.imageUrl,
biaoqian: values.biaoqian,
content: values.content.toHTML()// or values.content.toHTML()
}
}
})
if (this.props.type == 'contentAdd') {
this.props.newAddArticleContent(submitData)
} else if (this.props.type == 'contentEdit') {
this.props.updateArticleContent(submitData)
}
clearInterval(timer)
}
getContentById = () => {
let { searchParams } = this.state
searchParams = {
id: this.props.id
}
getArticleContentById(searchParams).then(
res => {
if (res.data.code == 200) {
this.props.form.setFieldsValue({
title: res.data.data.title,
zhaiyao: res.data.data.brief,
content: BraftEditor.createEditorState(res.data.data.content)
})
this.setState({
imageUrl: res.data.data.imagePath,
biaoqian: String(res.data.data.articleTag),
isShow: false
})
this.props.editStore.editTitle(res.data.data.title)
}
}
).catch(
err => { }
)
}
// look=()=>{
// this.props.editStore.previewArr(this.props.publishCode)
// }
componentDidMount() {
if(this.props.id){
this.getContentById()
}
// timer=setInterval(() => {
// let submitData = {}
// this.props.form.validateFields((err, values) => {
// if (!this.state.imageUrl.length) {
// this.setState({
// isShow: true
// })
// return
// }
// if (!err) {
// submitData = {
// title: values.title,
// zhaiyao: values.zhaiyao,
// image: this.state.imageUrl,
// biaoqian: values.biaoqian,
// content: values.content.toHTML()// or values.content.toHTML()
// }
// }
// })
// console.log(submitData)
// if (this.props.type == 'contentAdd') {
// this.props.newAddArticleContent(submitData)
// } else if (this.props.type == 'contentEdit') {
// this.props.updateArticleContent(submitData)
// }
// }, 5000)
}
componentWillReceiveProps(nextProps){
this.setState({
id:nextProps.id
})
}
render() {
const { setPreviewType } = this.props
const { getFieldDecorator } = this.props.form;
const { editorState, outputHTML } = this.state
const formItemLayout = {
labelCol: {
xs: { span: 24 },
sm: { span: 6 },
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 16 },
},
};
return (
<div>
<Form onSubmit={this.handleSubmit} className='container333'>
<FormItem
label="请输入主标题:"
{...formItemLayout}
>
{getFieldDecorator('title', {
rules: [{
required: true, message: '请输入主标题名称',
}]
})(
<Input placeholder="请输入主题" />
)}
</FormItem>
<FormItem
label="摘要:"
{...formItemLayout}
>
{getFieldDecorator('zhaiyao', {
rules: [{
required: true, message: '限制200个字',
}],
})(
<TextArea placeholder="限制200个字" autosize={{ minRows: 5, maxRows: 5 }} />
)}
</FormItem>
<FormItem
label="封面图片:"
{...formItemLayout}
>
{/* {getFieldDecorator('image', {
rules: [{
required: true, message: '请上传封面图片',
}]
})( */}
<div>
{this.state.imageUrl ? <Uploading changeImg={this.changeImg} imageUrl={this.state.imageUrl} /> : null}
{this.state.imageUrl ? null : <Uploading changeImg={this.changeImg} />}
</div>
{/* )} */}
</FormItem>
{this.state.isShow ? <p style={{marginLeft:'25%',marginTop:'-2%',color:'red'}}>请上传封面图片</p> : null}
<FormItem
label="文章标签:"
{...formItemLayout}
>
{getFieldDecorator('biaoqian', {
initialValue: this.state.biaoqian
})(
<RadioGroup name="radiogroup" >
<Radio name='feel' value={'1'} >new</Radio>
<Radio name='feel' value={'2'} >hot</Radio>
</RadioGroup>
)}
</FormItem>
<FormItem
label="内容编辑器:"
{...formItemLayout}
>
{getFieldDecorator('content', {
validateTrigger: 'onBlur',
rules: [
{ required: true },
{
validator: (rule, value, callback) => {
if (value.isEmpty()) {
callback('请输入正文内容')
} else {
callback()
}
}
}
]
})(
// <FuWenBen/>
<BraftEditor
height={0}
controls={
[
'undo', 'redo', 'split', 'font-size', 'font-family', 'line-height', 'letter-spacing',
'indent', 'text-color', 'bold', 'italic', 'underline', 'strike-through',
'superscript', 'subscript', 'remove-styles', 'emoji', 'text-align', 'split', 'headings', 'list_ul',
'list_ol', 'blockquote', 'code', 'split', 'link', 'split', 'hr', 'split', 'media', 'clear'
]
}
fontFamilies={
[
{
name: '宋体',
family: '"宋体",sans-serif'
}, {
name: '黑体',
family: '"黑体",serif'
}, {
name: '隶书',
family: '隶书'
},
{
name: '微软雅黑',
family: '微软雅黑'
},
{
name: '楷体',
family: '楷体'
},
{
name: 'Impact',
family: 'Impact,Charcoal'
}, {
name: 'Monospace',
family: '"Courier New", Courier, monospace'
}, {
name: 'Tahoma',
family: "tahoma, 'Hiragino Sans GB', sans-serif"
}]
}
media={{
uploadFn: (info) => {
let formData = new window.FormData()
formData.append('file', info.file, info.file.name)
Axios({
headers: {
'Content-Type': 'multipart/form-data'
},
method: 'post',
data: formData,
url: 'http://192.168.5.14:8081/node/file_upload'
}).then(res => {
if (res.data.code === 200) {
let imgurl = res.data.result[0].photoBig
let imgObj = {
data: {
link: 'http://192.168.5.14:8081/' + imgurl
}
}
info.success({
url: imgObj.data.link
// meta: {
// id: 'xxx',
// title: 'xxx',
// alt: 'xxx',
// loop: true, // 指定音视频是否循环播放
// autoPlay: true, // 指定音视频是否自动播放
// controls: true, // 指定音视频是否显示控制栏
// poster: 'http://xxx/xx.png', // 指定视频播放器的封面
// }
})
} else {
}
}, err => {
})
}
}}
/>
)}
</FormItem>
<div className='footer11'>
<div className='footer-right'>
每5分钟保存一次
</div>
</div>
<div className='footerbox'>
<Button type='primary' size='large' htmlType="submit" style={{ marginRight: 10, marginLeft: 10 }} className='save'>保存</Button>
<Button type='primary' size='large' onClick={this.look}><Link to={{pathname: '/home/preview',state:{id:this.state.id,type:'article',publishCode:this.props.publishCode}}}>预览</Link></Button>
</div>
</Form>
</div>
)
}
}
const WrappedEditForm = Form.create()(EditForm);
export default WrappedEditForm
BRAFT EDITOR富文本编辑器的更多相关文章
- 关于百度Editor富文本编辑器 自定义上传位置
因为要在网站上编辑富文本数据,所以直接采用百度的富文本编辑器,但是这个编辑器有个缺点,默认情况下,文件只能上传到网站的根目录,不能自定义路径. 而且json配置文件只能和controller.jsp在 ...
- uniapp - 富文本编辑器editor(仅支持App和微信小程序)
uniapp - editor富文本编辑器用法示例 丢几个图,用心看下去(-.-) 这里使用了https://ext.dcloud.net.cn/plugin?id=412 插件,用于选择字体颜色.其 ...
- 如何对富文本编辑器(FCK Html Editor)的工具栏进行扩展?
我们在项目开发过程中,会经常使用到富文本编辑器.GeneXus内置的富文本编辑器FCK Html Editor使用起来非常方便,只要将页面变量的控件类型(Control Type)选择为FCK Htm ...
- 富文本编辑器Simditor的简易使用
最近打算自己做一个博客系统,并不打算使用帝国cms或者wordpress之类的做后台管理!自己处于学习阶段也就想把从前台到后台一起谢了.好了,废话不多说了,先来看看富文本编辑器SimDitor,这里是 ...
- JavaScript 富文本编辑器
WEB项目中使用UEditor(富文本编辑器) UEditor - 完整示例 http://ueditor.baidu.com/website/onlinedemo.html UEditor注意事项: ...
- 富文本编辑器kindeditor配置
<!--富文本编辑器kindeditor配置↓ --> <link type="text/css" rel="stylesheet" href ...
- web开发实战--弹出式富文本编辑器的实现思路和踩过的坑
前言: 和弟弟合作, 一起整了个智慧屋的小web站点, 里面包含了很多经典的智力和推理题. 其实该站点从技术层面来分析的话, 也算一个信息发布站点. 因此在该网站的后台运营中, 富文本的编辑器显得尤为 ...
- 对于MVC中应用百度富文本编辑器问题的解决办法
1.对于应用富文本编辑器post提交表单内容提示有危险的解决办法: [ValidateInput(false)] //文本编辑器的表单提交不用提示危险 [HttpPost] public Action ...
- 轻量级富文本编辑器wangEditor源码结构介绍
1. 引言 wangEditor——一款轻量级html富文本编辑器(开源软件) 网站:http://www.wangeditor.com/ demo演示:http://www.wangeditor.c ...
随机推荐
- C# WPF 窗体传递消息
对于存在窗体的WPF程序(或者说,起码在任务栏上有个图标,即ShowInTaskbar = true),互相传递消息是很容易的. 步骤: 1,寻找窗体的句柄 2,运用windows API: Send ...
- CodeForces - 205B - Little Elephant and Sorting
先上题目: Little Elephant and Sorting time limit per test 1 second memory limit per test 256 megabytes i ...
- RDS for MySQL Mysqldump 常见问题和处理
https://help.aliyun.com/knowledge_detail/41732.html?spm=5176.7841698.2.13.u67H3h
- DataSource是一个java ee的标准接口和servlet一样,用于数据库连接池上
1.DataSource是一个java ee的标准接口和servlet一样,用于数据库连接池上,需要第三方来具体实现. 2.DataSource是一个java ee的标准接口和servlet一样,用于 ...
- Workflow:实现一个简单的审批流程
1. 创建一个空白的项目,在其中创建Host – Windows Console Application,Client – Windows forms Application和DataExchange ...
- 微信小程序的小问题(2)
1.在小程序中,有时需要用到背景图片,但是如果使用background-image的话,就无法控制图片的大小,background-image一般用于将图片压缩为1像素的背景图片,然后自动填充铺满.使 ...
- android自带的处理Bitmap out Memory 的处理,我仅仅是改变了些写法成为自己用的东西
每天上万次的启动载入证明这个载入是不错的; 第三方的载入框架非常多,推荐使用成熟框架,比方大家都知道的ImageLoad等, 这里的仅仅供学习; 我也曾在一个菜谱的项目里写过载入手机相冊图片的,只是当 ...
- AFNetworking 3.0携带參数上传文件Demo
一.服务端代码: 服务端是java用国产nutz搞的,实际mvc框架都大同小异.就是提交文件的同一时候还带了个表单參数 @AdaptBy(type=UploadAdaptor.class, args= ...
- HDU 2110-Crisis of HDU(母函数)
Crisis of HDU Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- codeforces 898F Hash
F. Restoring the Expression time limit per test 2 seconds memory limit per test 256 megabytes input ...