From fef6e0fd84419b43ada2b1f111cdee27cd9d65ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Mon, 21 Apr 2025 11:46:54 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B6=85=E7=AE=A1=E5=90=8E=E5=8F=B0=20-=20?= =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E5=88=A0=E9=99=A4=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/superadmin/config/route.php | 2 +- .../company/DeleteCompanyController.php | 16 ++-- SuperAdmin/app/dashboard/projects/page.tsx | 82 ++++++++++++++++++- 3 files changed, 89 insertions(+), 11 deletions(-) diff --git a/Server/application/superadmin/config/route.php b/Server/application/superadmin/config/route.php index d3269626..f24e000b 100644 --- a/Server/application/superadmin/config/route.php +++ b/Server/application/superadmin/config/route.php @@ -36,8 +36,8 @@ Route::group('', function () { Route::group('company', function () { Route::post('create', 'app\superadmin\controller\company\CreateCompanyController@index'); Route::post('update', 'app\superadmin\controller\company\UpdateCompanyController@index'); + Route::post('delete', 'app\superadmin\controller\company\DeleteCompanyController@index'); Route::get('list', 'app\superadmin\controller\company\GetCompanyListController@index'); Route::get('detail/:id', 'app\superadmin\controller\company\GetCompanyDetailForUpdateController@index'); - Route::post('delete/:id', 'app\superadmin\controller\company\DeleteCompanyController@index'); }); })->middleware(['app\superadmin\middleware\AdminAuth']); \ No newline at end of file diff --git a/Server/application/superadmin/controller/company/DeleteCompanyController.php b/Server/application/superadmin/controller/company/DeleteCompanyController.php index 6c43f85f..29547137 100644 --- a/Server/application/superadmin/controller/company/DeleteCompanyController.php +++ b/Server/application/superadmin/controller/company/DeleteCompanyController.php @@ -61,16 +61,14 @@ class DeleteCompanyController extends BaseController * @param int $companId * @throws \Exception */ - protected function deleteUser(int $companId): void + protected function deleteUsers(int $companId): void { - $user = UserModel::where('companyId', $companId)->find(); + $users = UserModel::where('companyId', $companId)->select(); - if (!$user) { - throw new \Exception('用户不存在', 404); - } - - if (!$user->delete()) { - throw new \Exception('用户删除失败', 400); + foreach ($users as $user) { + if (!$user->delete()) { + throw new \Exception($user->username . ' 用户删除失败', 400); + } } } @@ -87,7 +85,7 @@ class DeleteCompanyController extends BaseController $this->deleteCompany($companId); // 2. 删除用户 - $this->deleteUser($companId); + $this->deleteUsers($companId); return $this; } diff --git a/SuperAdmin/app/dashboard/projects/page.tsx b/SuperAdmin/app/dashboard/projects/page.tsx index cd179a62..83b366c8 100644 --- a/SuperAdmin/app/dashboard/projects/page.tsx +++ b/SuperAdmin/app/dashboard/projects/page.tsx @@ -8,6 +8,14 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu" import { Plus, Search, MoreHorizontal, Edit, Eye, Trash, ChevronLeft, ChevronRight } from "lucide-react" import { toast } from "sonner" +import { + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog" interface Project { id: number @@ -27,6 +35,9 @@ export default function ProjectsPage() { const [currentPage, setCurrentPage] = useState(1) const [totalPages, setTotalPages] = useState(1) const [pageSize] = useState(10) + const [deleteDialogOpen, setDeleteDialogOpen] = useState(false) + const [deletingProjectId, setDeletingProjectId] = useState(null) + const [isDeleting, setIsDeleting] = useState(false) // 获取项目列表 useEffect(() => { @@ -59,6 +70,44 @@ export default function ProjectsPage() { } } + const handleDeleteClick = (projectId: number) => { + setDeletingProjectId(projectId) + setDeleteDialogOpen(true) + } + + const handleConfirmDelete = async () => { + if (!deletingProjectId) return + + setIsDeleting(true) + try { + const response = await fetch("http://yishi.com/company/delete", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + id: deletingProjectId + }), + }) + + const data = await response.json() + + if (data.code === 200) { + toast.success("删除成功") + // 刷新项目列表 + window.location.reload() + } else { + toast.error(data.msg || "删除失败") + } + } catch (error) { + toast.error("网络错误,请稍后重试") + } finally { + setIsDeleting(false) + setDeleteDialogOpen(false) + setDeletingProjectId(null) + } + } + return (
@@ -127,7 +176,10 @@ export default function ProjectsPage() { 编辑项目 - + handleDeleteClick(project.id)} + > 删除项目 @@ -179,6 +231,34 @@ export default function ProjectsPage() {
)} + + {/* 删除确认对话框 */} + + + + 确认删除 + + 删除项目将会删除本项目关联的所有账号,项目删除后不可恢复,是否确认删除? + + + + + + + +
) }