商品导入导出

This commit is contained in:
liu
2026-08-20 14:45:06 +08:00
parent 52ab195432
commit cd7007bc49
9 changed files with 1172 additions and 11 deletions
+42 -9
View File
@@ -1,4 +1,5 @@
import createAxios from '@/utils/request';
import { downloadBlob } from '@/api/common/download.ts';
import type IProduct from '@/domain/iProduct.ts';
import type { IBatchPriceUpdate, IPriceMatrix } from '@/domain/iProduct.ts';
@@ -9,6 +10,47 @@ export interface PriceMatrixParams {
pageSize?: number;
}
/** 导入校验错误行(Excel 行号,1 起) */
export interface IImportError {
row: number;
message: string;
}
/** 商品下拉选项(仅上架) */
export async function getProductOptions(keyword?: string) {
return createAxios<IProduct[]>({
url: '/product/goods/options',
method: 'get',
params: keyword ? { keyword } : {},
});
}
/** 商品列表导出(列格式与导入模板一致,导出文件修改后可直接重新导入) */
export async function exportProducts(params: { category_id?: number } = {}) {
return downloadBlob('/product/goods/export', params, '商品列表.xlsx');
}
/** 下载商品导入模板(列头 + 示例行) */
export async function downloadProductTemplate() {
return downloadBlob('/product/goods/export', { template: 1 }, '商品导入模板.xlsx');
}
/**
* Excel 批量导入商品(整表校验,有错全部不导入)
* 失败时 promise reject,错误行明细在 err.data.data.errors
*/
export async function importProducts(file: File) {
const formData = new FormData();
formData.append('file', file);
return createAxios<{ created: number }>({
url: '/product/goods/import',
method: 'post',
data: formData,
headers: { 'Content-Type': 'multipart/form-data' },
timeout: 60000,
});
}
/**
* A2 价格矩阵:行=商品,列=启用等级,值=按等级上浮比例换算的售价(成本价未设置 null);
* 仅成本价可编辑
@@ -31,12 +73,3 @@ export async function batchPrice(updates: IBatchPriceUpdate[]) {
data: { updates },
});
}
/** 商品下拉选项(仅上架) */
export async function getProductOptions(keyword?: string) {
return createAxios<IProduct[]>({
url: '/product/goods/options',
method: 'get',
params: keyword ? { keyword } : {},
});
}