| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- import {
- createStore
- } from 'vuex';
- import {
- getTime
- } from "../utils/index.js";
- import {
- getuidatas
- } from "../api/api.js";
-
- export default createStore({
- state: {
- formattedTime: getTime("yyyy-MM-dd hh:mm:ss"),
- uidatasdata: {},
- selectorid: null,
- selectorindex: null,
- status: null,
- num: 0,
- event:"故障",
- },
-
- mutations: {
- increment(state, n) {
-
- if (n == 1) {
- state.num++;
- } else {
- state.num = 0;
- }
- },
- getevent(state, event) {
- state.event = event;
- },
- setFormattedTime(state, time) {
- state.formattedTime = time;
- },
- setUidatasData(state, data) {
- state.uidatasdata = data;
- },
- setstatus(state, status) {
- state.status = status;
- },
- setSelectorId(state, id) {
- state.selectorid = id;
- },
- setSelectorIndex(state, index) {
- state.selectorindex = index;
- }
- },
-
- actions: {
- startClock({
- commit
- }) {
- setInterval(() => {
- const customFormat = 'yyyy-MM-dd hh:mm:ss';
- const formattedTime = getTime(customFormat);
- commit('setFormattedTime', formattedTime);
- }, 1000);
- },
-
- async fetchFaultsList({
- commit,
- state
- }) {
- try {
-
- let data = {
- id: "038f90dc-6e08-4a05-bf1e-7929e02f5fc5",
- page: 1,
- rows: 10000,
- };
- const response = await getuidatas(data);
- // status =response.status
- if (response.status == 'ok') {
-
- if (response.data != null && response.data != []) {
-
- const uidatasdata = response.data.reduce((obj, item) => {
- let a = item.module;
- let b = item[a];
- let numericValue = parseFloat(b); // 转换为数字
- let roundedValue = ''
- if (item.id == "BatCellVPeak_ValMaxCellVoltage" ||
- item.id == "BatCellVPeak_ValMinCellVoltage"||
- item.id == "PCSTotalOutputPower"
-
- ) {
- roundedValue = isNaN(numericValue) ? b : numericValue.toFixed(3);
- } else {
- if (item.id == "CellTemperatureLimitsStatus_MaxTemp" ||
- item.id == "CellTemperatureLimitsStatus_MinTemp" ||
- item.id == "TMS_Status_TMS_WATEROUT_TEMP" ||
- item.id == "TMS_Status_TMS_WATERIN_TEMP") {
- roundedValue = isNaN(numericValue) ? b : numericValue.toFixed(1);
- } else {
- if(item.id == "SOC"||
- item.id == "ChargingStation_1_telemetryFrameccu_EstimateTheRemainingChargingTime"||
- item.id == "ChargingStation_2_telemetryFrameccu_EstimateTheRemainingChargingTime"){
- roundedValue = isNaN(numericValue) ? b : numericValue.toFixed(0);
- }else{
- if(item.id == "PCSPortAPhaseVoltage" ||
- item.id == "PCSPortBPhaseVoltage" ||
- item.id == "PCSPortCPhaseVoltage" ||
- item.id == "PCSOutputA-phaseCurrent" ||
- item.id == "PCSOutputB-phaseCurrent"||
- item.id == "PCSOutputC-phaseCurrent"){
- roundedValue = isNaN(numericValue) ? b : numericValue.toFixed(2);
- }else{
-
- roundedValue = isNaN(numericValue) ? b : numericValue.toFixed(1);
- }
- }
- }
- }
- if (!isNaN(numericValue) && numericValue < 0) {
- roundedValue = Math.abs(numericValue);
- }
- return {
- ...obj,
- [item.id]: roundedValue
- };
- }, {});
-
- commit('setUidatasData', uidatasdata);
-
- if (uidatasdata.SysControl_RunCmd == 1 || uidatasdata.SysControl_Gun1RunCmd == 1 ||
- uidatasdata.SysControl_Gun2RunCmd == 1) {
- commit('setSelectorId', uidatasdata.SysInstall_EssRunModeManual);
- commit('setSelectorIndex', 1);
- } else {
- commit('setSelectorId', null);
- commit('setSelectorIndex', null);
- }
- if (state.num >= 3) {
- commit('increment', 0);
- commit('setstatus', response.status)
- }
- commit('increment', 1);
- } else {
- if (state.num >= 3) {
- commit('increment', 0);
- commit('setstatus', "NO")
- }
- commit('increment', 1);
- }
- } else {
- // Handle failure case if needed
- }
- } catch (error) {
- console.log(error);
- commit('setstatus', "NO")
- } finally {
- // Retry fetching data after a delay
- setTimeout(() => {
- this.dispatch('fetchFaultsList');
- }, 2000); // 2秒后重新获取数据
- }
-
-
- }
- }
- });
|