From 2b96f3b6503f50638f9a13cb42709064d3bee999 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Wed, 31 Mar 2021 20:20:21 +0800 Subject: [PATCH] =?UTF-8?q?update:=E6=9B=B4=E6=96=B0=E6=9D=83=E9=99=90?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- catch/permissions/controller/Permission.php | 1 + catch/permissions/controller/Role.php | 3 +- catch/permissions/model/Roles.php | 10 ++ catch/permissions/model/Users.php | 20 ++- catch/permissions/tables/Department.php | 50 ++++++ catch/permissions/tables/Job.php | 44 ++++++ catch/permissions/tables/Permission.php | 50 ++++++ catch/permissions/tables/Role.php | 42 +++++ catch/permissions/tables/User.php | 51 +++++++ catch/permissions/tables/forms/Department.php | 32 ++++ catch/permissions/tables/forms/Factory.php | 12 ++ catch/permissions/tables/forms/Job.php | 23 +++ catch/permissions/tables/forms/Permission.php | 143 ++++++++++++++++++ catch/permissions/tables/forms/Role.php | 66 ++++++++ catch/permissions/tables/forms/User.php | 42 +++++ 15 files changed, 582 insertions(+), 7 deletions(-) create mode 100644 catch/permissions/tables/Department.php create mode 100644 catch/permissions/tables/Job.php create mode 100644 catch/permissions/tables/Permission.php create mode 100644 catch/permissions/tables/Role.php create mode 100644 catch/permissions/tables/User.php create mode 100644 catch/permissions/tables/forms/Department.php create mode 100644 catch/permissions/tables/forms/Factory.php create mode 100644 catch/permissions/tables/forms/Job.php create mode 100644 catch/permissions/tables/forms/Permission.php create mode 100644 catch/permissions/tables/forms/Role.php create mode 100644 catch/permissions/tables/forms/User.php diff --git a/catch/permissions/controller/Permission.php b/catch/permissions/controller/Permission.php index 8c2845b..2052952 100644 --- a/catch/permissions/controller/Permission.php +++ b/catch/permissions/controller/Permission.php @@ -100,6 +100,7 @@ class Permission extends CatchController $permission = $this->permissions->findBy($id); $params = $request->param(); + // 按钮类型 if ($params['type'] == Permissions::BTN_TYPE && $permission->parent_id) { $parentPermission = $this->permissions->findBy($permission->parent_id); diff --git a/catch/permissions/controller/Role.php b/catch/permissions/controller/Role.php index 3c2da56..4692234 100644 --- a/catch/permissions/controller/Role.php +++ b/catch/permissions/controller/Role.php @@ -7,7 +7,6 @@ use catcher\base\CatchRequest as Request; use catcher\base\CatchController; use catcher\CatchResponse; use catcher\exceptions\FailedException; -use catcher\Tree; use think\response\Json; use catchAdmin\permissions\model\Roles as RoleModel; @@ -51,7 +50,7 @@ class Role extends CatchController $this->role->attachPermissions(array_unique($params['permissions'])); } // 分配部门 - if (count($params['departments'])) { + if (isset($params['departments']) && count($params['departments'])) { $this->role->attachDepartments($params['departments']); } // 添加角色 diff --git a/catch/permissions/model/Roles.php b/catch/permissions/model/Roles.php index 21fb2b3..af0a45d 100644 --- a/catch/permissions/model/Roles.php +++ b/catch/permissions/model/Roles.php @@ -35,8 +35,18 @@ class Roles extends CatchModel public function getList() { return $this->catchSearch() + ->with(['permissions', 'departments']) ->order('id', 'desc') ->select() + ->each(function (&$item){ + $permissions = $item->permissions->column('id'); + unset($item['permissions']); + $item['permissions'] = $permissions; + + $departments = $item->departments->column('id'); + unset($item['departments']); + $item['departments'] = $departments; + }) ->toTree(); } diff --git a/catch/permissions/model/Users.php b/catch/permissions/model/Users.php index ba20368..943d94a 100644 --- a/catch/permissions/model/Users.php +++ b/catch/permissions/model/Users.php @@ -5,6 +5,7 @@ use catchAdmin\permissions\model\search\UserSearch; use catcher\base\CatchModel; use catcher\exceptions\FailedException; use catcher\Utils; +use think\Paginator; class Users extends CatchModel { @@ -47,16 +48,25 @@ class Users extends CatchModel * 用户列表 * * @time 2019年12月08日 - * @throws \think\db\exception\DbException - * @return \think\Paginator + * @return array|\think\Paginator + *@throws \think\db\exception\DbException */ - public function getList(): \think\Paginator + public function getList() { - return $this->withoutField(['updated_at'], true) + $users = $this->withoutField(['updated_at', 'password', 'remember_token'], true) ->catchSearch() ->catchLeftJoin(Department::class, 'id', 'department_id', ['department_name']) + ->with(['jobs', 'roles']) ->order($this->aliasField('id'), 'desc') - ->paginate(); + ->paginate()->toArray(); + + foreach ($users['data'] as &$user) { + $user['roles'] = array_column($user['roles'], 'id'); + $user['jobs'] = array_column($user['jobs'], 'id'); + } + + + return Paginator::make($users['data'], $users['per_page'], $users['current_page'], $users['total']); } /** diff --git a/catch/permissions/tables/Department.php b/catch/permissions/tables/Department.php new file mode 100644 index 0000000..b50692c --- /dev/null +++ b/catch/permissions/tables/Department.php @@ -0,0 +1,50 @@ +getTable('user')->header([ + HeaderItem::label('部门名称')->prop('department_name'), + HeaderItem::label('排序')->prop('sort')->withEditNumberComponent(), + HeaderItem::label('状态')->prop('status')->withSwitchComponent(), + HeaderItem::label('创建时间')->prop('created_at'), + HeaderItem::label('操作')->width(260)->actions([ + Actions::update(''), + Actions::delete(''), + ]) + ])->withApiRoute('departments')->withActions([ + Actions::create() + ])->withSearch([ + Search::text('department_name', '请输入部门名称'), + Search::status() + ])->withDialogWidth('35%') + ->toTreeTable()->render(); + } + + /** + * form 方式 + * + * @time 2021年03月29日 + * @return array + */ + protected function form(): array + { + return Factory::create('department'); + } +} \ No newline at end of file diff --git a/catch/permissions/tables/Job.php b/catch/permissions/tables/Job.php new file mode 100644 index 0000000..72d3d7e --- /dev/null +++ b/catch/permissions/tables/Job.php @@ -0,0 +1,44 @@ +getTable('job') + ->header([ + HeaderItem::label('')->type('selection'), + HeaderItem::label('岗位名称')->prop('job_name'), + HeaderItem::label('编码')->prop('coding'), + HeaderItem::label('状态')->prop('status')->withSwitchComponent(), + HeaderItem::label('创建时间')->prop('created_at'), + HeaderItem::label('操作')->width(250)->actions([ + Actions::update(), + Actions::delete() + ]) + ]) + ->withActions([ + Actions::create() + ]) + ->withSearch([ + Search::text('job_name', '岗位名称') + ]) + ->withApiRoute('jobs') + ->selectionChange() + ->render(); + } + + + public function form() + { + // TODO: Implement form() method. + return Factory::create('job'); + } +} \ No newline at end of file diff --git a/catch/permissions/tables/Permission.php b/catch/permissions/tables/Permission.php new file mode 100644 index 0000000..8eca0fa --- /dev/null +++ b/catch/permissions/tables/Permission.php @@ -0,0 +1,50 @@ +getTable('permission') + ->header([ + HeaderItem::label('菜单名称')->prop('permission_name'), + HeaderItem::label('路由Path')->prop('route'), + HeaderItem::label('权限标识')->prop('actionList')->width(250)->component('actions', 'actionList'), + HeaderItem::label('状态')->prop('hidden')->withSwitchComponent(), + HeaderItem::label('排序')->prop('sort')->withEditNumberComponent(), + HeaderItem::label('创建时间')->prop('created_at'), + HeaderItem::label('操作')->width(250)->actions([ + Actions::update(), + Actions::delete() + ]) + ]) + ->withActions([ + Actions::create() + ]) + ->withSearch([ + Search::text('permission_name', '菜单名称') + ]) + ->withFilterParams([ + 'permission_name' => '', + 'actionList' => 'actionList' + ]) + ->withDefaultQueryParams(['actionList']) + ->withApiRoute('permissions') + ->toTreeTable() + ->render(); + } + + + public function form() + { + // TODO: Implement form() method. + return Factory::create('permission'); + } +} \ No newline at end of file diff --git a/catch/permissions/tables/Role.php b/catch/permissions/tables/Role.php new file mode 100644 index 0000000..b14208b --- /dev/null +++ b/catch/permissions/tables/Role.php @@ -0,0 +1,42 @@ +getTable('role') + ->header([ + HeaderItem::label('角色名称')->prop('role_name')->width(150), + HeaderItem::label('角色标识')->prop('identify')->width(150), + HeaderItem::label('角色描述')->prop('description'), + HeaderItem::label('创建时间')->prop('created_at'), + HeaderItem::label('操作')->width(250)->actions([ + Actions::update(''), Actions::delete('') + ]) + ]) + ->withSearch([ + Search::text('role_name', '角色名称'), + ]) + ->withApiRoute('roles') + ->withActions([ + Actions::create() + ])->withDialogWidth('40%') + ->toTreeTable() + ->render(); + } + + protected function form() + { + // TODO: Implement form() method. + return Factory::create('role'); + } +} \ No newline at end of file diff --git a/catch/permissions/tables/User.php b/catch/permissions/tables/User.php new file mode 100644 index 0000000..4f0dd4b --- /dev/null +++ b/catch/permissions/tables/User.php @@ -0,0 +1,51 @@ +getTable('user') + ->header([ + HeaderItem::label('')->selection(), + HeaderItem::label('用户名')->prop('username'), + HeaderItem::label('邮箱')->prop('email'), + HeaderItem::label('状态')->prop('status')->component('status', 'status'), + HeaderItem::label('创建时间')->prop('created_at'), + HeaderItem::label('操作')->width(150)->actions([ + Actions::update(''), Actions::delete('') + ]) + ]) + ->withSearch([ + Search::text('username', '用户名'), + Search::text('email', '邮箱'), + Search::status() + ]) + ->withApiRoute('users') + ->withActions([ + Actions::create() + ]) + ->withFilterParams([ + 'username' => '', + 'email' => '', + 'status' => '', + 'department_id' => '' + ]) + ->selectionChange() + ->render(); + } + + protected function form() + { + // TODO: Implement form() method. + return Factory::create('user'); + } +} \ No newline at end of file diff --git a/catch/permissions/tables/forms/Department.php b/catch/permissions/tables/forms/Department.php new file mode 100644 index 0000000..d78155f --- /dev/null +++ b/catch/permissions/tables/forms/Department.php @@ -0,0 +1,32 @@ +options( + DepartmentModel::field(['id', 'parent_id', 'department_name'])->select()->toTree() + )->clearable(true)->filterable(true)->props([ + 'props' => [ + 'value' => 'id', + 'label' => 'department_name', + 'checkStrictly' => true + ], + ])->style(['width' => '100%']), + Form::input('department_name', '部门名称')->required()->placeholder('请输入部门名称'), + Form::input('principal', '部门负责人'), + Form::input('mobile', '负责人联系方式'), + Form::email('email', '邮箱'), + Form::radio('status', '状态')->value(1)->options( + Form::options()->add('启用', 1)->add('禁用', 2)->render() + ), + Form::number('sort', '排序')->value(1)->min(1)->max(10000), + ]; + } +} \ No newline at end of file diff --git a/catch/permissions/tables/forms/Factory.php b/catch/permissions/tables/forms/Factory.php new file mode 100644 index 0000000..5641a96 --- /dev/null +++ b/catch/permissions/tables/forms/Factory.php @@ -0,0 +1,12 @@ +required(), + + self::input('coding', '岗位编码'), + + self::radio('status', '状态')->value(1)->options( + self::options()->add('启用', 1)->add('禁用', 2)->render() + ), + + self::number('sort', '排序')->value(1)->min(1)->max(10000), + ]; + } +} \ No newline at end of file diff --git a/catch/permissions/tables/forms/Permission.php b/catch/permissions/tables/forms/Permission.php new file mode 100644 index 0000000..2f7dd65 --- /dev/null +++ b/catch/permissions/tables/forms/Permission.php @@ -0,0 +1,143 @@ +getModules(); + // TODO: Implement fields() method. + return [ + self::cascader('parent_id', '父级菜单', [])->options( + Permissions::where('type', Permissions::MENU_TYPE)->field(['id', 'permission_name', 'parent_id']) + ->select()->toTree() + )->col(12)->props(self::props('permission_name', 'id', [ + 'checkStrictly' => true + ]))->style(['width' => '100%']), + + self::radio('type', '菜单类型') + ->button() + ->value(1) + ->options( + self::options()->add('菜单', 1)->add('按钮', 2)->render() + )->appendControl(1, [ + self::input('permission_name', '菜单名称')->required()->col(12), + self::input('permission_mark', '权限标识')->required()->col(12), + + self::select('module', '模块') + ->required() + ->style(['width' => '100%']) + ->col(12) + ->options($this->getModules()), + + self::input('icon', '菜单图标') + ->col(12) + ->style(['width' => '100%']) + ->clearable(true), + + self::input('route', '菜单Path')->col(12), + + self::cascader('component', '组件') + ->col(12) + ->options([]) + ->style(['width' => '100%']) + ->showAllLevels(false), + + self::input('redirect', 'Redirect')->col(12), + self::number('sort', '排序')->value(1)->col(12), + + self::radio('keepalive', 'Keepalive') + ->value(1) + ->col(12) + ->options( + self::options()->add('启用', 1) + ->add('禁用', 2) + ->render() + ), + + self::radio('hidden', 'Hidden')->value(1)->options( + self::options()->add('显示', 1)->add('隐藏', 2)->render() + )->col(12) + ]) + ->appendControl(2, [ + self::select('permission_name', '菜单名称') + ->allowCreate(true) + ->filterable(true) + ->options( + self::options()->add('列表', '列表') + ->add('创建', '创建') + ->add('更新', '更新')->add('读取', '读取') + ->add('删除', '删除')->add('禁用/启用', '禁用/启用') + ->add('导出', '导出')->add('导入', '导入')->render() + ) + ->required()->style(['width' => '100%'])->col(12), + self::select('permission_mark', '权限标识') + ->allowCreate(true) + ->filterable(true) + ->options( + self::options()->add('index', 'index') + ->add('create', 'create') + ->add('update', 'update')->add('read', 'read') + ->add('delete', 'delete')->add('disable', 'disable') + ->add('export', 'export')->add('import', 'import')->render() + ) + ->required()->col(12), + self::number('sort', '排序')->value(1)->col(12), + ])->col(12) + ]; + } + + + /** + * 获取模块 + * + * @time 2021年03月31日 + * @return array + */ + protected function getModules(): array + { + $modules = []; + + foreach(CatchAdmin::getModulesDirectory() as $d) { + $module = CatchAdmin::getModuleInfo($d); + + if (in_array($module['alias'], ['login'])) { + continue; + } + + if ($module['enable']) { + $modules[] = [ + 'value' => $module['alias'], + 'label' => $module['name'] + ]; + } + } + + return $modules; + } + + /** + * icons + * + * @time 2021年03月31日 + * @return array + */ + protected function getIcons(): array + { + $icons = ['platform-eleme', 'eleme', 'delete-solid', 'delete', 's-tools', 'setting', 'user-solid', 'user', 'phone', 'phone-outline', 'more', 'more-outline', 'star-on', 'star-off', 's-goods', 'goods', 'warning', 'warning-outline', 'question', 'info', 'remove', 'circle-plus', 'success', 'error', 'zoom-in', 'zoom-out', 'remove-outline', 'circle-plus-outline', 'circle-check', 'circle-close', 's-help', 'help', 'minus', 'plus', 'check', 'close', 'picture', 'picture-outline', 'picture-outline-round', 'upload', 'upload2', 'download', 'camera-solid', 'camera', 'video-camera-solid', 'video-camera', 'message-solid', 'bell', 's-cooperation', 's-order', 's-platform', 's-fold', 's-unfold', 's-operation', 's-promotion', 's-home', 's-release', 's-ticket', 's-management', 's-open', 's-shop', 's-marketing', 's-flag', 's-comment', 's-finance', 's-claim', 's-custom', 's-opportunity', 's-data', 's-check', 's-grid', 'menu', 'share', 'd-caret', 'caret-left', 'caret-right', 'caret-bottom', 'caret-top', 'bottom-left', 'bottom-right', 'back', 'right', 'bottom', 'top', 'top-left', 'top-right', 'arrow-left', 'arrow-right', 'arrow-down', 'arrow-up', 'd-arrow-left', 'd-arrow-right', 'video-pause', 'video-play', 'refresh', 'refresh-right', 'refresh-left', 'finished', 'sort', 'sort-up', 'sort-down', 'rank', 'loading', 'view', 'c-scale-to-original', 'date', 'edit', 'edit-outline', 'folder', 'folder-opened', 'folder-add', 'folder-remove', 'folder-delete', 'folder-checked', 'tickets', 'document-remove', 'document-delete', 'document-copy', 'document-checked', 'document', 'document-add', 'printer', 'paperclip', 'takeaway-box', 'search', 'monitor', 'attract', 'mobile', 'scissors', 'umbrella', 'headset', 'brush', 'mouse', 'coordinate', 'magic-stick', 'reading', 'data-line', 'data-board', 'pie-chart', 'data-analysis', 'collection-tag', 'film', 'suitcase', 'suitcase-1', 'receiving', 'collection', 'files', 'notebook-1', 'notebook-2', 'toilet-paper', 'office-building', 'school', 'table-lamp', 'house', 'no-smoking', 'smoking', 'shopping-cart-full', 'shopping-cart-1', 'shopping-cart-2', 'shopping-bag-1', 'shopping-bag-2', 'sold-out', 'sell', 'present', 'box', 'bank-card', 'money', 'coin', 'wallet', 'discount', 'price-tag', 'news', 'guide', 'male', 'female', 'thumb', 'cpu', 'link', 'connection', 'open', 'turn-off', 'set-up', 'chat-round', 'chat-line-round', 'chat-square', 'chat-dot-round', 'chat-dot-square', 'chat-line-square', 'message', 'postcard', 'position', 'turn-off-microphone', 'microphone', 'close-notification', 'bangzhu', 'time', 'odometer', 'crop', 'aim', 'switch-button', 'full-screen', 'copy-document', 'mic', 'stopwatch', 'medal-1', 'medal', 'trophy', 'trophy-1', 'first-aid-kit', 'discover', 'place', 'location', 'location-outline', 'location-information', 'add-location', 'delete-location', 'map-location', 'alarm-clock', 'timer', 'watch-1', 'watch', 'lock', 'unlock', 'key', 'service', 'mobile-phone', 'bicycle', 'truck', 'ship', 'basketball', 'football', 'soccer', 'baseball', 'wind-power', 'light-rain', 'lightning', 'heavy-rain', 'sunrise', 'sunrise-1', 'sunset', 'sunny', 'cloudy', 'partly-cloudy', 'cloudy-and-sunny', 'moon', 'moon-night', 'dish', 'dish-1', 'food', 'chicken', 'fork-spoon', 'knife-fork', 'burger', 'tableware', 'sugar', 'dessert', 'ice-cream', 'hot-water', 'water-cup', 'coffee-cup', 'cold-drink', 'goblet', 'goblet-full', 'goblet-square', 'goblet-square-full', 'refrigerator', 'grape', 'watermelon', 'cherry', 'apple', 'pear', 'orange', 'coffee', 'ice-tea', 'ice-drink', 'milk-tea', 'potato-strips', 'lollipop', 'ice-cream-square', 'ice-cream-round']; + + $options = self::options(); + + foreach ($icons as $icon) { + $icon = 'el-icon-' . $icon; + + $options->add(htmlspecialchars(sprintf(' %s', $icon, $icon)), $icon); + } + + return $options->render(); + } +} \ No newline at end of file diff --git a/catch/permissions/tables/forms/Role.php b/catch/permissions/tables/forms/Role.php new file mode 100644 index 0000000..65db298 --- /dev/null +++ b/catch/permissions/tables/forms/Role.php @@ -0,0 +1,66 @@ +options( + Roles::field(['id', 'parent_id', 'role_name'])->select()->toTree() + )->clearable(true)->filterable(true)->props([ + 'props' => [ + 'value' => 'id', + 'label' => 'role_name', + 'checkStrictly' => true + ], + ])->style(['width' => '100%']), + + self::input('role_name', '角色名称')->required() + ->clearable(true)->placeholder('请填写角色名称'), + + self::input('identify', '角色标识') + ->clearable(true)->required() + ->placeholder('请填写角色标识'), + + self::textarea('description', '角色描述') + ->clearable(true)->placeholder('请填写角色描述'), + + self::tree('permissions', '角色权限', []) + ->props(self::props('permission_name', 'id', [], + Permissions::field(['id', 'parent_id', 'permission_name'])->select()->toTree() + )) + ->required(), + + self::select('data_range', '数据权限') + ->placeholder('请选择数据权限') + ->options( + self::options()->add('全部数据权限', Roles::ALL_DATA) + ->add('自定义数据权限', Roles::SELF_CHOOSE) + ->add('仅本人数据权限', Roles::SELF_DATA) + ->add('本部门数据权限', Roles::DEPARTMENT_DATA) + ->add('部门以及以下数据权限', Roles::DEPARTMENT_DOWN_DATA) + ->render() + )->style(['width' => '100%']) + ->appendControl(Roles::SELF_CHOOSE, [ + self::cascader('departments', '自定义权限') + ->options( + DepartmentModel::field(['id', 'parent_id', 'department_name'])->select()->toTree() + ) + ->props(self::props('department_name', 'id', [ + 'multiple' => true, + 'emitPath' => false + ])) + ->showAllLevels(false) + ->style(['width' => '100%']), + ]) + ]; + } + +} \ No newline at end of file diff --git a/catch/permissions/tables/forms/User.php b/catch/permissions/tables/forms/User.php new file mode 100644 index 0000000..2b86244 --- /dev/null +++ b/catch/permissions/tables/forms/User.php @@ -0,0 +1,42 @@ +col(self::col(12))->clearable(true)->required(), + + self::cascader('department_id', '部门', []) + ->col(self::col(12)) + ->options( + DepartmentModel::field(['id', 'parent_id', 'department_name'])->select()->toTree() + ) + ->props(self::props('department_name', 'id', [ + 'checkStrictly' => true + ]))->clearable(true), + + self::email('email', '邮箱')->col(self::col(12))->required()->clearable(true), + + self::selectMultiple('jobs', '岗位', []) + ->col(self::col(12))->options( + Job::where('status', Job::ENABLE)->field(['id as value', 'job_name as label'])->select()->toArray() + )->clearable(true)->filterable(true), + + self::input('password', '密码')->col(self::col(12)) + ->placeholder('请输入密码')->clearable(true), + + self::tree('roles', '角色', []) + ->props(self::props('role_name', 'id', [], Roles::field(['id', 'parent_id', 'role_name'])->select()->toTree())) + ->required() + ]; + } + +} \ No newline at end of file