bad390c8a33169f7c8282c8c00d30e73fabafd34.svn-base 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { type } from "os";
  2. export default {
  3. //数据存放到缓存
  4. setCache: function (key, val) {
  5. if (val instanceof Array) {
  6. let str = JSON.stringify(val);
  7. window.sessionStorage.setItem(key, str);
  8. } else {
  9. window.sessionStorage.setItem(key, val);
  10. }
  11. },
  12. //获取缓存数据
  13. getCache: function (key) {
  14. return window.sessionStorage.getItem(key);
  15. },
  16. /**
  17. * 比赛时间计时器
  18. * @param {分钟} f
  19. * @param {秒} s
  20. * @param {回掉方法} fun
  21. */
  22. timer: function (f, s, fun) {
  23. let timing = setInterval(function () {
  24. s++;
  25. if (s < 10) {
  26. s = "0" + s;
  27. }
  28. if (s == 60) {
  29. f++;
  30. s = '00';
  31. }
  32. fun && fun(f, s);
  33. }, 1000)
  34. },
  35. /**
  36. * 玩法投注公共方法
  37. * @param {玩法组件的选择赔率id数组} betting
  38. * @param {*当前玩法赔率及相关数据} bettingInfo
  39. * @param {*当前玩法赔率数据信息列表} data
  40. * @param {*Vuex里面的投注列表} getBettingList
  41. * @param {*当前组的玩法的title} name
  42. * @param {*判断当前组件是否已有投注} dataNum
  43. * @param {*修改当前样式回调方法} callback
  44. * @param {*更新Vuex投注列表} fun
  45. */
  46. bettingFunction: function (betting, bettingInfo, data, getBettingList, name, dataNum, callback, fun) {
  47. let isTrue = true;
  48. betting.forEach((e, index) => {
  49. if (bettingInfo.id == e.id) {
  50. data.forEach((res) => {
  51. if (bettingInfo.id == res.id) {
  52. callback && callback(res, false);
  53. betting.splice(index, 1);
  54. }
  55. })
  56. isTrue = false;
  57. }
  58. });
  59. if (isTrue) {
  60. betting.push(bettingInfo);
  61. betting.forEach((e) => {
  62. if (bettingInfo.id == e.id) {
  63. data.forEach(res => {
  64. if (bettingInfo.id == res.id) {
  65. callback && callback(res, true);
  66. }
  67. })
  68. isTrue = false;
  69. }
  70. })
  71. }
  72. let obj = {
  73. title: name,
  74. data: betting
  75. };
  76. let array = [];
  77. if (dataNum != 10000) {
  78. getBettingList[dataNum] = obj;
  79. } else {
  80. if (getBettingList) {
  81. if (getBettingList.length > 0) {
  82. getBettingList.push(obj);
  83. }
  84. } else {
  85. array.push(obj);
  86. }
  87. }
  88. fun && fun(getBettingList, array);
  89. },
  90. /**
  91. * 获取vuex相对应玩法index下标和投注数据集合
  92. * @param {组件类所有玩法数据集合} data
  93. * @param {组件里玩法别名} title
  94. * @param {从Vuex里面的投注列表的匹配对应的投注数据集合} betting
  95. * @param {相对应玩法index下标} dataNum
  96. */
  97. getBettingId(data, title, callback) {
  98. if (data) {
  99. data.forEach((res, index) => {
  100. if (res.title == title) {
  101. callback && callback(res.data, index);
  102. }
  103. });
  104. }
  105. }
  106. }