- 新增 ToolbarButtonGroup 组件及类型定义,订单、波次等页面统一使用, 工具栏按钮样式分类(刷新/设置/操作/取消)收敛到一处 - 订单共享模块迁移至 views/order/shared:创建订单会话、通用表单、 导出、工具栏动作、订单元数据缓存;stockPickerHelpers 归入 stock/utils - 抽离 ScanBox 字段工厂、货主/快递下拉选项映射、状态文本工具, 新增 list-page.scss、status-text.scss,order-common-config 改为再导出 - UpperTable 虚拟滚动优化:实测行高兜底、渲染行数组引用复用、 rowKey/复制码/收起文本缓存、窗口行数按 4 行量化、ResizeObserver 同步视口, 减少滚动抖动与整表重建 - 列表页状态列改用轻量文本样式替代 el-tag,降低大列表渲染开销; 标签页缓存默认上限由 3 调整为 8 - 补充标签页性能测量结论、页面模板抽离现状与实施方案文档
46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
type ColumnItem = {
|
||
prop?: string
|
||
label?: string
|
||
formatter?: (row: any, column: any, cellValue: any, index: number) => any
|
||
}
|
||
|
||
type ExportOptions = {
|
||
rows: any[]
|
||
columns: ColumnItem[]
|
||
fileName?: string
|
||
transformCell?: (prop: string, value: any, row: any) => any
|
||
}
|
||
|
||
function normalizeCell(value: any) {
|
||
if (value === undefined || value === null) return ''
|
||
if (Array.isArray(value)) return value.join(', ')
|
||
if (typeof value === 'object') return JSON.stringify(value)
|
||
return value
|
||
}
|
||
|
||
export async function exportUpperTableRows(options: ExportOptions) {
|
||
// xlsx 体积较大(约 850KB),只在真正导出时加载,避免进入首屏依赖图
|
||
const XLSX = await import('xlsx')
|
||
const { rows, columns, fileName = `export-${Date.now()}.xlsx`, transformCell } = options
|
||
const exportColumns = (columns || []).filter((column) => !!column.prop)
|
||
const exportData = (rows || []).map((row, index) => {
|
||
const mapped: Record<string, any> = {}
|
||
exportColumns.forEach((column) => {
|
||
const prop = String(column.prop)
|
||
const label = column.label || prop
|
||
const rawValue = row[prop]
|
||
const formattedValue = column.formatter
|
||
? column.formatter(row, { property: prop }, rawValue, index)
|
||
: rawValue
|
||
const finalValue = transformCell ? transformCell(prop, formattedValue, row) : formattedValue
|
||
mapped[label] = normalizeCell(finalValue)
|
||
})
|
||
return mapped
|
||
})
|
||
|
||
const ws = XLSX.utils.json_to_sheet(exportData)
|
||
const wb = XLSX.utils.book_new()
|
||
XLSX.utils.book_append_sheet(wb, ws, '数据导出')
|
||
XLSX.writeFile(wb, fileName)
|
||
}
|