/** * 根据子节点 */ public function actionAjax() { $this->layout = false; $data = []; $parentId = $this->get('parent', '#'); $id = 1; $generator = new JSTreeGenerator(); if ($parentId != '#') { $len = strlen('node_'); $id = substr($parentId, $len, strlen($parentId) - $len); $data = $generator->generator(Permission::getSub($id)); } else { $data = $generator->getDefault(); } $this->setResponseData('item', Permission::findByCache($id)); $this->setResponseData('data', $data); }
/** * 获取角色对应的权限列表 */ public function actionPerm() { $data = []; $parentId = $this->get('parent', '#'); $roleId = $this->get('id', 0); $generator = new JSTreeGenerator(); if ($parentId != '#') { $len = strlen('node_'); $id = substr($parentId, $len, strlen($parentId) - $len); $data = $generator->generator(Permission::getSub($id), true); } else { $data = $generator->getDefault(); } if (!empty($roleId)) { $roles = RolePermission::findAllArray(['role_id' => $roleId]); Permission::setChecked($data, $roles); } $this->setResponseData('data', $data); }