-
Notifications
You must be signed in to change notification settings - Fork 10
/
UEditor.jsx
121 lines (103 loc) · 2.86 KB
/
UEditor.jsx
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
import React from 'react';
import { Spin } from 'antd';
import createScript from './createScript';
class UEditor extends React.Component {
constructor(props) {
super(props);
this.state = {
loading: false,
};
}
loadUE() {
const url = `/ueditor/ueditor.all.js`;
const configUrl = `/ueditor/ueditor.config.js`;
const langUrl = `/ueditor/lang/zh-cn/zh-cn.js`;
// 顺序很重要~
createScript(configUrl, () => {
createScript(url, () => {
createScript(langUrl, ::this.initUE);
});
});
}
initXiuMi(baseURL) {
UE.registerUI('dialog', (editor, uiName) => {
return new UE.ui.Button({
name: 'xiumi-connect',
title: '秀米',
onclick() {
const dialog = new UE.ui.Dialog({
iframeUrl: `${baseURL}xiumi-ue-dialog-v5.html`,
editor,
name: 'xiumi-connect',
title: '秀米图文消息助手',
cssRules: `width: ${window.innerWidth - 60}px;` + `height: ${window.innerHeight - 60}px;`,
});
dialog.render();
dialog.open();
},
});
});
}
initUE() {
const baseURL = `/webpage/p/ueditor/`;
if (this.props.withXiumi) {
this.initXiuMi(baseURL);
}
// UE.delEditor('container');
const ue = this.ue = UE.getEditor('container', {
UEDITOR_HOME_URL: baseURL,
serverUrl: `}/webpage/p/ueditor/loadUEController`,
initialFrameWidth: this.props.width,
initialFrameHeight: this.props.height,
zIndex: this.props.inModal ? 1001 : 999,
toolbars: [
[
'fullscreen', 'source', '|',
'fontfamily', 'fontsize', 'bold', 'italic', 'underline', '|',
'forecolor', 'backcolor', '|',
'insertorderedlist', 'insertunorderedlist', '|',
'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|',
'horizontal', 'lineheight', '|',
'link', 'unlink', 'insertimage', 'attachment', '|',
],
],
autoHeight: false,
autoFloatEnabled: !this.props.inModal,
removeFormatAttributes: 'lang, align, hspace, valign',
});
ue.ready(() => {
if (this.props.content) {
ue.setContent(this.props.content);
}
this.setState({ loading: false });
});
}
componentDidMount() {
if (!window.baidu || !baidu.editor) {
this.loadUE();
this.setState({ loading: true });
} else {
this.initUE();
}
}
componentWillUnmount() {
// 一定要写这一句
this.ue.destroy();
}
render() {
return (
<div style={{ lineHeight: 1 }}>
{ this.state.loading ? <Spin /> : null}
<script id="container" name="content" type="text/plain" />
</div>
);
}
}
UEditor.defaultProps = {
content: '',
width: 375,
height: 250,
withXiumi: false,
inModal: false,
};
export default UEditor;