修改测试问题
This commit is contained in:
@@ -135,6 +135,56 @@ export const yMethod = (arr: any) => {
|
||||
return [min, max]
|
||||
}
|
||||
|
||||
export interface ExportFileNameOptions {
|
||||
subject?: string
|
||||
feature: string
|
||||
date?: string | Date | string[] | null
|
||||
ext?: string
|
||||
}
|
||||
|
||||
/** 导出文件名中的日期,固定为当前年月日 yyyy-mm-dd */
|
||||
export const formatExportDate = (): string => {
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
const now = new Date()
|
||||
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`
|
||||
}
|
||||
|
||||
/** 波形下载文件名中的时间,固定为当前时间 yyyy-mm-dd-HH-mm-ss */
|
||||
export const formatExportDateTime = (): string => {
|
||||
const pad = (n: number) => String(n).padStart(2, '0')
|
||||
const now = new Date()
|
||||
return `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}`
|
||||
}
|
||||
|
||||
/** 监测点 / 设备 / 项目(可选)_ 功能 _ yyyy-mm-dd(当前日期) */
|
||||
export const buildExportBaseName = (options: Pick<ExportFileNameOptions, 'subject' | 'feature' | 'date'>): string => {
|
||||
const { subject, feature } = options
|
||||
const dateStr = formatExportDate()
|
||||
return [subject?.trim(), feature?.trim(), dateStr].filter(part => part).join('_')
|
||||
}
|
||||
|
||||
/** 波形 zip 下载:监测点_波形_yyyy-mm-dd-HH-mm-ss.zip(当前时间) */
|
||||
export const buildWaveExportFileName = (subject?: string): string => {
|
||||
const base = [subject?.trim(), '波形', formatExportDateTime()].filter(part => part).join('_')
|
||||
return `${base}.zip`
|
||||
}
|
||||
|
||||
export const buildExportFileName = (options: ExportFileNameOptions): string => {
|
||||
const ext = (options.ext || 'csv').replace(/^\./, '')
|
||||
return `${buildExportBaseName(options)}.${ext}`
|
||||
}
|
||||
|
||||
export const resolveExportFileName = (filenameOrOptions: string | ExportFileNameOptions): string => {
|
||||
if (typeof filenameOrOptions === 'string') {
|
||||
return filenameOrOptions
|
||||
}
|
||||
return buildExportFileName(filenameOrOptions)
|
||||
}
|
||||
|
||||
/** 从行数据中取监测点 / 设备 / 项目名称 */
|
||||
export const getExportSubjectFromRow = (row: any): string =>
|
||||
row?.lineName || row?.equipmentName || row?.projectName || row?.engineeringName || row?.name || ''
|
||||
|
||||
/**
|
||||
* title['A相','B相',]
|
||||
* data[[1,2],[3,4]]
|
||||
@@ -150,7 +200,8 @@ const convertToCSV = (title: object, data: any) => {
|
||||
})
|
||||
return csv
|
||||
}
|
||||
export const exportCSV = (title: object, data: any, filename: string) => {
|
||||
export const exportCSV = (title: object, data: any, filenameOrOptions: string | ExportFileNameOptions) => {
|
||||
const filename = resolveExportFileName(filenameOrOptions)
|
||||
const csv = convertToCSV(title, data)
|
||||
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' })
|
||||
const link = document.createElement('a')
|
||||
@@ -190,10 +241,13 @@ export const buildSeriesCsvData = (seriesList: Array<{ name: string; data?: any[
|
||||
return { titles, rows }
|
||||
}
|
||||
|
||||
export const exportSeriesCSV = (seriesList: Array<{ name: string; data?: any[] }>, filename: string) => {
|
||||
export const exportSeriesCSV = (
|
||||
seriesList: Array<{ name: string; data?: any[] }>,
|
||||
filenameOrOptions: string | ExportFileNameOptions
|
||||
) => {
|
||||
const { titles, rows } = buildSeriesCsvData(seriesList)
|
||||
if (!rows.length) return
|
||||
exportCSV(titles, rows, filename)
|
||||
exportCSV(titles, rows, filenameOrOptions)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user