重构前端逻辑

This commit is contained in:
dengqichen 2025-11-06 17:51:55 +08:00
parent 0ab4472a2f
commit bb1faa1495
10 changed files with 83 additions and 52 deletions

View File

@ -4,7 +4,7 @@ import { cva, type VariantProps } from "class-variance-authority"
import { cn } from "@/lib/utils" import { cn } from "@/lib/utils"
const badgeVariants = cva( const badgeVariants = cva(
"inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2", "inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
{ {
variants: { variants: {
variant: { variant: {

View File

@ -47,7 +47,7 @@ const DialogOverlay = React.forwardRef<
<DialogPrimitive.Overlay <DialogPrimitive.Overlay
ref={ref} ref={ref}
className={cn( className={cn(
"fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0", "fixed inset-0 z-50 bg-black/80 outline-none focus:outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
className className
)} )}
{...props} {...props}
@ -64,13 +64,13 @@ const DialogContent = React.forwardRef<
<DialogPrimitive.Content <DialogPrimitive.Content
ref={ref} ref={ref}
className={cn( className={cn(
"fixed left-[50%] top-[50%] z-50 flex flex-col w-full max-w-lg max-h-[90vh] translate-x-[-50%] translate-y-[-50%] border bg-background shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg", "fixed left-[50%] top-[50%] z-50 flex flex-col w-full max-w-lg max-h-[90vh] translate-x-[-50%] translate-y-[-50%] border bg-background shadow-lg duration-200 outline-none focus:outline-none focus-visible:outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",
className className
)} )}
{...props} {...props}
> >
{children} {children}
<DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground"> <DialogPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground">
<X className="h-4 w-4" /> <X className="h-4 w-4" />
<span className="sr-only">Close</span> <span className="sr-only">Close</span>
</DialogPrimitive.Close> </DialogPrimitive.Close>

View File

@ -66,7 +66,7 @@ const SheetContent = React.forwardRef<
> >
{children} {children}
{showClose && ( {showClose && (
<SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary"> <SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary">
<X className="h-4 w-4" /> <X className="h-4 w-4" />
<span className="sr-only">Close</span> <span className="sr-only">Close</span>
</SheetPrimitive.Close> </SheetPrimitive.Close>

View File

@ -61,7 +61,7 @@ const ToastAction = React.forwardRef<
<ToastPrimitives.Action <ToastPrimitives.Action
ref={ref} ref={ref}
className={cn( className={cn(
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-destructive/30 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive", "inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-destructive/30 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus-visible:ring-destructive",
className className
)} )}
{...props} {...props}
@ -76,7 +76,7 @@ const ToastClose = React.forwardRef<
<ToastPrimitives.Close <ToastPrimitives.Close
ref={ref} ref={ref}
className={cn( className={cn(
"absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600", "absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus-visible:opacity-100 focus:outline-none focus-visible:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus-visible:ring-red-400 group-[.destructive]:focus-visible:ring-offset-red-600",
className className
)} )}
toast-close="" toast-close=""

View File

@ -89,4 +89,12 @@
body { body {
@apply bg-background text-foreground; @apply bg-background text-foreground;
} }
/* 🔥 完全移除所有可能的焦点边框效果 */
[role="menu"],
[role="menuitem"],
[data-radix-dropdown-menu-content] {
outline: none !important;
box-shadow: none !important;
}
} }

View File

@ -333,9 +333,13 @@ export const ApplicationCard: React.FC<ApplicationCardProps> = ({
</div> </div>
{/* 部署按钮 */} {/* 部署按钮 */}
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<div className="w-full">
<Button <Button
onClick={() => setDeployDialogOpen(true)} onClick={() => setDeployDialogOpen(true)}
disabled={!environment.enabled || isDeploying || app.isDeploying} disabled={!environment.enabled || !environment.canDeploy || isDeploying || app.isDeploying}
size="sm" size="sm"
className={cn( className={cn(
'w-full text-xs h-8', 'w-full text-xs h-8',
@ -354,6 +358,15 @@ export const ApplicationCard: React.FC<ApplicationCardProps> = ({
</> </>
)} )}
</Button> </Button>
</div>
</TooltipTrigger>
{!environment.canDeploy && (
<TooltipContent>
<p></p>
</TooltipContent>
)}
</Tooltip>
</TooltipProvider>
{/* 部署表单对话框 */} {/* 部署表单对话框 */}
<DeploymentFormModal <DeploymentFormModal

View File

@ -63,7 +63,7 @@ const DeploymentFormModal: React.FC<DeploymentFormModalProps> = ({
// 审批信息 // 审批信息
approval: { approval: {
required: environment.requiresApproval ? 'true' : 'false', required: environment.requiresApproval ? 'true' : 'false',
userIds: environment.approvers?.map(a => a.userId.toString()).join(',') || '', userNames: environment.approvers?.map(a => a.username) || [],
}, },
// 通知信息(使用环境配置的通知设置) // 通知信息(使用环境配置的通知设置)
notification: { notification: {

View File

@ -78,19 +78,20 @@ const Dashboard: React.FC = () => {
const response = await getDeployEnvironments(); const response = await getDeployEnvironments();
if (response && response.teams) { // ✅ 新接口直接返回 teams 数组
if (response && response.length > 0) {
const prevTeamId = currentTeamId; const prevTeamId = currentTeamId;
const prevEnvId = currentEnvId; const prevEnvId = currentEnvId;
setTeams(response.teams); setTeams(response);
if (isInitialLoad) { if (isInitialLoad) {
// 首次加载:默认选中第一个团队和第一个环境 // 首次加载:默认选中第一个团队和第一个环境
if (response.teams.length > 0) { if (response.length > 0) {
setCurrentTeamId(response.teams[0].teamId); setCurrentTeamId(response[0].teamId);
if (response.teams[0].environments.length > 0) { if (response[0].environments.length > 0) {
setCurrentEnvId(response.teams[0].environments[0].environmentId); setCurrentEnvId(response[0].environments[0].environmentId);
} }
} }
setIsInitialLoad(false); setIsInitialLoad(false);
@ -98,12 +99,12 @@ const Dashboard: React.FC = () => {
// 后续刷新:保持当前选中的团队和环境 // 后续刷新:保持当前选中的团队和环境
// 如果之前选中的团队/环境仍然存在,保持选中 // 如果之前选中的团队/环境仍然存在,保持选中
if (prevTeamId !== null) { if (prevTeamId !== null) {
const teamExists = response.teams.some(t => t.teamId === prevTeamId); const teamExists = response.some(t => t.teamId === prevTeamId);
if (teamExists) { if (teamExists) {
setCurrentTeamId(prevTeamId); setCurrentTeamId(prevTeamId);
if (prevEnvId !== null) { if (prevEnvId !== null) {
const team = response.teams.find(t => t.teamId === prevTeamId); const team = response.find(t => t.teamId === prevTeamId);
const envExists = team?.environments.some(e => e.environmentId === prevEnvId); const envExists = team?.environments.some(e => e.environmentId === prevEnvId);
if (envExists) { if (envExists) {
setCurrentEnvId(prevEnvId); setCurrentEnvId(prevEnvId);
@ -112,11 +113,11 @@ const Dashboard: React.FC = () => {
setCurrentEnvId(team.environments[0].environmentId); setCurrentEnvId(team.environments[0].environmentId);
} }
} }
} else if (response.teams.length > 0) { } else if (response.length > 0) {
// 如果之前的团队不存在了,选择第一个团队 // 如果之前的团队不存在了,选择第一个团队
setCurrentTeamId(response.teams[0].teamId); setCurrentTeamId(response[0].teamId);
if (response.teams[0].environments.length > 0) { if (response[0].environments.length > 0) {
setCurrentEnvId(response.teams[0].environments[0].environmentId); setCurrentEnvId(response[0].environments[0].environmentId);
} }
} }
} }
@ -127,7 +128,7 @@ const Dashboard: React.FC = () => {
let hasChanges = false; let hasChanges = false;
// 遍历所有团队、环境、应用,检查部署状态 // 遍历所有团队、环境、应用,检查部署状态
response.teams.forEach(team => { response.forEach(team => {
team.environments.forEach(env => { team.environments.forEach(env => {
env.applications.forEach(app => { env.applications.forEach(app => {
// 如果应用在 deploying 状态中,但最新状态不是 RUNNING则移除 // 如果应用在 deploying 状态中,但最新状态不是 RUNNING则移除

View File

@ -45,10 +45,12 @@ export interface ApplicationConfig {
applicationName: string; applicationName: string;
applicationDesc?: string; applicationDesc?: string;
branch: string; branch: string;
deployBranch?: string; // 🆕 部署分支
deploySystemId?: number; deploySystemId?: number;
deploySystemName?: string; deploySystemName?: string;
deployJob?: string; deployJob?: string;
workflowDefinitionId?: number; workflowDefinitionId?: number;
workflowDefinitionFormId?: number; // 🆕 工作流表单ID
workflowDefinitionName?: string; workflowDefinitionName?: string;
workflowDefinitionKey?: string; workflowDefinitionKey?: string;
deployStatistics?: DeployStatistics; deployStatistics?: DeployStatistics;
@ -68,24 +70,31 @@ export interface DeployEnvironment {
notificationEnabled: boolean; // 🆕 是否启用通知 notificationEnabled: boolean; // 🆕 是否启用通知
notificationChannelId: number; // 🆕 通知渠道ID notificationChannelId: number; // 🆕 通知渠道ID
requireCodeReview: boolean; // 🆕 是否需要代码审查 requireCodeReview: boolean; // 🆕 是否需要代码审查
canDeploy: boolean; // 🆕 当前用户是否可以发起部署
canApprove: boolean; // 🆕 当前用户是否可以审批部署
applications: ApplicationConfig[]; applications: ApplicationConfig[];
} }
export interface TeamMember {
userId: number;
username: string;
realName: string;
roleInTeam: string;
}
export interface DeployTeam { export interface DeployTeam {
teamId: number; teamId: number;
teamCode: string; teamCode: string;
teamName: string; teamName: string;
teamRole: string | null; // ✅ 可能为 null
description?: string; description?: string;
ownerId: number; // 🆕 团队负责人ID
ownerName: string; // 🆕 团队负责人名称
members: TeamMember[]; // 🆕 团队成员列表
environments: DeployEnvironment[]; environments: DeployEnvironment[];
} }
export interface DeployEnvironmentsResponse { // ✅ 新接口直接返回 teams 数组
userId: number; export type DeployEnvironmentsResponse = DeployTeam[];
username: string;
realName: string;
teams: DeployTeam[];
}
export interface StartDeploymentRequest { export interface StartDeploymentRequest {
teamApplicationId: number; teamApplicationId: number;