74 lines
2.2 KiB
TypeScript
74 lines
2.2 KiB
TypeScript
import { http } from '@/api/http'
|
|
import type { ResourceNode } from '@/types/resource'
|
|
|
|
export interface LoginSuccess {
|
|
accessToken: string
|
|
refreshToken: string
|
|
expiresIn: number
|
|
mustChangePassword: boolean
|
|
}
|
|
|
|
export interface LoginNeedTenant {
|
|
needSelectTenant: true
|
|
tenants: { tenantCode: string; tenantName: string }[]
|
|
}
|
|
|
|
export type LoginResult = LoginSuccess | LoginNeedTenant
|
|
|
|
/** 登录:缺省 tenantCode 时按用户名自动探测;多租户返回 needSelectTenant。 */
|
|
export function login(username: string, password: string, tenantCode?: string): Promise<LoginResult> {
|
|
return http.post<LoginResult>('/auth/login', { username, password, ...(tenantCode ? { tenantCode } : {}) })
|
|
}
|
|
|
|
/** 当前用户菜单树。 */
|
|
export function fetchMenus(): Promise<ResourceNode[]> {
|
|
return http.get<ResourceNode[]>('/auth/menus')
|
|
}
|
|
|
|
/** 当前用户权限码与超管标志(供按钮/路由级权限控制)。 */
|
|
export function fetchPermissions(): Promise<{ super: boolean; permissions: string[] }> {
|
|
return http.get<{ super: boolean; permissions: string[] }>('/auth/permissions')
|
|
}
|
|
|
|
/** 注册账号。 */
|
|
export function register(data: {
|
|
tenantCode: string
|
|
username: string
|
|
password: string
|
|
email?: string
|
|
phone?: string
|
|
}): Promise<{ id: string; username: string }> {
|
|
return http.post<{ id: string; username: string }>('/auth/register', data)
|
|
}
|
|
|
|
/** 修改本人密码。 */
|
|
export function changePassword(oldPassword: string, newPassword: string): Promise<unknown> {
|
|
return http.patch('/auth/me/password', { oldPassword, newPassword })
|
|
}
|
|
|
|
export interface TenantBrand {
|
|
name: string
|
|
brandName: string | null
|
|
logoUrl: string | null
|
|
themeColor: string | null
|
|
copyright: string | null
|
|
}
|
|
|
|
/** 当前租户品牌。 */
|
|
export function fetchBrand(signal?: AbortSignal): Promise<TenantBrand> {
|
|
return http.get<TenantBrand>('/auth/brand', { signal })
|
|
}
|
|
|
|
export interface SwitchTenantResult {
|
|
accessToken: string
|
|
refreshToken: string
|
|
expiresIn: number
|
|
tenantCode: string
|
|
tenantName: string
|
|
}
|
|
|
|
/** 平台超管切换租户。 */
|
|
export function switchTenant(tenantCode: string): Promise<SwitchTenantResult> {
|
|
return http.post<SwitchTenantResult>('/auth/switch-tenant', { tenantCode })
|
|
}
|