index.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. import { createStore } from 'vuex'
  2. export default createStore({
  3. state: {
  4. siteId: 1,//公共api请求参数->siteId
  5. Time_Data: [],//公共api请求参数->Time_Data
  6. queryType: '',//监控设备->数据报表api请求参数->queryType
  7. table_list: [
  8. {
  9. name: "电流",
  10. list: [
  11. { name: "A相电流", value: "Ia" },
  12. { name: "B相电流", value: "Ib" },
  13. { name: "C相电流", value: "Ic" },
  14. ],
  15. },
  16. {
  17. name: "功率",
  18. list: [
  19. { name: "A相有功功率 kW", value: "Pa" },
  20. { name: "A相无功功率 kVar", value: "Qa" },
  21. { name: "B相有功功率 kW", value: "Pb" },
  22. { name: "B相无功功率 kVar", value: "Qb" },
  23. { name: "C相有功功率 kW", value: "Pc" },
  24. { name: "C相无功功率 kVar", value: "Qc" },
  25. { name: "总有功功率 kW", value: "P" },
  26. { name: "总无功功率 kW", value: "Q" },
  27. { name: "实时需量 kW", value: "Demand" },
  28. ],
  29. },
  30. {
  31. name: "电度",
  32. list: [
  33. { name: "正有功电度 kWh", value: "Epp" },
  34. { name: "负有功电度 kWh", value: "Epn" },
  35. { name: "正无功电度 kvarh", value: "Eqp" },
  36. { name: "负无功电度 kvarh", value: "Eqn" },
  37. ],
  38. },
  39. {
  40. name: "电压",
  41. list: [
  42. { name: "A相电压 kV", value: "Ua" },
  43. { name: "B相电压 kV", value: "Ub" },
  44. { name: "C相电压 kV", value: "Uc" },
  45. { name: "回路电压 V", value: "Ul" },
  46. { name: "AB线电压 V", value: "Uab" },
  47. { name: "BC线电压 V", value: "Ubc" },
  48. { name: "CA线电压 V", value: "Uca" },
  49. ],
  50. },
  51. {
  52. name: "温度 ℃",
  53. list: [
  54. { name: "外接温度1", value: "T1" },
  55. { name: "外接温度2", value: "T2" },
  56. { name: "外接温度3", value: "T3" },
  57. { name: "外接温度4", value: "T4" },
  58. { name: "环境温度", value: "DeviceTemp" },
  59. ],
  60. },
  61. {
  62. name: "频率 Hz",
  63. list: [{ name: "频率", value: "F" }],
  64. },
  65. {
  66. name: "功率因数",
  67. list: [
  68. { name: "A相功率因数", value: "COSa" },
  69. { name: "B相功率因数", value: "COSb" },
  70. { name: "C相功率因数", value: "COSc" },
  71. { name: "功率因数", value: "COS" },
  72. ],
  73. },
  74. {
  75. name: "谐波电流有效值 A",
  76. list: [
  77. { name: "Ia总谐波电流", value: "IHa" },
  78. { name: "Ib总谐波电流", value: "IHa" },
  79. { name: "Ic总谐波电流", value: "IHc" },
  80. ],
  81. },
  82. {
  83. name: "通讯参数",
  84. list: [{ name: "设备信号强度", value: "SignalIntensity" }],
  85. },
  86. {
  87. name: "电压突变 次",
  88. list: [
  89. { name: "电压暂升次数", value: "Upt" },
  90. { name: "电压暂降次数", value: "Udt" },
  91. { name: "电压中断次数", value: "Ust" },
  92. ],
  93. },
  94. ],//数据报表->默认tabs数据
  95. se_tabs: [
  96. { label: '电流', name: "I" },
  97. { label: '功率', name: "P" },
  98. { label: '电度', name: "KWh" },
  99. { label: '电压', name: "V" },
  100. { label: '温度', name: "C" },
  101. { label: '频率', name: "HZ" },
  102. { label: '功率因数', name: "PS" },
  103. { label: '谐波电流有效值', name: "RMS" },
  104. { label: '通讯参数', name: "DDB" },
  105. { label: '电压突变', name: "VT" },
  106. ],
  107. run_off_Status: null,//运行状态统计->echarts->OFF次数分布和运行状态曲线图表 api信息存储
  108. timearr: [],//公共处理开始时间和结束时间中的时间段天数 值存储
  109. HistoricalCurve:null,//历史趋势->echarts->曲线图表 api信息存储
  110. },
  111. mutations: {
  112. /**
  113. * @公共api请求参数siteId
  114. * @param {*}} state
  115. * @param {*} val
  116. */
  117. increment(state, val) {
  118. state.siteId = val
  119. },
  120. /**
  121. * @数据报表 —> 多选按钮数据处理
  122. * @param {*} state
  123. * @param {*} checked_list
  124. */
  125. checkedCities_all(state, checked_list) {
  126. state.queryType = ''
  127. var checked = ''
  128. for (let i in checked_list) {
  129. checked_list[i] === "电流"
  130. ? checked = "I"
  131. : checked_list[i] === "功率"
  132. ? checked = "P"
  133. : checked_list[i] === "电度"
  134. ? checked = "KWh"
  135. : checked_list[i] === "电压"
  136. ? checked = "V"
  137. : checked_list[i] === "温度"
  138. ? checked = "C"
  139. : checked_list[i] === "频率"
  140. ? checked = "HZ"
  141. : checked_list[i] === "功率因数"
  142. ? checked = "PS"
  143. : checked_list[i] === "谐波电流有效值"
  144. ? checked = "RMS"
  145. : checked_list[i] === "通讯参数"
  146. ? checked = "DDB"
  147. : checked_list[i] === "电压突变"
  148. ? checked = "VT"
  149. : ""
  150. state.queryType += checked_list.length > 1 ? checked + "," : checked;
  151. }
  152. state.queryType = checked_list.length > 1 ? state.queryType.slice(0, state.queryType.length - 1) : state.queryType
  153. },
  154. /**
  155. * @历史趋势 -> echarts ->曲线图表 api信息存储
  156. */
  157. HistoricalCurve(state,data){
  158. state.HistoricalCurve = data
  159. },
  160. /**
  161. * @运行状态统计 -> echarts -> OFF次数分布和运行状态曲线图表 api信息存储
  162. */
  163. run_off_Status(state, data) {
  164. state.run_off_Status = data
  165. },
  166. /**
  167. * @公共处理时区方法
  168. */
  169. TimeAll_function(state, time) {
  170. state.Time_Data = []
  171. for (let i in time) {
  172. var Y = time[i].getFullYear() < 10 ? '0' + time[i].getFullYear() : time[i].getFullYear()
  173. var M = (time[i].getMonth() + 1) < 10 ? '0' + (time[i].getMonth() + 1) : (time[i].getMonth() + 1)
  174. var D = time[i].getDate() < 10 ? '0' + time[i].getDate() : time[i].getDate()
  175. var HH = time[i].getHours() < 10 ? '0' + time[i].getHours() : time[i].getHours()
  176. var MM = time[i].getMinutes() < 10 ? '0' + time[i].getMinutes() : time[i].getMinutes()
  177. var SS = time[i].getSeconds() < 10 ? '0' + time[i].getSeconds() : time[i].getSeconds()
  178. // console.log(Y + '-' + M + '-' + D + ' ' + HH + ':' + MM + ':' + SS)
  179. state.Time_Data.push(Y + '-' + M + '-' + D + ' ' + HH + ':' + MM + ':' + SS)
  180. }
  181. },
  182. /**
  183. * @公共处理开始时间和结束时间中的时间段天数
  184. * @param {*} state
  185. * @param {*} begin 开始时间和结束时间
  186. */
  187. getAll(state, begin) {
  188. let arr1 = begin[0].split("-");
  189. let arr2 = begin[1].split("-");
  190. let arr1_ = new Date();
  191. let arrTime = [];
  192. arr1_.setUTCFullYear(arr1[0], arr1[1] - 1, arr1[2]);
  193. let arr2_ = new Date();
  194. arr2_.setUTCFullYear(arr2[0], arr2[1] - 1, arr2[2]);
  195. let unixDb = arr1_.getTime();
  196. let unixDe = arr2_.getTime();
  197. for (let k = unixDb; k <= unixDe;) {
  198. arrTime.push(datetimeparse(k, "YY-MM-DD"));
  199. k = k + 24 * 60 * 60 * 1000;
  200. }
  201. state.timearr = arrTime
  202. // return arrTime;
  203. // 时间格式处理
  204. function datetimeparse(timestamp, format, prefix) {
  205. if (typeof timestamp == "string") {
  206. timestamp = Number(timestamp);
  207. }
  208. //转换时区
  209. let currentZoneTime = new Date(timestamp);
  210. let currentTimestamp = currentZoneTime.getTime();
  211. let offsetZone = currentZoneTime.getTimezoneOffset() / 60; //如果offsetZone>0是西区,西区晚
  212. let offset = null;
  213. //客户端时间与服务器时间保持一致,固定北京时间东八区。
  214. offset = offsetZone + 8;
  215. currentTimestamp = currentTimestamp + offset * 3600 * 1000;
  216. let newtimestamp = null;
  217. if (currentTimestamp) {
  218. if (currentTimestamp.toString().length === 13) {
  219. newtimestamp = currentTimestamp.toString();
  220. } else if (currentTimestamp.toString().length === 10) {
  221. newtimestamp = currentTimestamp + "000";
  222. } else {
  223. newtimestamp = null;
  224. }
  225. } else {
  226. newtimestamp = null;
  227. }
  228. let dateobj = newtimestamp
  229. ? new Date(parseInt(newtimestamp))
  230. : new Date();
  231. let YYYY = dateobj.getFullYear();
  232. let MM =
  233. dateobj.getMonth() > 8
  234. ? dateobj.getMonth() + 1
  235. : "0" + (dateobj.getMonth() + 1);
  236. let DD =
  237. dateobj.getDate() > 9 ? dateobj.getDate() : "0" + dateobj.getDate();
  238. let HH =
  239. dateobj.getHours() > 9 ? dateobj.getHours() : "0" + dateobj.getHours();
  240. let mm =
  241. dateobj.getMinutes() > 9
  242. ? dateobj.getMinutes()
  243. : "0" + dateobj.getMinutes();
  244. let ss =
  245. dateobj.getSeconds() > 9
  246. ? dateobj.getSeconds()
  247. : "0" + dateobj.getSeconds();
  248. let output = "";
  249. let separator = "/";
  250. if (format) {
  251. separator = format.match(/-/) ? "-" : "/";
  252. output += format.match(/yy/i) ? YYYY : "";
  253. output += format.match(/MM/)
  254. ? (output.length ? separator : "") + MM
  255. : "";
  256. output += format.match(/dd/i)
  257. ? (output.length ? separator : "") + DD
  258. : "";
  259. output += format.match(/hh/i) ? (output.length ? " " : "") + HH : "";
  260. output += format.match(/mm/) ? (output.length ? ":" : "") + mm : "";
  261. output += format.match(/ss/i) ? (output.length ? ":" : "") + ss : "";
  262. } else {
  263. output += YYYY + separator + MM + separator + DD;
  264. }
  265. output = prefix ? prefix + output : output;
  266. return newtimestamp ? output : "";
  267. }
  268. },
  269. }
  270. })