优化更新

This commit is contained in:
2026-02-11 17:13:18 +08:00
parent ada5e027fa
commit e265bcc28d
28 changed files with 1661 additions and 155 deletions

View File

@@ -4,15 +4,20 @@ namespace App\Http\Controllers\Auth\Admin;
use App\Http\Controllers\Controller;
use App\Services\Auth\PermissionService;
use App\Services\Auth\ImportExportService;
use Illuminate\Http\Request;
class Permission extends Controller
{
protected $permissionService;
protected $importExportService;
public function __construct(PermissionService $permissionService)
{
public function __construct(
PermissionService $permissionService,
ImportExportService $importExportService
) {
$this->permissionService = $permissionService;
$this->importExportService = $importExportService;
}
/**
@@ -177,4 +182,54 @@ class Permission extends Controller
'data' => ['count' => $count],
]);
}
/**
* 导出权限
*/
public function export(Request $request)
{
$validated = $request->validate([
'ids' => 'nullable|array',
'ids.*' => 'integer',
]);
$filename = $this->importExportService->exportPermissions($validated['ids'] ?? []);
$filePath = $this->importExportService->getExportFilePath($filename);
return response()->download($filePath, $filename)->deleteFileAfterSend();
}
/**
* 导入权限
*/
public function import(Request $request)
{
$validated = $request->validate([
'file' => 'required|file|mimes:xlsx,xls',
]);
$file = $request->file('file');
$realPath = $file->getRealPath();
$filename = $file->getClientOriginalName();
$result = $this->importExportService->importPermissions($filename, $realPath);
return response()->json([
'code' => 200,
'message' => "导入完成,成功 {$result['success_count']} 条,失败 {$result['error_count']}",
'data' => $result,
]);
}
/**
* 下载权限导入模板
*/
public function downloadTemplate()
{
$filename = $this->importExportService->downloadPermissionTemplate();
$filePath = $this->importExportService->getExportFilePath($filename);
return response()->download($filePath, $filename)->deleteFileAfterSend();
}
}

View File

@@ -4,15 +4,20 @@ namespace App\Http\Controllers\Auth\Admin;
use App\Http\Controllers\Controller;
use App\Services\Auth\RoleService;
use App\Services\Auth\ImportExportService;
use Illuminate\Http\Request;
class Role extends Controller
{
protected $roleService;
protected $importExportService;
public function __construct(RoleService $roleService)
{
public function __construct(
RoleService $roleService,
ImportExportService $importExportService
) {
$this->roleService = $roleService;
$this->importExportService = $importExportService;
}
/**
@@ -237,4 +242,54 @@ class Role extends Controller
'data' => $result,
]);
}
/**
* 导出角色
*/
public function export(Request $request)
{
$validated = $request->validate([
'ids' => 'nullable|array',
'ids.*' => 'integer',
]);
$filename = $this->importExportService->exportRoles($validated['ids'] ?? []);
$filePath = $this->importExportService->getExportFilePath($filename);
return response()->download($filePath, $filename)->deleteFileAfterSend();
}
/**
* 导入角色
*/
public function import(Request $request)
{
$validated = $request->validate([
'file' => 'required|file|mimes:xlsx,xls',
]);
$file = $request->file('file');
$realPath = $file->getRealPath();
$filename = $file->getClientOriginalName();
$result = $this->importExportService->importRoles($filename, $realPath);
return response()->json([
'code' => 200,
'message' => "导入完成,成功 {$result['success_count']} 条,失败 {$result['error_count']}",
'data' => $result,
]);
}
/**
* 下载角色导入模板
*/
public function downloadTemplate()
{
$filename = $this->importExportService->downloadRoleTemplate();
$filePath = $this->importExportService->getExportFilePath($filename);
return response()->download($filePath, $filename)->deleteFileAfterSend();
}
}