正在显示
1 个修改的文件
包含
21 行增加
和
1 行删除
@@ -8,6 +8,7 @@ use think\Controller; | @@ -8,6 +8,7 @@ use think\Controller; | ||
8 | use think\Hook; | 8 | use think\Hook; |
9 | use think\Lang; | 9 | use think\Lang; |
10 | use think\Session; | 10 | use think\Session; |
11 | +use fast\Tree; | ||
11 | 12 | ||
12 | /** | 13 | /** |
13 | * 后台控制器基类 | 14 | * 后台控制器基类 |
@@ -425,6 +426,13 @@ class Backend extends Controller | @@ -425,6 +426,13 @@ class Backend extends Controller | ||
425 | $searchfield = (array)$this->request->request("searchField/a"); | 426 | $searchfield = (array)$this->request->request("searchField/a"); |
426 | //自定义搜索条件 | 427 | //自定义搜索条件 |
427 | $custom = (array)$this->request->request("custom/a"); | 428 | $custom = (array)$this->request->request("custom/a"); |
429 | + //是否返回树形结构 | ||
430 | + $istree = $this->request->request("isTree", 0); | ||
431 | + $ishtml = $this->request->request("isHtml", 0); | ||
432 | + if($istree) { | ||
433 | + $word = []; | ||
434 | + $pagesize = 99999; | ||
435 | + } | ||
428 | $order = []; | 436 | $order = []; |
429 | foreach ($orderby as $k => $v) { | 437 | foreach ($orderby as $k => $v) { |
430 | $order[$v[0]] = $v[1]; | 438 | $order[$v[0]] = $v[1]; |
@@ -467,9 +475,21 @@ class Backend extends Controller | @@ -467,9 +475,21 @@ class Backend extends Controller | ||
467 | unset($item['password'], $item['salt']); | 475 | unset($item['password'], $item['salt']); |
468 | $list[] = [ | 476 | $list[] = [ |
469 | $primarykey => isset($item[$primarykey]) ? $item[$primarykey] : '', | 477 | $primarykey => isset($item[$primarykey]) ? $item[$primarykey] : '', |
470 | - $field => isset($item[$field]) ? $item[$field] : '' | 478 | + $field => isset($item[$field]) ? $item[$field] : '', |
479 | + 'pid' => isset($item['pid']) ? $item['pid'] : 0 | ||
471 | ]; | 480 | ]; |
472 | } | 481 | } |
482 | + if($istree) { | ||
483 | + $tree = Tree::instance(); | ||
484 | + $tree->init(collection($list)->toArray(), 'pid'); | ||
485 | + $list = $tree->getTreeList($tree->getTreeArray(0), $field); | ||
486 | + if(!$ishtml){ | ||
487 | + foreach ($list as &$item) { | ||
488 | + $item = str_replace(' ', ' ', $item); | ||
489 | + } | ||
490 | + unset($item); | ||
491 | + } | ||
492 | + } | ||
473 | } | 493 | } |
474 | //这里一定要返回有list这个字段,total是可选的,如果total<=list的数量,则会隐藏分页按钮 | 494 | //这里一定要返回有list这个字段,total是可选的,如果total<=list的数量,则会隐藏分页按钮 |
475 | return json(['list' => $list, 'total' => $total]); | 495 | return json(['list' => $list, 'total' => $total]); |
-
请 注册 或 登录 后发表评论