| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 | <?phpnamespace app\sys\controller;// 引入框架内置类use think\facade\View;// 引入表格和表单构建器use app\common\facade\MakeBuilder;// use app\common\builder\FormBuilder;use app\common\builder\TableBuilder;use app\admin\model\SysMenu as SysMenuModel;use think\facade\Request;class SysMenu extends Base{    public function index()    {        $list = SysMenuModel::select();        View::assign('list', obj_tree($list));        View::assign('type',  ['目录', '菜单', '按钮']);        return View::fetch();    }    public function save($id = 0)    {        if ($this->app->request->isPost()) {            $param = $this->app->request->param();                        if ($param['name'] == '') {                $this->error("目录名不能为空");            }            try {                if ($param['id'] != 0) {                    SysMenuModel::update([                        'pid' => $param['pid'],                        'name' => $param['name'],                        'url' => $param['url'] ?: null,                        'type' => $param['type'],                        'icon' => $param['icon']                    ], ['id'=>$param['id']]);                } else {                    SysMenuModel::create([                        'pid' => $param['pid'],                        'name' => $param['name'],                        'url' => $param['url'] ?: null,                        'type' => $param['type'],                        'icon' => $param['icon']                    ]);                }                // 删除菜单目录缓存                \think\Facade\Cache::set('menus', null);            } catch (\Exception $e) {                $msg = $e->getMessage();                $this->error("错误提示:".$msg);            }            $this->success('操作成功', 'sys_menu/index');        } else {            if ($id != 0) {                $data = SysMenuModel::find($id);            } else {                $data = [                    'id' => 0,                    'pid' => 0,                    'name' => '',                    'url' => '',                    'type' => 0,                    'icon' =>''                ];            }                        View::assign('data', $data);            return View::fetch();        }    }    public function delete($id = null)    {        if ($this->app->request->isAjax()) {            if (SysMenuModel::where('pid', $id)->value('id')) {                return ['code'=>0, 'msg'=>'此权限子权限不为空, 若要删除请先清空子权限'];            }            if (SysMenuModel::destroy($id)) {                return ['code' => 1,'msg'=>"删除成功"];            } else {                return ['code' => 0,'msg'=>"删除失败"];            }        }    }}
 |