131 lines
2.9 KiB
TypeScript
131 lines
2.9 KiB
TypeScript
// src/api/warehouse.ts
|
||
import request from '@/utils/request'
|
||
|
||
// ============ 类型定义 ============
|
||
|
||
/** 仓库类型 */
|
||
export type WarehouseType = 'erp' | 'cloud' | 'physical' | 'virtual'
|
||
|
||
/** 仓库状态 */
|
||
export type WarehouseStatus = 'active' | 'inactive'
|
||
|
||
/** 仓库 - 对应后端返回字段(snake_case) */
|
||
export interface Warehouse {
|
||
id: number
|
||
name: string
|
||
type: WarehouseType
|
||
cloud_system?: string | null
|
||
owner_code?: string | null
|
||
cloud_code?: string | null
|
||
app_key?: string | null
|
||
app_secret?: string | null
|
||
remark?: string | null
|
||
created_at: string
|
||
updated_at: string
|
||
}
|
||
|
||
/** 仓库列表查询参数 */
|
||
export interface WarehouseListParams {
|
||
keyword?: string
|
||
type?: WarehouseType
|
||
status?: WarehouseStatus
|
||
page?: number
|
||
limit?: number
|
||
}
|
||
|
||
/** 仓库列表响应 */
|
||
export interface WarehouseListResponse {
|
||
list: Warehouse[]
|
||
total: number
|
||
current_page: number
|
||
last_page: number
|
||
}
|
||
|
||
/** 创建仓库请求 */
|
||
export interface CreateWarehouseData {
|
||
name: string
|
||
type: WarehouseType
|
||
cloud_system?: string
|
||
owner_code?: string
|
||
cloud_code?: string
|
||
app_key?: string
|
||
app_secret?: string
|
||
remark?: string
|
||
}
|
||
|
||
/** 更新仓库请求 */
|
||
export interface UpdateWarehouseData {
|
||
name?: string
|
||
type?: WarehouseType
|
||
cloud_system?: string
|
||
owner_code?: string
|
||
cloud_code?: string
|
||
app_key?: string
|
||
app_secret?: string
|
||
remark?: string
|
||
}
|
||
|
||
// ============ API 函数 ============
|
||
|
||
/**
|
||
* 获取仓库列表
|
||
* @param params 查询参数(关键词、类型、分页)
|
||
*/
|
||
export function getWarehouseList(params?: WarehouseListParams) {
|
||
return request.get<WarehouseListResponse>('/warehouses', { params })
|
||
}
|
||
|
||
/**
|
||
* 获取仓库详情
|
||
* @param id 仓库ID
|
||
*/
|
||
export function getWarehouseDetail(id: string | number) {
|
||
return request.get<Warehouse>(`/warehouses/${id}`)
|
||
}
|
||
|
||
/**
|
||
* 创建仓库
|
||
* @param data 仓库数据
|
||
*/
|
||
export function createWarehouse(data: CreateWarehouseData) {
|
||
return request.post<Warehouse>('/warehouses', data)
|
||
}
|
||
|
||
/**
|
||
* 更新仓库
|
||
* @param id 仓库ID
|
||
* @param data 更新数据
|
||
*/
|
||
export function updateWarehouse(id: string | number, data: UpdateWarehouseData) {
|
||
return request.put<Warehouse>(`/warehouses/${id}`, data)
|
||
}
|
||
|
||
/**
|
||
* 删除仓库
|
||
* @param id 仓库ID
|
||
*/
|
||
export function deleteWarehouse(id: string | number) {
|
||
return request.delete<void>(`/warehouses/${id}`)
|
||
}
|
||
|
||
/**
|
||
* 获取仓库模板绑定列表
|
||
*/
|
||
export function getWarehouseBindings(warehouseId: string) {
|
||
return request.get(`/warehouse/bindings/${warehouseId}`)
|
||
}
|
||
|
||
/**
|
||
* 添加仓库模板绑定
|
||
*/
|
||
export function addBinding(data: any) {
|
||
return request.post('/warehouse/bindings', data)
|
||
}
|
||
|
||
/**
|
||
* 更新仓库模板绑定
|
||
*/
|
||
export function updateBinding(id: string, data: any) {
|
||
return request.put(`/warehouse/bindings/${id}`, data)
|
||
}
|