You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

67 lines
1.3 KiB

import Vue from 'vue'
import Vuex from 'vuex'
import request from '@/common/request'
Vue.use(Vuex)
var timer=null
export default new Vuex.Store({
state:{
userInfo:{},
token:"",
baseInfo:{//地块信息
id:"",
name:"",
},
sysMsgNum:'',//系统信息数量
isShowSysNum:true,
},
getters:{
userInfo: state=>state.userInfo,
token: state=>state.token,
},
mutations:{
setUserInfo(state, val){
state.userInfo={
...val.userInfo,
companyName:val.departs[0].departName
}
state.token=val.token
this.dispatch('getSysMsg')
},
outLogin(state){
state.userInfo={}
state.baseInfo={}
state.token=''
clearTimeout(timer)
uni.reLaunch({
url:"/pages/home/login",
})
},
setHeadImg(state,val){
state.userInfo.avatar=val
},
setBaseId(state, val){//基地id
state.baseInfo={...state.baseInfo,...val}
},
setSysMsgNum(state,val){
state.sysMsgNum=val
if(val>0 && state.isShowSysNum){
uni.setTabBarBadge({ index:2, text:`${val}` })
}
},
setSysMsgShow(state,val){
state.isShowSysNum=val
},
},
actions:{
async getSysMsg({commit,dispatch}){
var res=await request("/api/message/readNum",{disabledLoad:true})
if(res.statu){
commit("setSysMsgNum",res.data)
}else{
commit("setSysMsgNum",'')
}
timer=setTimeout(()=>dispatch('getSysMsg'),30*60*1000)
},
}
})