import { getAuthHeaders } from '@/api/authHeaders';
|
import { request } from '@/api/request';
|
import type {
|
TenantEmployeeCreateRequest,
|
TenantEmployeeCreateResponse,
|
TenantEmployeeDeleteRequest,
|
TenantEmployeeDeleteResponse,
|
TenantEmployeeDetailRequest,
|
TenantEmployeeDetailResponse,
|
TenantEmployeeExportRequest,
|
TenantEmployeeExportResponse,
|
TenantEmployeeImportRequest,
|
TenantEmployeeImportResponse,
|
TenantEmployeeListRequest,
|
TenantEmployeeListResponse,
|
TenantEmployeeUpdateBody,
|
TenantEmployeeUpdateRequest,
|
TenantEmployeeUpdateResponse,
|
TenantOrgTreeRequest,
|
TenantOrgTreeResponse,
|
TenantRoleOptionRequest,
|
TenantRoleOptionResponse,
|
} from './types';
|
|
/** 员工分页列表。 */
|
export const getEmployeeList = (params: TenantEmployeeListRequest) =>
|
request<TenantEmployeeListRequest, TenantEmployeeListResponse>({
|
url: '/tenant/employees',
|
method: 'GET',
|
params,
|
headers: getAuthHeaders(),
|
});
|
|
/** 创建员工。 */
|
export const createEmployee = (data: TenantEmployeeCreateRequest) =>
|
request<TenantEmployeeCreateRequest, TenantEmployeeCreateResponse>({
|
url: '/tenant/employees',
|
method: 'POST',
|
data,
|
headers: getAuthHeaders(),
|
});
|
|
/** 员工详情。 */
|
export const getEmployeeDetail = ({ id }: TenantEmployeeDetailRequest) =>
|
request<TenantEmployeeDetailRequest, TenantEmployeeDetailResponse>({
|
url: `/tenant/employees/${id}`,
|
method: 'GET',
|
headers: getAuthHeaders(),
|
});
|
|
/** 更新员工基本信息。 */
|
export const updateEmployee = ({ id, ...data }: TenantEmployeeUpdateRequest) =>
|
request<TenantEmployeeUpdateBody, TenantEmployeeUpdateResponse>({
|
url: `/tenant/employees/${id}`,
|
method: 'PUT',
|
data,
|
headers: getAuthHeaders(),
|
});
|
|
/** 删除员工。 */
|
export const deleteEmployee = ({ id }: TenantEmployeeDeleteRequest) =>
|
request<TenantEmployeeDeleteRequest, TenantEmployeeDeleteResponse>({
|
url: `/tenant/employees/${id}`,
|
method: 'DELETE',
|
headers: getAuthHeaders(),
|
});
|
|
/** 导出员工 Excel 文件流。 */
|
export const exportEmployees = (params: TenantEmployeeExportRequest = {}) =>
|
request<TenantEmployeeExportRequest, TenantEmployeeExportResponse>({
|
url: '/tenant/employees/export',
|
method: 'GET',
|
params,
|
responseType: 'blob',
|
headers: getAuthHeaders(),
|
});
|
|
/** 批量导入员工 Excel。 */
|
export const importEmployees = ({ file }: TenantEmployeeImportRequest) => {
|
const formData = new FormData();
|
formData.append('file', file);
|
|
return request<FormData, TenantEmployeeImportResponse>(
|
{
|
url: '/tenant/employees/import',
|
method: 'POST',
|
data: formData,
|
headers: getAuthHeaders(),
|
},
|
{
|
// 不同文件请求体无法通过 FormData 区分,关闭合并。
|
merge: false,
|
},
|
);
|
};
|
|
/** 组织树,用于组织下拉选项。 */
|
export const getOrgTree = (params: TenantOrgTreeRequest = {}) =>
|
request<TenantOrgTreeRequest, TenantOrgTreeResponse>({
|
url: '/tenant/organizations/tree',
|
method: 'GET',
|
params,
|
headers: getAuthHeaders(),
|
});
|
|
/** 角色列表,用于角色下拉选项。 */
|
export const getRoleOptions = () =>
|
request<TenantRoleOptionRequest, TenantRoleOptionResponse>({
|
url: '/tenant/roles',
|
method: 'GET',
|
headers: getAuthHeaders(),
|
});
|