Files
smart_storage_app/pages/tabbar/components/dischargeChart/index.vue

299 lines
7.3 KiB
Vue
Raw Normal View History

2025-06-30 10:21:25 +08:00
<template>
<view class="warp">
<zero-loading v-if="chartLoading" position="absolute"></zero-loading>
<charts v-else :id="'pcChart'" :options="charge_option"></charts>
</view>
</template>
<script>
import charts from "@/components/charts/index";
export default {
components: {
charts
},
data() {
return {
charge_option: {},
stationId: null,
2026-03-09 14:50:40 +08:00
chartLoading: false,
chartChargePv:{
chartChargeEle:[],
chartPv:[]
}
2025-06-30 10:21:25 +08:00
}
},
props: {
activeTime: {
type: String,
default: 'day'
}
},
computed: {
currentStation() {
return this.vuex_currentStation;
},
2026-03-09 14:50:40 +08:00
inverterFlag(){
return this.vuex_inverterFlag;
},
2025-06-30 10:21:25 +08:00
},
watch: {
currentStation: {
handler(val) {
if (val && val.id) {
this.stationId = val.id
2026-03-09 14:50:40 +08:00
this.getData();
2025-06-30 10:21:25 +08:00
}
},
deep: true,
immediate: true
},
activeTime: {
handler(val) {
if (val && this.stationId) {
2026-03-09 14:50:40 +08:00
this.getData();
2025-06-30 10:21:25 +08:00
}
},
deep: true,
immediate: true
}
},
methods: {
2026-03-09 14:50:40 +08:00
async getData() {
await this.GetChargeChart()
if(this.inverterFlag === 1){
this.GetPvChart()
}
},
async GetPvChart() {
this.chartLoading = true
//充放电曲线
let self = this;
return new Promise((resolve, reject) => {
self.$u.api.homePageData
.getPvElecData({
stationId: this.stationId,
type: this.activeTime,
})
.then((res) => {
self.chartLoading = false;
self.chartChargePv.chartPv = res.data;
self.initChargeChart(self.chartChargePv);
resolve();
})
.catch((err) => {
reject("错误");
});
});
2025-06-30 10:21:25 +08:00
},
async GetChargeChart() {
this.chartLoading = true
//充放电曲线
let self = this;
return new Promise((resolve, reject) => {
self.$u.api.homePageData
.GetKJYElecData({
stationId: this.stationId,
type: this.activeTime,
})
.then((res) => {
self.chartLoading = false
2026-03-09 14:50:40 +08:00
if(self.inverterFlag !== 1){
self.initChargeChart(res.data);
}else{
self.chartChargePv.chartChargeEle = res.data;
}
2025-06-30 10:21:25 +08:00
resolve();
})
.catch((err) => {
reject("错误");
});
});
},
initChargeChart(val) {
let x_data = [];
let charge_data = [];
let discharge_data = [];
let pv_data = [];
let benefit_data = [];
2026-03-09 14:50:40 +08:00
let self = this;
if (val.chartChargeEle && val.chartChargeEle.length > 0) {
val.chartChargeEle.forEach((item,idx) => {
2025-06-30 10:21:25 +08:00
x_data.push(item.date);
charge_data.push(item.chargeElec);
discharge_data.push(item.dischargeElec);
2026-03-09 14:50:40 +08:00
if(self.inverterFlag === 1){pv_data.push(val.chartPv.length > 0? val.chartPv[idx].powerGenerate:'0')};
2025-06-30 10:21:25 +08:00
benefit_data.push(item.income);
});
} else {
x_data = [0, 0, 0, 0, 0, 0, 0];
charge_data = [0, 0, 0, 0, 0, 0, 0];
discharge_data = [0, 0, 0, 0, 0, 0, 0];
pv_data = [0, 0, 0, 0, 0, 0, 0];
benefit_data = [0, 0, 0, 0, 0, 0, 0];
}
2026-03-09 14:50:40 +08:00
let optionConfigPv = {
color: ["#009458", "#BFE49F", "#3977B1"],
legend:[this.$t('homePage.home.charge'), this.$t('homePage.home.disCharge'), this.$t(
'homePage.home.photovoltaicCharge')],
series: [{
data: charge_data,
type: "bar",
name: this.$t('homePage.home.charge'),
},
{
data: discharge_data,
type: "bar",
name: this.$t('homePage.home.disCharge'),
},
{
data: pv_data,
type: "bar",
name: this.$t('homePage.home.photovoltaicCharge'),
}
]
};
let optionConfig = {
color: ["#009458", "#BFE49F"],
legend:[this.$t('homePage.home.charge'), this.$t('homePage.home.disCharge')],
series: [{
data: charge_data,
type: "bar",
name: this.$t('homePage.home.charge'),
},
{
data: discharge_data,
type: "bar",
name: this.$t('homePage.home.disCharge'),
}
]
};
2025-06-30 10:21:25 +08:00
//充放电图表
this.charge_option = {
tooltip: {
trigger: "axis",
textStyle: {
textShadowBlur: 10, // 重点
textShadowColor: 'transparent', // 重点
},
axisPointer: {},
confine: true,
position: function(point, params, dom, rect, size) {
// 鼠标坐标和提示框位置的参考坐标系是以外层div的左上角那一点为原点x轴向右y轴向下
// 提示框位置
var x = 0; // x坐标位置
var y = 0; // y坐标位置
// 当前鼠标位置
var pointX = point[0];
var pointY = point[1];
// 外层div大小
// var viewWidth = size.viewSize[0];
// var viewHeight = size.viewSize[1];
// 提示框大小
var boxWidth = size.contentSize[0];
var boxHeight = size.contentSize[1];
// boxWidth > pointX 说明鼠标左边放不下提示框
if (boxWidth > pointX) {
x = 5; // 自己定个x坐标值以防出屏
y -= 15; // 防止点被覆盖住,可根据情况自行调节
} else {
// 左边放的下
x = pointX - boxWidth - 15;
}
// boxHeight > pointY 说明鼠标上边放不下提示框
if (boxHeight + 20 > pointY) {
y = pointY + 15;
} else if (boxHeight > pointY) {
y = 5;
} else {
// 上边放得下
y += pointY - boxHeight;
}
return [x, y];
},
},
2026-03-09 14:50:40 +08:00
color: self.inverterFlag === 1? optionConfigPv.color:optionConfig.color,
2025-06-30 10:21:25 +08:00
legend: {
animation: false,
right: "0",
top: "0",
icon: "rect",
itemWidth: 10,
itemHeight: 10,
2026-03-09 14:50:40 +08:00
data: self.inverterFlag === 1? optionConfigPv.legend:optionConfig.legend,
2025-06-30 10:21:25 +08:00
},
grid: {
left: "15%",
right: "5%",
bottom: "12%",
top: "18%",
},
xAxis: {
type: "category",
data: x_data,
axisLabel: {
show: true,
color: "#A3A3A3",
formatter: function(params) {
let newParamsName = "";
const paramsNameNumber = params.length; // 文字总长度
const provideNumber = 11; //一行显示几个字
const rowNumber = Math.ceil(paramsNameNumber / provideNumber);
if (paramsNameNumber > provideNumber) {
for (let p = 0; p < rowNumber; p++) {
const start = p * provideNumber;
const end = start + provideNumber;
const tempStr =
p === rowNumber - 1 ?
params.substring(start, paramsNameNumber) :
params.substring(start, end) + "\n";
newParamsName += tempStr;
}
} else {
newParamsName = params;
}
return newParamsName;
},
},
axisLine: {
lineStyle: {
color: "#A3A3A3",
},
},
},
yAxis: {
name: this.$t('homePage.home.chargingandDischarging'),
nameTextStyle: {
fontSize: 12,
padding: [0, 0, 0, 20],
},
type: "value",
axisLabel: {
color: "#A3A3A3",
},
axisLine: {
show: false,
lineStyle: {
color: "#A3A3A3",
},
},
},
2026-03-09 14:50:40 +08:00
series: self.inverterFlag === 1? optionConfigPv.series:optionConfig.series,
2025-06-30 10:21:25 +08:00
};
},
},
}
</script>
<style lang="scss" scoped>
.warp {
width: 650rpx;
height: 500rpx;
margin-top: 20rpx;
position: relative;
}
</style>