{"id":5436,"date":"2016-10-09T15:12:45","date_gmt":"2016-10-09T07:12:45","guid":{"rendered":"https:\/\/sdeno.com\/?p=5436"},"modified":"2016-10-09T15:50:42","modified_gmt":"2016-10-09T07:50:42","slug":"%e5%8d%95%e6%89%93%e7%8b%ac%e6%96%97","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=5436","title":{"rendered":"node.js\u4e3aexpress\u6dfb\u52a0\u5bcc\u6587\u672c\u7f16\u8f91\u5668\u2014\u2014ueditor"},"content":{"rendered":"<p>\u5148\u5927\u6982\u9884\u89c8\u4e0b\u6211\u76ee\u5f55\u7ed3\u6784<\/p>\n<a href=\"https:\/\/sdeno.com\/?attachment_id=5438\" rel=\"attachment wp-att-5438\"><figure class=\"mdx-lazyload-container\" style=\"max-width:255px\"><div style=\"padding-top:208.23529411765%\"><\/div><div class=\"mdx-img-loading-sp mdui-valign\"><div><div class=\"mdui-spinner\"><\/div><\/div><\/div><img width=\"255\" height=\"531\" class=\"alignnone size-full wp-image-5438 lazyload\" title=\"ueditor1\" src=\"data:image\/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==\" data-src=\"https:\/\/sdeno.com\/wp-content\/uploads\/2016\/10\/ueditor1.jpg\" alt=\"ueditor1\"><\/figure><\/a>\n<p>&nbsp;<\/p>\n<p>1\uff0c\u9996\u5148\u4e0b\u8f7dueditor\u6a21\u5757<\/p>\n<pre>npm install ueditor --save<\/pre>\n<p>&nbsp;<\/p>\n<p>2\uff0c\u5148\u4e0b\u8f7dPHP\u7248\u672c\u7684ueditor\uff1a<a href=\"http:\/\/ueditor.baidu.com\/website\/download.html\" target=\"_blank\">http:\/\/ueditor.baidu.com\/website\/download.html<\/a><\/p>\n<p>\u5728public\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u5b57\u4e3aueditor\u7684\u6587\u4ef6\u5939\uff0c\u5c06\u4e0b\u8f7d\u4e0b\u6765\u7684ueditor\u5305\u89e3\u538b\u540e\u628a\u91cc\u9762\u7684\u6240\u6709\u6587\u4ef6\u90fd\u590d\u5236\u7c98\u8d34\u5230ueditor\u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n<p>\u7f16\u8f91\u6587\u4ef6ueditor.config.js\uff0c\u5c06\u91cc\u9762\u7684\u5185\u5bb9\u4fee\u6539\u4e3a\u5982\u4e0b\uff1a<\/p>\n<pre>serverUrl: URL + \"<span style=\"color: #ff0000;\">ue<\/span>\"<\/pre>\n<p>&nbsp;<\/p>\n<p>3\uff0c\u540e\u53f0\u7f16\u8f91<\/p>\n<pre>\/\/app.js\r\n\u6ce8\u610f\u6dfb\u52a0\u7684\u6a21\u5757\u548c\u4fee\u6539\u7684\u5730\u65b9\r\n\r\nvar bodyParser = require('body-parser')  \/\/express\u9ed8\u8ba4\u5e94\u8be5\u4f1a\u52a0\u8f7d\uff0c\u82e5\u6ca1\u6709\u624b\u52a8\u6dfb\u52a0\r\nvar ueditor = require(\"ueditor\")         \/\/\u91cd\u70b9\u52a0\u8f7d\r\napp.use(bodyParser.urlencoded({\r\n extended: true       \/\/\u9ed8\u8ba4\u662ffalse,\u73b0\u5728\u6539\u4e3atrue\r\n}))\r\napp.use(bodyParser.json());  \/\/express\u9ed8\u8ba4\u5e94\u8be5\u662f\u52a0\u8f7d\u7684\r\n\r\n\r\n\r\napp.use(\"\/ueditor\/ue\", ueditor(path.join(__dirname, 'public'), function(req, res, next) {\r\n \/\/ ueditor \u5ba2\u6237\u53d1\u8d77\u4e0a\u4f20\u56fe\u7247\u8bf7\u6c42\r\n if(req.query.action === 'uploadimage'){\r\n var foo = req.ueditor;\r\n\r\n var imgname = req.ueditor.filename;\r\n\r\n var img_url = '\/images\/ueditor\/';\r\n res.ue_up(img_url); \/\/\u4f60\u53ea\u8981\u8f93\u5165\u8981\u4fdd\u5b58\u7684\u5730\u5740 \u3002\u4fdd\u5b58\u64cd\u4f5c\u4ea4\u7ed9ueditor\u6765\u505a\r\n }\r\n \/\/ \u5ba2\u6237\u7aef\u53d1\u8d77\u56fe\u7247\u5217\u8868\u8bf7\u6c42\r\n else if (req.query.action === 'listimage'){\r\n var dir_url = '\/images\/ueditor\/';\r\n res.ue_list(dir_url); \/\/ \u5ba2\u6237\u7aef\u4f1a\u5217\u51fa dir_url \u76ee\u5f55\u4e0b\u7684\u6240\u6709\u56fe\u7247\r\n }\r\n \/\/ \u5ba2\u6237\u7aef\u53d1\u8d77\u5176\u5b83\u8bf7\u6c42\r\n else {\r\n\r\n res.setHeader('Content-Type', 'application\/json');\r\n res.redirect('<span style=\"color: #ff0000;\">\/ueditor\/php\/config.json<\/span>')  \/\/\u8fd9\u91cc\u7684\u8def\u5f84\u8981\u52a0\u8f7d\u5bf9\u5426\u5219\u5c31\u4e0d\u80fd\u4e0a\u4f20\u56fe\u7247\u3002\u5982\u679c\u4f60\u4e0b\u8f7d\u7684\u662fJSP\u90a3\u5c31\u5bf9\u5e94jsp\u76ee\u5f55\r\n}}));\r\n\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>4\uff0c\u5ba2\u6237\u7aef\u7f16\u8f91<\/p>\n<p>\u5728\u4f60\u9700\u8981\u663e\u793a\u7f16\u8f91\u5668\u7684\u9875\u9762\u52a0\u8f7d<\/p>\n<pre>\/\/\u6dfb\u52a0\u8fd93\u4e2a\u6587\u4ef6\r\nscript(src=\".\/ueditor\/ueditor.config.js\")\r\nscript(src=\".\/ueditor\/ueditor.all.min.js\")\r\nscript(src=\".\/ueditor\/lang\/zh-cn\/zh-cn.js\")\r\n\r\n\r\n\/\/\u5728\u9700\u8981\u63d2\u5165\u7f16\u8f91\u5668\u7684\u4f4d\u7f6e\uff0c\u52a0\u5165\r\ntextarea(value=\"\" name=\"con_text\" style=\"width:500px;min-height:420px;display:none\")\r\nscript(id=\"editor\" type=\"text\/plain\" style=\"width:1024px;height:500px;\")\r\nscript.\r\n var ue = UE.getEditor('editor');\r\n\r\n\r\n\r\n\r\n\/\/\u9875\u9762\u6700\u5e95\u90e8\u6dfb\u52a0\uff0c\u8fd9\u4e9b\u90fd\u662f\u7f16\u8f91\u5668\u63d0\u4f9b\u7684\u65b9\u6cd5\r\n$('#context').click(function(){\r\n $.ajax({\r\n   type: 'post',\r\n   url: 'admin_index',\r\n   data:{con_text:getContent()}  \/\/\u5229\u7528getContent()\u83b7\u53d6\u5230\u7684\u5185\u5bb9\uff0c\u4f20\u7ed9name=\"con_text\",\u63d0\u4ea4\u5230\u6570\u636e\u5e93\u91cc\r\n });\r\n return false;\r\n});\r\n\r\nfunction isFocus(e){\r\n alert(UE.getEditor('editor').isFocus());\r\n UE.dom.domUtils.preventDefault(e)\r\n }\r\n function setblur(e){\r\n UE.getEditor('editor').blur();\r\n UE.dom.domUtils.preventDefault(e)\r\n }\r\n function insertHtml() {\r\n var value = prompt('\u63d2\u5165html\u4ee3\u7801', '');\r\n UE.getEditor('editor').execCommand('insertHtml', value)\r\n }\r\n function createEditor() {\r\n enableBtn();\r\n UE.getEditor('editor');\r\n }\r\n function getAllHtml() {\r\n alert(UE.getEditor('editor').getAllHtml())\r\n }\r\n function getContent() { \/\/<span style=\"color: #ff0000;\">\u5176\u4e2d\u8fd9\u4e2a\u80fd\u83b7\u53d6\u5185\u5bb9\u5305\u62ecHTML\u6807\u7b7e<\/span>\r\n var arr = [];\r\n \/\/ arr.push(\"\u4f7f\u7528editor.getContent()\u65b9\u6cd5\u53ef\u4ee5\u83b7\u5f97\u7f16\u8f91\u5668\u7684\u5185\u5bb9\");\r\n \/\/ arr.push(\"\u5185\u5bb9\u4e3a\uff1a\");\r\n arr.push(UE.getEditor('editor').getContent());\r\n \/\/ alert(arr.join(\"\\n\"));\r\n return arr;\r\n }\r\n function getPlainTxt() {\r\n var arr = [];\r\n arr.push(\"\u4f7f\u7528editor.getPlainTxt()\u65b9\u6cd5\u53ef\u4ee5\u83b7\u5f97\u7f16\u8f91\u5668\u7684\u5e26\u683c\u5f0f\u7684\u7eaf\u6587\u672c\u5185\u5bb9\");\r\n arr.push(\"\u5185\u5bb9\u4e3a\uff1a\");\r\n arr.push(UE.getEditor('editor').getPlainTxt());\r\n alert(arr.join('\\n'))\r\n }\r\n function setContent(isAppendTo) {\r\n var arr = [];\r\n arr.push(\"\u4f7f\u7528editor.setContent('\u6b22\u8fce\u4f7f\u7528ueditor')\u65b9\u6cd5\u53ef\u4ee5\u8bbe\u7f6e\u7f16\u8f91\u5668\u7684\u5185\u5bb9\");\r\n UE.getEditor('editor').setContent('\u6b22\u8fce\u4f7f\u7528ueditor', isAppendTo);\r\n alert(arr.join(\"\\n\"));\r\n }\r\n function setDisabled() {\r\n UE.getEditor('editor').setDisabled('fullscreen');\r\n disableBtn(\"enable\");\r\n }\r\n\r\n function setEnabled() {\r\n UE.getEditor('editor').setEnabled();\r\n enableBtn();\r\n }\r\n\r\n function getText() {\r\n \/\/\u5f53\u4f60\u70b9\u51fb\u6309\u94ae\u65f6\u7f16\u8f91\u533a\u57df\u5df2\u7ecf\u5931\u53bb\u4e86\u7126\u70b9\uff0c\u5982\u679c\u76f4\u63a5\u7528getText\u5c06\u4e0d\u4f1a\u5f97\u5230\u5185\u5bb9\uff0c\u6240\u4ee5\u8981\u5728\u9009\u56de\u6765\uff0c\u7136\u540e\u53d6\u5f97\u5185\u5bb9\r\n var range = UE.getEditor('editor').selection.getRange();\r\n range.select();\r\n var txt = UE.getEditor('editor').selection.getText();\r\n alert(txt)\r\n }\r\n\r\n function getContentTxt() {\r\n var arr = [];\r\n \/\/ arr.push(\"\u4f7f\u7528editor.getContentTxt()\u65b9\u6cd5\u53ef\u4ee5\u83b7\u5f97\u7f16\u8f91\u5668\u7684\u7eaf\u6587\u672c\u5185\u5bb9\");\r\n \/\/ arr.push(\"\u7f16\u8f91\u5668\u7684\u7eaf\u6587\u672c\u5185\u5bb9\u4e3a\uff1a\");\r\n arr.push(UE.getEditor('editor').getContentTxt());\r\n return arr;\r\n }\r\n function hasContent() {\r\n var arr = [];\r\n arr.push(\"\u4f7f\u7528editor.hasContents()\u65b9\u6cd5\u5224\u65ad\u7f16\u8f91\u5668\u91cc\u662f\u5426\u6709\u5185\u5bb9\");\r\n arr.push(\"\u5224\u65ad\u7ed3\u679c\u4e3a\uff1a\");\r\n arr.push(UE.getEditor('editor').hasContents());\r\n alert(arr.join(\"\\n\"));\r\n }\r\n function setFocus() {\r\n UE.getEditor('editor').focus();\r\n }\r\n function deleteEditor() {\r\n disableBtn();\r\n UE.getEditor('editor').destroy();\r\n }\r\n function disableBtn(str) {\r\n var div = document.getElementById('btns');\r\n var btns = UE.dom.domUtils.getElementsByTagName(div, \"button\");\r\n for (var i = 0, btn; btn = btns[i++];) {\r\n if (btn.id == str) {\r\n UE.dom.domUtils.removeAttributes(btn, [\"disabled\"]);\r\n } else {\r\n btn.setAttribute(\"disabled\", \"true\");\r\n }\r\n }\r\n }\r\n function enableBtn() {\r\n var div = document.getElementById('btns');\r\n var btns = UE.dom.domUtils.getElementsByTagName(div, \"button\");\r\n for (var i = 0, btn; btn = btns[i++];) {\r\n UE.dom.domUtils.removeAttributes(btn, [\"disabled\"]);\r\n }\r\n }\r\n\r\n function getLocalData () {\r\n alert(UE.getEditor('editor').execCommand( \"getlocaldata\" ));\r\n }\r\n\r\n function clearLocalData () {\r\n UE.getEditor('editor').execCommand( \"clearlocaldata\" );\r\n alert(\"\u5df2\u6e05\u7a7a\u8349\u7a3f\u7bb1\")\r\n }\r\n\r\n\r\n\r\n\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5148\u5927\u6982\u9884\u89c8\u4e0b\u6211\u76ee\u5f55\u7ed3\u6784 &nbsp; 1\uff0c\u9996\u5148\u4e0b\u8f7dueditor\u6a21\u5757 npm install ueditor  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-5436","post","type-post","status-publish","format-standard","hentry","category-nodejs"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/5436","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5436"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/5436\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5436"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5436"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5436"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}