From 9d25cddcb35ea0a665f9b75c27ba1dcdf387a098 Mon Sep 17 00:00:00 2001 From: wangxuefeng Date: Fri, 7 Mar 2025 10:06:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=94=A8=E6=88=B7=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E5=A4=A9=E6=A2=AF=E7=99=BB=E9=99=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/platform/src/io/user.ts | 99 +++++++++++++++++++ .../src/router/routes/modules/user.ts | 22 +++++ apps/platform/src/store/modules/user.ts | 9 +- 3 files changed, 129 insertions(+), 1 deletion(-) diff --git a/apps/platform/src/io/user.ts b/apps/platform/src/io/user.ts index e4948c6..34dfaa5 100644 --- a/apps/platform/src/io/user.ts +++ b/apps/platform/src/io/user.ts @@ -9,3 +9,102 @@ export const logout = async () => { const response = await instance.post('/logout'); return response.data; }; + +/** + * 用户信息接口 + */ +export interface UserInfo { + /** 用户ID */ + UserID: number; + /** 用户名 */ + Username: string; + /** 头像URL */ + Avatar: string; + /** 用户别名/真实姓名 */ + Alias: string; + /** 创建时间 */ + CreatedAt: string; + /** 更新时间 */ + UpdatedAt: string; +} + +/** + * 获取当前登录用户信息 + * + * @returns {Promise<{code: number, data: UserInfo, message: string}>} 返回包含用户信息的响应对象 + * + * @example + * ```typescript + * const userInfo = await getCurrentUser(); + * console.log(userInfo.data.Username); // 输出当前用户名 + * ``` + */ +export const getCurrentUser = async () => { + const response = await instance.get('/api/v1/users/current'); + return response.data; +}; + +/** + * 获取指定用户信息 + * + * @param {number|string} id 用户ID + * @returns {Promise<{code: number, data: UserInfo, message: string}>} 返回包含用户信息的响应对象 + * + * @example + * ```typescript + * // 获取ID为2594的用户信息 + * const userInfo = await getUserById(2594); + * console.log(userInfo.data.Username); // 输出用户名 + * ``` + */ +export const getUserById = async (id: number | string) => { + const response = await instance.get(`/api/v1/users/${id}`); + return response.data; +}; + +/** + * 用户列表项接口 + */ +export interface UserListItem { + /** 用户ID */ + user_id: number; + /** 用户名 */ + username: string; + /** 头像URL */ + avatar: string; + /** 用户别名/真实姓名 */ + alias: string; + /** 创建时间 */ + created_at: string; + /** 更新时间 */ + updated_at: string; +} + +/** + * 用户列表查询参数 + */ +export interface UserListParams { + /** 页码,默认1 */ + page?: number | string; + /** 每页数量,默认20 */ + per_page?: number | string; +} + +/** + * 获取用户列表 + * + * @param {UserListParams} params 查询参数,包含页码和每页数量 + * @returns {Promise<{code: number, data: {list: UserListItem[], total: number}, message: string}>} 返回包含用户列表的响应对象 + * + * @example + * ```typescript + * // 获取第1页,每页20条记录 + * const result = await getUserList({ page: 1, per_page: 20 }); + * console.log(`总用户数: ${result.data.total}`); + * console.log(`第一个用户: ${result.data.list[0].username}`); + * ``` + */ +export const getUserList = async (params: UserListParams = {}) => { + const response = await instance.get('/api/v1/users', { params }); + return response.data; +}; diff --git a/apps/platform/src/router/routes/modules/user.ts b/apps/platform/src/router/routes/modules/user.ts index 859ace4..4f539dd 100644 --- a/apps/platform/src/router/routes/modules/user.ts +++ b/apps/platform/src/router/routes/modules/user.ts @@ -1,4 +1,6 @@ import type { RouteRecordRaw } from 'vue-router'; +import { Y_CODE_RENDERER_URL } from '@/constants'; +import { LOW_CODE_APPLICATION_ID, LOW_CODE_PROJECT_ID } from '@/constants/low-code'; const moduleName = 'user'; @@ -12,6 +14,26 @@ const routes: Array = [ icon: 'ant-design:user-outlined', }, children: [ + { + path: 'list', + name: `${moduleName}-list`, + meta: { + title: '项目列表', + keepAlive: true, + icon: 'ant-design:list', + app: { + url: Y_CODE_RENDERER_URL, + name: 'y-code-platform-project-list', + // sync: true, + // alive: true, + // degrade: true, + applicationId: LOW_CODE_APPLICATION_ID, + projectId: LOW_CODE_PROJECT_ID, + fileId: 'b91ra0ej4', + }, + }, + component: () => import('@/components/renderer-adapter/index.vue'), + }, { path: 'login', name: `${moduleName}-login`, diff --git a/apps/platform/src/store/modules/user.ts b/apps/platform/src/store/modules/user.ts index 4ff51ea..139a2fc 100644 --- a/apps/platform/src/store/modules/user.ts +++ b/apps/platform/src/store/modules/user.ts @@ -4,6 +4,7 @@ import { useSSEStore } from './sse'; import { store } from '@/store'; import { resetRouter } from '@/router'; import tianti from '@/io/tianti'; +import { getCurrentUser } from '@/io/user'; export const useUserStore = defineStore( 'user', @@ -32,7 +33,13 @@ export const useUserStore = defineStore( tianti.checkQuery(); setTimeout(() => { const token = localStorage.getItem('y-code-access-token'); - setToken(token || ''); + if (token) { + setToken(token); + getCurrentUser().then((res) => { + userInfo.value = res.data.data; + console.log('userInfo', userInfo.value); + }); + } }, 0); }; /** 登出 */