diff --git a/src/mock/index.js b/src/mock/index.js index 3909f3d..2d2e85d 100644 --- a/src/mock/index.js +++ b/src/mock/index.js @@ -1,13 +1,27 @@ const data = [ + // 3% { - lottery: [], + lottery: ['五星仙元', '四星仙元'], min: 1, - max: 2, + max: 3, }, + // 7% { - lottery: [], - min: 1, - max: 2, + lottery: ['转生四星法宝', '转生五星法宝'], + min: 3, + max: 10, + }, + // 12% + { + lottery: ['五星20速坐骑', '四星18速坐骑'], + min: 10, + max: 23, + }, + // 20% + { + lottery: ['五星加强天书', '四星加强天书', '五星加强妖石', '四星加强妖石'], + min: 23, + max: 44, }, ] diff --git a/src/pages/index.vue b/src/pages/index.vue index b1f39a8..c1aa05a 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -62,8 +62,22 @@ const chou = number => { const suan = () => { const n = Math.random() * 100 const r = getRnadomFiveInt() + let boo = false + let result = '' // 通过这个n 来跟奖品数据lotteryList进行对比得出 在min 和 max之间返回回来 而后在list中随机出一个 - return `五星仙元-${r}` + lotteryList.map(item => { + if (item.min <= n && item.max > n) { + boo = true + // 命中该奖品类 + const data = item.lottery + // 随机在data中选中一个返回 + result = `${data[Math.floor(Math.random() * data.length)]}-${r}` + } + }) + if (boo) { + return result + } + return `200w银元宝-${r}` } const getRnadomFiveInt = () => {