年会抽奖页面html,index.html

年会抽奖

rel="stylesheet"

href="js/element-ui@2.4.11/lib/theme-chalk/index.css"

/>

{{ item.name }}

@click="onKick(item, index)"

class="lucky-dog"

v-for="(item, index) in result[currentAward]"

:key="index"

>

{{ item.name }}

换个现代浏览器吧!

v-for="(item, index) in awards"

:key="index"

:label="item.name"

:value="index"

>

{{

buttonText

}}

下一轮

size="small"

:disabled="running"

type="warning"

size="small"

class="el-icon-refresh"

@click="onReplay"

circle

>

{{players.length}}

new Vue({

el: '#app',

data: {

running: false,

awards: [],

currentAward: 0,

result: [],

players: [],

batchPlayers: [],

members: [],

},

watch: {

currentAward: function() {

this.batchPlayers = [];

},

},

computed: {

buttonDisabled: function() {

return (

this.result[this.currentAward].length >=

this.awards[this.currentAward].count || this.players.length === 0

);

},

goOn: function() {

return (

this.result[this.currentAward].length <

this.awards[this.currentAward].count &&

this.result[this.currentAward].length > 0

);

},

buttonText: function() {

if (this.running) {

return '停止';

}

if (this.goOn) {

return '继续';

}

return '开始';

},

},

methods: {

toggle: function() {

if (this.running) {

this.stop();

} else {

this.start();

}

},

getSpeed: function() {

return [0.1 * Math.random() + 0.01, -(0.1 * Math.random() + 0.01)];

},

start: function() {

this.running = true;

TagCanvas.SetSpeed('myCanvas', [5, 1]);

},

stop: function() {

this.running = false;

TagCanvas.SetSpeed('myCanvas', this.getSpeed());

var total = this.awards[this.currentAward].count;

this.result[this.currentAward] =

this.result[this.currentAward] || [];

var todo = total - this.result[this.currentAward].length;

var N = +localStorage.getItem('batchNumber') || 20;

var batchPlayers = [];

for (var i = 0, ln = Math.min(N, todo, this.players.length); i < ln; i++) {

var index = this.getRandomInt(0, this.players.length - 1);

batchPlayers.push(this.players.splice(index, 1)[0]);

}

//

// if (this.players.length === 0) {

// this.players = this.copy(this.members);

// this.$alert('所有人员都已中奖,剩余奖品将在现场所有人里抽取', '提示')

// }

this.batchPlayers = batchPlayers;

this.result.splice(

this.currentAward,

1,

this.result[this.currentAward].concat(batchPlayers)

);

localStorage.setItem('players', JSON.stringify(this.players));

localStorage.setItem('result', JSON.stringify(this.result));

TagCanvas.Reload('myCanvas');

},

onNext: function() {

this.batchPlayers = [];

if (this.currentAward < this.awards.length - 1) {

this.currentAward += 1;

}

},

getRandomInt: function(min, max) {

min = Math.ceil(min);

max = Math.floor(max);

return Math.floor(Math.random() * (max - min + 1)) + min;

},

init: function() {

try {

TagCanvas.Start('myCanvas', 'tags', {

textColour: null,

dragControl: 1,

decel: 0.95,

textHeight: 14,

minSpeed: 0.01,

initial: [

0.1 * Math.random() + 0.01,

-(0.1 * Math.random() + 0.01),

],

});

} catch (e) {

// something went wrong, hide the canvas container

document.getElementById('myCanvasContainer').style.display =

'none';

}

},

onReplay: function() {

var vm = this;

this.$confirm('重新抽奖会清空当前奖项的结果,无法撤销!', '确定要重新抽奖吗?', {

confirmButtonText: '确定',

cancelButtonText: '取消',

type: 'warning',

}).then(function() {

vm.batchPlayers = [];

var p = vm.result.splice(vm.currentAward, 1, []);

vm.players = vm.players.concat(p[0]);

localStorage.setItem('players', JSON.stringify(vm.players))

localStorage.setItem('result', JSON.stringify(vm.result));

});

},

onKeyup: function(e) {

console.log(e);

// 空格或回车键

if (e.keyCode === 13 || e.keyCode === 32) {

this.$refs.action.$el.click();

}

},

copy: function(obj) {

return JSON.parse(JSON.stringify(obj));

},

onKick: function(player) {

var vm = this;

var index = vm.result[vm.currentAward].indexOf(player);

this.$confirm('去掉后可继续抽一名', '去掉这名中奖者吗?', {

confirmButtonText: '确定',

cancelButtonText: '取消',

type: 'warning',

}).then(function() {

if (vm.batchPlayers.indexOf(player) > -1) {

vm.batchPlayers.splice(vm.batchPlayers.indexOf(player), 1);

}

vm.result[vm.currentAward].splice(index, 1);

localStorage.setItem('result', JSON.stringify(vm.result));

});

},

},

created: function() {

this.awards = JSON.parse(localStorage.getItem('awards')) || [];

if (this.awards.length === 0) {

location.href = 'setting.html';

}

var result = JSON.parse(localStorage.getItem('result')) || [];

for (var i = 0; i < this.awards.length; i++) {

result[i] = result[i] || [];

}

this.result = result;

this.choosed = JSON.parse(localStorage.getItem('choosed')) || {};

console.log(this.choosed);

var awards = JSON.parse(localStorage.getItem('awards')) || [];

this.rewards = awards.map(function(item, index) {

return {

level: index + 1,

name: item.name,

count: item.count,

editing: {},

};

});

console.log(this.rewards);

},

mounted: function() {

var members = JSON.parse(localStorage.getItem('members')) || window.members;

this.players = JSON.parse(localStorage.getItem('players')) || members;

this.members = this.copy(members);

localStorage.setItem('players', JSON.stringify(this.players));

var canvas = this.$refs.canvas;

canvas.width = document.body.offsetWidth;

canvas.height = document.body.offsetHeight;

this.$nextTick(function() {

this.init();

});

document.body.addEventListener('keyup', this.onKeyup)

},

});

一键复制

编辑

Web IDE

原始数据

按行查看

历史

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值