330 lines
8.3 KiB
TypeScript
330 lines
8.3 KiB
TypeScript
// @ts-ignore
|
|
/* eslint-disable */
|
|
import { AdminAPI } from '@/constants/api';
|
|
import { EmployType, JobType } from '@/constants/job';
|
|
import { request } from '@umijs/max';
|
|
import { SortOrder } from 'antd/es/table/interface';
|
|
import { buildUrl } from '@/services/utils';
|
|
|
|
function transformPageParams(params: API.PageParams & Record<string, any>) {
|
|
params.page = params.current;
|
|
delete params.current;
|
|
Object.keys(params).forEach((key: string) => {
|
|
if (typeof params[key] === 'string' && !params[key]) {
|
|
delete params[key];
|
|
}
|
|
});
|
|
return params;
|
|
}
|
|
|
|
function camelToSnakeCase(str: string) {
|
|
return str.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1_$2').toLowerCase();
|
|
}
|
|
|
|
function transformSort(sort: Record<string, SortOrder>) {
|
|
if (!sort) {
|
|
return {};
|
|
}
|
|
const sortField = Object.keys(sort)[0];
|
|
if (!sort[sortField]) {
|
|
return {};
|
|
}
|
|
const asc = sort[sortField] === 'ascend';
|
|
return { sortField: camelToSnakeCase(sortField), asc };
|
|
}
|
|
|
|
function sortTableList<T extends { created: number; updated: number }>(
|
|
response: API.TableList<T>,
|
|
{ sortField, asc }: ReturnType<typeof transformSort>,
|
|
): API.TableList<T> {
|
|
if (sortField === 'created' || sortField === 'updated') {
|
|
response.data.sort((itemA, itemB) => {
|
|
const valueA = Number(itemA[sortField]);
|
|
const valueB = Number(itemB[sortField]);
|
|
return asc ? valueA - valueB : valueB - valueA;
|
|
});
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
export async function getJobList(
|
|
params: API.PageParams & Partial<API.JobListItem>,
|
|
options?: {
|
|
[key: string]: any;
|
|
},
|
|
) {
|
|
if (!params.category) {
|
|
params.category = JobType.All;
|
|
}
|
|
if (!params.cityCode) {
|
|
params.cityCode = 'ALL';
|
|
}
|
|
if (!params.employType) {
|
|
params.employType = EmployType.All;
|
|
}
|
|
const result = await request<API.TableList<API.JobListItem>>(AdminAPI.JOB_LIST, {
|
|
method: 'POST',
|
|
data: {
|
|
...transformPageParams(params),
|
|
...(options || {}),
|
|
},
|
|
});
|
|
result.success = true;
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* 更新通告接口,必须传 数据库 id 和 jobId
|
|
*/
|
|
export async function updateJobInfo(options: API.UpdateJobParams) {
|
|
return request<API.JobListItem>(AdminAPI.JOB_UPDATE, {
|
|
method: 'POST',
|
|
data: {
|
|
...(options || {}),
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function getGroupList(
|
|
params: API.PageParams & Partial<API.GroupListItem>,
|
|
options?: { [key: string]: any },
|
|
) {
|
|
const result = await request<API.TableList<API.GroupListItem>>(AdminAPI.GROUP_LIST, {
|
|
method: 'POST',
|
|
data: {
|
|
...transformPageParams(params),
|
|
...(options || {}),
|
|
},
|
|
});
|
|
result.success = true;
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* 更新群信息,必须传 数据库 id
|
|
*/
|
|
export async function updateGroupInfo(options: API.UpdateGroupParams) {
|
|
return request<API.GroupListItem>(AdminAPI.GROUP_UPDATE, {
|
|
method: 'POST',
|
|
data: {
|
|
...(options || {}),
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function getAnchorGroupList(
|
|
params: API.PageParams & Partial<API.AnchorGroupListItem>,
|
|
options?: { [key: string]: any },
|
|
) {
|
|
const result = await request<API.TableList<API.AnchorGroupListItem>>(AdminAPI.ANCHOR_GROUP_LIST, {
|
|
method: 'POST',
|
|
data: {
|
|
...transformPageParams(params),
|
|
...(options || {}),
|
|
},
|
|
});
|
|
return result;
|
|
}
|
|
|
|
export async function addAnchorGroup(options?: { [key: string]: any }) {
|
|
return request<API.GroupListItem>(AdminAPI.ADD_ANCHOR_GROUP, {
|
|
method: 'POST',
|
|
data: {
|
|
...(options || {}),
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function getPublisherList(
|
|
params: API.PageParams & Partial<API.PublisherListItem>,
|
|
sort: Record<string, SortOrder>,
|
|
) {
|
|
const url = params.hasDeclareOrder ? AdminAPI.PUBLISHER_DECLARATION_LIST : AdminAPI.PUBLISHER_LIST;
|
|
const result = await request<API.TableList<API.PublisherListItem>>(url, {
|
|
method: 'POST',
|
|
data: {
|
|
...transformPageParams(params),
|
|
...transformSort(sort),
|
|
},
|
|
});
|
|
return result;
|
|
}
|
|
|
|
export async function updatePublisherInfo(options: API.UpdatePublisherParams) {
|
|
return request<API.PublisherListItem>(AdminAPI.PUBLISHER_UPDATE, {
|
|
method: 'POST',
|
|
data: {
|
|
...(options || {}),
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function getAnchorList(
|
|
params: API.PageParams & Partial<API.AnchorListItem>,
|
|
options?: { [key: string]: any },
|
|
) {
|
|
const result = await request<API.TableList<API.AnchorListItem>>(AdminAPI.ANCHOR_LIST, {
|
|
method: 'POST',
|
|
data: {
|
|
...transformPageParams(params),
|
|
...(options || {}),
|
|
},
|
|
});
|
|
return result;
|
|
}
|
|
|
|
export async function updateAnchorInfo(options: API.UpdateAnchorParams) {
|
|
return request<API.DeclarationListItem>(AdminAPI.ANCHOR_UPDATE, {
|
|
method: 'POST',
|
|
data: {
|
|
...(options || {}),
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function getMaterialList(
|
|
params: API.PageParams & Partial<API.MaterialListItem>,
|
|
sort: Record<string, SortOrder>,
|
|
) {
|
|
const formatedSort = transformSort(sort);
|
|
const result = await request<API.TableList<API.MaterialListItem>>(AdminAPI.MATERIAL_LIST, {
|
|
method: 'POST',
|
|
data: {
|
|
...transformPageParams(params),
|
|
...formatedSort,
|
|
},
|
|
});
|
|
|
|
return sortTableList<API.MaterialListItem>(result, formatedSort);
|
|
}
|
|
|
|
export async function updateMaterialInfo(options: API.UpdateMaterialParams) {
|
|
return request<API.DeclarationListItem>(AdminAPI.MATERIAL_UPDATE, {
|
|
method: 'POST',
|
|
data: {
|
|
...(options || {}),
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function getDeclarationList(
|
|
params: API.PageParams & Partial<API.DeclarationListItem>,
|
|
options?: { [key: string]: any },
|
|
) {
|
|
const result = await request<API.TableList<API.DeclarationListItem>>(AdminAPI.DECLARATION_LIST, {
|
|
method: 'POST',
|
|
data: {
|
|
...transformPageParams(params),
|
|
...(options || {}),
|
|
},
|
|
});
|
|
return result;
|
|
}
|
|
|
|
export async function updateDeclarationInfo(options: API.UpdateDeclarationParams) {
|
|
return request<API.DeclarationListItem>(AdminAPI.DECLARATION_UPDATE, {
|
|
method: 'POST',
|
|
data: {
|
|
...(options || {}),
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function getStaffList(
|
|
params: API.PageParams & Partial<API.StaffListItem>,
|
|
options?: { [key: string]: any },
|
|
) {
|
|
const result = await request<API.TableList<API.StaffListItem>>(AdminAPI.STAFF_LIST, {
|
|
method: 'GET',
|
|
params: {
|
|
...transformPageParams(params),
|
|
...(options || {}),
|
|
},
|
|
});
|
|
return result;
|
|
}
|
|
|
|
export async function getAllStaffList() {
|
|
return await request<API.StaffListItem[]>(AdminAPI.STAFF_ALL, { method: 'GET' });
|
|
}
|
|
|
|
export async function updateStaff(options: API.UpdateStaffParams) {
|
|
return request(AdminAPI.STAFF_UPDATE, {
|
|
method: 'POST',
|
|
data: {
|
|
...(options || {}),
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function deleteStaff(id: number) {
|
|
return request(buildUrl(AdminAPI.STAFF_DELETE, { id }), {
|
|
method: 'DELETE',
|
|
});
|
|
}
|
|
|
|
export async function setDefaultStaff(id: number) {
|
|
return request(buildUrl(AdminAPI.STAFF_SET_DEFAULT, { id }), {
|
|
method: 'PUT',
|
|
});
|
|
}
|
|
|
|
export async function getCityOpratorList(
|
|
params: API.PageParams & Partial<API.CityOperatorListItem>,
|
|
options?: { [key: string]: any },
|
|
) {
|
|
const result = await request<API.TableList<API.CityOperatorListItem>>(AdminAPI.CITY_OPERATOR_LIST, {
|
|
method: 'GET',
|
|
params: {
|
|
...transformPageParams(params),
|
|
...(options || {}),
|
|
},
|
|
});
|
|
return result;
|
|
}
|
|
|
|
export async function updateCityOperator(options: API.UpdateCityOperator) {
|
|
return request<API.GroupListItem>(AdminAPI.CITY_OPERATOR_UPDATE, {
|
|
method: 'POST',
|
|
data: {
|
|
...(options || {}),
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function deleteCityOperator(id: number) {
|
|
return request(buildUrl(AdminAPI.CITY_OPERATOR_DELETE, { id }), {
|
|
method: 'DELETE',
|
|
});
|
|
}
|
|
|
|
export async function getGiveVipList(
|
|
params: API.PageParams & Partial<API.GiveVipListItem>,
|
|
options?: { [key: string]: any },
|
|
) {
|
|
const result = await request<API.TableList<API.GiveVipListItem>>(AdminAPI.GIVE_VIP_LIST, {
|
|
method: 'POST',
|
|
data: {
|
|
...transformPageParams(params),
|
|
...(options || {}),
|
|
},
|
|
});
|
|
return result;
|
|
}
|
|
|
|
export async function postGiveVip(options: API.PostGiveVip) {
|
|
return request<API.GiveVipListItem>(AdminAPI.GIVE_VIP, {
|
|
method: 'POST',
|
|
data: {
|
|
...(options || {}),
|
|
},
|
|
});
|
|
}
|
|
|
|
export async function getProductList(productType: API.ProductType) {
|
|
return request<API.ProductSpecListItem[]>(buildUrl(AdminAPI.PRODUCT_LIST, { productType }), {
|
|
method: 'GET',
|
|
});
|
|
}
|