oms/frontend/src/api/exportTask.ts
liufumingren fe97be2893 feat(shop-product): 店铺商品支持店铺/平台类型/商家编码多值筛选
- 列表接口支持 shop_ids / platform_types / outer_codes(逗号分隔或数组,去重、上限 200),店铺与平台类型为 IN 条件,商家编码为多值精确匹配;保留单值 shop_id 与关键词模糊查询

- 前端:店铺改为多选虚拟下拉、新增平台类型多选、新增商家编码多值控件(收起英文逗号拼接、展开一行一个)

- 导出同步支持多值筛选(多选控件按 CSV 提交)并补上「平台类型」列

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-06 22:22:41 +08:00

100 lines
2.9 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
/** 是否多选:多选值提交时按英文逗号拼接(如店铺/平台类型) */
multiple?: boolean
}
/** 导出任务状态: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>
}