98 lines
1.6 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.

import request from '@/utils/request'
const API_BASE = ''
export interface LoginParams {
username?: string
password?: string
loginType?: string
authCode?: string
}
// 注册参数
export interface RegisterParams {
username: string
password: string
realName: string
roleId: number
deptId: number
email?: string
phone?: string
}
export interface LoginResponse {
token: string // 后端返回的是 token
accessToken?: string // 兼容旧版
refreshToken?: string
tokenType?: string
expiresIn?: number
userId?: number
username?: string
realName?: string
avatar?: string
roleIds?: string
userInfo?: UserInfo // 可选,后端可能不返回
}
export interface UserInfo {
id: number
username: string
realName: string
email: string
phone: string
avatar: string
deptId: number
deptName: string
roleIds?: string // 角色ID列表(逗号分隔)
roles: string[]
permissions: string[]
}
/**
* 用户登录
*/
export const login = (data: LoginParams) => {
return request.post<LoginResponse>(
`/auth/login`,
data
)
}
/**
* 用户注册
*/
export const register = (data: RegisterParams) => {
return request.post<UserInfo>(
`/auth/register`,
data
)
}
/**
* 获取用户信息
*/
export const getUserInfo = () => {
return request.get<UserInfo>(
`/auth/userinfo`
)
}
/**
* 退出登录
*/
export const logout = () => {
return request.post<string>(
`/auth/logout`
)
}
/**
* 刷新Token
*/
export const refreshToken = () => {
return request.post<LoginResponse>(
`/auth/refresh`
)
}