2026-02-28 15:29:12 +08:00
|
|
|
import { request } from '@umijs/max';
|
2026-03-30 02:56:16 +00:00
|
|
|
import type {
|
|
|
|
|
ApiResponse,
|
|
|
|
|
CurrentUser,
|
|
|
|
|
LoginParams,
|
|
|
|
|
LoginResult,
|
|
|
|
|
PaginatedData,
|
|
|
|
|
PaginationParams,
|
|
|
|
|
Product,
|
|
|
|
|
StockSummary,
|
|
|
|
|
StockGroup,
|
|
|
|
|
StockCheck,
|
|
|
|
|
StockAdjust,
|
|
|
|
|
User,
|
|
|
|
|
Role,
|
|
|
|
|
Menu,
|
|
|
|
|
OperationLog,
|
|
|
|
|
SystemConfig,
|
|
|
|
|
Relation,
|
|
|
|
|
RelationHistory,
|
|
|
|
|
} from '@/types/api';
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
// ── Auth ──────────────────────────────────────────
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const login = (data: LoginParams) =>
|
|
|
|
|
request<ApiResponse<LoginResult>>('/api/v1/auth/login', { method: 'POST', data });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const logout = () =>
|
|
|
|
|
request<ApiResponse>('/api/v1/auth/logout', { method: 'POST' });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const getUserInfo = () =>
|
|
|
|
|
request<ApiResponse<CurrentUser>>('/api/v1/auth/info', { method: 'GET' });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const changePassword = (data: { oldPassword: string; newPassword: string }) =>
|
|
|
|
|
request<ApiResponse>('/api/v1/auth/password', { method: 'PUT', data });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
// ── Users ─────────────────────────────────────────
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const listUsers = (params: PaginationParams & { username?: string; realName?: string }) =>
|
|
|
|
|
request<ApiResponse<PaginatedData<User>>>('/api/v1/system/users', { method: 'GET', params });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const getUser = (id: string) =>
|
|
|
|
|
request<ApiResponse<User>>(`/api/v1/system/users/${id}`, { method: 'GET' });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const createUser = (data: Partial<User> & { password?: string }) =>
|
|
|
|
|
request<ApiResponse>('/api/v1/system/users', { method: 'POST', data });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const updateUser = (id: string, data: Partial<User>) =>
|
|
|
|
|
request<ApiResponse>(`/api/v1/system/users/${id}`, { method: 'PUT', data });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const deleteUser = (id: string) =>
|
|
|
|
|
request<ApiResponse>(`/api/v1/system/users/${id}`, { method: 'DELETE' });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const updateUserStatus = (id: string, status: number) =>
|
|
|
|
|
request<ApiResponse>(`/api/v1/system/users/${id}/status`, { method: 'PUT', data: { status } });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
// ── Roles ─────────────────────────────────────────
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const listRoles = (params?: PaginationParams & { roleName?: string }) =>
|
|
|
|
|
request<ApiResponse<PaginatedData<Role>>>('/api/v1/system/roles', { method: 'GET', params });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const createRole = (data: Partial<Role>) =>
|
|
|
|
|
request<ApiResponse>('/api/v1/system/roles', { method: 'POST', data });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const updateRole = (id: string, data: Partial<Role>) =>
|
|
|
|
|
request<ApiResponse>(`/api/v1/system/roles/${id}`, { method: 'PUT', data });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const deleteRole = (id: string) =>
|
|
|
|
|
request<ApiResponse>(`/api/v1/system/roles/${id}`, { method: 'DELETE' });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const setRolePermissions = (id: string, menuIds: string[]) =>
|
|
|
|
|
request<ApiResponse>(`/api/v1/system/roles/${id}/permissions`, { method: 'PUT', data: { menuIds } });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
// ── Menus ─────────────────────────────────────────
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const listMenus = () =>
|
|
|
|
|
request<ApiResponse<PaginatedData<Menu>>>('/api/v1/system/menus', { method: 'GET' });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const createMenu = (data: Partial<Menu>) =>
|
|
|
|
|
request<ApiResponse>('/api/v1/system/menus', { method: 'POST', data });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const updateMenu = (id: string, data: Partial<Menu>) =>
|
|
|
|
|
request<ApiResponse>(`/api/v1/system/menus/${id}`, { method: 'PUT', data });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const deleteMenu = (id: string) =>
|
|
|
|
|
request<ApiResponse>(`/api/v1/system/menus/${id}`, { method: 'DELETE' });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
// ── Logs ──────────────────────────────────────────
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const listLogs = (params: PaginationParams & { username?: string; module?: string; operation?: string }) =>
|
|
|
|
|
request<ApiResponse<PaginatedData<OperationLog>>>('/api/v1/system/logs', { method: 'GET', params });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
// ── Configs ───────────────────────────────────────
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const listConfigs = () =>
|
|
|
|
|
request<ApiResponse<PaginatedData<SystemConfig>>>('/api/v1/system/configs', { method: 'GET' });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const updateConfig = (key: string, value: string) =>
|
|
|
|
|
request<ApiResponse>(`/api/v1/system/configs/${key}`, { method: 'PUT', data: { configValue: value } });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
// ── Products ──────────────────────────────────────
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const listProducts = (params: PaginationParams & { productName?: string; spec?: string; color?: string; location?: string }) =>
|
|
|
|
|
request<ApiResponse<PaginatedData<Product>>>('/api/v1/inventory/products', { method: 'GET', params });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const getProduct = (id: string) =>
|
|
|
|
|
request<ApiResponse<Product>>(`/api/v1/inventory/products/${id}`, { method: 'GET' });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const createProduct = (data: Partial<Product>) =>
|
|
|
|
|
request<ApiResponse>('/api/v1/inventory/products', { method: 'POST', data });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const updateProduct = (id: string, data: Partial<Product>) =>
|
|
|
|
|
request<ApiResponse>(`/api/v1/inventory/products/${id}`, { method: 'PUT', data });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const deleteProduct = (id: string) =>
|
|
|
|
|
request<ApiResponse>(`/api/v1/inventory/products/${id}`, { method: 'DELETE' });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const exportProducts = () =>
|
|
|
|
|
request('/api/v1/inventory/products/export', { method: 'GET', responseType: 'blob' });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
// ── Stocks ────────────────────────────────────────
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const getStockSummary = () =>
|
|
|
|
|
request<ApiResponse<StockSummary>>('/api/v1/inventory/stocks/summary', { method: 'GET' });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const getStockByColor = () =>
|
|
|
|
|
request<ApiResponse<PaginatedData<StockGroup>>>('/api/v1/inventory/stocks/by-color', { method: 'GET' });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const getStockByLocation = () =>
|
|
|
|
|
request<ApiResponse<PaginatedData<StockGroup>>>('/api/v1/inventory/stocks/by-location', { method: 'GET' });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
// ── Stock Checks ──────────────────────────────────
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const listStockChecks = (params: PaginationParams) =>
|
|
|
|
|
request<ApiResponse<PaginatedData<StockCheck>>>('/api/v1/inventory/checks', { method: 'GET', params });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const getStockCheck = (id: string) =>
|
|
|
|
|
request<ApiResponse<StockCheck>>(`/api/v1/inventory/checks/${id}`, { method: 'GET' });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const createStockCheck = (data: Partial<StockCheck>) =>
|
|
|
|
|
request<ApiResponse>('/api/v1/inventory/checks', { method: 'POST', data });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const confirmStockCheck = (id: string) =>
|
|
|
|
|
request<ApiResponse>(`/api/v1/inventory/checks/${id}/confirm`, { method: 'POST' });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
// ── Stock Adjusts ─────────────────────────────────
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const listStockAdjusts = (params: PaginationParams) =>
|
|
|
|
|
request<ApiResponse<PaginatedData<StockAdjust>>>('/api/v1/inventory/adjusts', { method: 'GET', params });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const getStockAdjust = (id: string) =>
|
|
|
|
|
request<ApiResponse<StockAdjust>>(`/api/v1/inventory/adjusts/${id}`, { method: 'GET' });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const createStockAdjust = (data: Partial<StockAdjust>) =>
|
|
|
|
|
request<ApiResponse>('/api/v1/inventory/adjusts', { method: 'POST', data });
|
2026-02-28 15:29:12 +08:00
|
|
|
|
2026-03-30 02:56:16 +00:00
|
|
|
export const approveStockAdjust = (id: string, action: number) =>
|
|
|
|
|
request<ApiResponse>(`/api/v1/inventory/adjusts/${id}/approve`, { method: 'POST', data: { action } });
|
|
|
|
|
|
|
|
|
|
// ── CRM Relations ─────────────────────────────────
|
|
|
|
|
|
|
|
|
|
export const listUpstream = (depth = 1) =>
|
|
|
|
|
request<ApiResponse<PaginatedData<Relation>>>('/api/v1/crm/graph/upstream', { method: 'GET', params: { depth } });
|
|
|
|
|
|
|
|
|
|
export const listDownstream = (depth = 1) =>
|
|
|
|
|
request<ApiResponse<PaginatedData<Relation>>>('/api/v1/crm/graph/downstream', { method: 'GET', params: { depth } });
|
|
|
|
|
|
|
|
|
|
export const createRelation = (data: {
|
|
|
|
|
fromTenantId: string;
|
|
|
|
|
toTenantId: string;
|
|
|
|
|
relationType: string;
|
|
|
|
|
validFrom?: string;
|
|
|
|
|
validTo?: string;
|
|
|
|
|
}) =>
|
|
|
|
|
request<ApiResponse>('/api/v1/crm/relationships', { method: 'POST', data });
|
|
|
|
|
|
|
|
|
|
export const updateRelation = (id: string, data: { status: number; validFrom?: string; validTo?: string }) =>
|
|
|
|
|
request<ApiResponse>(`/api/v1/crm/relationships/${id}`, { method: 'PUT', data });
|
|
|
|
|
|
|
|
|
|
export const listRelationHistory = (params?: PaginationParams) =>
|
|
|
|
|
request<ApiResponse<PaginatedData<RelationHistory>>>('/api/v1/crm/relationships/history', { method: 'GET', params });
|