feat: 提示词

This commit is contained in:
2026-06-16 12:12:33 +08:00
parent 05fff65acf
commit d9b8567b6d
9 changed files with 113 additions and 26 deletions

View File

@@ -5,3 +5,4 @@ docs/openapi.json文件是后端提供的标准OpenAPI接口文档你需要
3. 按模块拆分接口请求函数;
4. 严格遵循文档字段,不新增、不删减参数,区分必填/可选;
5. 按现有src/api/modules中的格式书写
6. 定义的TS类型名称interface以I开头命名type以T开头命名

View File

@@ -1,2 +1 @@
export * from './login.ts'
export * from './user.ts'

View File

@@ -1,17 +1,62 @@
import { requestClient } from '@/api/request'
/** 登录响应数据类型 */
export interface ILoginResponse {
token: string
}
/** 登录请求数据类型 */
export interface ILoginRequest {
/**
* 登录请求参数
*
* 对应 OpenAPI: LoginRequest
*/
export interface LoginRequest {
/** 用户名,不能为空 */
username: string
/** 密码,不能为空 */
password: string
}
/** 登录 */
function login(req: ILoginRequest) {
return requestClient.post<ILoginResponse>('/account', req)
/**
* 注册请求参数
*
* 对应 OpenAPI: RegisterRequest
*/
export interface RegisterRequest {
/** 用户名,长度限制 3-32 位 */
username: string
/** 密码,长度限制 6-64 位 */
password: string
}
/**
* 登录/注册响应
*
* 对应 OpenAPI: LoginResponse
*/
export interface LoginResponse {
/** Sa-Token 认证令牌UUID 格式) */
token: string
}
/**
* 用户登录
*
* 使用用户名和密码进行登录认证,成功返回 Sa-Token 令牌。
* 该接口无需登录即可调用。
*
* @param req - 登录请求参数
* @returns 包含认证令牌的响应
*/
export function login(req: LoginRequest) {
return requestClient.post<LoginResponse>('/account/login', req)
}
/**
* 用户注册
*
* 注册新账号。用户名长度 3-32 位,密码长度 6-64 位。
* 注册成功后自动登录并返回 token。
* 该接口无需登录即可调用。
*
* @param req - 注册请求参数
* @returns 包含认证令牌的响应
*/
export function register(req: RegisterRequest) {
return requestClient.post<LoginResponse>('/account/register', req)
}

View File

@@ -1,12 +0,0 @@
import { requestClient } from '@/api/request'
/** 账户信息 */
export interface IUserInfo {
id: number
username: string
}
/** 获取账户信息 */
function getAccountInfo() {
return requestClient.get<IUserInfo>('/user/info')
}

2
src/api/modules/index.ts Normal file
View File

@@ -0,0 +1,2 @@
export * from './account/index.ts'
export * from './user/index.ts'

View File

@@ -0,0 +1 @@
export * from './info.ts'

View File

@@ -0,0 +1,51 @@
import { requestClient } from '@/api/request'
/**
* 性别枚举
*
* 对应 OpenAPI: Sex (x-enums)
* 1 = 男2 = 女
*/
export const Sex = {
/** 男 */
MALE: 1,
/** 女 */
FEMALE: 2
} as const
/** 性别类型 */
export type SexType = (typeof Sex)[keyof typeof Sex]
/**
* 用户信息响应
*
* 对应 OpenAPI: UserInfoResponse
* 所有字段均为可选,部分字段可能为 null
*/
export interface UserInfoResponse {
/** 用户昵称,最长 16 位 */
nickName?: string
/** 头像图片 URL 地址,可能为 null */
avatar?: string | null
/** 个性签名,最长 64 位,可能为 null */
signature?: string | null
/** 年龄,可能为 null */
age?: number | null
/** 性别1=男2=女,可能为 null */
sex?: SexType | null
/** 生日ISO 8601 日期格式),可能为 null */
birthday?: string | null
}
/**
* 获取当前登录用户信息
*
* 根据请求头中的 saToken 获取当前登录用户的详细信息,
* 包括昵称、头像、个性签名、年龄、性别、生日。
* 需登录认证。
*
* @returns 当前登录用户的详细信息
*/
export function getUserInfo() {
return requestClient.get<UserInfoResponse>('/user/info')
}

View File

@@ -63,11 +63,11 @@ class RequestClient {
config.url = resolvePathParams(config.url, reqConfig.pathParams)
}
// 跳过鉴权时不注入 token
// 跳过鉴权时不注入 saToken
if (!reqConfig?.skipAuth) {
const accountStore = useAccountStore()
if (accountStore.token) {
config.headers.Authorization = `Bearer ${accountStore.token}`
config.headers.saToken = accountStore.token
}
}

View File

@@ -14,7 +14,7 @@ export interface ApiResponse<T = unknown> {
export interface InternalRequestConfig extends AxiosRequestConfig {
/** 路径参数,替换 URL 中的 :param 占位符(如 /user/:id → /user/1 */
pathParams?: Record<string, string | number>
/** 跳过鉴权注入(不携带 Authorization 头) */
/** 跳过鉴权注入(不携带 saToken 头) */
skipAuth?: boolean
}