{"id":22932,"date":"2024-11-21T13:48:13","date_gmt":"2024-11-21T05:48:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/22932\/"},"modified":"2024-11-21T13:48:13","modified_gmt":"2024-11-21T05:48:13","slug":"thinkphp5%e6%80%8e%e4%b9%88%e5%8a%a0layui%e5%ae%9e%e7%8e%b0%e5%9b%be%e7%89%87%e4%b8%8a%e4%bc%a0%e5%8a%9f%e8%83%bd","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/22932\/","title":{"rendered":"thinkphp5\u600e\u4e48\u52a0layui\u5b9e\u73b0\u56fe\u7247\u4e0a\u4f20\u529f\u80fd"},"content":{"rendered":"<p>\u7f51\u7ad9\u4e2d\u5f88\u591a\u8868\u5355\u90fd\u4f1a\u7528\u5230\u4e0a\u4f20\u56fe\u7247\uff0clogo\uff0c\u7167\u7247\uff0c\u7528\u6237\u4e5f\u4f1a\u4e0a\u4f20\u56fe\u7247\uff0c\u8fd9\u4e2a\u65f6\u5019\u7f51\u7ad9\u5c31\u9700\u8981\u4e00\u4e2a\u4e0a\u4f20\u56fe\u7247\u7684\u529f\u80fd\uff0c\u800c\u4e14\u5728\u4e0a\u4f20\u540e\u5e0c\u671b\u80fd\u9884\u89c8\u4e00\u4e0b\u770b\u4e0a\u4f20\u7684\u5bf9\u4e0d\u5bf9\u3002<\/p>\n<p>5\u52a0\u5b9e\u73b0\u56fe\u7247\u4e0a\u4f20\u529f\u80fd\uff08\u5e26\u56fe\u7247\u9884\u89c8\uff09\u601d\u8def\uff0c\u5f02\u6b65\u4f20\u8f93\u56fe\u7247\u5e76\u9884\u89c8\uff0c\u5c06\u5f02\u6b65\u4e0a\u4f20\u540e\u7684\u503c\u8fd4\u56de\u8868\u5355\u9690\u85cf\u57df\u518d\u63d0\u4ea4\u3002<\/p>\n<h3>1\u3001\u5f15\u5165\u6587\u4ef6<\/h3>\n<p>\u9996\u5148\uff0c\u8981\u5f15\u5165jQuery\u6587\u4ef6\uff0c\u8fd9\u662f\u5fc5\u987b\u7684<\/p>\n<pre>&lt;link&gt;&lt;script&gt;&lt;\/script&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>2\u3001HTML\u90e8\u5206<\/h3>\n<pre><\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236<br \/>\n<i>\ue67c<\/i>\u4e0a\u4f20\u56fe\u7247 @@##@@&nbsp;&nbsp;\/&gt; \u4fdd\u5b58 <\/p>\n<h3>3\u3001\u529f\u80fd\u5b9e\u73b0<\/h3>\n<pre>&lt;script&gt;\n\tlayui.use([&#039;form&#039;,&#039;layer&#039;,&#039;upload&#039;],function(){\n\t\t$ = layui.jquery;\n\t\tvar form = layui.form;\n\t\tlayer = layui.layer;\n\n\t\tvar upload = layui.upload;\n   \n\t\t \/\/\u6267\u884c\u5b9e\u4f8b\n\t\tvar uploadInst = upload.render({\n\t\t\telem: &#039;#upload_img&#039; \/\/\u7ed1\u5b9a\u5143\u7d20\n\t\t\t,url: &#039;\/admins.php\/admins\/video\/upload_img&#039; \/\/\u4e0a\u4f20\u63a5\u53e3\n\t\t\t,accept:&#039;images&#039;\n\t\t\t,done: function(res){\n\t\t\t  \/\/\u4e0a\u4f20\u5b8c\u6bd5\u56de\u8c03\n\t\t\t  $(&#039;#pre_img&#039;).attr(&#039;src&#039;,res.msg);\n\t\t\t  $(&#039;input[name=\"img\"]&#039;).val(res.msg);\n\t\t\t}\n\t\t\t,error: function(){\n\t\t\t  \/\/\u8bf7\u6c42\u5f02\u5e38\u56de\u8c03\n\t\t\t}\n\t\t});\n\t});\n\n\t\/\/ \u4fdd\u5b58\n\tfunction save(){\n\t\tvar title = $.trim($(&#039;input[name=\"title\"]&#039;).val());\n\t\tvar url = $.trim($(&#039;input[name=\"url\"]&#039;).val());\n\t\tif(title == &#039;&#039;){\n\t\t\tlayer.msg(&#039;\u8bf7\u8f93\u5165\u5f71\u7247\u540d\u79f0&#039;,{&#039;icon&#039;:2,&#039;anim&#039;:6});\n\t\t\treturn;\n\t\t}\n\t\tif(url == &#039;&#039;){\n\t\t\tlayer.msg(&#039;\u8bf7\u8f93\u5165\u5f71\u7247\u5730\u5740&#039;,{&#039;icon&#039;:2,&#039;anim&#039;:6});\n\t\t\treturn;\n\t\t}\n\t\t$.post(&#039;\/admins.php\/admins\/video\/save&#039;,$(&#039;form&#039;).serialize(),function(res){\n\t\t\tif(res.code&gt;0){\n\t\t\t\tlayer.msg(res.msg,{&#039;icon&#039;:2,&#039;anim&#039;:2});\n\t\t\t}else{\n\t\t\t\tlayer.msg(res.msg,{&#039;icon&#039;:1});\n\t\t\t\tsetTimeout(function(){parent.window.location.reload();},1000);\n\t\t\t}\n\t\t},&#039;json&#039;);\n\t}\n&lt;\/script&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h3>4\u3001\u540e\u53f0\u5904\u7406<\/h3>\n<h4>\u56fe\u7247\u4e0a\u4f20<\/h4>\n<pre>public&nbsp;function&nbsp;upload_img(){\n\t$file&nbsp;=&nbsp;request()-&amp;gt;file('file');\n\tif($file==null){\n\t\texit(json_encode(array('code'=&amp;gt;1,'msg'=&amp;gt;'\u6ca1\u6709\u6587\u4ef6\u4e0a\u4f20')));\n\t}\n\t$info&nbsp;=&nbsp;$file-&amp;gt;move(ROOT_PATH.'public'.DS.'uploads');\n\t$ext&nbsp;=&nbsp;($info-&amp;gt;getExtension());\n\tif(!in_array($ext,array('jpg','jpeg','gif','png'))){\n\t\texit(json_encode(array('code'=&amp;gt;1,'msg'=&amp;gt;'\u6587\u4ef6\u683c\u5f0f\u4e0d\u652f\u6301')));\n\t}\n\t$img&nbsp;=&nbsp;'\/uploads\/'.$info-&amp;gt;getSaveName();\n\texit(json_encode(array('code'=&amp;gt;0,'msg'=&amp;gt;$img)));\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<h4>\u4fdd\u5b58\u5185\u5bb9<\/h4>\n<pre>public&nbsp;function&nbsp;save(){\n\t$id&nbsp;=&nbsp;(int)input('post.id');\n\t$data['title']&nbsp;=&nbsp;trim(input('post.title'));\n\t$data['channel_id']&nbsp;=&nbsp;(int)input('post.channel_id');\n\t$data['charge_id']&nbsp;=&nbsp;(int)input('post.charge_id');\n\t$data['area_id']&nbsp;=&nbsp;(int)input('post.area_id');\n\t$data['img']&nbsp;=&nbsp;trim(input('post.img'));\n\t$data['url']&nbsp;=&nbsp;trim(input('post.url'));\n\t$data['keywords']&nbsp;=&nbsp;trim(input('post.keywords'));\n\t$data['desc']&nbsp;=&nbsp;trim(input('post.desc'));\n\t$data['status']&nbsp;=&nbsp;(int)input('post.status');\n\n\tif($data['title']&nbsp;==&nbsp;''){\n\t\texit(json_encode(array('code'=&amp;gt;1,'msg'=&amp;gt;'\u5f71\u7247\u540d\u79f0\u4e0d\u80fd\u4e3a\u7a7a')));\n\t}\n\tif($data['url']&nbsp;==&nbsp;''){\n\t\texit(json_encode(array('code'=&amp;gt;1,'msg'=&amp;gt;'\u5f71\u7247\u5730\u5740\u4e0d\u80fd\u4e3a\u7a7a')));\n\t}\n\n\tif($id){\n\t\t$this-&amp;gt;db-&amp;gt;table('video')-&amp;gt;where(array('id'=&amp;gt;$id))-&amp;gt;update($data);\n\t}else{\n\t\t$data['add_time']&nbsp;=&nbsp;time();\n\t\t$this-&amp;gt;db-&amp;gt;table('video')-&amp;gt;insert($data);\n\t}\n\texit(json_encode(array('code'=&amp;gt;0,'msg'=&amp;gt;'\u4fdd\u5b58\u6210\u529f')));\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236<br \/>\n<img> <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f5\u600e\u4e48\u52a0\u5b9e\u73b0\u56fe\u7247\u4e0a\u4f20\u529f\u80fd\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7f51\u7ad9\u4e2d\u5f88\u591a\u8868\u5355\u90fd\u4f1a\u7528\u5230\u4e0a\u4f20\u56fe\u7247\uff0clogo\uff0c\u7167\u7247\uff0c\u7528\u6237\u4e5f\u4f1a\u4e0a\u4f20\u56fe\u7247\uff0c\u8fd9\u4e2a\u65f6\u5019\u7f51\u7ad9\u5c31\u9700\u8981\u4e00\u4e2a\u4e0a\u4f20\u56fe\u7247\u7684\u529f\u80fd\uff0c\u800c\u4e14\u5728\u4e0a\u4f20\u540e\u5e0c\u671b\u80fd\u9884\u89c8\u4e00\u4e0b\u770b\u4e0a\u4f20\u7684\u5bf9\u4e0d\u5bf9\u3002 5\u52a0\u5b9e\u73b0\u56fe\u7247\u4e0a\u4f20\u529f\u80fd\uff08\u5e26\u56fe\u7247\u9884\u89c8\uff09\u601d\u8def\uff0c\u5f02\u6b65\u4f20\u8f93\u56fe\u7247\u5e76\u9884\u89c8\uff0c\u5c06\u5f02\u6b65\u4e0a\u4f20\u540e\u7684\u503c\u8fd4\u56de\u8868\u5355\u9690\u85cf\u57df\u518d\u63d0\u4ea4\u3002 1\u3001\u5f15\u5165\u6587\u4ef6 \u9996\u5148\uff0c\u8981\u5f15\u5165jQuery\u6587\u4ef6\uff0c\u8fd9\u662f\u5fc5\u987b\u7684 &lt;link&gt;&lt;script&gt;&lt;\/script&gt; \u767b\u5f55\u540e\u590d\u5236 2\u3001HTML\u90e8\u5206 \u767b\u5f55\u540e\u590d\u5236 \ue67c\u4e0a\u4f20\u56fe\u7247 @@##@@&nbsp;&nbsp;\/&gt; \u4fdd\u5b58 3\u3001\u529f\u80fd\u5b9e\u73b0 &lt;script&gt; layui.use([&#039;form&#039;,&#039;layer&#039;,&#039;upload&#039;],function(){ $ = layui.jquery; var form = layui.form; layer = layui.layer; var upload = layui.upload; \/\/\u6267\u884c\u5b9e\u4f8b var uploadInst = upload.render({ elem: &#039;#upload_img&#039; \/\/\u7ed1\u5b9a\u5143\u7d20 ,url: &#039;\/admins.php\/admins\/video\/upload_img&#039; \/\/\u4e0a\u4f20\u63a5\u53e3 ,accept:&#039;images&#039; ,done: function(res){ \/\/\u4e0a\u4f20\u5b8c\u6bd5\u56de\u8c03 $(&#039;#pre_img&#039;).attr(&#039;src&#039;,res.msg); $(&#039;input[name=&#8221;img&#8221;]&#039;).val(res.msg); } ,error: function(){ \/\/\u8bf7\u6c42\u5f02\u5e38\u56de\u8c03 } }); }); \/\/ \u4fdd\u5b58 function [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-22932","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22932","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=22932"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/22932\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=22932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=22932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=22932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}