Files
yuto-water-h5/src/api/user.ts
Ubuntu ed9eedc519 feat: Phase 3 - API layer + Pinia stores + app integration
- HTTP client (axios interceptors, token mgmt, typed APIs)
- Pinia stores: token, user (login/logout), app (dark mode, sidebar)
- globalConfig TS types + Window augmentation
- Vue Router (hash history, auth guard)
- Login/Home/Mine pages (Vant UI)
- Vant integration + globalConfig dev script
- Build passes (vue-tsc + vite)
2026-06-15 20:56:05 +08:00

106 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* 用户相关 API
*
* 包含登录、获取用户信息、退出登录、重置密码等用户模块接口。
*
* @module api/user
*/
import { post, get } from '@/utils/http'
// ══════════════════════════════════════════════
// 请求参数类型
// ══════════════════════════════════════════════
/** 登录请求参数 */
export interface LoginParams {
/** 用户名 */
username: string
/** 密码 */
password: string
/** 验证码 */
code?: string
/** 验证码唯一标识 */
uuid?: string
}
/** 重置密码请求参数 */
export interface ResetPasswordParams {
/** 旧密码 */
oldPassword: string
/** 新密码 */
newPassword: string
}
// ══════════════════════════════════════════════
// 响应数据类型
// ══════════════════════════════════════════════
/** 登录返回结果 */
export interface LoginResult {
/** 认证 Token */
token: string
}
/** 用户信息 */
export interface UserInfo {
/** 用户 ID */
userId: string | number
/** 用户名 */
userName: string
/** 昵称 */
nickName: string
/** 头像地址 */
avatar: string
/** 手机号 */
phonenumber?: string
/** 邮箱 */
email?: string
/** 性别0-男 1-女 2-未知) */
sex?: string
/** 部门名称 */
deptName?: string
/** 角色列表 */
roles?: string[]
/** 权限列表 */
permissions?: string[]
}
// ══════════════════════════════════════════════
// API 方法
// ══════════════════════════════════════════════
/**
* 用户登录
* @param params - 登录参数(用户名、密码、验证码等)
* @returns 返回包含 Token 的登录结果
*/
export function login(params: LoginParams): Promise<LoginResult> {
return post<LoginResult>('/login', params)
}
/**
* 获取当前登录用户信息
* @returns 用户详细信息
*/
export function getUserInfo(): Promise<UserInfo> {
return get<UserInfo>('/getInfo')
}
/**
* 退出登录
* @returns Promise<void>
*/
export function logout(): Promise<void> {
return post<void>('/logout')
}
/**
* 重置密码
* @param params - 旧密码和新密码
* @returns Promise<void>
*/
export function resetPassword(params: ResetPasswordParams): Promise<void> {
return post<void>('/system/user/profile/resetPwd', params)
}