first commit
This commit is contained in:
46
src/apis/auth/index.ts
Normal file
46
src/apis/auth/index.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import type * as T from './type'
|
||||
import http from '@/utils/http'
|
||||
|
||||
export type * from './type'
|
||||
|
||||
const BASE_URL = '/auth'
|
||||
|
||||
/** @desc 账号登录 */
|
||||
export function accountLogin(req: T.AccountLoginReq) {
|
||||
return http.post<T.LoginResp>(`${BASE_URL}/login`, req)
|
||||
}
|
||||
|
||||
/** @desc 手机号登录 */
|
||||
export function phoneLogin(req: T.PhoneLoginReq) {
|
||||
return http.post<T.LoginResp>(`${BASE_URL}/login`, req)
|
||||
}
|
||||
|
||||
/** @desc 邮箱登录 */
|
||||
export function emailLogin(req: T.EmailLoginReq) {
|
||||
return http.post<T.LoginResp>(`${BASE_URL}/login`, req)
|
||||
}
|
||||
|
||||
/** @desc 三方账号登录 */
|
||||
export function socialLogin(req: any) {
|
||||
return http.post<T.LoginResp>(`${BASE_URL}/login`, req)
|
||||
}
|
||||
|
||||
/** @desc 三方账号登录授权 */
|
||||
export function socialAuth(source: string) {
|
||||
return http.get<T.SocialAuthAuthorizeResp>(`${BASE_URL}/${source}`)
|
||||
}
|
||||
|
||||
/** @desc 退出登录 */
|
||||
export function logout() {
|
||||
return http.post(`${BASE_URL}/logout`)
|
||||
}
|
||||
|
||||
/** @desc 获取用户信息 */
|
||||
export const getUserInfo = () => {
|
||||
return http.get<T.UserInfo>(`${BASE_URL}/user/info`)
|
||||
}
|
||||
|
||||
/** @desc 获取路由信息 */
|
||||
export const getUserRoute = () => {
|
||||
return http.get<T.RouteItem[]>(`${BASE_URL}/user/route`)
|
||||
}
|
||||
88
src/apis/auth/type.ts
Normal file
88
src/apis/auth/type.ts
Normal file
@@ -0,0 +1,88 @@
|
||||
/** 用户类型 */
|
||||
export interface UserInfo {
|
||||
id: string
|
||||
username: string
|
||||
nickname: string
|
||||
gender: 0 | 1 | 2
|
||||
email: string
|
||||
phone: string
|
||||
avatar: string
|
||||
pwdResetTime: string
|
||||
pwdExpired: boolean
|
||||
registrationDate: string
|
||||
deptName: string
|
||||
roles: string[]
|
||||
permissions: string[]
|
||||
}
|
||||
|
||||
/** 路由类型 */
|
||||
export interface RouteItem {
|
||||
id: string
|
||||
title: string
|
||||
parentId: string
|
||||
type: 1 | 2 | 3
|
||||
path: string
|
||||
name: string
|
||||
component: string
|
||||
redirect: string
|
||||
icon: string
|
||||
isExternal: boolean
|
||||
isHidden: boolean
|
||||
isCache: boolean
|
||||
permission: string
|
||||
roles: string[]
|
||||
sort: number
|
||||
status: 0 | 1
|
||||
children: RouteItem[]
|
||||
activeMenu: string
|
||||
alwaysShow: boolean
|
||||
breadcrumb: boolean
|
||||
showInTabs: boolean
|
||||
affix: boolean
|
||||
}
|
||||
|
||||
/** 认证类型 */
|
||||
export type AuthType = 'ACCOUNT' | 'PHONE' | 'EMAIL' | 'SOCIAL'
|
||||
|
||||
export const AuthTypeConstants = {
|
||||
ACCOUNT: 'ACCOUNT',
|
||||
PHONE: 'PHONE',
|
||||
EMAIL: 'EMAIL',
|
||||
SOCIAL: 'SOCIAL',
|
||||
} as const
|
||||
|
||||
/** 基础认证请求接口 */
|
||||
export interface AuthReq {
|
||||
clientId?: string
|
||||
authType?: AuthType
|
||||
}
|
||||
|
||||
/** 账号登录请求参数 */
|
||||
export interface AccountLoginReq extends AuthReq {
|
||||
username: string
|
||||
password: string
|
||||
captcha: string
|
||||
uuid: string
|
||||
}
|
||||
|
||||
/** 手机号登录请求参数 */
|
||||
export interface PhoneLoginReq extends AuthReq {
|
||||
phone: string
|
||||
captcha: string
|
||||
}
|
||||
|
||||
/** 邮箱登录请求参数 */
|
||||
export interface EmailLoginReq extends AuthReq {
|
||||
email: string
|
||||
captcha: string
|
||||
}
|
||||
|
||||
/** 登录响应类型 */
|
||||
export interface LoginResp {
|
||||
token: string
|
||||
}
|
||||
|
||||
/** 第三方登录授权类型 */
|
||||
export interface SocialAuthAuthorizeResp {
|
||||
authorizeUrl: string
|
||||
}
|
||||
Reference in New Issue
Block a user