lixin-web
Version:
vue and bootstrap
76 lines (69 loc) • 2.33 kB
JavaScript
import { round, zipObject,groupBy,remove } from "lodash";
import axios from "axios";
import { ajax } from "../../js/util/axios";
const brandName = '利信'
const groupCode = ['ffc','ssc','x511','k3','c3','kl8','pk10']
const groupLabel = ['分分彩','时时彩','11选5','快3','3D','快乐8','PK10']
const state = {
isPortrait: true,
// lottoList: [{ code: "", label: "全部游戏" }],
lottoListMap: { "": "全部游戏" },
lottoNavList:{},
lottoGroup:zipObject(groupCode,groupLabel)
};
const getters = {
isPortrait: state => state.isPortrait,
// lottoList: state => state.lottoList,
lottoGroup: state => state.lottoGroup,
lottoListMap: state => state.lottoListMap,
lottoNavList: state => state.lottoNavList,
};
const actions = {
getLottoList({state, commit }, callback = () => {}) {
if (state.lottoNavList.ssc) {
callback(state.lottoNavList);
} else {
axios.post("/api/game-lottery/static-info").then(({ data }) => {
let list = data.map(({ shortName, showName,frequency,type }) => {
return { code: shortName, label: frequency == 'self' ? showName.replace('自主',brandName) : showName,frequency,type };
}).sort(i => !i.label.includes(brandName))
// commit("setLottoList", list);
commit("setLottoNavList",list );
commit(
"setLottoListMap",
zipObject(list.map(i => i.code), list.map(i => i.label))
);
callback();
});
}
}
};
const mutations = {
setOrien(state, isPortrait) {
state.isPortrait = isPortrait;
},
// setLottoList(state, list) {
// state.lottoList = state.lottoList.concat(list);
// },
setLottoListMap(state, data) {
state.lottoListMap = { ...state.lottoListMap, ...data };
},
setLottoNavList(state,data){
//LodashModuleReplacementPlugin -> groupBy(data,'type'),'type' can not use
let list = Object.values(groupBy(data,i => i.type))
list.unshift(
remove(list[0],i => i.frequency == 'self')
.map(i => {
return {...i,label:brandName + i.label}
})
.sort((a,b) => a.code > b.code)
)
state.lottoNavList = zipObject(groupCode,list.slice(0,7))
}
};
export default {
state,
getters,
actions,
mutations
};