03f924e2e8164d92ae0d9641608bd4deaeaa8f99.svn-base 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. import { type } from "os";
  2. export default {
  3. /**
  4. * 获取缓存sessionStorage数据
  5. * @param {*str} key
  6. * @param {* obj||str} val
  7. */
  8. setCache: function (key, val) {
  9. if (val instanceof Array) {
  10. let str = JSON.stringify(val);
  11. window.sessionStorage.setItem(key, str);
  12. } else {
  13. window.sessionStorage.setItem(key, val);
  14. }
  15. },
  16. /**
  17. * 获取缓存sessionStorage数据
  18. * @param {*str} key
  19. */
  20. getCache: function (key) {
  21. return window.sessionStorage.getItem(key);
  22. },
  23. /**
  24. * 获取缓存localStorage数据
  25. * @param {*str} key
  26. * @param {* obj||str} val
  27. */
  28. setItem: function (key,val) {
  29. if (val instanceof Array || val instanceof Object) {
  30. let str = JSON.stringify(val);
  31. localStorage.setItem(key, str);
  32. } else {
  33. localStorage.setItem(key, val);
  34. }
  35. //return localStorage.setItem(key,val);
  36. },
  37. /**
  38. * 获取缓存localStorage数据
  39. * @param {*str} key
  40. */
  41. getItem: function (key) {
  42. return localStorage.getItem(key);
  43. },
  44. /**
  45. * 比赛时间计时器
  46. * @param {分钟} f
  47. * @param {秒} s
  48. * @param {回掉方法} fun
  49. */
  50. timer: function (f, s, fun) {
  51. let timing = setInterval(function () {
  52. s++;
  53. if (s < 10) {
  54. s = "0" + s;
  55. }
  56. if (s == 60) {
  57. f++;
  58. s = '00';
  59. }
  60. fun && fun(f, s);
  61. }, 1000)
  62. },
  63. /**
  64. * 玩法投注公共方法
  65. * @param {obj} betting 玩法组件的选择赔率id数组
  66. * @param {*obj} bettingInfo 当前玩法赔率及相关数据
  67. * @param {*obj} data当前玩法赔率数据信息列表
  68. * @param {*obj} getBettingList Vuex里面的投注列表
  69. * @param {*str} name 当前组的玩法的title
  70. * @param {*int} dataNum 判断当前组件是否已有投注
  71. * @param {*int} limit 投注数量
  72. * @param {*function} callback 修改当前样式回调方法
  73. * @param {*function} fun 更新Vuex投注列表
  74. */
  75. bettingFunction: function (betting, bettingInfo, data, getBettingList, name, dataNum,limit,callback, fun) {
  76. let isTrue = true;
  77. let isAlert = false;
  78. betting.forEach((e, index) => {
  79. //删除投注数据
  80. if (bettingInfo.id == e.id) {
  81. data.forEach((res) => {
  82. if (bettingInfo.id == res.id) {
  83. callback && callback(res, false);
  84. betting.splice(index, 1);
  85. }
  86. })
  87. isTrue = false;
  88. }
  89. });
  90. //添加投注数据
  91. if (isTrue) {
  92. if(limit >= 10 ) {
  93. isAlert =true;
  94. }else{
  95. betting.push(bettingInfo);
  96. betting.forEach((e) => {
  97. if (bettingInfo.id == e.id) {
  98. data.forEach(res => {
  99. if (bettingInfo.id == res.id) {
  100. callback && callback(res, true);
  101. }
  102. })
  103. }
  104. })
  105. }
  106. }
  107. //初始化添加投注数据
  108. let obj = {
  109. title: name,
  110. data: betting
  111. };
  112. let array = [];
  113. if (dataNum != 10000) {
  114. getBettingList[dataNum] = obj;
  115. } else {
  116. if (getBettingList) {
  117. if (getBettingList.length > 0) {
  118. getBettingList.push(obj);
  119. }
  120. } else {
  121. array.push(obj);
  122. }
  123. }
  124. fun && fun(getBettingList, array,isAlert);
  125. },
  126. /**
  127. * 获取vuex相对应玩法index下标和投注数据集合
  128. * @param {组件类所有玩法数据集合} data
  129. * @param {组件里玩法别名} title
  130. * @param {从Vuex里面的投注列表的匹配对应的投注数据集合} betting
  131. * @param {相对应玩法index下标} dataNum
  132. */
  133. getBettingId(data, title, callback) {
  134. if (data) {
  135. data.forEach((res, index) => {
  136. if (res.title == title) {
  137. callback && callback(res.data, index);
  138. }
  139. });
  140. }
  141. },
  142. /**
  143. * 接口轮询定时器
  144. * @param {function} callback 定时器回调方法
  145. */
  146. ajaxTimerFun(callback,timers=2000){
  147. //到计时
  148. let timing = setInterval(function(){
  149. callback && callback(timing)
  150. },timers);
  151. // },5000);
  152. },
  153. /**
  154. * 复合算法
  155. * @param {int} data 第几场赛事
  156. * @param {array} dataList 投注赛事列表
  157. */
  158. betPlay(data,dataList){
  159. let addSum =0;
  160. let listLenth = dataList.length;
  161. //调用赔率算法
  162. addSum = this.oddsAlgorithm(data,dataList);
  163. //组合算法分母
  164. function denominator (num){
  165. let group =1;
  166. for(let i = listLenth ; i >(listLenth -num);i--){
  167. let add = group*i
  168. group = add;
  169. }
  170. return group;
  171. }
  172. //组合算法分子
  173. function molecule (num){
  174. let son =1;
  175. for(let i = num ; i >1;i--){
  176. let add = son*i;
  177. son = add;
  178. }
  179. return son;
  180. }
  181. //组合算法
  182. function algorithm(data) {
  183. return {
  184. title:`${data}串1`,//algorithm
  185. index:denominator(data)/molecule(data),
  186. odds:addSum,
  187. };
  188. }
  189. return algorithm(data);
  190. },
  191. /**
  192. * 赔率算法
  193. * @param {int} index 第几次赛事
  194. * @param {[]} dataList 赛事列表
  195. */
  196. oddsAlgorithm(index,dataList){
  197. let oddsArray=[];
  198. let num = index;
  199. let list = [];
  200. dataList.forEach((res)=>{
  201. oddsArray.push(res.odds);
  202. })
  203. for (let i=0;i<Math.pow(2, oddsArray.length);i++){
  204. let a = 0;
  205. let b = "";
  206. for (let j=0;j<oddsArray.length;j++){
  207. if (i>>j&1){
  208. a++;
  209. b += oddsArray[j]+',';
  210. }
  211. }
  212. if(a==num){
  213. let array = b.split(',');
  214. array.pop();
  215. list.push(array);
  216. }
  217. }
  218. let odds =0;
  219. list.forEach(e=>{
  220. let h =1;
  221. e.forEach(res=>{
  222. h = h*(1+res*1)
  223. })
  224. odds +=h*1-1;
  225. })
  226. return odds;
  227. }
  228. }