index.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import Vue from "vue";
  2. import Vuex from "vuex";
  3. import axios from "@/utils/axios";
  4. import api from "@/api/index";
  5. import moment from "moment";
  6. Vue.use(Vuex);
  7. let projectId: any = (<any>window).projectId;
  8. export default new Vuex.Store({
  9. state: {
  10. realTimeData: [], //实时数据
  11. airCondition: {}, //空调情况
  12. lastMonthData: [], //上月数据
  13. lastAllEnergy: {}, //上月所有能耗数据
  14. weatherCont: {}, //天气
  15. bodyWidth: null,
  16. bodyHeight: null,
  17. },
  18. getters: {
  19. getBodyWidthHeight(state) {
  20. return [state.bodyWidth, state.bodyHeight];
  21. },
  22. },
  23. mutations: {
  24. setBodyWidth(state, width) {
  25. // debugger;
  26. state.bodyWidth = width;
  27. },
  28. setBodyHeight(state, height) {
  29. state.bodyHeight = height;
  30. },
  31. getRealTimeData(state, data) {
  32. //debugger;
  33. state.realTimeData = data;
  34. },
  35. getAirCondition(state, data) {
  36. state.airCondition = data;
  37. },
  38. getLastMonthData(state, data) {
  39. state.lastMonthData = data;
  40. },
  41. getLastAllEnergy(state, data) {
  42. state.lastAllEnergy = data;
  43. },
  44. getWeahter(state, data) {
  45. state.weatherCont = data;
  46. },
  47. },
  48. actions: {
  49. getRealTimeData({ state, commit }, data) {
  50. console.log("projectId", projectId);
  51. //实时数据
  52. axios
  53. .get(api.queryEnvCurrent + `?projectId=${projectId}`)
  54. .then((res: any) => {
  55. //debugger
  56. var resdata = res.data.data || [];
  57. commit("getRealTimeData", resdata);
  58. });
  59. },
  60. getAirCondition({ state, commit }, data) {
  61. //空调状态
  62. axios
  63. .get(api.queryConditionerStatus + `?projectId=${projectId}`)
  64. .then((res: any) => {
  65. var resdata = res.data.data || {};
  66. // debugger;
  67. commit("getAirCondition", resdata);
  68. });
  69. },
  70. getRealTimeTemp({ state, commit }, data) {
  71. //实时温度
  72. return axios.get(
  73. api.queryIndoorTempList + `?projectId=${projectId}`
  74. );
  75. },
  76. getLastMonthData({ state, commit }, data) {
  77. //上月数据
  78. axios
  79. .get(api.queryEnvHistory + `?projectId=${projectId}`)
  80. .then((res: any) => {
  81. //debugger;
  82. var resdata = res.data.data || [];
  83. commit("getLastMonthData", resdata);
  84. });
  85. },
  86. getLastAllEnergy({ state, commit }, data) {
  87. //上月所有能耗数据 上月总能耗 上月节约能耗
  88. var monthTime = moment().subtract(1, "month"); //往前取15分钟
  89. var monthTimeStr = monthTime.format("YYYYMM");
  90. axios
  91. .post(api.queryLastAllEnergy, {
  92. criteria: {
  93. projectId: projectId,
  94. yyyymm: monthTimeStr,
  95. },
  96. })
  97. .then((res: any) => {
  98. // debugger;
  99. var resdata = (res.data.content || [])[0] || {};
  100. commit("getLastAllEnergy", resdata);
  101. });
  102. },
  103. getWeahter({ state, commit }, data) {
  104. axios
  105. .get(api.getWeatherCurrent + `?projectId=${projectId}`)
  106. .then((res: any) => {
  107. //temperature = res.data.content.temperature;
  108. //debugger;
  109. var weatherCont = res.data.content || {};
  110. commit("getWeahter", weatherCont);
  111. });
  112. },
  113. },
  114. });