From d4b60864a4e2418558119d268f3b16e395cd2991 Mon Sep 17 00:00:00 2001 From: chenJinxu <2183691628@qq.com> Date: Mon, 4 Mar 2024 15:16:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20=E5=91=A8/=E6=9C=88?= =?UTF-8?q?=E6=97=A5=E6=9C=9F=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/utils-service.js | 77 +++++++++++++++++++++++++ src/views/insight/index.vue | 7 ++- src/views/insight/signsReport.vue | 96 ++++++++++++++++++------------- 3 files changed, 136 insertions(+), 44 deletions(-) diff --git a/src/services/utils-service.js b/src/services/utils-service.js index b5132f1..6f44d1b 100644 --- a/src/services/utils-service.js +++ b/src/services/utils-service.js @@ -193,3 +193,80 @@ export function nameConvert(name) { } return userName; } + +// 获取最近两年的月份,返回每个月的开始时间和结束时间,当前年份和当前月份 +/** + * + * @param {*} yearsBack 获取的最近多少年份 + * @returns + */ +export function getMonthsByYear(yearsBack) { + const currentDate = new Date(); + const startYear = currentDate.getFullYear() - yearsBack; + const endYear = currentDate.getFullYear(); + + const dates = []; + + for (let year = startYear; year <= endYear; year++) { + for (let month = 0; month < 12; month++) { + const startOfMonth = new Date(year, month, 2); + startOfMonth.setHours(0, 0, 0, 0); + + const endOfMonth = new Date(year, month + 1, 0); + endOfMonth.setHours(23, 59, 59, 999); + + // 只保留当前年份之前的月份数据 + if (year < currentDate.getFullYear() || (year === currentDate.getFullYear() && month <= currentDate.getMonth())) { + dates.push({ + start: startOfMonth.toISOString().split('T')[0], + end: endOfMonth.toISOString().split('T')[0], + curYear: year, + curMonth: month + 1 + }); + } + } + } + + return dates; +} + +// 获取最近一年的周报,从上周五到上周六,返回周开始和结束时间的年月日 +export function getWeeksByYear(yearsBack) { + const currentDate = new Date(); + const startDate = new Date(currentDate.getFullYear() - yearsBack || 1, currentDate.getMonth(), currentDate.getDate()); + const endDate = new Date(currentDate.getFullYear(), currentDate.getMonth()); + + const result = []; + + while (startDate <= endDate) { + /* const monthStart = new Date(startDate.getFullYear(), startDate.getMonth(), 1) */ // 获取该月有多少天 + const daysInMonth = new Date(startDate.getFullYear(), startDate.getMonth() + 1, 0).getDate(); + + for (let week = 0; week < 5; week++) { + // 假设每月至少有4周,最多包含5周 + const weekStartDate = new Date(startDate); + weekStartDate.setDate(Math.max(1, weekStartDate.getDate() - (weekStartDate.getDay() || 7) + 7)); // 上周六 + const weekEndDate = new Date(weekStartDate); + weekEndDate.setDate(weekEndDate.getDate() + 6); // 下周五 + + // 防止跨越到下个月 + if (weekEndDate.getDate() > daysInMonth) { + break; + } + + result.push({ + curYear: startDate.getFullYear(), + curMonth: startDate.getMonth() + 1, + month: `${startDate.getFullYear()}-${startDate.getMonth() + 1}`, + start: weekStartDate.toISOString().split('T')[0], + end: weekEndDate.toISOString().split('T')[0] + }); + + startDate.setDate(startDate.getDate() + 7); + } + + startDate.setMonth(startDate.getMonth() + 1); + } + + return result; +} diff --git a/src/views/insight/index.vue b/src/views/insight/index.vue index a7401e4..7f3c0f5 100644 --- a/src/views/insight/index.vue +++ b/src/views/insight/index.vue @@ -1017,7 +1017,7 @@ export default { let max = 0; data.forEach(item => { if (item.value > max) { - max = item.value; + max = item.value || '--'; } }); data.forEach(item => { @@ -1063,7 +1063,7 @@ export default { let max = 0; data.forEach(item => { if (item.value > max) { - max = item.value; + max = item.value || '--'; } }); data.forEach(item => { @@ -1145,7 +1145,7 @@ export default { } }); ydata.push({ - value: item.value, + value: item.value || '--', label: { show: false }, @@ -1309,6 +1309,7 @@ export default { align: 'center' }, formatter: function (params) { + console.log("params", params); return params[0].marker + params[0].name + '
' + params[0].value; } }, diff --git a/src/views/insight/signsReport.vue b/src/views/insight/signsReport.vue index 48c8162..49f9d90 100644 --- a/src/views/insight/signsReport.vue +++ b/src/views/insight/signsReport.vue @@ -2,7 +2,7 @@