You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
3.7 KiB
Plaintext

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!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>