feat(auth): implement login and user management features

- Added server-side login action with form handling and cookie storage
- Implemented user authentication service with token management
- Created user list page with data fetching from userService
- Developed reusable DataTable component with selection and pagination
- Enhanced AppSidebar with nested navigation and active state tracking
- Updated icon definitions and sprite symbols for UI consistency
- Improved HTTP client to properly handle request bodies for different methods
- Refactored auth store to manage authentication state and cookies
- Added strict typing for navigation items and table columns
- Removed obsolete code and simplified authentication flow
This commit is contained in:
Chaos
2025-11-24 17:11:41 +08:00
parent 3515faa814
commit ed542f108c
16 changed files with 472 additions and 203 deletions

View File

@@ -0,0 +1,41 @@
<script lang="ts">
import DataTable from '$lib/components/DataTable.svelte';
import type { BaseRecord, TableColumn } from '$lib/types/dataTable.ts';
import type { PageData } from './$types'; // SvelteKit 自动生成的类型
// 从 load 函数获取的数据
export let data: PageData;
console.log(data);
// 1. 定义具体的业务接口
interface Role {
id: number;
name: string;
}
interface UserRecord extends BaseRecord {
username: string;
nickname: string;
roles: Role[];
email?: string; // 可选字段
}
// 2. 定义列配置
// 注意:这里显式声明了 TableColumn<UserRecord>[]
// 好处:如果我在 key 里写 "mobile"TS 会报错,因为 UserRecord 里没有 mobile。
const columns: TableColumn<UserRecord>[] = [
{ key: 'id', label: 'ID', width: '50px' },
{ key: 'nickname', label: '用户昵称' }, // 用 nickname 作为 key
{ key: 'roles', label: '角色列表' }, // key 必须是 'roles'
{ key: 'username', label: '登录账号' }
];
function handleEdit(e: CustomEvent<UserRecord>) {
// e.detail 自动被推断为 UserRecord 类型,不是 any
console.log(e.detail.username);
}
</script>
<div class="p-6">
</div>