From 003c3ebc3d75d82121ad65d7752853b22329f1b2 Mon Sep 17 00:00:00 2001 From: huangjinysf Date: Sun, 21 Dec 2025 12:08:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E5=8F=96=E6=97=A5=E6=9C=9F=E8=8C=83?= =?UTF-8?q?=E5=9B=B4=E8=AE=A1=E7=AE=97=E9=80=BB=E8=BE=91=E5=88=B0=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/dateFormat.js | 59 +++++++++++++++++++++++++ src/views/eq/ItemAnalysis.vue | 25 ++--------- src/views/eq/index.vue | 77 +++------------------------------ src/views/plan/ItemAnalysis.vue | 25 ++--------- src/views/plan/index.vue | 24 ++-------- src/views/qc/ItemAnalysis.vue | 25 ++--------- src/views/qc/index.vue | 24 ++-------- 7 files changed, 79 insertions(+), 180 deletions(-) create mode 100644 src/utils/dateFormat.js diff --git a/src/utils/dateFormat.js b/src/utils/dateFormat.js new file mode 100644 index 0000000..146d12f --- /dev/null +++ b/src/utils/dateFormat.js @@ -0,0 +1,59 @@ +/** + * 日期格式化工具函数 + */ + +/** + * 将日期对象格式化为 YYYY-MM-DD 格式的字符串 + * @param {Date} date - 日期对象 + * @returns {string} 格式化后的日期字符串 + */ +export function formatDate(date) { + if (!date) return ''; + + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + + return `${year}-${month}-${day}`; +} + +/** + * 将日期对象格式化为 YYYY-MM-DD HH:mm:ss 格式的字符串 + * @param {Date} date - 日期对象 + * @returns {string} 格式化后的日期时间字符串 + */ +export function formatDateTime(date) { + if (!date) return ''; + + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + const hours = String(date.getHours()).padStart(2, '0'); + const minutes = String(date.getMinutes()).padStart(2, '0'); + const seconds = String(date.getSeconds()).padStart(2, '0'); + + return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`; +} + +/** + * 根据时间范围文字(如"近1年")计算开始和结束日期 + * @param {string} timeRange - 时间范围文字 + * @returns {Object} 包含开始和结束日期的对象 + */ +export function getDateRangeByTimeRange(timeRange) { + const endDate = new Date(); + const startDate = new Date(); + + if (timeRange === '近1年') { + startDate.setFullYear(endDate.getFullYear() - 1); + } else if (timeRange === '近2年') { + startDate.setFullYear(endDate.getFullYear() - 2); + } else if (timeRange === '近3年') { + startDate.setFullYear(endDate.getFullYear() - 3); + } + + return { + start_date: formatDate(startDate), + end_date: formatDate(endDate) + }; +} \ No newline at end of file diff --git a/src/views/eq/ItemAnalysis.vue b/src/views/eq/ItemAnalysis.vue index f60a257..993cde3 100644 --- a/src/views/eq/ItemAnalysis.vue +++ b/src/views/eq/ItemAnalysis.vue @@ -84,6 +84,7 @@