index.ts 3.6 KB

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