forked from alibaba/ice
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathContentEditor.jsx
More file actions
157 lines (146 loc) · 4.62 KB
/
ContentEditor.jsx
File metadata and controls
157 lines (146 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import React, { Component } from 'react';
import IceContainer from '@icedesign/container';
import { Input, Grid, Form, Button, Select } from '@icedesign/base';
import {
FormBinderWrapper as IceFormBinderWrapper,
FormBinder as IceFormBinder,
FormError as IceFormError,
} from '@icedesign/form-binder';
import RichEditor from './RichEditor';
const { Row, Col } = Grid;
const FormItem = Form.Item;
export default class ContentEditor extends Component {
static displayName = 'ContentEditor';
static propTypes = {};
static defaultProps = {};
constructor(props) {
super(props);
this.state = {
value: {
title: '',
desc: '',
author: '',
body: null,
cats: [],
},
};
}
formChange = (value) => {
console.log('value', value);
this.setState({
value,
});
};
handleSubmit = () => {
this.postForm.validateAll((errors, values) => {
console.log('errors', errors, 'values', values);
if (errors) {
return false;
}
// ajax values
});
};
render() {
return (
<div className="content-editor">
<IceFormBinderWrapper
ref={(refInstance) => {
this.postForm = refInstance;
}}
value={this.state.value}
onChange={this.formChange}
>
<IceContainer title="文章发布">
<Form labelAlign="top" style={styles.form}>
<Row>
<Col span="11">
<FormItem label="标题" required>
<IceFormBinder name="title" required message="标题必填">
<Input placeholder="这里填写文章标题" />
</IceFormBinder>
<IceFormError name="title" />
</FormItem>
</Col>
</Row>
<Row>
<Col span="11">
<FormItem label="作者" required>
<IceFormBinder
name="author"
required
message="作者信息必填"
>
<Input placeholder="填写作者名称" />
</IceFormBinder>
<IceFormError name="author" />
</FormItem>
</Col>
<Col span="11" offset="2">
<FormItem label="分类" required>
<IceFormBinder
name="cats"
required
type="array"
message="分类必填支持多个"
>
<Select
style={styles.cats}
multiple
placeholder="请选择分类"
dataSource={[
{ label: '分类1', value: 'cat1' },
{ label: '分类2', value: 'cat2' },
{ label: '分类3', value: 'cat3' },
]}
/>
</IceFormBinder>
<IceFormError
name="cats"
render={(errors) => {
console.log('errors', errors);
return (
<div>
<span style={{ color: 'red' }}>
{errors.map((item) => item.message).join(',')}
</span>
<span style={{ marginLeft: 10 }}>
不知道选择什么分类?请 <a href="#">点击这里</a>{' '}
查看
</span>
</div>
);
}}
/>
</FormItem>
</Col>
</Row>
<FormItem label="描述">
<IceFormBinder name="desc">
<Input multiple placeholder="这里填写正文描述" />
</IceFormBinder>
</FormItem>
<FormItem label="正文" required>
<IceFormBinder name="body">
<RichEditor />
</IceFormBinder>
</FormItem>
<FormItem label=" ">
<Button type="primary" onClick={this.handleSubmit}>
发布文章
</Button>
</FormItem>
</Form>
</IceContainer>
</IceFormBinderWrapper>
</div>
);
}
}
const styles = {
form: {
marginTop: 30,
},
cats: {
width: '100%',
},
};