oms/frontend/src/api/exportTask.ts
liufumingren 839b81f661 feat: 商品与外部仓库关联所属货主(下属公司)
- products、warehouses 新增 subsidiary_id(下属公司),创建/更新必填并校验归属当前主体
- 商品批量导入新增「所属货主」列,按下属公司名称匹配,缺失时报错
- 商品、外部仓库列表与导出新增所属货主列、筛选与下拉控件
- 仓库下拉与详情接口返回 subsidiary_id / subsidiary_name

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-05 00:50:27 +08:00

98 lines
2.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { get, post } from '@/utils/request'
import request from '@/utils/request'
/**
* 导出类型:由后端注册表定义(见 backend/app/utils/exportDefs.js#EXPORT_TYPES),
* 前端不做枚举收窄,新增类型时后端改一处即可
*/
export type ExportType = string
/** 筛选字段控件类型:文本 / 下拉 / 日期 / 数字 / 商品选择器 / 店铺选择器 / 仓库选择器 / 下属公司选择器 */
export type ExportFilterType =
| 'text'
| 'select'
| 'date'
| 'number'
| 'product'
| 'shop'
| 'warehouse'
| 'subsidiary'
/** 筛选字段下拉选项 */
export interface ExportFilterOption {
label: string
value: string | number
}
/** 筛选字段定义(后端随导出类型一起下发,前端据此动态渲染提交表单) */
export interface ExportFilterDef {
key: string
label: string
type: ExportFilterType
options?: ExportFilterOption[]
placeholder?: string
}
/** 导出任务状态:0待处理 1处理中 2已完成 3失败 */
export type ExportStatus = 0 | 1 | 2 | 3
/** 导出类型选项(后端返回,含该类型可传的筛选字段定义) */
export interface ExportTypeOption {
value: ExportType
label: string
filters: ExportFilterDef[]
}
/** 导出任务项 */
export interface ExportTaskItem {
id: number
principal_id: number
type: ExportType
type_label?: string
status: ExportStatus
status_label?: string
sql?: string
file_name: string | null
file_path: string | null
total_count: number
processed_count: number
progress: number
error_message: string | null
created_at: string
}
/** 导出筛选条件(按类型可选,字段集合见后端下发的 ExportFilterDef[]) */
export type ExportFilters = Record<string, string | number | boolean | null | undefined>
/** 导出类型选项(含筛选字段定义) */
export function getExportTypes() {
return get<ExportTypeOption[]>('/export-tasks/types')
}
/** 提交导出任务:立即返回任务ID */
export function submitExport(payload: { type: ExportType; filters?: ExportFilters }) {
return post<{ id: number; type: ExportType; status: number }>('/export-tasks', payload)
}
/** 导出任务列表(按主体隔离) */
export function getExportTasks(params?: object) {
return get<{ list: ExportTaskItem[]; total: number; page: number; pageSize: number }>(
'/export-tasks',
params,
)
}
/** 导出任务进度 */
export function getExportTask(id: number) {
return get<ExportTaskItem>('/export-tasks/' + id)
}
/**
* 下载导出文件:以 blob 形式拉取(走鉴权拦截器),由调用方触发浏览器下载
* @param id 任务ID
* @return Promise<Blob> CSV 文件流
*/
export function downloadExport(id: number) {
return request.get('/export-tasks/' + id + '/download', { responseType: 'blob' }) as unknown as Promise<Blob>
}