55 lines
1.4 KiB
PHP
Executable File
55 lines
1.4 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\BaseApp\BaseController;
|
|
use App\Service\RoleService;
|
|
use Exception;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Psr\Container\ContainerExceptionInterface;
|
|
use Psr\Container\NotFoundExceptionInterface;
|
|
|
|
class RoleController extends BaseController
|
|
{
|
|
//
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->insertField = ['name', 'value', 'desc'];
|
|
$this->updateField = ['id', 'name', 'value', 'desc'];
|
|
$this->service = RoleService::getInstance();
|
|
}
|
|
|
|
/**
|
|
* 获取角色菜单ID
|
|
* @Method GET
|
|
* @return JsonResponse
|
|
* @throws ContainerExceptionInterface
|
|
* @throws NotFoundExceptionInterface
|
|
*/
|
|
public function getMenuIdsByRoleIds(): JsonResponse
|
|
{
|
|
$roleId = request()->get('role_id', null);
|
|
return jok(
|
|
$this->service->getMenuIdsByRoleIds($roleId)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 保存角色菜单
|
|
* @Method POST
|
|
* @return JsonResponse
|
|
* @throws Exception
|
|
*/
|
|
public function saveRoleMenu(): JsonResponse
|
|
{
|
|
$this->insertField = ['role_id', 'menu_id'];
|
|
$this->checkRequiredFields(request()->post());
|
|
$roleId = request()->post('role_id');
|
|
$menuIds = request()->post('menu_id', []);
|
|
return jok(
|
|
$this->service->saveRoleMenu($roleId, $menuIds)
|
|
);
|
|
}
|
|
}
|