import { type } from "os"; export default { //数据存放到sessionStorage缓存 setCache: function (key, val) { if (val instanceof Array) { let str = JSON.stringify(val); window.sessionStorage.setItem(key, str); } else { window.sessionStorage.setItem(key, val); } }, //获取缓存sessionStorage数据 getCache: function (key) { return window.sessionStorage.getItem(key); }, //获取缓存localStorage数据 setItem: function (key,val) { return localStorage.setItem(key,val); }, //获取缓存localStorage数据 getItem: function (key) { return localStorage.getItem(key); }, /** * 比赛时间计时器 * @param {分钟} f * @param {秒} s * @param {回掉方法} fun */ timer: function (f, s, fun) { let timing = setInterval(function () { s++; if (s < 10) { s = "0" + s; } if (s == 60) { f++; s = '00'; } fun && fun(f, s); }, 1000) }, /** * 玩法投注公共方法 * @param {玩法组件的选择赔率id数组} betting * @param {*当前玩法赔率及相关数据} bettingInfo * @param {*当前玩法赔率数据信息列表} data * @param {*Vuex里面的投注列表} getBettingList * @param {*当前组的玩法的title} name * @param {*判断当前组件是否已有投注} dataNum * @param {*修改当前样式回调方法} callback * @param {*更新Vuex投注列表} fun */ bettingFunction: function (betting, bettingInfo, data, getBettingList, name, dataNum, callback, fun) { let isTrue = true; betting.forEach((e, index) => { if (bettingInfo.id == e.id) { data.forEach((res) => { if (bettingInfo.id == res.id) { callback && callback(res, false); betting.splice(index, 1); } }) isTrue = false; } }); if (isTrue) { betting.push(bettingInfo); betting.forEach((e) => { if (bettingInfo.id == e.id) { data.forEach(res => { if (bettingInfo.id == res.id) { callback && callback(res, true); } }) isTrue = false; } }) } let obj = { title: name, data: betting }; let array = []; if (dataNum != 10000) { getBettingList[dataNum] = obj; } else { if (getBettingList) { if (getBettingList.length > 0) { getBettingList.push(obj); } } else { array.push(obj); } } fun && fun(getBettingList, array); }, /** * 获取vuex相对应玩法index下标和投注数据集合 * @param {组件类所有玩法数据集合} data * @param {组件里玩法别名} title * @param {从Vuex里面的投注列表的匹配对应的投注数据集合} betting * @param {相对应玩法index下标} dataNum */ getBettingId(data, title, callback) { if (data) { data.forEach((res, index) => { if (res.title == title) { callback && callback(res.data, index); } }); } }, /** * 接口轮询定时器 * @param {function} callback 定时器回调方法 */ ajaxTimerFun(callback){ //到计时 let timing = setInterval(function(){ callback && callback(timing) },43200000); // },5000); }, /** * 复合算法 * @param {int} data 第几场赛事 * @param {array} dataList 投注赛事列表 */ betPlay(data,dataList){ let listLenth = dataList.length; //赔率算法 let addSum =1; dataList.forEach((res,index )=>{ //if(data >= index+1){ let add = addSum *(1+res.odds*1); addSum =add //} }) //组合算法分母 function denominator (num){ let group =1; for(let i = listLenth ; i >(listLenth -num);i--){ let add = group*i group = add; } return group; } //组合算法分子 function molecule (num){ let son =1; for(let i = num ; i >1;i--){ let add = son*i; son = add; } return son; } //组合算法 function algorithm(data) { return { title:`${data}串1`,//algorithm index:denominator(data)/molecule(data), odds:addSum-1, }; } return algorithm(data); } }