<?php
namespace app\admin\logic;
use app\admin\model\User;
use app\admin\model\Role;
use app\admin\model\Menu;
use think\exception\ValidateException;
use app\BaseController;
class IndexForm extends  Base
{
    //获取数据
    public function authList(){
    	if($this->role==1){
    		$list=Menu::order('sort ASC')->select()->toArray();
    	}else if($this->role==4){
    		 $menu_auth=Role::where('id',$this->role)->value('menu_auth');
             $this->menu_auth=json_decode($menu_auth,1);
    		$list=Menu::where('id','in',$this->menu_auth)->order('sort ASC')->select()->toArray();
    	}else{
    		$list=Menu::where('id','in',$this->menu_auth)->order('sort ASC')->select()->toArray();
    	}
    	$list=generateTree($list);
    	$auth_json=[];
    	foreach ($list as $key => $value) {
    		if(isset($value['children'])){
    			$children=[];
    			foreach ($value['children'] as $k => $v) {
    				$children[]=[
			          "path"=>$v['path'],
			          "name"=>$v['name'],
			          "component"=>$v['component'],
			          'hidden'=>$v['status']?0:1,
			          "meta"=>[
			            "title"=>$v['title'],
			            "icon"=>$v['icon']
			          ]
			        ];
    			}
    			$auth_json[]=[
	    			"path"=>$value['path'],
			        "component"=>"Layout",
			        "redirect"=>'noRedirect',
			        "name"=>$value['name'],
			        'hidden'=>$value['status']?0:1,
				    "meta"=>[
				    	"title"=>$value['title'],
				    	"icon"=>$value['icon'],
				    ],
				    "alwaysShow"=>true,
				    "children"=>$children
	    		];
    		}else{
    			$auth_json[]=[
	    			"path"=>$value['path']=='/'?'/':$value['path'],
			        "component"=>"Layout",
			        "name"=>$value['name'],
			        'hidden'=>$value['status']?0:1,
			        "redirect"=>$value['path']=='/'?'/index':$value['path'],
				    "children"=>[
				       [
				          "path"=>$value['path']=='/'?'/index':$value['path'],
				          "name"=>$value['name'],
				          "component"=>$value['component'],
				          "meta"=>[
				            "title"=>$value['title'],
				            "icon"=>$value['icon'],
				            "affix"=>true,
				            "noKeepAlive"=>true
				          ]
				       ]
				     ]
	    		];
    		}
    	}
    	return fetchJson($auth_json);

    }
}