editor.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>富文本编辑器</title>
  6. <meta name="renderer" content="webkit">
  7. <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  8. <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  9. <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
  10. <link rel="stylesheet" href="../css/public.css" media="all">
  11. </head>
  12. <body>
  13. <div class="layuimini-container">
  14. <div class="layuimini-main">
  15. <blockquote class="layui-elem-quote">
  16. 富文本编辑器使用开源项目:wangEditor<br>
  17. 具体使用请参考下方官网,以下仅做示例,上传接口请改为实际后端接口<br>
  18. 目前上传接口返回数据是写死在json里面的<br>
  19. <a href="http://www.wangeditor.com" target="_blank" class="layui-btn layui-btn-danger">wangEditor</a>
  20. </blockquote>
  21. <div id="editor" style="margin: 50px 0 50px 0">
  22. <p>欢迎使用 <b>wangEditor</b> 富文本编辑器</p>
  23. </div>
  24. <pre class="layui-code">
  25. var E = window.wangEditor;
  26. var editor = new E('#editor');
  27. editor.customConfig.uploadImgServer = "../api/upload.json";
  28. editor.customConfig.uploadFileName = 'image';
  29. editor.customConfig.pasteFilterStyle = false;
  30. editor.customConfig.uploadImgMaxLength = 5;
  31. editor.customConfig.uploadImgHooks = {
  32. // 上传超时
  33. timeout: function (xhr, editor) {
  34. layer.msg('上传超时!')
  35. },
  36. // 如果服务器端返回的不是 {errno:0, data: [...]} 这种格式,可使用该配置
  37. customInsert: function (insertImg, result, editor) {
  38. console.log(result);
  39. if (result.code == 1) {
  40. var url = result.data.url;
  41. url.forEach(function (e) {
  42. insertImg(e);
  43. })
  44. } else {
  45. layer.msg(result.msg);
  46. }
  47. }
  48. };
  49. editor.customConfig.customAlert = function (info) {
  50. layer.msg(info);
  51. };
  52. editor.create();
  53. </pre>
  54. </div>
  55. </div>
  56. <!-- 注意, 只需要引用 JS,无需引用任何 CSS !!!-->
  57. <script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
  58. <script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
  59. <script type="text/javascript">
  60. layui.use(['layer','wangEditor'], function () {
  61. var $ = layui.jquery,
  62. layer = layui.layer,
  63. wangEditor = layui.wangEditor;
  64. var editor = new wangEditor('#editor');
  65. editor.customConfig.uploadImgServer = "../api/upload.json";
  66. editor.customConfig.uploadFileName = 'image';
  67. editor.customConfig.pasteFilterStyle = false;
  68. editor.customConfig.uploadImgMaxLength = 5;
  69. editor.customConfig.uploadImgHooks = {
  70. // 上传超时
  71. timeout: function (xhr, editor) {
  72. layer.msg('上传超时!')
  73. },
  74. // 如果服务器端返回的不是 {errno:0, data: [...]} 这种格式,可使用该配置
  75. customInsert: function (insertImg, result, editor) {
  76. console.log(result);
  77. if (result.code == 1) {
  78. var url = result.data.url;
  79. url.forEach(function (e) {
  80. insertImg(e);
  81. })
  82. } else {
  83. layer.msg(result.msg);
  84. }
  85. }
  86. };
  87. editor.customConfig.customAlert = function (info) {
  88. layer.msg(info);
  89. };
  90. editor.create();
  91. });
  92. </script>
  93. </body>
  94. </html>