修改测试问题

This commit is contained in:
guanj
2026-06-16 08:34:45 +08:00
parent 1c01fe5ae1
commit d9dfd804c5
63 changed files with 5289 additions and 3842 deletions

View File

@@ -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)
}
/**

View File

@@ -1,3 +1,4 @@
import { buildExportBaseName, type ExportFileNameOptions } from '@/utils/echartMethod'
import { ElMessage } from 'element-plus'
import { nextTick } from 'vue'
import { exportExcel } from '@/views/system/reportForms/export.js'
@@ -12,6 +13,10 @@ export function parseLuckysheetSheets(sheets: any[]) {
/* ignore invalid json */
}
}
if (!item.config) item.config = {}
if (item.row == null) item.row = 36
if (item.column == null) item.column = 18
if (!item.data) item.data = []
item.celldata?.forEach((cell: any) => {
if (item.data?.[cell.r]?.[cell.c]?.v != null) {
item.data[cell.r][cell.c] = cell.v
@@ -47,10 +52,15 @@ export function renderLuckysheetReport(
sheets: any[],
options: Record<string, any> = {}
) {
if (!Array.isArray(sheets) || sheets.length === 0) {
destroyLuckysheet()
return
}
parseLuckysheetSheets(sheets)
destroyLuckysheet()
nextTick(() => {
requestAnimationFrame(() => {
if (!document.getElementById(container)) return
luckysheet.create({
container,
...DEFAULT_REPORT_OPTIONS,
@@ -62,7 +72,7 @@ export function renderLuckysheetReport(
}
/** 安全导出 Luckysheet无数据时提示并返回 false */
export function exportLuckysheetFile(filename: string, hasData = true): boolean {
export function exportLuckysheetFile(filenameOrOptions: string | ExportFileNameOptions, hasData = true): boolean {
if (!hasData) {
ElMessage.warning('暂无数据')
return false
@@ -77,6 +87,8 @@ export function exportLuckysheetFile(filename: string, hasData = true): boolean
ElMessage.warning('暂无数据')
return false
}
const filename =
typeof filenameOrOptions === 'string' ? filenameOrOptions : buildExportBaseName(filenameOrOptions)
exportExcel(sheets, filename)
ElMessage.success('生成成功')
return true