diff --git a/catch/permissions/controller/Role.php b/catch/permissions/controller/Role.php index 7605d90..d9c1315 100644 --- a/catch/permissions/controller/Role.php +++ b/catch/permissions/controller/Role.php @@ -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('
', '权限'); - $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(); diff --git a/catch/permissions/model/HasRolesTrait.php b/catch/permissions/model/HasRolesTrait.php index f9219c8..8b4cd04 100644 --- a/catch/permissions/model/HasRolesTrait.php +++ b/catch/permissions/model/HasRolesTrait.php @@ -13,11 +13,12 @@ trait HasRolesTrait return $this->belongsToMany(Roles::class, 'user_has_roles', 'role_id', 'uid'); } - /** - * - * @time 2019年12月08日 - * @return mixed - */ + /** + * + * @time 2019年12月08日 + * @param array $fields + * @return mixed + */ public function getRoles() { return $this->roles()->select(); @@ -54,4 +55,4 @@ trait HasRolesTrait return $this->roles()->detach($roles); } -} \ No newline at end of file +} diff --git a/catch/permissions/model/Permissions.php b/catch/permissions/model/Permissions.php index 880b11e..9ae2ce7 100644 --- a/catch/permissions/model/Permissions.php +++ b/catch/permissions/model/Permissions.php @@ -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') @@ -53,4 +60,4 @@ class Permissions extends CatchModel { return $this->belongsToMany(Roles::class, 'role_has_permissions', 'role_id', 'permission_id'); } -} \ No newline at end of file +} diff --git a/catch/system/controller/DataDictionary.php b/catch/system/controller/DataDictionary.php index caf642d..26893d8 100644 --- a/catch/system/controller/DataDictionary.php +++ b/catch/system/controller/DataDictionary.php @@ -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, [])); } /** diff --git a/catch/user/controller/User.php b/catch/user/controller/User.php index 7163c67..7ad08a6 100644 --- a/catch/user/controller/User.php +++ b/catch/user/controller/User.php @@ -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();