| | |
| | | </div> |
| | | </el-card> |
| | | </el-col> |
| | | <!-- <el-col :xs="24" :lg="12"> |
| | | <el-col :xs="24" :lg="12"> |
| | | <el-card class="chart-card" shadow="never"> |
| | | <template #header> |
| | | <div class="chart-head"> |
| | | <span class="chart-title">能耗单价对比</span> |
| | | <span class="chart-title">能耗用量对比</span> |
| | | <div class="chart-tools" @click.stop> |
| | | <button |
| | | class="chart-tool" |
| | | type="button" |
| | | @click="downloadChart('price', '能耗单价对比')" |
| | | @click="downloadChart('unit', '能耗用量对比')" |
| | | > |
| | | 下载 |
| | | </button> |
| | | <button |
| | | class="chart-tool" |
| | | type="button" |
| | | @click="openBigChart('price', '能耗单价对比')" |
| | | @click="openBigChart('unit', '能耗用量对比')" |
| | | > |
| | | 大图 |
| | | </button> |
| | |
| | | </div> |
| | | </template> |
| | | <div |
| | | ref="priceChartWrap" |
| | | ref="unitChartWrap" |
| | | class="chart-wrap" |
| | | v-loading="tableLoading" |
| | | > |
| | | <div |
| | | ref="priceChart" |
| | | class="chart-content" |
| | | ref="unitChart" |
| | | class="chart-content" |
| | | v-show="hasTableData" |
| | | ></div> |
| | | <div class="chart-empty" v-show="!hasTableData"> |
| | |
| | | </div> |
| | | </div> |
| | | </el-card> |
| | | </el-col> --> |
| | | </el-col> |
| | | </el-row> |
| | | </div> |
| | | </transition> |
| | |
| | | </el-table-column> |
| | | <el-table-column prop="dosage" label="用量" align="right"> |
| | | <template #default="scope"> |
| | | <span class="consumption-value">{{ |
| | | <span class="unit-value">{{ |
| | | formatNumber(scope.row.dosage, 2) |
| | | }}</span> |
| | | <span class="consumption-unit">{{ scope.row.unit }}</span> |
| | | <span class="unit-unit">{{ scope.row.unit }}</span> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column |
| | |
| | | if (key === "cost") return costChartInstance; |
| | | if (key === "type") return typeChartInstance; |
| | | if (key === "purpose") return purposeChartInstance; |
| | | if (key === "price") return priceChartInstance; |
| | | if (key === "unit") return unitChartInstance; |
| | | return null; |
| | | }; |
| | | |
| | | const ensurePanelForChart = (key) => { |
| | | if (key === "cost" || key === "type") chartPanel.value = "core"; |
| | | if (key === "purpose" || key === "price") chartPanel.value = "advanced"; |
| | | if (key === "purpose" || key === "unit") chartPanel.value = "advanced"; |
| | | }; |
| | | |
| | | const downloadChart = (key, title) => { |
| | |
| | | |
| | | const prop = sortState.prop; |
| | | const direction = sortState.order === "ascending" ? 1 : -1; |
| | | const numFields = new Set(["price", "cost", "consumption"]); |
| | | const numFields = new Set(["price", "cost", "unit"]); |
| | | |
| | | return data.sort((a, b) => { |
| | | const av = a?.[prop]; |
| | |
| | | const costChart = ref(null); |
| | | const typeChart = ref(null); |
| | | const purposeChart = ref(null); |
| | | const priceChart = ref(null); |
| | | const unitChart = ref(null); |
| | | |
| | | const costChartWrap = ref(null); |
| | | const typeChartWrap = ref(null); |
| | | const purposeChartWrap = ref(null); |
| | | const priceChartWrap = ref(null); |
| | | const unitChartWrap = ref(null); |
| | | |
| | | const tableAnchor = ref(null); |
| | | |
| | |
| | | let costChartInstance = null; |
| | | let typeChartInstance = null; |
| | | let purposeChartInstance = null; |
| | | let priceChartInstance = null; |
| | | let unitChartInstance = null; |
| | | |
| | | // 图表区切换:core | advanced | none(点击当前选中可收起) |
| | | const chartPanel = ref("core"); |
| | | |
| | | const ensureChartsReady = (panel) => { |
| | | if (panel === "core") { |
| | | if (costChart.value && !costChartInstance) |
| | | if (costChart.value && !costChartInstance) { |
| | | costChartInstance = echarts.init(costChart.value); |
| | | if (typeChart.value && !typeChartInstance) |
| | | setTimeout(() => costChartInstance?.resize(), 50); |
| | | } |
| | | if (typeChart.value && !typeChartInstance) { |
| | | typeChartInstance = echarts.init(typeChart.value); |
| | | if (costChartInstance) updateCostChart(); |
| | | if (typeChartInstance) updateTypeChart(); |
| | | setTimeout(() => typeChartInstance?.resize(), 50); |
| | | } |
| | | return; |
| | | } |
| | | if (panel === "advanced") { |
| | | if (purposeChart.value && !purposeChartInstance) |
| | | if (purposeChart.value && !purposeChartInstance) { |
| | | purposeChartInstance = echarts.init(purposeChart.value); |
| | | if (priceChart.value && !priceChartInstance) |
| | | priceChartInstance = echarts.init(priceChart.value); |
| | | if (purposeChartInstance) updatePurposeChart(); |
| | | if (priceChartInstance) updatePriceChart(); |
| | | setTimeout(() => purposeChartInstance?.resize(), 50); |
| | | } |
| | | if (unitChart.value && !unitChartInstance) { |
| | | unitChartInstance = echarts.init(unitChart.value); |
| | | setTimeout(() => unitChartInstance?.resize(), 50); |
| | | } |
| | | } |
| | | }; |
| | | |
| | |
| | | watch(chartPanel, (val) => { |
| | | if (val !== "none") resizeChartsAfterExpand(); |
| | | }); |
| | | |
| | | // 监听表格数据变化,确保数据加载后图表正确渲染 |
| | | watch(tableData, () => { |
| | | nextTick(() => { |
| | | updateCharts(); |
| | | nextTick(() => { |
| | | handleResize(); |
| | | }); |
| | | }); |
| | | }, { deep: true }); |
| | | |
| | | // 获取能耗类型标签类型 |
| | | const getEnergyTypeType = (type) => { |
| | |
| | | const typeCosts = {}; |
| | | |
| | | data.forEach((item) => { |
| | | if (!typeCosts[item.energyType]) { |
| | | typeCosts[item.energyType] = 0; |
| | | if (!typeCosts[item.energyTyep]) { |
| | | typeCosts[item.energyTyep] = 0; |
| | | } |
| | | typeCosts[item.energyType] += parseFloat(item.cost); |
| | | typeCosts[item.energyTyep] += parseFloat(item.cost); |
| | | }); |
| | | |
| | | const chartData = Object.entries(typeCosts).map(([name, value]) => ({ |
| | |
| | | purposeChartInstance.setOption(option); |
| | | }; |
| | | |
| | | // 更新能耗单价对比图 |
| | | const updatePriceChart = () => { |
| | | // 更新能耗用量对比图 |
| | | const updateConsumptionChart = () => { |
| | | const data = tableData.value; |
| | | const priceData = {}; |
| | | const unitData = {}; |
| | | |
| | | data.forEach((item) => { |
| | | if (!priceData[item.energyType]) { |
| | | priceData[item.energyType] = { |
| | | if (!unitData[item.energyTyep]) { |
| | | unitData[item.energyTyep] = { |
| | | 生产: 0, |
| | | 办公: 0, |
| | | }; |
| | | } |
| | | if (priceData[item.energyType].hasOwnProperty(item.type)) { |
| | | priceData[item.energyType][item.type] = parseFloat(item.price); |
| | | if (unitData[item.energyTyep].hasOwnProperty(item.type)) { |
| | | unitData[item.energyTyep][item.type] += parseFloat( |
| | | item.dosage || 0 |
| | | ); |
| | | } |
| | | }); |
| | | |
| | | const energyTypes = Object.keys(priceData); |
| | | const productionPrices = energyTypes.map((type) => priceData[type].生产); |
| | | const officePrices = energyTypes.map((type) => priceData[type].办公); |
| | | const energyTypes = Object.keys(unitData); |
| | | const productionConsumptions = energyTypes.map( |
| | | (type) => unitData[type].生产 |
| | | ); |
| | | const officeConsumptions = energyTypes.map( |
| | | (type) => unitData[type].办公 |
| | | ); |
| | | |
| | | const option = { |
| | | tooltip: { |
| | |
| | | "box-shadow: 0 14px 40px rgba(15,23,42,.14); border-radius: 12px;", |
| | | }, |
| | | legend: { |
| | | data: ["生产能耗单价", "办公能耗单价"], |
| | | data: ["生产能耗用量", "办公能耗用量"], |
| | | top: 0, |
| | | right: 10, |
| | | textStyle: { color: "rgba(15, 23, 42, 0.62)" }, |
| | |
| | | }, |
| | | yAxis: { |
| | | type: "value", |
| | | name: "单价(元)", |
| | | name: "用量", |
| | | nameTextStyle: { color: "rgba(15, 23, 42, 0.58)" }, |
| | | axisLabel: { color: "rgba(15, 23, 42, 0.58)" }, |
| | | axisLine: { show: false }, |
| | |
| | | }, |
| | | series: [ |
| | | { |
| | | name: "生产能耗单价", |
| | | name: "生产能耗用量", |
| | | type: "bar", |
| | | data: productionPrices, |
| | | data: productionConsumptions, |
| | | itemStyle: { |
| | | color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ |
| | | { offset: 0, color: "#2f6fed" }, |
| | |
| | | }, |
| | | }, |
| | | { |
| | | name: "办公能耗单价", |
| | | name: "办公能耗用量", |
| | | type: "bar", |
| | | data: officePrices, |
| | | data: officeConsumptions, |
| | | itemStyle: { |
| | | color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [ |
| | | { offset: 0, color: "#16a34a" }, |
| | |
| | | }, |
| | | ], |
| | | }; |
| | | priceChartInstance.setOption(option); |
| | | unitChartInstance.setOption(option); |
| | | }; |
| | | |
| | | // 统计维度切换 |
| | |
| | | |
| | | // 查询 |
| | | const handleQuery = () => { |
| | | |
| | | queryPulse.value = true; |
| | | window.setTimeout(() => { |
| | | queryPulse.value = false; |
| | |
| | | // 更新所有图表 |
| | | const updateCharts = () => { |
| | | nextTick(() => { |
| | | // 确保 core 面板的图表始终初始化(因为默认显示的是 core) |
| | | ensureChartsReady("core"); |
| | | |
| | | // 同时也初始化当前可见面板的图表 |
| | | if (chartPanel.value === "advanced") { |
| | | ensureChartsReady("advanced"); |
| | | } |
| | | |
| | | // 更新所有已初始化的图表 |
| | | if (costChartInstance) updateCostChart(); |
| | | if (typeChartInstance) updateTypeChart(); |
| | | if (purposeChartInstance) updatePurposeChart(); |
| | | if (priceChartInstance) updatePriceChart(); |
| | | if (unitChartInstance) updateConsumptionChart(); |
| | | }); |
| | | }; |
| | | |
| | |
| | | costChartInstance && costChartInstance.resize(); |
| | | typeChartInstance && typeChartInstance.resize(); |
| | | purposeChartInstance && purposeChartInstance.resize(); |
| | | priceChartInstance && priceChartInstance.resize(); |
| | | unitChartInstance && unitChartInstance.resize(); |
| | | }; |
| | | |
| | | onMounted(() => { |
| | |
| | | width: 100%; |
| | | } |
| | | |
| | | .consumption-value { |
| | | .unit-value { |
| | | font-weight: bold; |
| | | color: var(--lux-primary); |
| | | } |
| | | |
| | | .consumption-unit { |
| | | .unit-unit { |
| | | font-size: 12px; |
| | | color: var(--lux-muted); |
| | | margin-left: 2px; |