| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <template>
- <threejs-base-dialog>
- <template #title>
- 储能实时数据
- </template>
- <template #data>
- <div v-for="item in storageList" :key="item.name">
- <span>{{ item.name }}:</span>
- <span class="value">{{ item.value }}{{ item.unit }}</span>
- </div>
- </template>
- </threejs-base-dialog>
- </template>
- <script>
- import threejsBaseDialog from './base.vue'
- import { getLatestByDevice } from "@/api/mgr/elecStoreIndex";
- import { numToStr } from "@/utils";
- let timer = null;
- export default {
- components: {
- threejsBaseDialog,
- },
- props: {
- propData: {
- type: Object,
- default: () => {
- return {};
- },
- },
- },
- data() {
- return {
- storageList: [
- {
- name: "当前容量",
- value: 0,
- unit: "kW·h",
- },
- {
- name: "充电功率",
- value: 0,
- unit: "kW",
- },
- {
- name: "放电功率",
- value: 0,
- unit: "kW",
- },
- ],
- };
- },
- beforeDestroy() {
- timer && clearInterval(timer);
- },
- mounted() {
- this.init();
- },
- methods: {
- async init() {
- await this.getStorageData();
- timer = setInterval(this.getStorageData, 1000 * 60 * 3);
- },
- async getStorageData() {
- try {
- const params = {};
- if (this.propData.areaCode && this.propData.areaCode !== '-1') {
- params.areaCode = this.propData.areaCode;
- }
- if (this.propData.facsCode) {
- params.facsCode = this.propData.facsCode;
- }
- const { data } = await getLatestByDevice(params);
- if (!data || !Array.isArray(data) || data.length === 0) {
- const [capacity, charge, discharge] = this.storageList;
- capacity.value = 0;
- charge.value = 0;
- discharge.value = 0;
- this.storageList = [capacity, charge, discharge];
- return;
- }
- // 汇总所有设备的数据
- let totalCapacity = 0; // 当前容量总和(单位:kW·h)
- let totalChargePower = 0; // 充电功率总和(单位:W -> kW)
- let totalDischargePower = 0; // 放电功率总和(单位:W -> kW)
- data.forEach(device => {
- totalCapacity += device.currentCapacity || 0;
- totalChargePower += (device.chargeVoltage || 0) / 1000; // W转kW
- totalDischargePower += (device.dischargePower || 0) / 1000; // W转kW
- });
- const [capacity, charge, discharge] = this.storageList;
- capacity.value = numToStr(totalCapacity.toFixed(2));
- charge.value = numToStr(totalChargePower.toFixed(2));
- discharge.value = numToStr(totalDischargePower.toFixed(2));
- this.storageList = [capacity, charge, discharge];
- } catch (error) {
- console.error('获取储能数据失败:', error);
- }
- },
- },
- };
- </script>
|