提交
This commit is contained in:
1 parent
833544def3
commit
16be6fa22d
204 files changed
+455089
-46491
No files matched your search
@@ -11,6 +11,7 @@ import {
|
||||
demoUnits
|
||||
} from './mock-data'
|
||||
import { DEFAULT_LIST_PAGE_SIZE } from '@/utils/table/tableConfig'
|
||||
import request from '@/utils/http'
|
||||
|
||||
type PageParams = { page?: number; pageSize?: number; keyword?: string }
|
||||
|
||||
@@ -387,3 +388,113 @@ export async function fetchAttachmentDownloadUrl(_data: { fileUrl: string; fileN
|
||||
await delay()
|
||||
return { downloadUrl: '#' }
|
||||
}
|
||||
|
||||
|
||||
const DEMO_PRODUCT_EXPORT_COLS = [
|
||||
{ field: 'id', title: 'id' },
|
||||
{ field: 'name', title: '商品名称' },
|
||||
{ field: 'skuCode', title: 'SKU编码' },
|
||||
{ field: 'categoryName', title: '分类' },
|
||||
{ field: 'measureValue', title: '计量' },
|
||||
{ field: 'unitName', title: '单位' },
|
||||
{ field: 'imageUrl', title: '图片URL' },
|
||||
{ field: 'isActive', title: '状态' },
|
||||
{ field: 'createAt', title: '创建时间' }
|
||||
]
|
||||
|
||||
const DEMO_CATEGORY_EXPORT_COLS = [
|
||||
{ field: 'id', title: 'id' },
|
||||
{ field: 'name', title: '分类名称' },
|
||||
{ field: 'parentId', title: '父分类ID' },
|
||||
{ field: 'parentName', title: '父分类名称' },
|
||||
{ field: 'sortOrder', title: '排序' },
|
||||
{ field: 'priceCoefficient', title: '价格系数(%)' },
|
||||
{ field: 'isActive', title: '状态' },
|
||||
{ field: 'imageUrl', title: '图片URL' }
|
||||
]
|
||||
|
||||
function pickExportColumns(
|
||||
all: { field: string; title: string }[],
|
||||
visible?: string[]
|
||||
) {
|
||||
if (!visible?.length) return all
|
||||
const set = new Set(visible)
|
||||
const picked = all.filter((c) => set.has(c.field))
|
||||
return picked.length ? picked : all
|
||||
}
|
||||
|
||||
/** Demo 商品列表导出(Mock 筛行 + 后端 xlsx) */
|
||||
export async function fetchExportDemoProducts(payload: Record<string, any> = {}) {
|
||||
await delay()
|
||||
let list = [...products]
|
||||
if (payload.categoryId) list = list.filter((p) => p.categoryId === payload.categoryId)
|
||||
if (payload.isActive === true || payload.isActive === false) {
|
||||
list = list.filter((p) => p.isActive === payload.isActive)
|
||||
}
|
||||
list = filterKeyword(list, ['name', 'skuCode'], payload.keyword)
|
||||
if (payload.ids?.length) {
|
||||
const idSet = new Set(payload.ids.map(String))
|
||||
list = list.filter((p) => idSet.has(String(p.id)))
|
||||
}
|
||||
const cols = pickExportColumns(DEMO_PRODUCT_EXPORT_COLS, payload.columns)
|
||||
const rows = list.map((row) => ({
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
skuCode: (row as any).skuCode || 'SKU-DEMO',
|
||||
categoryName: row.categoryName,
|
||||
measureValue: (row as any).measureValue ?? 1,
|
||||
unitName: row.unitName,
|
||||
imageUrl: row.imageUrl,
|
||||
isActive: row.isActive ? '启用' : '禁用',
|
||||
createAt: row.createAt
|
||||
}))
|
||||
return request.post({
|
||||
url: '/web/admin/demo/xlsx-export',
|
||||
data: {
|
||||
sheetTitle: '商品数据',
|
||||
filenameStem: '商品数据',
|
||||
columns: cols,
|
||||
rows
|
||||
},
|
||||
responseType: 'blob'
|
||||
})
|
||||
}
|
||||
|
||||
/** Demo 分类列表导出(Mock 筛行 + 后端 xlsx) */
|
||||
export async function fetchExportDemoCategories(payload: Record<string, any> = {}) {
|
||||
await delay()
|
||||
let list = [...categories]
|
||||
if (payload.isActive === true || payload.isActive === false) {
|
||||
list = list.filter((c) => c.isActive === payload.isActive)
|
||||
}
|
||||
list = filterKeyword(list, ['name'], payload.keyword)
|
||||
if (payload.ids?.length) {
|
||||
const idSet = new Set(payload.ids.map(String))
|
||||
list = list.filter((c) => idSet.has(String(c.id)))
|
||||
}
|
||||
const idToName = new Map(list.map((c) => [c.id, c.name]))
|
||||
// parent may be outside filtered set — use full categories map
|
||||
const allNames = new Map(categories.map((c) => [c.id, c.name]))
|
||||
const cols = pickExportColumns(DEMO_CATEGORY_EXPORT_COLS, payload.columns)
|
||||
const rows = list.map((row) => ({
|
||||
id: row.id,
|
||||
name: row.name,
|
||||
parentId: row.parentId || '',
|
||||
parentName: row.parentId ? allNames.get(row.parentId) || '' : '',
|
||||
sortOrder: row.sortOrder,
|
||||
priceCoefficient: row.priceCoefficient ?? 0,
|
||||
isActive: row.isActive ? '启用' : '禁用',
|
||||
imageUrl: row.imageUrl || ''
|
||||
}))
|
||||
return request.post({
|
||||
url: '/web/admin/demo/xlsx-export',
|
||||
data: {
|
||||
sheetTitle: '分类数据',
|
||||
filenameStem: '分类数据',
|
||||
columns: cols,
|
||||
rows
|
||||
},
|
||||
responseType: 'blob'
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user