From 8f3f2d63a0be73aaff8fcfa3d69875a1fdcfecd5 Mon Sep 17 00:00:00 2001 From: Chaos Date: Tue, 25 Nov 2025 07:33:58 +0800 Subject: [PATCH] =?UTF-8?q?refactor(layout):=20=E9=87=8D=E6=9E=84=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=B8=83=E5=B1=80=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将原有布局中的侧边栏和头部组件拆分为独立的 AppSidebar 和 AppHeader 组件 - 移除内联的导航逻辑和样式,交由专用组件管理 - 更新图标库,优化部分图标的显示效果 - 简化认证存储逻辑,增强状态持久化与安全性 - 优化侧边栏状态管理机制,提高响应式体验 - 改进登录流程错误处理,增加网络异常提示 - 调整路由组件结构,提升代码可维护性 --- src/routes/auth/login/+page.server.ts | 18 ++++++++- src/routes/auth/login/+page.svelte | 54 ++++++++++++++++++--------- 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/src/routes/auth/login/+page.server.ts b/src/routes/auth/login/+page.server.ts index 6f4555d..de2e5b7 100644 --- a/src/routes/auth/login/+page.server.ts +++ b/src/routes/auth/login/+page.server.ts @@ -1,5 +1,5 @@ import type { Actions } from './$types'; -import { fail } from '@sveltejs/kit'; +import { fail, redirect } from '@sveltejs/kit'; import { authService } from '$lib/api/services/authService.ts'; import { resolve } from '$app/paths'; import { HttpError } from '$lib/api/httpClient.ts'; @@ -25,6 +25,22 @@ export const actions:Actions = { }) } + const regexp = /^[a-zA-Z0-9_-]{5,16}$/ + + if (!regexp.test(username)){ + return fail(400,{ + username: username.toString(), + message: '用户名格式错误,请输入5-16位字符,只能包含字母、数字、下划线、减号' + }) + } + + if (password.length<8 || password.length>16){ + return fail(400,{ + message: '密码格式错误,请输入8-16位字符' + }) + } + + try{ const response = await authService.login({username,password}); diff --git a/src/routes/auth/login/+page.svelte b/src/routes/auth/login/+page.svelte index ad0f499..e4314c0 100644 --- a/src/routes/auth/login/+page.svelte +++ b/src/routes/auth/login/+page.svelte @@ -2,10 +2,10 @@ import { resolve } from '$app/paths'; import Icon from '$lib/components/icon/Icon.svelte'; import { toast } from '$lib/stores/toastStore.ts'; - import { enhance } from '$app/forms'; - import type { EnhanceResult, LoginFailure } from '$lib/types/api.ts'; - + import { enhance } from '$app/forms'; + import { goto } from '$app/navigation'; + let loading = false; @@ -24,13 +24,25 @@
{ + loading = true; return async ({ result , update }) => { - const res = result as EnhanceResult; - if (res.status === 200) { - toast.success('登录成功'); - update(); - } else { - toast.error(res.data.message); + loading = false; + if (result.type === 'failure') { + + if (typeof result.data?.message === 'string' ){ + toast.error(result.data?.message) + } + await update(); + + }else if (result.type === 'success') { + + if (typeof result.data?.message === 'string' ){ + toast.success(result.data?.message || '登录成功') + } + + if (result.data?.redirectTo && typeof result.data?.redirectTo === 'string') { + await goto(resolve(result.data.redirectTo)); + } } }; }} @@ -38,7 +50,7 @@
- +
@@ -67,7 +81,10 @@ required /> - + @@ -75,19 +92,20 @@
-
-