diff --git a/src/lib/api/services/deviceTypesService.ts b/src/lib/api/services/deviceTypesService.ts new file mode 100644 index 0000000..fe73c2a --- /dev/null +++ b/src/lib/api/services/deviceTypesService.ts @@ -0,0 +1,17 @@ +import { api } from '$lib/api/httpClient.ts'; + +import type { Options } from '$lib/types/api.ts'; + +export const deviceTypesService = { + getDeviceTypesOptions: async (token:string) => { + const result = await api.get('/device-types/options',{ + headers:{Authorization: `${token}`} + }); + + if (result.code != 200 || !result.data){ + throw new Error(result.msg); + } + + return result.data; + } +} \ No newline at end of file diff --git a/src/lib/components/Modal.svelte b/src/lib/components/Modal.svelte new file mode 100644 index 0000000..e19b048 --- /dev/null +++ b/src/lib/components/Modal.svelte @@ -0,0 +1,171 @@ + + + + + + + \ No newline at end of file diff --git a/src/lib/components/form/AddDevice.svelte b/src/lib/components/form/AddDevice.svelte new file mode 100644 index 0000000..b1eb961 --- /dev/null +++ b/src/lib/components/form/AddDevice.svelte @@ -0,0 +1,238 @@ + + +
+
+
+

基础信息

+ +
+ + + + + + + + + +
+
+
+ +
+
+
+

网络接口 (Interfaces)

+ +
+ + {#each formData.interfaces as iface, i (i)} +
+ +
+ 接口 #{i + 1}: {iface.name || '(未命名)'} + +
+ +
+
+ + + + + +
+ +
+
+

IP / VLAN 配置

+ +
+ + {#if iface.addressConfigs.length === 0} +
暂无 IP 配置
+ {/if} + + {#each iface.addressConfigs as addr, j (j)} +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+
+ {/each} +
+
+
+ {/each} +
+
+ + +
+ + + +
+
\ No newline at end of file diff --git a/src/lib/types/api.ts b/src/lib/types/api.ts index 08c1157..9208bdf 100644 --- a/src/lib/types/api.ts +++ b/src/lib/types/api.ts @@ -37,19 +37,43 @@ export interface DeviceResponse { remark: string; } -export interface CreateDeviceRequest { - name: string; - model: string; - typeId: number; - locationId: number; - snmpCommunity: string; - manufacturer: string; - purchaseDate: Date; - status: number; - remark: string; -} export interface Options { label: string; value: string; +} + + +export interface InterfaceAddressConfigRequest { + vlanId?: number | null; + ipAddress?: string; + subnetMask?: string; + gatewayIp?: string; + broadcastAddress?: string; + isPrimary: boolean; + isDhcp: boolean; + mtu?: number | null; + dnsServers?: string[]; // 简化处理,前端可用逗号分隔字符串转换 +} + +export interface NetworkInterfaceRequest { + name: string; + type: number | null; // 1:物理口, 2:聚合口, 3:虚拟口 + macAddress?: string; + portSpeed?: number | null; + duplex?: number | null; + remark?: string; + addressConfigs: InterfaceAddressConfigRequest[]; +} + +export interface CreateDeviceRequest { + name: string; + typeId: number | null; + locationId?: number | null; + model: string; + manufacturer: string; + snmpCommunity?: string; + purchaseDate?: string; // 对应 Java LocalDate (YYYY-MM-DD) + remark?: string; + interfaces: NetworkInterfaceRequest[]; } \ No newline at end of file diff --git a/src/routes/api/devices/+server.ts b/src/routes/api/devices/+server.ts new file mode 100644 index 0000000..ba77a99 --- /dev/null +++ b/src/routes/api/devices/+server.ts @@ -0,0 +1,20 @@ +import { log } from '$lib/log.ts'; + + +export async function POST({ request }) { + const data = await request.json(); + + // 实际应用中:将 data 存入数据库 + + log.info('client request data', data) + + return new Response( + JSON.stringify({ message: 'User created successfully', user: data }), + { + status: 201, // 201 Created + headers: { + 'Content-Type': 'application/json' + } + } + ); +} \ No newline at end of file diff --git a/src/routes/app/+layout.svelte b/src/routes/app/+layout.svelte index c9f1271..861f50f 100644 --- a/src/routes/app/+layout.svelte +++ b/src/routes/app/+layout.svelte @@ -13,7 +13,7 @@ -
+
{@render children()}
diff --git a/src/routes/app/settings/devices/+page.server.ts b/src/routes/app/settings/devices/+page.server.ts index 2bbb7ab..a21dc93 100644 --- a/src/routes/app/settings/devices/+page.server.ts +++ b/src/routes/app/settings/devices/+page.server.ts @@ -2,6 +2,7 @@ import type { PageServerLoad } from './$types'; import { COOKIE_TOKEN_KEY } from '$lib/components/constants/cookiesConstants.ts'; import { redirect } from '@sveltejs/kit'; import { deviceService } from '$lib/api/services/deviceService.ts'; +import { deviceTypesService } from '$lib/api/services/deviceTypesService.ts'; export const load:PageServerLoad = async ({ cookies }) => { @@ -12,11 +13,12 @@ export const load:PageServerLoad = async ({ cookies }) => { } const result = deviceService.getAllDevices({ page: 1, size: 10 ,token:token}); - + const options = deviceTypesService.getDeviceTypesOptions( token); return { streamed:{ result: { - list: result + list: result, + options: options } } }; diff --git a/src/routes/app/settings/devices/+page.svelte b/src/routes/app/settings/devices/+page.svelte index a51e19f..1af8432 100644 --- a/src/routes/app/settings/devices/+page.svelte +++ b/src/routes/app/settings/devices/+page.svelte @@ -1,34 +1,66 @@ -
-

设备管理

- \ No newline at end of file