diff --git a/.idea/dataSources.xml b/.idea/dataSources.xml new file mode 100644 index 0000000..2069a40 --- /dev/null +++ b/.idea/dataSources.xml @@ -0,0 +1,15 @@ + + + + + mariadb + true + org.mariadb.jdbc.Driver + jdbc:mariadb://10.91.3.253:3306/chaos + + + + $ProjectFileDir$ + + + \ No newline at end of file diff --git a/src/app.html b/src/app.html index 4939117..20d06dc 100644 --- a/src/app.html +++ b/src/app.html @@ -1,5 +1,5 @@ - + diff --git a/src/lib/api/httpClient.ts b/src/lib/api/httpClient.ts index 6ae9f77..2390b27 100644 --- a/src/lib/api/httpClient.ts +++ b/src/lib/api/httpClient.ts @@ -63,7 +63,7 @@ const httpRequest = async ( options: RequestOptions = {} ): Promise> => { const fullUrl = `${API_BASE_URL}${url}`; - const { body, headers, ...rest } = options; + const { body , headers, ...rest } = options; diff --git a/src/lib/api/services/deviceService.ts b/src/lib/api/services/deviceService.ts new file mode 100644 index 0000000..960819a --- /dev/null +++ b/src/lib/api/services/deviceService.ts @@ -0,0 +1,46 @@ +import { api } from '$lib/api/httpClient.ts'; +import type { PageResult } from '$lib/types/dataTable.ts'; +import type { CreateDeviceRequest, DeviceResponse } from '$lib/types/api.ts'; + + +export const deviceService = { + getAllDevices: async ({ page, size,type,keyword,token}:{ + page: number, + size: number, + type?: number, + keyword?: string, + token:string + }) => { + const formData = new FormData(); + formData.append('pageNum', page.toString()); + formData.append('pageSize', size.toString()); + if ( type){ + formData.append('type', type.toString()); + } + if ( keyword){ + formData.append('keyword', keyword); + } + + const result = await api.get>('/devices',{ + body: formData, + headers:{Authorization: `${token}`} + }); + + if (result.code != 200 || !result.data){ + throw new Error(result.msg); + } + + return result.data; + }, + createDevice: async (device: CreateDeviceRequest,token:string) => { + + const result = await api.post('/devices',{ + body: JSON.stringify(device), + 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/api/services/userService.ts b/src/lib/api/services/userService.ts index a4c9deb..190d91a 100644 --- a/src/lib/api/services/userService.ts +++ b/src/lib/api/services/userService.ts @@ -14,7 +14,7 @@ export const userService = { const formData = new FormData(); formData.append('pageNum', page.toString()); formData.append('pageSize', size.toString()); - const response = await api.get>( + const response = await api.get>( '/user/all', { body: formData, diff --git a/src/lib/components/icon/Sprite.svelte b/src/lib/components/icon/Sprite.svelte index 8ec7d36..62af56e 100644 --- a/src/lib/components/icon/Sprite.svelte +++ b/src/lib/components/icon/Sprite.svelte @@ -127,4 +127,7 @@ + + + \ No newline at end of file diff --git a/src/lib/components/layout/app/AppSidebar.svelte b/src/lib/components/layout/app/AppSidebar.svelte index b1b829a..ddfead5 100644 --- a/src/lib/components/layout/app/AppSidebar.svelte +++ b/src/lib/components/layout/app/AppSidebar.svelte @@ -1,5 +1,4 @@ - {#snippet menuItem(item: ProcessedNavItem)} -
  • - {#if item.subItems && item.subItems.length > 0} -
    - - - + {#if item.icon} - - {/if} {item.label} -
      - {#each item.subItems as subItem (subItem.id)} - {@render menuItem(subItem)} - {/each} -
    -
    - {:else} - - - + {#if item.icon} - - {:else} - - {/if} {item.label} - - {/if} -
  • - {/snippet} -
    - - \ No newline at end of file + border-radius: 20px; + } + diff --git a/src/lib/components/table/DeviceTable.svelte b/src/lib/components/table/DeviceTable.svelte new file mode 100644 index 0000000..e69de29 diff --git a/src/lib/components/table/UserTable.svelte b/src/lib/components/table/UserTable.svelte new file mode 100644 index 0000000..f846e69 --- /dev/null +++ b/src/lib/components/table/UserTable.svelte @@ -0,0 +1,160 @@ + +
    + {#if users.total > 0} +
    + + + +
    +
    +
    + + {#if roles} +
    + + {#each roles as role(role.id)} + + {/each} +
    + {/if} +
    +
    + + + + +
    + + +
    + + + + + + {#each newRowTitles as item,index(index)} + + {/each} + + + + + + {#if users.records} + + {#each users.records as record(record.id)} + + + + + + + + + {/each} + + + + + + + + + {/if} + +
    + + {item.title}
    + + {record.id}{record.username}{record.nickname} +
    + {#if record.avatar} +  + {/if} +
    +
    + {#each record.roles as role (role.id)} + {role.name} + {/each} +
    +
    +
    + page {users.current} of {users.pages} +
    + +
    + + + + + +
    + +
    + +
    +
    +
    + +
    + +
    + {:else } +

    No users found

    + {/if} +
    \ No newline at end of file diff --git a/src/lib/components/table/UserTableOld.svelte b/src/lib/components/table/UserTableOld.svelte new file mode 100644 index 0000000..f5984b2 --- /dev/null +++ b/src/lib/components/table/UserTableOld.svelte @@ -0,0 +1,201 @@ + + +
    + +
    +

    用户管理

    + +
    + + +
    +
    +
    + + {#await data.streamed.roles} +
    + {:then roles } +
    + + {#each roles as role(role.id)} + + {/each} +
    + {/await} +
    +
    + + + + +
    + + +
    + + + + + + {#each newRowTitles as item,index(index)} + + {/each} + + + + {#await data.streamed.userList} + + + + + + {:then userList} + + {#each userList.records as record(record.id)} + + + + + + + + + {/each} + + + + + + + + {:catch error} + + + + + + + {/await} + +
    + + {item.title}
    +
    +
    + +
    +
    + + {record.id}{record.username}{record.nickname} +
    + {#if record.avatar} +  + {/if} +
    +
    + {#each record.roles as role (role.id)} + {role.name} + {/each} +
    +
    +
    + page {userList.current} of {userList.pages} +
    + +
    + + + + + +
    + +
    + +
    +
    +
    +
    +

    组件加载失败: {error.message}

    + +
    +
    + +
    + +
    + \ No newline at end of file diff --git a/src/lib/types/api.ts b/src/lib/types/api.ts index 646f23c..76319f1 100644 --- a/src/lib/types/api.ts +++ b/src/lib/types/api.ts @@ -24,3 +24,27 @@ export interface LoginSuccess { } +export interface DeviceResponse { + id: number; + name: string; + model: string; + typeId: number; + locationId: number; + snmpCommunity: string; + manufacturer: string; + purchaseDate: Date; + status: number; + remark: string; +} + +export interface CreateDeviceRequest { + name: string; + model: string; + typeId: number; + locationId: number; + snmpCommunity: string; + manufacturer: string; + purchaseDate: Date; + status: number; + remark: string; +} \ No newline at end of file diff --git a/src/lib/types/icon-ids.ts b/src/lib/types/icon-ids.ts index 299f11c..7a59567 100644 --- a/src/lib/types/icon-ids.ts +++ b/src/lib/types/icon-ids.ts @@ -16,5 +16,6 @@ export type IconId = "user-settings" | "user-profile"| "auth"| - "chevron-up-down" + "chevron-up-down"| + "laptop-settings" ; \ No newline at end of file diff --git a/src/lib/types/layout.ts b/src/lib/types/layout.ts index 39f9d91..2668bd0 100644 --- a/src/lib/types/layout.ts +++ b/src/lib/types/layout.ts @@ -5,7 +5,7 @@ export interface NavItem { id: string; icon?: IconId; label: string; - href: RouteId; + href?: RouteId; isActive?: boolean; isDisabled?: boolean; isHidden?: boolean; diff --git a/src/routes/admin/+page.svelte b/src/routes/admin/+page.svelte index 483c8d6..7b77f0f 100644 --- a/src/routes/admin/+page.svelte +++ b/src/routes/admin/+page.svelte @@ -1,18 +1,4 @@
    - - {#if isAdmin} -
    - 是管理员 -
    - {:else } -
    - 没有权限 -
    - {/if}
    \ No newline at end of file diff --git a/src/routes/app/settings/auth/users/+page.svelte b/src/routes/app/settings/auth/users/+page.svelte index 668d1b3..83db4be 100644 --- a/src/routes/app/settings/auth/users/+page.svelte +++ b/src/routes/app/settings/auth/users/+page.svelte @@ -1,192 +1,31 @@ -
    - -
    -

    用户管理

    - +
    +

    用户管理

    + - - -
    -
    -
    - - {#await data.streamed.roles} -
    - {:then roles } -
    - - {#each roles as role(role.id)} - - {/each} -
    - {/await} -
    -
    - - - - -
    - - -
    - - - - - - {#each newRowTitles as item,index(index)} - - {/each} - - - - {#await data.streamed.userList} - - - - - - {:then userList} - - {#each userList.records as record(record.id)} - - - - - - - - - {/each} - - - - - - - - {:catch error} - - - - - - - {/await} - -
    - - {item.title}
    -
    -
    - -
    -
    - - {record.id}{record.username}{record.nickname} -
    - {#if record.avatar} -  - {/if} -
    -
    - {#each record.roles as role (role.id)} - {role.name} - {/each} -
    -
    -
    - page {userList.current} of {userList.pages} -
    - -
    - - - - - -
    - -
    - -
    -
    -
    -
    -

    组件加载失败: {error.message}

    - -
    -
    - -
    -
    - \ No newline at end of file +{#await data.streamed.userList} + 加载中 +{:then result} + {#await data.streamed.roles} + 加载中 + {:then roles} + + {:catch err} +

    出错了: {err.message}

    + {/await} +{:catch err} +

    出错了: {err.message}

    +{/await} \ No newline at end of file diff --git a/src/routes/app/settings/device/list/+page.server.ts b/src/routes/app/settings/device/list/+page.server.ts new file mode 100644 index 0000000..3e2e1ca --- /dev/null +++ b/src/routes/app/settings/device/list/+page.server.ts @@ -0,0 +1,25 @@ +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'; + +export const load:PageServerLoad = async ({ cookies }) => { + + const token = cookies.get(COOKIE_TOKEN_KEY); + + if (!token) { + throw redirect(302, '/auth/login'); + } + + const result = await deviceService.getAllDevices({ page: 1, size: 10 ,token:token}); + console.log('result', result); + + + return { + streamed:{ + result: { + list: result + } + } + }; +}; \ No newline at end of file diff --git a/src/routes/app/settings/device/list/+page.svelte b/src/routes/app/settings/device/list/+page.svelte new file mode 100644 index 0000000..ebb7e2f --- /dev/null +++ b/src/routes/app/settings/device/list/+page.svelte @@ -0,0 +1,30 @@ + + +
    +

    设备管理

    + +
    + +{#await data.streamed.deviceList} +

    正在加载设备列表...

    +

    请稍后...

    + {:then result} +
    + 加载成功 +
    + {:catch error} +

    {error}

    +

    请稍后...

    + {/await} \ No newline at end of file diff --git a/src/routes/app/settings/device/type/+page.svelte b/src/routes/app/settings/device/type/+page.svelte new file mode 100644 index 0000000..e69de29