import Vue from 'vue'; import Vuex from 'vuex'; import publicFun from '@/assets/publicFunction'; Vue.use(Vuex); /** * 设置全局访问的state对象 */ const state={ gameRatio:'', //玩法比率数据 activity:publicFun.getCache('activity'),//活动类别 ballId:publicFun.getCache('ballId'),//球类Id show:'',//Loading组件的状态显隐 isShow:false,//登录按钮点击显示登录页 rgShow:false,//注册组件显示 macth_id:publicFun.getCache('macth_id'),//赛事id betting:JSON.parse(publicFun.getCache('betting')),//投注数据 isBetting:publicFun.getCache('isBetting'),//是否展示投注窗口 deleteType:'',//投注框数据删除id或类型 token:'', } /** * 实时监听state里面值的变法(最新变法) */ const getters={ getGameRatio(state){ return state.gameRatio; }, getActivity(state){ return state.activity; }, getBallId(state){ return state.ballId; }, getShow(state){ return state.show; }, getIsShow(state){ return state.isShow; }, getRgShow(state){ return state.rgShow; }, getMatchId(state){ return state.macth_id; }, getBetting(state){ return state.betting; }, getIsBetting(state){ return state.isBetting; }, getDeleteType(state){ return state.deleteType; }, getToken(state){ return state.token; } } /** * 设置对外可调用的方法 */ const mutations = { newGameRatio(state,val){ //publicFun.getCache('activity') state.gameRatio = val; }, newActivity(state,val){ state.activity = val; publicFun.setCache('activity',val) }, newBallId(state,val){ state.ballId = val; publicFun.setCache('ballId',val) }, newShow(state,val){ state.show = val; }, newisShow(state,val){ state.isShow = val; }, newRgShow(state,val){ state.rgShow = val; }, newMacth_id(state,val){ state.macth_id = val; publicFun.setCache('macth_id',val); }, newBetting(state,val){ state.betting = val; publicFun.setCache('betting',val); }, newIsBetting(state,val){ state.isBetting = val; publicFun.setCache('isBetting',val); }, newToken(state,val){ state.token = val; // publicFun.setItem('token',val); }, newDeleteType(state,val){ state.deleteType = val; }, } /** * 这里面的方法是用来异步触发mutations里面的方法 */ const actions={ GETGAMERATIO(context,val){ context.commit('newGameRatio',val) }, GETACTIVITY(context,val){ context.commit('newActivity',val); }, GET_BALL_ID(context,val){ context.commit('newBallId',val); }, GETSHOW(context,val){ context.commit('newShow',val) }, GET_ISSHOW(context,val){ context.commit('newisShow',val) }, GETRGSHOW(context,val){ context.commit('newRgShow',val) }, MACTH_ID(context,val){ context.commit('newMacth_id',val) }, BETTING(context,val){ context.commit('newBetting',val) }, ISBETTING(context,val){ context.commit('newIsBetting',val) }, DEL_TYPE(context,val){ context.commit('newDeleteType',val) }, SET_TOKEN(context,val){ context.commit('newToken',val) } } const store =new Vuex.Store({ state, getters, mutations, actions }); export default store;