- 独立改密页 + 路由守卫拦截待改密 - auth store 持久化 mustChangePassword - 用户创建表单加「首登强制改密」开关(默认勾选) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
107 lines
3.0 KiB
TypeScript
107 lines
3.0 KiB
TypeScript
import { http } from '@/api/http'
|
||
|
||
export type UserStatus = 'enabled' | 'disabled'
|
||
|
||
export interface User {
|
||
id: string
|
||
tenantCode: string
|
||
username: string
|
||
nickname: string | null
|
||
email: string | null
|
||
phone: string | null
|
||
avatar: string | null
|
||
status: UserStatus
|
||
lockedAt: number | null
|
||
lockReason: string | null
|
||
orgCode: string | null
|
||
createdAt: number
|
||
updatedAt: number
|
||
}
|
||
|
||
export interface UserListQuery {
|
||
page: number
|
||
pageSize: number
|
||
username?: string
|
||
nickname?: string
|
||
phone?: string
|
||
status?: UserStatus | ''
|
||
}
|
||
|
||
export interface UserListResult {
|
||
list: User[]
|
||
total: number
|
||
page: number
|
||
pageSize: number
|
||
}
|
||
|
||
export interface UserUpsertData {
|
||
username?: string
|
||
password?: string
|
||
nickname?: string
|
||
email?: string
|
||
phone?: string
|
||
orgCode?: string | null
|
||
status?: UserStatus
|
||
mustChangePassword?: boolean
|
||
}
|
||
|
||
/** 用户分页列表。 */
|
||
export function listUsers(query: UserListQuery, signal?: AbortSignal): Promise<UserListResult> {
|
||
const params: Record<string, unknown> = { page: query.page, pageSize: query.pageSize }
|
||
if (query.username) params.username = query.username
|
||
if (query.nickname) params.nickname = query.nickname
|
||
if (query.phone) params.phone = query.phone
|
||
if (query.status) params.status = query.status
|
||
return http.get<UserListResult>('/users', { params, signal })
|
||
}
|
||
|
||
/** 新增用户。 */
|
||
export function createUser(data: UserUpsertData): Promise<User> {
|
||
return http.post<User>('/users', data)
|
||
}
|
||
|
||
/** 更新用户(username 不可改)。 */
|
||
export function updateUser(id: string, data: UserUpsertData): Promise<User> {
|
||
return http.patch<User>(`/users/${id}`, data)
|
||
}
|
||
|
||
/** 删除用户(软删)。 */
|
||
export function deleteUser(id: string): Promise<unknown> {
|
||
return http.delete(`/users/${id}`)
|
||
}
|
||
|
||
/** 批量删除用户。 */
|
||
export function batchDeleteUsers(ids: string[]): Promise<{ total: number; success: number; failed: string[] }> {
|
||
return http.post('/users/batch-delete', { ids })
|
||
}
|
||
|
||
/** 重置密码。 */
|
||
export function resetPassword(id: string, password: string): Promise<unknown> {
|
||
return http.patch(`/users/${id}/password`, { password })
|
||
}
|
||
|
||
/** 用户已分配的角色 code 列表。 */
|
||
export function listUserRoles(userId: string, signal?: AbortSignal): Promise<string[]> {
|
||
return http.get<string[]>(`/users/${userId}/roles`, { signal })
|
||
}
|
||
|
||
/** 分配角色(整体替换)。 */
|
||
export function assignUserRoles(userId: string, roleCodes: string[]): Promise<unknown> {
|
||
return http.put(`/users/${userId}/roles`, { roleCodes })
|
||
}
|
||
|
||
/** 踢出用户全部会话。 */
|
||
export function kickSessions(userId: string): Promise<unknown> {
|
||
return http.post(`/users/${userId}/kick-sessions`)
|
||
}
|
||
|
||
/** 锁定用户(可附原因)。 */
|
||
export function lockUser(userId: string, reason?: string): Promise<User> {
|
||
return http.post<User>(`/users/${userId}/lock`, { reason })
|
||
}
|
||
|
||
/** 解锁用户。 */
|
||
export function unlockUser(userId: string): Promise<User> {
|
||
return http.post<User>(`/users/${userId}/unlock`)
|
||
}
|