From 0f2acb6e99ca56c64e8930b046020958af429b58 Mon Sep 17 00:00:00 2001 From: zch Date: Fri, 15 Nov 2024 15:30:42 +0800 Subject: [PATCH] =?UTF-8?q?add(ruoyi-ui):=20=E6=96=B0=E5=A2=9E=E5=9B=BE?= =?UTF-8?q?=E8=A1=A8=E7=BB=84=E4=BB=B6=E5=92=8C=E5=AE=9E=E7=94=A8=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E5=87=BD=E6=95=B0-=20=E6=B7=BB=E5=8A=A0=20Chart.vue?= =?UTF-8?q?=20=E7=BB=84=E4=BB=B6=E7=94=A8=E4=BA=8E=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=9B=BE=E8=A1=A8=20-=20=E6=96=B0=E5=A2=9E=20dateReportUtils.j?= =?UTF-8?q?s=20=E6=96=87=E4=BB=B6=EF=BC=8C=E6=8F=90=E4=BE=9B=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E8=8C=83=E5=9B=B4=E8=AE=A1=E7=AE=97=E5=87=BD=E6=95=B0?= =?UTF-8?q?=20-=20=E6=B7=BB=E5=8A=A0=20electricityIcon.svg=20=E5=9B=BE?= =?UTF-8?q?=E6=A0=87=E6=96=87=E4=BB=B6=20-=20=E6=96=B0=E5=A2=9E=20export.j?= =?UTF-8?q?s=20=E6=96=87=E4=BB=B6=EF=BC=8C=E5=AE=9E=E7=8E=B0=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD=20-=20=E5=9C=A8?= =?UTF-8?q?=20package.json=20=E4=B8=AD=E6=B7=BB=E5=8A=A0=20echarts-liquidf?= =?UTF-8?q?ill=20=E5=92=8C=20xlsx=20=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-ui/package.json | 4 +- .../src/assets/images/electricityIcon.svg | 6 ++ ruoyi-ui/src/components/Charts/Chart.vue | 51 +++++++++++++++ ruoyi-ui/src/utils/dateReportUtils.js | 63 +++++++++++++++++++ ruoyi-ui/src/utils/export.js | 36 +++++++++++ 5 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 ruoyi-ui/src/assets/images/electricityIcon.svg create mode 100644 ruoyi-ui/src/components/Charts/Chart.vue create mode 100644 ruoyi-ui/src/utils/dateReportUtils.js create mode 100644 ruoyi-ui/src/utils/export.js diff --git a/ruoyi-ui/package.json b/ruoyi-ui/package.json index 431f62a..6daf376 100644 --- a/ruoyi-ui/package.json +++ b/ruoyi-ui/package.json @@ -42,6 +42,7 @@ "core-js": "3.37.1", "dplayer": "^1.27.1", "echarts": "5.4.0", + "echarts-liquidfill": "^3.1.0", "element-ui": "2.15.14", "file-saver": "2.0.5", "fuse.js": "6.4.3", @@ -59,7 +60,8 @@ "vue-meta": "2.4.0", "vue-router": "3.4.9", "vuedraggable": "2.24.3", - "vuex": "3.6.0" + "vuex": "3.6.0", + "xlsx": "^0.18.5" }, "devDependencies": { "@vue/cli-plugin-babel": "4.4.6", diff --git a/ruoyi-ui/src/assets/images/electricityIcon.svg b/ruoyi-ui/src/assets/images/electricityIcon.svg new file mode 100644 index 0000000..c150c81 --- /dev/null +++ b/ruoyi-ui/src/assets/images/electricityIcon.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/ruoyi-ui/src/components/Charts/Chart.vue b/ruoyi-ui/src/components/Charts/Chart.vue new file mode 100644 index 0000000..6eb0e6e --- /dev/null +++ b/ruoyi-ui/src/components/Charts/Chart.vue @@ -0,0 +1,51 @@ + + + diff --git a/ruoyi-ui/src/utils/dateReportUtils.js b/ruoyi-ui/src/utils/dateReportUtils.js new file mode 100644 index 0000000..6485110 --- /dev/null +++ b/ruoyi-ui/src/utils/dateReportUtils.js @@ -0,0 +1,63 @@ +export function getHoursBetween(startHourStr, endHourStr) { + const startHour = new Date(startHourStr) + let endHour = new Date(endHourStr) + let nowDate = new Date() + nowDate.setHours(nowDate.getHours() - 1); + if (endHour.getTime() > nowDate.getTime()) { + endHour = nowDate + } + const hours = [] + while (startHour <= endHour) { + const hourString = `${startHour.getFullYear()}-${String(startHour.getMonth() + 1).padStart(2, '0')}-${String(startHour.getDate()).padStart(2, '0')} ${String(startHour.getHours()).padStart(2, '0')}:00:00` + hours.push(hourString) + startHour.setTime(startHour.getTime() + 60 * 60 * 1000) + } + // return hours; + return hours.sort((a, b) => new Date(b) - new Date(a)) +} + +export function getDatesBetween(startDateStr, endDateStr) { + const startDate = new Date(startDateStr) + let endDate = new Date(endDateStr) + let nowDate = new Date() + nowDate.setHours(nowDate.getHours() - 1); + if (endDate.getTime() > nowDate.getTime()) { + endDate = nowDate + } + const dates = [] + while (startDate <= endDate) { + dates.push(`${startDate.getFullYear()}-${String(startDate.getMonth() + 1).padStart(2, '0')}-${String(startDate.getDate()).padStart(2, '0')}`) + startDate.setDate(startDate.getDate() + 1) + } + // return dates; + return dates.sort((a, b) => new Date(b) - new Date(a)) +} + +export function getMonthsBetween(startMonthStr, endMonthStr) { + const result = [] + const startDate = new Date(startMonthStr + '-01') + let endDate = new Date(endMonthStr + '-01') + const currentDate = new Date(startDate) + let nowDate = new Date() + nowDate.setHours(nowDate.getHours() - 1); + if (endDate.getTime() > nowDate.getTime()) { + endDate = nowDate + } + while (currentDate <= endDate) { + const year = currentDate.getFullYear() + const month = String(currentDate.getMonth() + 1).padStart(2, '0') + result.push(`${year}-${month}`) + currentDate.setMonth(currentDate.getMonth() + 1) + } + return result.sort((a, b) => new Date(b) - new Date(a)) +} + +export function getYearsBetween(startYearStr, endYearStr) { + const result = [] + const startYear = Number(startYearStr.substring(0, 4)) + const endYear = Number(endYearStr.substring(0, 4)) + for (let i = startYear; i <= endYear; i++) { + result.push(`${i}`) + } + return result.sort((a, b) => new Date(b) - new Date(a)) +} diff --git a/ruoyi-ui/src/utils/export.js b/ruoyi-ui/src/utils/export.js new file mode 100644 index 0000000..3c8c6c8 --- /dev/null +++ b/ruoyi-ui/src/utils/export.js @@ -0,0 +1,36 @@ + +import FileSaver from "file-saver"; +import XLSX from "xlsx"; + + +/** + * 字符权限校验 + * @param {Array} value 校验值 + * @returns {Boolean} + * id:表ID + * name:导出表名字 + *xlsxParam:true/false:如果表格里有数字、日期这些、需要加上raw: true + */ +export function handleExport(id,name,xlsxParam) { + var wb = XLSX.utils.table_to_book( + document.querySelector('#'+id), + {raw: xlsxParam} + ); + + var wbout = XLSX.write(wb, { + bookType: "xlsx", + bookSST: true, + type: "array", + }); + try { + FileSaver.saveAs( + new Blob([wbout], { type: "application/octet-stream" }), + name+".xlsx" + ); + } catch (e) { + if (typeof console !== "undefined") { + console.log(e, wbout); + } + } + return wbout; +}