{"id":951,"date":"2021-01-20T14:59:28","date_gmt":"2021-01-20T06:59:28","guid":{"rendered":"http:\/\/blog.yyhcw.com\/?p=951"},"modified":"2021-01-20T14:59:28","modified_gmt":"2021-01-20T06:59:28","slug":"thinkcmf%e5%90%8e%e5%8f%b0%e6%a8%a1%e6%9d%bflayuimini%e8%8f%9c%e5%8d%95json%e6%a0%bc%e5%bc%8f","status":"publish","type":"post","link":"http:\/\/blog.yyhcw.com\/post\/951.html","title":{"rendered":"thinkcmf\u540e\u53f0\u6a21\u677flayuimini\u83dc\u5355json\u683c\u5f0f"},"content":{"rendered":"<!--wp-compress-html--><!--wp-compress-html no compression--><p>\u8fd9\u4e24\u5929\u4f7f\u7528<a href=\"http:\/\/blog.yyhcw.com\/post\/tag\/thinkcmf\" class=\"tag-tooltip\" data-toggle=\"tooltip\" title=\"\u67e5\u770b\u66f4\u591a\u5173\u4e8e thinkcmf \u7684\u6587\u7ae0\" target=\"_blank\">thinkcmf<\/a>6\u505a\u540e\u53f0\uff0c\u4f46\u662f\u611f\u89c9\u5176\u5b98\u65b9\u81ea\u5e26\u540e\u53f0\u6a21\u677f\u65e0\u6cd5\u81ea\u9002\u5e94\uff0c\u4e8e\u662f\u51b3\u5b9a\u4f7f\u7528layuimini\u505a\u540e\u53f0\u6a21\u677f\uff0c\u4e0b\u8f7d\u6a21\u677f\u53d1\u4e0b\u83dc\u5355\u662f\u5728\u6587\u4ef6\u4e2d\u4ee5json\u683c\u5f0f\u5b58\u5728\u7684\uff0c\u5948\u4e0e<a href=\"http:\/\/blog.yyhcw.com\/post\/tag\/thinkcmf\" class=\"tag-tooltip\" data-toggle=\"tooltip\" title=\"\u67e5\u770b\u66f4\u591a\u5173\u4e8e thinkcmf \u7684\u6587\u7ae0\" target=\"_blank\">thinkcmf<\/a>\u7684\u83dc\u5355\u76f4\u63a5\u5728\u6587\u4ef6\u4e2d\u663e\u793a\u7684\uff0c\u4e0d\u77e5\u9053\u600e\u4e48\u80fd\u83b7\u7684json\u683c\u5f0f\u83dc\u5355\uff0c\u53ea\u80fd\u81ea\u5df1\u5199\u4e00\u4e2a\u63a5\u53e3\u6765\u83b7\u53d6\u4e86\uff01<\/p>\n<p>\u5f88\u7b80\u5355\u7684\u76f4\u63a5\u4e0a\u4ee3\u7801\uff1a<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:php decode:true\" title=\"thinkcmf\u540e\u53f0\u83dc\u5355\">function getsubmenu($list){\r\n        $childs = [];\r\n        foreach ($list as $vol){\r\n            $subs = [];\r\n            if(isset($vol['items'])){\r\n                $subs = $this-&gt;getsubmenu($vol['items']);\r\n            }\r\n            $icon = $vol['icon'] ? 'fa fa-'.$vol['icon'] : '';\r\n            $submenu = [\r\n                'title'=&gt;$vol['name'],\r\n                'icon'  =&gt; $icon,\r\n                'href'=&gt;$vol['url'],\r\n                'target'=&gt;'_self',\r\n            ];\r\n            if(isset($vol['items'])){\r\n                $submenu['child'] = $subs;\r\n            }\r\n            $childs[] = $submenu;\r\n            unset($submenu);\r\n        }\r\n        return $childs;\r\n    }\r\n    public function index()\r\n    {\r\n        $adminId = cmf_get_current_admin_id();\r\n        $cmfAdminThemePath    = config('template.cmf_admin_theme_path');\r\n        $cmfAdminDefaultTheme = config('template.cmf_admin_default_theme');\r\n        $adminThemePath = \"{$cmfAdminThemePath}{$cmfAdminDefaultTheme}\";\r\n        $logo = cmf_get_root().\"\/\".$adminThemePath.'\/public\/assets\/themes\/'.cmf_get_admin_style().'\/images\/logo.png';\r\n        $menus = cache('admin_menus_' . $adminId);\r\n        if($menus){\r\n            $parent = $childs = $subs = [];\r\n            foreach ($menus as $key=&gt;$vo){\r\n                $parent = $submenu = $childs = [];\r\n                if(isset($vo['items'])){\r\n                    $childs = $this-&gt;getsubmenu($vo['items']);\r\n                }\r\n                $parent = [\r\n                    'title'=&gt;$vo['name'],\r\n                    'icon'  =&gt; 'fa fa-'.$vo['icon'],\r\n                    'href'=&gt;'',\r\n                    'target'=&gt;'_self',\r\n                    'child'=&gt;$childs\r\n                ];\r\n                $subs[] = $parent;\r\n                unset($parent);\r\n            }\r\n            $items = [\r\n                'homeInfo'=&gt;[\r\n                    'title'=&gt;'\u9996\u9875',\r\n                    'href'=&gt;''\r\n                ],\r\n                'logoInfo'=&gt;[\r\n                    'title'=&gt;'MINI',\r\n                    'image'=&gt;$logo,\r\n                    'href'=&gt;''\r\n                ],\r\n                'menuInfo'=&gt;$subs\r\n            ];\r\n            echo json_encode($items);\r\n        }\r\n    }<\/pre>\n<p>\u968f\u4fbf\u641e\u4e2aAPI\u63a5\u53e3\u4f9b\u540e\u53f0\u8c03\u7528\u5373\u53ef\uff0c\u76ee\u524d\u5b98\u65b9\u6a21\u677f\u4f7f\u7528\u6b64\u65b9\u5f0f\u6b63\u5e38\uff0c\u7279\u522b\u8bf4\u660e\u4e00\u4e0b\uff0c\u53ea\u6709\u767b\u5f55\u540e\u53f0\u624d\u4f1a\u6709\u83dc\u5355\u4fe1\u606f\uff0c\u5426\u5219\u5c06\u4ec0\u4e48\u4e5f\u4e0d\u4f1a\u663e\u793a\uff0c\u56e0\u4e3a\u8fd9\u91cc\u4f7f\u7528\u7684\u662f $menus = cache('admin_menus_' . $adminId); \u53ea\u6709\u767b\u5f55\u540e\u624d\u6709\u7684\uff01<\/p>\n<p>\u81ea\u5df1\u66f4\u6362\u540e\u53f0\u6a21\u677f\u518d\u4e5f\u4e0d\u662f\u4ec0\u4e48\u96be\u9898\u4e86<\/p>\n<!--wp-compress-html no compression--><!--wp-compress-html-->","protected":false},"excerpt":{"rendered":"\u8fd9\u4e24\u5929\u4f7f\u7528thinkcmf6\u505a\u540e\u53f0\uff0c\u4f46\u662f\u611f\u89c9\u5176\u5b98\u65b9\u81ea\u5e26\u540e\u53f0\u6a21\u677f\u65e0\u6cd5\u81ea\u9002\u5e94\uff0c\u4e8e\u662f\u51b3\u5b9a\u4f7f\u7528layuimini\u505a\u540e\u53f0 \u00b7\u00b7\u00b7","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3],"tags":[58],"views":84866,"_links":{"self":[{"href":"http:\/\/blog.yyhcw.com\/api\/wp\/v2\/posts\/951"}],"collection":[{"href":"http:\/\/blog.yyhcw.com\/api\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/blog.yyhcw.com\/api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/blog.yyhcw.com\/api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/blog.yyhcw.com\/api\/wp\/v2\/comments?post=951"}],"version-history":[{"count":0,"href":"http:\/\/blog.yyhcw.com\/api\/wp\/v2\/posts\/951\/revisions"}],"wp:attachment":[{"href":"http:\/\/blog.yyhcw.com\/api\/wp\/v2\/media?parent=951"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/blog.yyhcw.com\/api\/wp\/v2\/categories?post=951"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/blog.yyhcw.com\/api\/wp\/v2\/tags?post=951"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}