add(ruoyi-ui): 新增图表组件和实用工具函数- 添加 Chart.vue 组件用于创建图表

- 新增 dateReportUtils.js 文件,提供日期范围计算函数
- 添加 electricityIcon.svg 图标文件
- 新增 export.js 文件,实现表格导出功能
- 在 package.json 中添加 echarts-liquidfill 和 xlsx 依赖
IOT
zch 2 months ago
parent 9b1ae8246e
commit 0f2acb6e99

@ -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",

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<svg version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" width="114px" height="87px" xmlns="http://www.w3.org/2000/svg">
<g transform="matrix(1 0 0 1 -135 -174 )">
<path d="M 8 79 L 114 79 L 114 87 L 0 87 L 0 0 L 8 0 L 8 79 Z M 106.3740234375 7.759765625 C 106.7080078125 8.099609375 106.875 8.53385416666666 106 9.0625 L 106 33.701171875 C 106.875 34.494140625 106.51318359375 35.0511067708333 105.78955078125 35.3720703125 C 105.06591796875 35.6930338541667 104.4072265625 35.5514322916667 103.8134765625 34.947265625 L 97.078125 28.09375 L 61.8427734375 63.947265625 C 61.4716796875 64.3248697916667 61.044921875 64.513671875 60.5625 64.513671875 C 60.080078125 64.513671875 59.6533203125 64.3248697916667 59.2822265625 63.947265625 L 46.3125 50.75 L 23.15625 74.3125 L 12.46875 63.4375 L 45.0322265625 30.302734375 C 45.4033203125 29.9251302083333 45.830078125 29.736328125 46.3125 29.736328125 C 46.794921875 29.736328125 47.2216796875 29.9251302083333 47.5927734375 30.302734375 L 60.5625 43.5 L 86.390625 17.21875 L 79.6552734375 10.365234375 C 79.0615234375 9.76106770833333 78.92236328125 9.0908203125 79.23779296875 8.3544921875 C 79.55322265625 7.6181640625 80.1005859375 7.25 80.8798828125 8 L 105.09375 8 C 105.61328125 7.25 106.0400390625 7.419921875 106.3740234375 7.759765625 Z " fill-rule="nonzero" fill="#000000" stroke="none" transform="matrix(1 0 0 1 135 174 )" />
</g>
</svg>

@ -0,0 +1,51 @@
<template>
<div />
</template>
<script>
import * as echarts from 'echarts';
import 'echarts-liquidfill'
import Logo from "@/layout/components/Sidebar/Logo";
export default {
watch:{
chartOption: {
handler(newVal, oldVal) {
if(newVal){
this.initChart(newVal)
}
},
deep: true, //
}
},
props:['chartOption'],
expose: ['setData'],
data() {
return {
chart: null,
}
},
mounted() {
if(this.chartOption){
this.initChart(this.chartOption)
}
},
beforeDestroy() {
if (!this.chart) {
return
}
this.chart.dispose()
this.chart = null
},
methods: {
setData(option) {
this.initChart(option)
},
initChart(option) {
this.chart = echarts.init(this.$el, 'macarons')
this.chart.setOption(option)
}
}
}
</script>

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

@ -0,0 +1,36 @@
import FileSaver from "file-saver";
import XLSX from "xlsx";
/**
* 字符权限校验
* @param {Array} value 校验值
* @returns {Boolean}
* id:表ID
* name:导出表名字
*xlsxParamtrue/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;
}
Loading…
Cancel
Save