84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
import { BaseResponse, Pageable } from '@/shared/model-components';
|
|
import { unwrap } from '@u/asyncs';
|
|
import { ajaxEngine } from './axios_instance';
|
|
import { UserType } from '@/shared/model-user';
|
|
import { SonAccountItem, SubmitSonAccount } from '@/shared/model-sonaccount';
|
|
|
|
export interface SonAccountResponse extends BaseResponse, Pageable {
|
|
accounts: SonAccountItem[];
|
|
}
|
|
|
|
export interface SonAccountListQuery {
|
|
keyword?: string, type?: UserType, page?: number, state?: boolean
|
|
}
|
|
|
|
/**
|
|
* 请求系统账号列表
|
|
* @returns 系统账号列表
|
|
* @param params
|
|
*/
|
|
export async function getSonAccountList(
|
|
params: SonAccountListQuery
|
|
): Promise<SonAccountResponse> {
|
|
const response = await ajaxEngine().get<SonAccountResponse>(`/subaccount`, { params });
|
|
return unwrap(response);
|
|
}
|
|
|
|
/**
|
|
* 更改用户可用性状态
|
|
* @param uid 账号Id
|
|
* @param enabled 是否启用
|
|
*/
|
|
export async function changeSonAccountStatus(uid: string, enabled: boolean): Promise<BaseResponse> {
|
|
const response = await ajaxEngine().put(`/subaccount/${uid}/enabled`, {
|
|
enabled
|
|
});
|
|
return unwrap(response);
|
|
}
|
|
|
|
/**
|
|
* 重置密码
|
|
* @param uid 账号Id
|
|
* @return 验证码
|
|
*/
|
|
export async function resetPassword(uid: string) {
|
|
const response = await ajaxEngine().delete<BaseResponse & { verify: string }>(`/subaccount/${uid}/password`);
|
|
return unwrap(response);
|
|
}
|
|
|
|
export interface ChangeUserInfoParams {
|
|
username?: string;
|
|
contact?: string;
|
|
name?: string;
|
|
phone?: string;
|
|
region?: string;
|
|
unitServiceFee?: number;
|
|
}
|
|
|
|
/**
|
|
* 修改用户信息。
|
|
* @param uid
|
|
* @param data 修改后的用户信息
|
|
*/
|
|
export async function changeUserInfo(uid: string, data: SonAccountItem): Promise<BaseResponse> {
|
|
const response = await ajaxEngine().put(`/subaccount/${uid}`, data);
|
|
return unwrap(response);
|
|
}
|
|
|
|
/**
|
|
* 创建子账号。
|
|
* @param data 创建的用户信息
|
|
*/
|
|
export async function createUser(data: SubmitSonAccount): Promise<BaseResponse & { verify: string }> {
|
|
const response = await ajaxEngine().post(`/subaccount`, data);
|
|
return unwrap(response);
|
|
}
|
|
|
|
/**
|
|
* 获取所有可以选择的角色
|
|
*/
|
|
export async function getPrivileges(): Promise<BaseResponse & { privileges: SonAccountItem['privileges'] }> {
|
|
const response = await ajaxEngine().get<BaseResponse & { privileges: SonAccountItem['privileges'] }>(`/privileges`);
|
|
return unwrap(response);
|
|
}
|