-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy patheditor.html
101 lines (94 loc) · 3.73 KB
/
editor.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>富文本编辑器</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
<link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
<div class="layuimini-container">
<div class="layuimini-main">
<blockquote class="layui-elem-quote">
富文本编辑器使用开源项目:wangEditor<br>
具体使用请参考下方官网,以下仅做示例,上传接口请改为实际后端接口<br>
目前上传接口返回数据是写死在json里面的<br>
<a href="http://www.wangeditor.com" target="_blank" class="layui-btn layui-btn-danger">wangEditor</a>
</blockquote>
<div id="editor" style="margin: 50px 0 50px 0">
<p>欢迎使用 <b>wangEditor</b> 富文本编辑器</p>
</div>
<pre class="layui-code">
var E = window.wangEditor;
var editor = new E('#editor');
editor.customConfig.uploadImgServer = "../api/upload.json";
editor.customConfig.uploadFileName = 'image';
editor.customConfig.pasteFilterStyle = false;
editor.customConfig.uploadImgMaxLength = 5;
editor.customConfig.uploadImgHooks = {
// 上传超时
timeout: function (xhr, editor) {
layer.msg('上传超时!')
},
// 如果服务器端返回的不是 {errno:0, data: [...]} 这种格式,可使用该配置
customInsert: function (insertImg, result, editor) {
console.log(result);
if (result.code == 1) {
var url = result.data.url;
url.forEach(function (e) {
insertImg(e);
})
} else {
layer.msg(result.msg);
}
}
};
editor.customConfig.customAlert = function (info) {
layer.msg(info);
};
editor.create();
</pre>
</div>
</div>
<!-- 注意, 只需要引用 JS,无需引用任何 CSS !!!-->
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script type="text/javascript">
layui.use(['layer','wangEditor'], function () {
var $ = layui.jquery,
layer = layui.layer,
wangEditor = layui.wangEditor;
var editor = new wangEditor('#editor');
editor.customConfig.uploadImgServer = "../api/upload.json";
editor.customConfig.uploadFileName = 'image';
editor.customConfig.pasteFilterStyle = false;
editor.customConfig.uploadImgMaxLength = 5;
editor.customConfig.uploadImgHooks = {
// 上传超时
timeout: function (xhr, editor) {
layer.msg('上传超时!')
},
// 如果服务器端返回的不是 {errno:0, data: [...]} 这种格式,可使用该配置
customInsert: function (insertImg, result, editor) {
console.log(result);
if (result.code == 1) {
var url = result.data.url;
url.forEach(function (e) {
insertImg(e);
})
} else {
layer.msg(result.msg);
}
}
};
editor.customConfig.customAlert = function (info) {
layer.msg(info);
};
editor.create();
});
</script>
</body>
</html>