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.
 
 
 
 
 

88 lines
1.8 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
state.token=val.token
uni.setStorageSync('token', val.token)
this.dispatch('getSysMsg')
},
outLogin(state){
state.userInfo={}
state.baseInfo={}
state.token=''
uni.removeStorageSync('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,getters}){
var res=await request("/suyuan/messageApi/queryMessageUnreadNum",{
disabledLoad:true,
method:"post",
body:{
companyId: getters.userInfo.companyId,
msgType:0,
}
})
if(res.statu){
commit("setSysMsgNum",res.data)
}else{
commit("setSysMsgNum",'')
}
timer=setTimeout(()=>dispatch('getSysMsg'),30*60*1000)
},
async getUserInfo({commit},val){
if(val){
var res=await request("/common/api/dict/queryUserInfoByToken",{
params:{token:val}
})
if(res.statu){
commit('setUserInfo',{userInfo:res.data, token:val})
uni.switchTab({url:'/pages/home/index'})
return false
}else{
return true
}
}
return true
},
}
})