user.ts 1.6 KB
import { ApiClient } from '../core/client';

export interface UserPageParams {
  current?: number;
  size?: number;
  keyword?: string;
  mobile?: string;
  orgId?: number;
  roleId?: number;
  status?: number;
}

export interface UserPageItem {
  userId: number;
  account: string;
  name: string;
  mobile: string;
  email?: string;
  orgId?: number;
  orgPath?: string;
  dataScope?: number;
  dataScopeLabel?: string;
  status: number;
  lastLoginAt?: string;
  roleNames?: string[];
  roleCodes?: string[];
  remark?: string;
}

export interface UserCreatePayload {
  account: string;
  name: string;
  mobile: string;
  email?: string;
  orgId: number;
  dataScope?: number;
  status?: number;
  roleIds?: number[];
  remark?: string;
}

export interface UserUpdatePayload extends Omit<UserCreatePayload, 'account'> {
  userId: number;
}

export interface UserPageResult {
  records: UserPageItem[];
  total: number;
  current: number;
  size: number;
  pages: number;
}

class User extends ApiClient {
  page(params: UserPageParams) {
    return this.post<UserPageResult>('/system/user/page', params);
  }

  create(payload: UserCreatePayload) {
    return this.post<null>('/system/user/create', payload);
  }

  update(payload: UserUpdatePayload) {
    return this.post<null>('/system/user/update', payload);
  }

  resetPassword(userId: number, payload: { password: string }) {
    return this.post<null>(`/system/user/${userId}/reset-password`, payload);
  }

  updateStatus(userId: number, payload: { status: number }) {
    return this.post<null>(`/system/user/${userId}/status`, payload);
  }
}

export const user = new User();