| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- 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
- },
-
- mutations: {
- increment(state) {
- state.count++;
- },
- 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 }) {
- try {
- let data = {
- id: "3224a3eb-2375-4dfc-99ce-b182edd30996",
- page: 1,
- rows: 10000,
- };
- const response = await getuidatas(data);
- // status =response.status
- commit('setstatus',response.status)
- if (response.status == 'ok') {
- 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 == "BatSysLimitVal_MaxCellTemperatureLimit" ||
- item.id == "BatCellVPeak_ValMinCellVoltage" ||
- item.id == "CellTemperatureLimitsStatus_MinTemp"
- ) {
- roundedValue = isNaN(numericValue) ? b : numericValue.toFixed(3);
- } else {
- roundedValue = isNaN(numericValue) ? b : numericValue.toFixed(2);
- }
- 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);
- }
- } else {
- // Handle failure case if needed
- }
- } catch (error) {
- commit('setstatus',"NO")
- } finally {
- // Retry fetching data after a delay
- setTimeout(() => {
- this.dispatch('fetchFaultsList');
- }, 2000); // 2秒后重新获取数据
- }
- }
- }
- });
|