修改权限
This commit is contained in:
@@ -49,8 +49,8 @@ class Role extends CatchController
|
||||
{
|
||||
$this->role->storeBy($request->param());
|
||||
|
||||
if (!empty($request->param('permissionids'))) {
|
||||
$this->role->attach($request->param('permissionids'));
|
||||
if (!empty($request->param('permissions'))) {
|
||||
$this->role->attach($request->param('permissions'));
|
||||
}
|
||||
// 添加角色
|
||||
return CatchResponse::success();
|
||||
@@ -58,7 +58,9 @@ class Role extends CatchController
|
||||
|
||||
public function read($id)
|
||||
{
|
||||
|
||||
$role = $this->role->findBy($id);
|
||||
$role->permissions = $role->getPermissions();
|
||||
return CatchResponse::success($role);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,23 +71,7 @@ class Role extends CatchController
|
||||
* @return string
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$role = $this->role->findBy($id);
|
||||
|
||||
$form = new CatchForm();
|
||||
$form->formId('role');
|
||||
$form->hidden('parent_id')->default($role->parent_id);
|
||||
$form->text('role_name', '角色名称', true)->default($role->name)->verify('required')->placeholder('请输入角色名称');
|
||||
$form->textarea('description', '角色描述')->default($role->description)->placeholder('请输入角色描述');
|
||||
$form->dom('<div id="permissions"></div>', '权限');
|
||||
$form->formBtn('submitRole');
|
||||
|
||||
return $this->fetch([
|
||||
'form' => $form->render(),
|
||||
'role_id' => $role->id,
|
||||
'parent_id' => $role->parent_id
|
||||
]);
|
||||
}
|
||||
{}
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -103,8 +89,8 @@ class Role extends CatchController
|
||||
|
||||
$role->detach();
|
||||
|
||||
if (!empty($request->param('permissionids'))) {
|
||||
$role->attach($request->param('permissionids'));
|
||||
if (!empty($request->param('permissions'))) {
|
||||
$role->attach($request->param('permissions'));
|
||||
}
|
||||
|
||||
return CatchResponse::success();
|
||||
|
@@ -16,6 +16,7 @@ trait HasRolesTrait
|
||||
/**
|
||||
*
|
||||
* @time 2019年12月08日
|
||||
* @param array $fields
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRoles()
|
||||
|
@@ -40,8 +40,15 @@ class Permissions extends CatchModel
|
||||
$query->where('parent_id', $search['id'])
|
||||
->whereOr('id', $search['id']);
|
||||
})
|
||||
->when($search['permission_ids'] ?? false, function ($query) use ($search){
|
||||
$query->whereIn('id', $search['permission_ids']);
|
||||
->when($search['role_id'] ?? false, function ($query) use ($search){
|
||||
$permissionIds = [];
|
||||
$permissions = Roles::where('id', $search['role_id'])->find()->getPermissions();
|
||||
foreach ($permissions as $_permission) {
|
||||
$permissionIds[] = $_permission->pivot->permission_id;
|
||||
}
|
||||
if(!empty($permissionIds)) {
|
||||
$query->whereIn('id', $permissionIds);
|
||||
}
|
||||
})
|
||||
->order('sort', 'desc')
|
||||
->order('id', 'desc')
|
||||
|
@@ -32,7 +32,36 @@ class DataDictionary extends CatchController
|
||||
{
|
||||
$tables = Db::query('show table status');
|
||||
|
||||
return CatchResponse::paginate(Paginator::make($tables, $request->get('limit') ?? 10, $request->get('page'), count($tables), false, []));
|
||||
$tablename = $request->get('tablename');
|
||||
$engine = $request->get('engine');
|
||||
|
||||
$searchTables = [];
|
||||
$searchMode = false;
|
||||
if ($tablename || $engine) {
|
||||
$searchMode = true;
|
||||
}
|
||||
|
||||
foreach ($tables as $key => &$table) {
|
||||
$table = array_change_key_case($table);
|
||||
$table['index_length'] = $table['index_length'] > 1024 ? intval($table['index_length']/1024) .'MB' : $table['index_length'].'KB';
|
||||
$table['data_length'] = $table['data_length'] > 1024 ? intval($table['data_length']/1024) .'MB' : $table['data_length'].'KB';
|
||||
$table['create_time'] = date('Y-m-d', strtotime($table['create_time']));
|
||||
// 搜索
|
||||
if ($tablename && !$engine && stripos($table['name'], $tablename) !== false) {
|
||||
$searchTables[] = $table;
|
||||
}
|
||||
// 搜索
|
||||
if (!$tablename && $engine && stripos($table['engine'], $engine) !== false) {
|
||||
$searchTables[] = $table;
|
||||
}
|
||||
|
||||
if ($tablename && $engine && stripos($table['engine'], $engine) !== false && stripos($table['name'], $tablename) !== false) {
|
||||
$searchTables[] = $table;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return CatchResponse::paginate(Paginator::make(!$searchMode ? $tables : $searchTables, $request->get('limit') ?? 10, $request->get('page') ?? 1, $searchMode ? count($searchTables) : count($tables), false, []));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -57,9 +57,7 @@ class User extends CatchController
|
||||
{
|
||||
$this->user->storeBy($request->post());
|
||||
|
||||
if (!empty($request->param('roleids'))) {
|
||||
$this->user->attach($request->param('roleids'));
|
||||
}
|
||||
$this->user->attach($request->param('roles'));
|
||||
|
||||
return CatchResponse::success('', '添加成功');
|
||||
}
|
||||
@@ -72,7 +70,9 @@ class User extends CatchController
|
||||
*/
|
||||
public function read($id)
|
||||
{
|
||||
return CatchResponse::success($this->user->findBy($id));
|
||||
$user = $this->user->findBy($id);
|
||||
$user->roles = $user->getRoles();
|
||||
return CatchResponse::success($user);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,8 +96,8 @@ class User extends CatchController
|
||||
|
||||
$user->detach();
|
||||
|
||||
if (!empty($request->param('roleids'))) {
|
||||
$user->attach($request->param('roleids'));
|
||||
if (!empty($request->param('roles'))) {
|
||||
$user->attach($request->param('roles'));
|
||||
}
|
||||
|
||||
return CatchResponse::success();
|
||||
|
Reference in New Issue
Block a user