移动储能车V1版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import {
  2. createStore
  3. } from 'vuex';
  4. import {
  5. getTime
  6. } from "../utils/index.js";
  7. import {
  8. getuidatas
  9. } from "../api/api.js";
  10. export default createStore({
  11. state: {
  12. formattedTime: getTime("yyyy-MM-dd hh:mm:ss"),
  13. uidatasdata: {},
  14. selectorid: null,
  15. selectorindex: null,
  16. status: null,
  17. num: 0,
  18. event:"故障",
  19. },
  20. mutations: {
  21. increment(state, n) {
  22. if (n == 1) {
  23. state.num++;
  24. } else {
  25. state.num = 0;
  26. }
  27. },
  28. getevent(state, event) {
  29. state.event = event;
  30. },
  31. setFormattedTime(state, time) {
  32. state.formattedTime = time;
  33. },
  34. setUidatasData(state, data) {
  35. state.uidatasdata = data;
  36. },
  37. setstatus(state, status) {
  38. state.status = status;
  39. },
  40. setSelectorId(state, id) {
  41. state.selectorid = id;
  42. },
  43. setSelectorIndex(state, index) {
  44. state.selectorindex = index;
  45. }
  46. },
  47. actions: {
  48. startClock({
  49. commit
  50. }) {
  51. setInterval(() => {
  52. const customFormat = 'yyyy-MM-dd hh:mm:ss';
  53. const formattedTime = getTime(customFormat);
  54. commit('setFormattedTime', formattedTime);
  55. }, 1000);
  56. },
  57. async fetchFaultsList({
  58. commit,
  59. state
  60. }) {
  61. try {
  62. let data = {
  63. id: "3224a3eb-2375-4dfc-99ce-b182edd30996",
  64. page: 1,
  65. rows: 10000,
  66. };
  67. const response = await getuidatas(data);
  68. // status =response.status
  69. if (response.status == 'ok') {
  70. if (response.data != null && response.data != []) {
  71. const uidatasdata = response.data.reduce((obj, item) => {
  72. let a = item.module;
  73. let b = item[a];
  74. let numericValue = parseFloat(b); // 转换为数字
  75. let roundedValue = ''
  76. if (item.id == "BatCellVPeak_ValMaxCellVoltage" ||
  77. item.id == "BatCellVPeak_ValMinCellVoltage"||
  78. item.id == "PCSTotalOutputPower"
  79. ) {
  80. roundedValue = isNaN(numericValue) ? b : numericValue.toFixed(3);
  81. } else {
  82. if (item.id == "CellTemperatureLimitsStatus_MaxTemp" ||
  83. item.id == "CellTemperatureLimitsStatus_MinTemp" ||
  84. item.id == "TMS_Status_TMS_WATEROUT_TEMP" ||
  85. item.id == "TMS_Status_TMS_WATERIN_TEMP") {
  86. roundedValue = isNaN(numericValue) ? b : numericValue.toFixed(1);
  87. } else {
  88. if(item.id == "SOC"||
  89. item.id == "ChargingStation_1_telemetryFrameccu_EstimateTheRemainingChargingTime"||
  90. item.id == "ChargingStation_2_telemetryFrameccu_EstimateTheRemainingChargingTime"){
  91. roundedValue = isNaN(numericValue) ? b : numericValue.toFixed(0);
  92. }else{
  93. if(item.id == "PCSPortAPhaseVoltage" ||
  94. item.id == "PCSPortBPhaseVoltage" ||
  95. item.id == "PCSPortCPhaseVoltage" ||
  96. item.id == "PCSOutputA-phaseCurrent" ||
  97. item.id == "PCSOutputB-phaseCurrent"||
  98. item.id == "PCSOutputC-phaseCurrent"){
  99. roundedValue = isNaN(numericValue) ? b : numericValue.toFixed(2);
  100. }else{
  101. roundedValue = isNaN(numericValue) ? b : numericValue.toFixed(1);
  102. }
  103. }
  104. }
  105. }
  106. if (!isNaN(numericValue) && numericValue < 0) {
  107. roundedValue = Math.abs(numericValue);
  108. }
  109. return {
  110. ...obj,
  111. [item.id]: roundedValue
  112. };
  113. }, {});
  114. commit('setUidatasData', uidatasdata);
  115. if (uidatasdata.SysControl_RunCmd == 1 || uidatasdata.SysControl_Gun1RunCmd == 1 ||
  116. uidatasdata.SysControl_Gun2RunCmd == 1) {
  117. commit('setSelectorId', uidatasdata.SysInstall_EssRunModeManual);
  118. commit('setSelectorIndex', 1);
  119. } else {
  120. commit('setSelectorId', null);
  121. commit('setSelectorIndex', null);
  122. }
  123. if (state.num >= 3) {
  124. commit('increment', 0);
  125. commit('setstatus', response.status)
  126. }
  127. commit('increment', 1);
  128. } else {
  129. if (state.num >= 3) {
  130. commit('increment', 0);
  131. commit('setstatus', "NO")
  132. }
  133. commit('increment', 1);
  134. }
  135. } else {
  136. // Handle failure case if needed
  137. }
  138. } catch (error) {
  139. console.log(error);
  140. commit('setstatus', "NO")
  141. } finally {
  142. // Retry fetching data after a delay
  143. setTimeout(() => {
  144. this.dispatch('fetchFaultsList');
  145. }, 2000); // 2秒后重新获取数据
  146. }
  147. }
  148. }
  149. });