优化更新
This commit is contained in:
@@ -53,15 +53,21 @@ public function headings(): array
|
||||
*/
|
||||
public function map($department): array
|
||||
{
|
||||
$parentName = '';
|
||||
if ($department->parent_id) {
|
||||
$parent = Department::find($department->parent_id);
|
||||
$parentName = $parent ? $parent->name : '';
|
||||
}
|
||||
|
||||
return [
|
||||
$department->id,
|
||||
$department->name,
|
||||
$department->parent_id ? Department::find($department->parent_id)?->name : '',
|
||||
$parentName,
|
||||
$department->leader,
|
||||
$department->phone,
|
||||
$department->sort,
|
||||
(int)$department->sort,
|
||||
$department->status == 1 ? '启用' : '禁用',
|
||||
$department->created_at ? $department->created_at->toDateTimeString() : '',
|
||||
$department->created_at ? (string)$department->created_at : '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\Auth\Permission;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
|
||||
class PermissionExport implements FromCollection, WithHeadings, WithMapping, ShouldAutoSize
|
||||
{
|
||||
protected $permissionIds;
|
||||
|
||||
public function __construct(array $permissionIds = [])
|
||||
{
|
||||
$this->permissionIds = $permissionIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据集合
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
$query = Permission::query();
|
||||
|
||||
if (!empty($this->permissionIds)) {
|
||||
$query->whereIn('id', $this->permissionIds);
|
||||
}
|
||||
|
||||
return $query->orderBy('sort')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置表头
|
||||
*/
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'ID',
|
||||
'权限标题',
|
||||
'权限编码',
|
||||
'权限类型',
|
||||
'父级ID',
|
||||
'路由路径',
|
||||
'前端组件',
|
||||
'排序',
|
||||
'状态',
|
||||
'创建时间',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 映射数据
|
||||
*/
|
||||
public function map($permission): array
|
||||
{
|
||||
return [
|
||||
$permission->id,
|
||||
$permission->title,
|
||||
$permission->name,
|
||||
$this->getTypeName($permission->type),
|
||||
$permission->parent_id ?: 0,
|
||||
$permission->path,
|
||||
$permission->component,
|
||||
(int)$permission->sort,
|
||||
$permission->status == 1 ? '启用' : '禁用',
|
||||
$permission->created_at ? (string)$permission->created_at : '',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取类型名称
|
||||
*/
|
||||
protected function getTypeName($type): string
|
||||
{
|
||||
$types = [
|
||||
'menu' => '菜单',
|
||||
'api' => 'API接口',
|
||||
'button' => '按钮',
|
||||
'url' => '链接',
|
||||
];
|
||||
return $types[$type] ?? $type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\Auth\Role;
|
||||
use Maatwebsite\Excel\Concerns\FromCollection;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
|
||||
class RoleExport implements FromCollection, WithHeadings, WithMapping, ShouldAutoSize
|
||||
{
|
||||
protected $roleIds;
|
||||
|
||||
public function __construct(array $roleIds = [])
|
||||
{
|
||||
$this->roleIds = $roleIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取数据集合
|
||||
*/
|
||||
public function collection()
|
||||
{
|
||||
$query = Role::with(['permissions']);
|
||||
|
||||
if (!empty($this->roleIds)) {
|
||||
$query->whereIn('id', $this->roleIds);
|
||||
}
|
||||
|
||||
return $query->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置表头
|
||||
*/
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'ID',
|
||||
'角色名称',
|
||||
'角色编码',
|
||||
'描述',
|
||||
'权限',
|
||||
'排序',
|
||||
'状态',
|
||||
'创建时间',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 映射数据
|
||||
*/
|
||||
public function map($role): array
|
||||
{
|
||||
return [
|
||||
$role->id,
|
||||
$role->name,
|
||||
$role->code,
|
||||
$role->description,
|
||||
$role->permissions->pluck('title')->implode(','),
|
||||
(int)$role->sort,
|
||||
$role->status == 1 ? '启用' : '禁用',
|
||||
$role->created_at ? (string)$role->created_at : '',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -64,8 +64,8 @@ public function map($user): array
|
||||
$user->department ? $user->department->name : '',
|
||||
$user->roles->pluck('name')->implode(','),
|
||||
$user->status == 1 ? '启用' : '禁用',
|
||||
$user->last_login_at ? $user->last_login_at->toDateTimeString() : '',
|
||||
$user->created_at ? $user->created_at->toDateTimeString() : '',
|
||||
$user->last_login_at ? (string)$user->last_login_at : '',
|
||||
$user->created_at ? (string)$user->created_at : '',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user