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 ...
随机推荐
- 【ACM】nyoj_106_背包问题_201308152026
背包问题时间限制:3000 ms | 内存限制:65535 KB 难度:3描述 现在有很多物品(它们是可以分割的),我们知道它们每个物品的单位重量的价值v和重量w(1<=v,w<=10 ...
- assign retain 和copy的区别
assign 对基础数据类型 (NSInteger,CGFloat)和C数据类型(int, float, double, char)等 等. 此标记说明设置器直接进⾏行赋值,这也是默认值.在使⽤用垃圾 ...
- PyQt5学习随笔01--计算一个目录里我们码的代码行数&&PyQt的多线程通信
今天突然想知道自学习Python以来我一共码了多少行代码了,于是写了一个简单的程序: __author__ = 'jiangzhiheng' # coding=utf-8 from PyQt5.QtC ...
- zoj2676 Network Wars(0-1分数规划,最大流模板)
Network Wars 07年胡伯涛的论文上的题:http://wenku.baidu.com/view/87ecda38376baf1ffc4fad25.html 代码: #include < ...
- selenium使用chrome抓取自动消失弹框的方法
selenium使用chrome抓取自动消失弹框的方法 转:https://blog.csdn.net/kennin19840715/article/details/76512394
- tiny4412移植opencv2.4.7手记
在买了新的4412板子后.打算趁着刚成功在6410上移植过的经验,速度解决下.不想出现了各种问题.小结下: 1.关于opencv的移植: tiny4412的linux3.5上,须要把opencv的li ...
- 学习笔记二十三——字符函数库cctype【转】
本文转载自: 字符函数库cctype 在头文件cctype(ctype.h)中定义了一些函数原型,可以简化输入确定字符是否为大写字母.数字.标点符号等工作. 例如: 如果ch是一个字母,则isalph ...
- 如何使用git 生成patch 和打入patch 标签: gitpatch【转】
本文转载自:http://blog.csdn.net/liuhaomatou/article/details/54410361 平时我们在使用git 管理项目的时候,会遇到这样一种情况,那就是客户使用 ...
- string[][]和string[,] 以及 int[][]和int[,]
string[][]和string[,] http://www.codewars.com/kata/56f3a1e899b386da78000732/train/csharp Write a func ...
- tflearn mnist 使用MLP 全连接网络一般都会加dropout哇
# -*- coding: utf-8 -*- """ Deep Neural Network for MNIST dataset classification task ...