重构消息通知弹窗

This commit is contained in:
dengqichen 2025-11-20 17:16:13 +08:00
parent 21f0b965bc
commit 1838a26494
4 changed files with 10 additions and 4 deletions

View File

@ -30,7 +30,7 @@ import {
} from '@/components/ui/select'; } from '@/components/ui/select';
import { useToast } from '@/components/ui/use-toast'; import { useToast } from '@/components/ui/use-toast';
import type { ServerResponse, ServerCategoryResponse } from '../types'; import type { ServerResponse, ServerCategoryResponse } from '../types';
import { OsType, OsTypeLabels, AuthType, AuthTypeLabels } from '../types'; import { OsType, OsTypeLabels, AuthType, AuthTypeLabels, ServerStatus } from '../types';
import { createServer, updateServer, getServerCategories } from '../service'; import { createServer, updateServer, getServerCategories } from '../service';
import { serverFormSchema, type ServerFormValues } from '../schema'; import { serverFormSchema, type ServerFormValues } from '../schema';
import { Eye, EyeOff, X, Plus } from 'lucide-react'; import { Eye, EyeOff, X, Plus } from 'lucide-react';
@ -111,6 +111,7 @@ export const ServerEditDialog: React.FC<ServerEditDialogProps> = ({
osType: server.osType, osType: server.osType,
osVersion: server.osVersion || '', osVersion: server.osVersion || '',
hostname: server.hostname || '', hostname: server.hostname || '',
status: server.status,
description: server.description || '', description: server.description || '',
cpuCores: server.cpuCores, cpuCores: server.cpuCores,
memorySize: server.memorySize, memorySize: server.memorySize,
@ -131,6 +132,7 @@ export const ServerEditDialog: React.FC<ServerEditDialogProps> = ({
osType: undefined, osType: undefined,
osVersion: '', osVersion: '',
hostname: '', hostname: '',
status: ServerStatus.UNKNOWN,
description: '', description: '',
cpuCores: undefined, cpuCores: undefined,
memorySize: undefined, memorySize: undefined,

View File

@ -1,5 +1,5 @@
import { z } from 'zod'; import { z } from 'zod';
import { OsType, AuthType } from './types'; import { OsType, AuthType, ServerStatus } from './types';
/** /**
* *
@ -41,6 +41,7 @@ export const serverFormSchema = z.object({
osType: z.nativeEnum(OsType).optional(), osType: z.nativeEnum(OsType).optional(),
osVersion: z.string().max(100, '操作系统版本不能超过100个字符').optional(), osVersion: z.string().max(100, '操作系统版本不能超过100个字符').optional(),
hostname: z.string().max(100, '主机名不能超过100个字符').optional(), hostname: z.string().max(100, '主机名不能超过100个字符').optional(),
status: z.nativeEnum(ServerStatus).optional(),
description: z.string().max(500, '描述不能超过500个字符').optional(), description: z.string().max(500, '描述不能超过500个字符').optional(),
cpuCores: z.number().min(1, 'CPU核心数必须大于0').optional(), cpuCores: z.number().min(1, 'CPU核心数必须大于0').optional(),
memorySize: z.number().min(1, '内存大小必须大于0').optional(), memorySize: z.number().min(1, '内存大小必须大于0').optional(),

View File

@ -6,6 +6,7 @@ import type {
ServerResponse, ServerResponse,
ServerRequest, ServerRequest,
} from './types'; } from './types';
import type { ServerFormValues } from './schema';
import type { Page } from '@/types/base'; import type { Page } from '@/types/base';
// API 基础路径 // API 基础路径
@ -87,13 +88,13 @@ export const getServer = (id: number) =>
/** /**
* *
*/ */
export const createServer = (data: ServerRequest) => export const createServer = (data: ServerFormValues) =>
request.post<ServerResponse>(SERVER_URL, data); request.post<ServerResponse>(SERVER_URL, data);
/** /**
* *
*/ */
export const updateServer = (id: number, data: ServerRequest) => export const updateServer = (id: number, data: ServerFormValues) =>
request.put<ServerResponse>(`${SERVER_URL}/${id}`, data); request.put<ServerResponse>(`${SERVER_URL}/${id}`, data);
/** /**

View File

@ -182,6 +182,8 @@ export interface ServerRequest {
osVersion?: string; osVersion?: string;
/** 主机名 */ /** 主机名 */
hostname?: string; hostname?: string;
/** 连接状态(更新时保留原状态) */
status?: ServerStatus;
/** 描述 */ /** 描述 */
description?: string; description?: string;
/** CPU核心数 */ /** CPU核心数 */