useProjectStore.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { defineStore } from "pinia";
  2. import { getWeather, getProjectObj, queryLastEnergy } from "@/api/index";
  3. interface projectStoreState {
  4. weatherCont: any;
  5. projectId: string;
  6. projectObj: any;
  7. lastAllEnergy: any;
  8. }
  9. const useProjectStore = defineStore({
  10. id: "project",
  11. state: (): projectStoreState => {
  12. return {
  13. weatherCont: {}, //天气
  14. projectId: "Pj1101080259", // "Pj3301100002",
  15. projectObj: {},
  16. lastAllEnergy: {},
  17. };
  18. },
  19. getters: {
  20. floorIdAfter() {},
  21. },
  22. actions: {
  23. setProjectId(param: any) {
  24. //console.log("this", this);
  25. //debugger;
  26. this.projectId = param;
  27. },
  28. async setProjectObj() {
  29. try {
  30. var res = await getProjectObj();
  31. var project = res.data.content[0] || {};
  32. this.projectObj = project;
  33. } catch (err) {}
  34. },
  35. async setWeather() {
  36. try {
  37. var res = await getWeather();
  38. var weatherRes = res.data.content || {};
  39. this.weatherCont = weatherRes;
  40. } catch (err) {}
  41. },
  42. async setLastAllEnergy() {
  43. try {
  44. var res = await queryLastEnergy();
  45. var resdata = (res.data.content || [])[0] || {};
  46. this.lastAllEnergy = resdata;
  47. } catch (err) {}
  48. },
  49. },
  50. });
  51. export default useProjectStore;