// 用户数据模块 import api from '@/common/request/index' import store from '@/store' import { setStorage, getStorage, removeStorage } from '@/util/index.js' const state = { houseId: getStorage('houseId') || '', houseQuery: {} || {}, houseList: [] } const actions = { // 设置状态 setHouseId({commit},id) { commit('SET_HOUSE_ID',id); }, setHouseQuery({commit},query = {}) { commit('SET_HOUSE_QUERY',query); }, async initList({commit},type){ if(type == 'all'){ await api('system.allRoomsList').then(res => { if(res.code == 1){ // 存储棚室列表 commit('SET_HOUSE_LIST', res.data) } }) } if(type == 'device'){ await api('system.allRoomsHasDeviceList').then(res => { if(res.code == 1){ // 存储棚室列表 commit('SET_HOUSE_LIST', res.data) } }) } if(type == 'plant'){ await api('system.allRoomsHasPlantList').then(res => { if(res.code == 1){ // 存储棚室列表 commit('SET_HOUSE_LIST', res.data) } }) } } } const mutations = { // 保存棚室ID ['SET_HOUSE_ID'](state, houseId) { state.houseId = houseId setStorage('houseId', houseId) }, // 存储搜索状态 ['SET_HOUSE_QUERY'](state, query) { state.houseQuery = query }, // 保存棚室ID ['SET_HOUSE_LIST'](state, list) { state.houseList = list }, } const getters = { } export default { state, mutations, actions, getters }