rooms.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // 用户数据模块
  2. import api from '@/common/request/index'
  3. import store from '@/store'
  4. import { setStorage, getStorage, removeStorage } from '@/util/index.js'
  5. const state = {
  6. houseId: getStorage('houseId') || '',
  7. houseQuery: {} || {},
  8. houseList: []
  9. }
  10. const actions = {
  11. // 设置状态
  12. setHouseId({commit},id) {
  13. commit('SET_HOUSE_ID',id);
  14. },
  15. setHouseQuery({commit},query = {}) {
  16. commit('SET_HOUSE_QUERY',query);
  17. },
  18. async initList({commit},type){
  19. if(type == 'all'){
  20. await api('system.allRoomsList').then(res => {
  21. if(res.code == 1){
  22. // 存储棚室列表
  23. commit('SET_HOUSE_LIST', res.data)
  24. }
  25. })
  26. }
  27. if(type == 'device'){
  28. await api('system.allRoomsHasDeviceList').then(res => {
  29. if(res.code == 1){
  30. // 存储棚室列表
  31. commit('SET_HOUSE_LIST', res.data)
  32. }
  33. })
  34. }
  35. if(type == 'plant'){
  36. await api('system.allRoomsHasPlantList').then(res => {
  37. if(res.code == 1){
  38. // 存储棚室列表
  39. commit('SET_HOUSE_LIST', res.data)
  40. }
  41. })
  42. }
  43. }
  44. }
  45. const mutations = {
  46. // 保存棚室ID
  47. ['SET_HOUSE_ID'](state, houseId) {
  48. state.houseId = houseId
  49. setStorage('houseId', houseId)
  50. },
  51. // 存储搜索状态
  52. ['SET_HOUSE_QUERY'](state, query) {
  53. state.houseQuery = query
  54. },
  55. // 保存棚室ID
  56. ['SET_HOUSE_LIST'](state, list) {
  57. state.houseList = list
  58. },
  59. }
  60. const getters = {
  61. }
  62. export default {
  63. state,
  64. mutations,
  65. actions,
  66. getters
  67. }