菜单新增隐藏显示功能

This commit is contained in:
yanwenwu 2020-05-20 11:31:04 +08:00
parent ff1d7dfd2e
commit 70b6b0407c
4 changed files with 70 additions and 1 deletions

View File

@ -119,6 +119,30 @@ class Permission extends CatchController
return CatchResponse::success($this->permissions->deleteBy($id));
}
/**
* 显示/隐藏
*
* @author JaguarJack
* @email njphper@gmail.com
* @time 2020/5/19
* @param $id
* @return Json
*/
public function show($id)
{
$permission = $this->permissions->findBy($id);
$permission->status = $permission->status == Permissions::ENABLE ? Permissions::DISABLE : Permissions::ENABLE;
if ($permission->save()) {
$this->permissions->where('parent_id', $id)->update([
'status' => $permission->status,
]);
}
return CatchResponse::success($permission->save());
}
}

View File

@ -0,0 +1,42 @@
<?php
use think\migration\Migrator;
use think\migration\db\Column;
class AddPermissionStatusColumn extends Migrator
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
*
* The following commands can be used in this method and Phinx will
* automatically reverse them when rolling back:
*
* createTable
* renameTable
* addColumn
* renameColumn
* addIndex
* addForeignKey
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change()
{
if ($this->hasTable('permissions')) {
$table = $this->table('permissions');
$table->addColumn('status', 'integer', [
'limit' => \Phinx\Db\Adapter\MysqlAdapter::INT_TINY,
'default' => 1,
'comment' => '1 显示 2 隐藏',
'after' => 'type'])
->update();
}
}
}

View File

@ -21,6 +21,7 @@ class Permissions extends CatchModel
'keepalive',
'hide_children_in_menu',
'creator_id',
'status',
'module', // 模块
'route', // 路由
'method', // 请求方法
@ -71,7 +72,7 @@ class Permissions extends CatchModel
return parent::whereIn('id', $permissionIds)
->field(['permission_name as title', 'id', 'parent_id',
'route', 'icon', 'component', 'redirect',
'keepalive as keepAlive', 'hide_children_in_menu', 'type', 'permission_mark'
'keepalive as keepAlive', 'hide_children_in_menu', 'type', 'permission_mark', 'status'
])
->select();
}

View File

@ -5,6 +5,8 @@ $router->resource('roles', '\catchAdmin\permissions\controller\Role');
$router->get('/role/get/permissions', '\catchAdmin\permissions\controller\Role@getPermissions');
// 权限
$router->resource('permissions', '\catchAdmin\permissions\controller\Permission');
$router->put('permissions/show/<id>', '\catchAdmin\permissions\controller\Permission@show');
// 部门
$router->resource('departments', '\catchAdmin\permissions\controller\Department');
// 岗位