ueditor.html 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  5. <title>LayTp极速后台开发框架UEditor编辑器</title>
  6. <script>
  7. if(localStorage.getItem("staticDomain")){
  8. document.write("<script type='text/javascript' src='" + localStorage.getItem("staticDomain") + "/component/jquery_3.3.1.js' charset='utf-8'><\/script>");
  9. document.write("<script type='text/javascript' src='" + localStorage.getItem("staticDomain") + "/plugin/ueditor/ueditor.config.js' charset='utf-8'><\/script>");
  10. document.write("<script type='text/javascript' src='" + localStorage.getItem("staticDomain") + "/plugin/ueditor/ueditor.all.js' charset='utf-8'><\/script>");
  11. }else{
  12. document.write("<script type='text/javascript' src='/static/component/jquery_3.3.1.js' charset='utf-8'><\/script>");
  13. document.write("<script type='text/javascript' src='/static/plugin/ueditor/ueditor.config.js' charset='utf-8'><\/script>");
  14. document.write("<script type='text/javascript' src='/static/plugin/ueditor/ueditor.all.js' charset='utf-8'><\/script>");
  15. }
  16. </script>
  17. <style>
  18. body {
  19. padding: 0;
  20. margin: 0;
  21. }
  22. </style>
  23. </head>
  24. <body>
  25. <script class="editor" id="ueditorUEditor" name="ueditorUEditor" type="text/plain"></script>
  26. <script>
  27. /**
  28. * 获取Url中传递的参数值
  29. * @param name 参数名
  30. * @returns {string}
  31. */
  32. function getUrlParam(name) {
  33. let sear = window.location.search.substr(1);
  34. let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
  35. let r = sear.match(reg);
  36. return r ? sear.match(reg)[2] : "";
  37. }
  38. /**
  39. * 如下两句为了渲染编辑页面,编辑器的内容
  40. */
  41. let id = getUrlParam('id');
  42. // 得到url中传递的val,val的值就是编辑页面需要渲染编辑器内容的值
  43. let editorVal = $('.editorContent[data-id="'+id+'"]', window.parent.document).text();
  44. // 将编辑器的内容设置成val
  45. $("#ueditorUEditor").html(editorVal);
  46. // 得到url中传递的upload_type,upload_type的值就是编辑器的文件上传方式
  47. let uploadType = getUrlParam('upload_type');
  48. // 编辑器的文件上传方式如果没有设置,默认使用local,本地上传方式
  49. if(!uploadType){
  50. uploadType = 'local';
  51. }
  52. // 验证upload_type的值,目前仅允许设置成local ali-oss qiniu-kodo三种中的一种
  53. if(uploadType !== 'local' && uploadType !== 'ali-oss' && uploadType !== 'qiniu-kodo'){
  54. console.log('编辑器的文件上传方式错误');
  55. }
  56. // 根据上传方式和是否多域名配置的不同,设置编辑器的配置 serverUrl
  57. var serverUrl = '';
  58. if(uploadType === 'local'){
  59. if(localStorage.getItem("adminApiDomain")){
  60. serverUrl = localStorage.getItem("adminApiDomain") + '/plugin/ueditor/common/upload/accept/file/dir/ueditor';
  61. }else{
  62. serverUrl = '/plugin/ueditor/common/upload/accept/file/dir/ueditor';
  63. }
  64. }else if(uploadType === 'ali-oss'){
  65. if(localStorage.getItem("adminApiDomain")){
  66. serverUrl = localStorage.getItem("adminApiDomain") + '/plugin/ueditor/common/upload/accept/file/dir/ueditor/upload_type/ali-oss';
  67. }else{
  68. serverUrl = '/plugin/ueditor/common/upload/accept/file/dir/ueditor/upload_type/ali-oss';
  69. }
  70. }else if(uploadType === 'qiniu-kodo'){
  71. if(localStorage.getItem("adminApiDomain")){
  72. serverUrl = localStorage.getItem("adminApiDomain") + '/plugin/ueditor/common/upload/accept/file/dir/ueditor/upload_type/qiniu-kodo';
  73. }else{
  74. serverUrl = '/plugin/ueditor/common/upload/accept/file/dir/ueditor/upload_type/qiniu-kodo';
  75. }
  76. }
  77. // 根据是否多域名配置,设置编辑器的配置 UEDITOR_HOME_URL
  78. var UEDITOR_HOME_URL = '';
  79. if(localStorage.getItem("staticDomain")){
  80. UEDITOR_HOME_URL = localStorage.getItem("staticDomain") + '/plugin/ueditor/';
  81. }else{
  82. UEDITOR_HOME_URL = '/static/plugin/ueditor/';
  83. }
  84. // 根据是否多域名配置,设置编辑器的配置 langPath
  85. var langPath = '';
  86. if(localStorage.getItem("staticDomain")){
  87. langPath = localStorage.getItem("staticDomain") + '/plugin/ueditor/lang/';
  88. }else{
  89. langPath = '/static/plugin/ueditor/lang/';
  90. }
  91. window.ue = UE.getEditor("ueditorUEditor", {
  92. zIndex: 0,
  93. serverUrl: serverUrl,
  94. UEDITOR_HOME_URL: UEDITOR_HOME_URL,
  95. langPath: langPath,
  96. imageFieldName: "laytpUEditorUploadFile",
  97. imageActionName: "uploadimage",
  98. imageUrlPrefix: ""
  99. });
  100. window.getEditorContent = function () {
  101. return window.ue.getContent();
  102. }
  103. </script>
  104. </body>
  105. </html>