From a65a63373c0e1ae7d68e12d5b83aa19c3c3f19dc Mon Sep 17 00:00:00 2001 From: PPPSCN <35696959@qq.com> Date: Fri, 6 Apr 2018 23:44:18 +0800 Subject: [PATCH] =?UTF-8?q?selectpage=E6=94=AF=E6=8C=81=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E6=A0=91=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/controller/Backend.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/application/common/controller/Backend.php b/application/common/controller/Backend.php index 77a5f817..41189ab5 100644 --- a/application/common/controller/Backend.php +++ b/application/common/controller/Backend.php @@ -8,6 +8,7 @@ use think\Controller; use think\Hook; use think\Lang; use think\Session; +use fast\Tree; /** * 后台控制器基类 @@ -124,6 +125,10 @@ class Backend extends Controller Hook::listen('admin_nologin', $this); $url = Session::get('referer'); $url = $url ? $url : $this->request->url(); + if ($url == '/') { + $this->redirect('index/login', [], 302, ['referer' => $url]); + exit; + } $this->error(__('Please login first'), url('index/login', ['url' => $url])); } // 判断是否需要验证权限 @@ -431,6 +436,12 @@ class Backend extends Controller $searchfield = (array) $this->request->request("searchField/a"); //自定义搜索条件 $custom = (array) $this->request->request("custom/a"); + //是否返回树形结构 + $istree = $this->request->request("isTree", 0); + if($istree) { + $word = []; + $pagesize = 99999; + } $order = []; foreach ($orderby as $k => $v) { @@ -481,6 +492,15 @@ class Backend extends Controller ->field("{$primarykey},{$field}") ->field("password,salt", true) ->select(); + if($istree) { + $tree = Tree::instance(); + $tree->init(collection($list)->toArray(), 'pid'); + $list = $tree->getTreeList($tree->getTreeArray(0), 'name'); + foreach ($list as &$item) { + $item = str_replace(' ', ' ', $item); + } + unset($item); + } } //这里一定要返回有list这个字段,total是可选的,如果total<=list的数量,则会隐藏分页按钮 return json(['list' => $list, 'total' => $total]);