Browse Source

前端联调抽奖功能

master
左文祺 8 years ago
parent
commit
3b373fa969
  1. 129
      src/static/index.js
  2. 1
      src/static/jquery-svg3dtagcloud-plugin-master/js/jquery.svg3dtagcloud.js
  3. 83
      src/static/manage.js
  4. 4
      src/templates/index.html
  5. 10
      src/templates/manage.html

129
src/static/index.js

@ -26,7 +26,7 @@ class BS {
} }
static stopAndResult(award_id) { static stopAndResult(award_id) {
return this.fetch('/draw_lottery',{award_id}); return this.fetch('/draw_lottery', {award_id});
} }
static getLucklessUsers() { static getLucklessUsers() {
@ -42,15 +42,23 @@ class BS {
return this.fetch('/awards'); return this.fetch('/awards');
} }
static getAward(award_id) {
return this.fetch('/award', {
award_id
});
}
static getUsers() { static getUsers() {
return this.fetch('/users'); return this.fetch('/users');
} }
} }
class UI { class UI {
constructor() { constructor() {
this.running = false; this.running = false;
this.currentAward = '';
this.entries = []; this.entries = [];
this.settings = { this.settings = {
width: 800, width: 800,
@ -84,12 +92,17 @@ class UI {
// tooltipDiffY: 10 // tooltipDiffY: 10
}; };
this.buildCloud().then(()=>{ this.buildCloud().then(() => {
this.settings.entries = this.entries; this.settings.entries = this.entries;
this.svg3DTagCloud = new SVG3DTagCloud(document.getElementById('holder'), this.settings); this.svg3DTagCloud = new SVG3DTagCloud(document.getElementById('holder'), this.settings);
}); });
this.bindEvent(); this.bindEvent();
this.initVisualSocket();
BS.getAwards().then(resp => {
console.log(resp)
})
} }
buildCloud() { buildCloud() {
return BS.getUsers().then((resp) => { return BS.getUsers().then((resp) => {
console.log(resp); console.log(resp);
@ -97,8 +110,8 @@ class UI {
$(resp.data).each((i, val) => { $(resp.data).each((i, val) => {
entry.push({ entry.push({
label: val.name, label: val.name,
uid:val.uid, uid: val.uid,
role:val.role, role: val.role,
url: 'javascript:void(0)', url: 'javascript:void(0)',
target: '_top' target: '_top'
}) })
@ -107,14 +120,37 @@ class UI {
}) })
} }
initVisualSocket() {
let tempAwardId = '';
setInterval(() => {
tempAwardId = localStorage.getItem('current_award');
if (this.currentAward !== tempAwardId) {
this.currentAward = tempAwardId;
this.refreshCurrentAward();
}
}, 2 * 1000);
}
refreshCurrentAward() {
BS.getAward(this.currentAward).then((resp) => {
console.log(resp);
if (resp.status === 200) {
let awardInfo = resp.data;
$('#currentAwardName').html(awardInfo.award_name);
$('#currentTimes').html(awardInfo.award_capacity);
}
})
}
bindEvent() { bindEvent() {
$('#start').click(() => { $('#start').click(() => {
if (this.running) { if (this.running) {
alert('正在抽奖'); alert('正在抽奖');
return; return;
} }
//todo BS.run().then(resp => {
BS.run().then(resp=>{
console.log(resp); console.log(resp);
this.svg3DTagCloud.speed(6); this.svg3DTagCloud.speed(6);
this.running = true; this.running = true;
@ -122,13 +158,11 @@ class UI {
}); });
$('#end').click(() => { $('#end').click(() => {
console.log('click'); console.log('click');
//todo BS.stopAndResult(this.currentAward).then(resp => {
BS.stopAndResult("9f7cfd85a39e40f2975e7a62ca9dbca5").then(resp=>{
console.log(resp); console.log(resp);
this.stop(); if (resp.status === 200) {
let uid= 'G0001'; this.render(resp.data, 0);
let index = $(`[data-uid=${uid}]`).data('index'); }
this.render(index);
}); });
}); });
$('#test').click(() => { $('#test').click(() => {
@ -137,25 +171,17 @@ class UI {
} }
render(i) {
this.chose(i); render(data, i) {
/* console.log(i); // debugger
if (i >= 5) { if (i >= data.length) {
setTimeout(() => { this.currentlist(data);
this.stop();
setTimeout(() => {
this.list();
}, 1000)
}, 1000);
return; return;
} }
setTimeout(() => { this.chose(data[i]).then(() => {
this.stop(); i++;
setTimeout(() => { this.render(data, i);
this.chose(i); });
this.render(++i);
}, 500)
}, 2500)*/
} }
stop() { stop() {
@ -164,13 +190,48 @@ class UI {
this.svg3DTagCloud.speed(1); this.svg3DTagCloud.speed(1);
} }
chose(i) { chose(user) {
return new Promise((resolve) => {
let uid = user.uid;
let name = user.name;
let index = $(`[data-uid=${uid}]`).data('index');
this.svg3DTagCloud.chose([{ this.svg3DTagCloud.chose([{
index: i index
}]); }]);
let currentList = `<li><i class="fa fa-user"></i>${name}</li>`;
let currentList = `<li><i class="fa fa-user"></i>张三三</li>`;
$('.current-list').append(currentList); $('.current-list').append(currentList);
setTimeout(() => {
// this.stop()
resolve();
}, 3 * 1000)
}).then(() => {
return new Promise((resolve) => {
this.stop();
setTimeout(() => {
resolve();
}, 500)
});
})
}
currentlist(data) {
let offset = $(".holder").offset();
let DOM = '<ul>'
for (let user of data) {
DOM += `<li>${user.name}</li>`;
}
DOM += `</ul>`;
layer.open({
type: 1,
area: '800px',
offset: [offset.top, offset.left],
closeBtn: 1, //不显示关闭按钮
anim: 3,
title: '本次中奖名单',
shadeClose: false, //开启遮罩关闭
content: `<div class="luckerList">${DOM}</div>`
});
} }
list() { list() {
@ -181,7 +242,7 @@ class UI {
offset: [offset.top, offset.left], offset: [offset.top, offset.left],
closeBtn: 1, //不显示关闭按钮 closeBtn: 1, //不显示关闭按钮
anim: 3, anim: 3,
title: '中奖名单', title: '本次中奖名单',
shadeClose: false, //开启遮罩关闭 shadeClose: false, //开启遮罩关闭
content: '<div class="luckerList"><ul><li>1111</li><li>111</li><li>2222</li></ul></div>' content: '<div class="luckerList"><ul><li>1111</li><li>111</li><li>2222</li></ul></div>'
}); });

1
src/static/jquery-svg3dtagcloud-plugin-master/js/jquery.svg3dtagcloud.js

@ -280,6 +280,7 @@ THE SOFTWARE.
} }
entry.index = index; entry.index = index;
entry.uid = entryObj.uid;
entry.mouseOver = false; entry.mouseOver = false;
entry.vectorPosition = { x:x, y:y, z:z }; entry.vectorPosition = { x:x, y:y, z:z };

83
src/static/manage.js

@ -1,44 +1,85 @@
/** /**
* Created by zuowenqi on 2018/2/2 0002 * Created by zuowenqi on 2018/2/2 0002
*/ */
class BS{ class BS {
constructor(){ constructor() {
} }
static fetch(url,data,type){
return new Promise((resolve)=>{ static fetch(url, data, type) {
return new Promise((resolve) => {
$.ajax({ $.ajax({
type:type?type:'GET', type: type ? type : 'GET',
data:data?data:{}, data: data ? data : {},
url, url,
success(resp){ success(resp) {
resolve(resp) resolve(resp)
} }
}) })
}) })
} }
static addAwards(award_name,award_capacity){
console.log(); static addAwards(award_name, award_capacity) {
return this.fetch('/add_award',{ award_capacity*=1;
award_name,award_capacity return this.fetch('/add_award', {
award_name, award_capacity
}); });
} }
static getAwards(){
static getAwards() {
return this.fetch('/awards'); return this.fetch('/awards');
} }
static setCurrent(id){
return new Promise(resolve=>{
let prev =localStorage.getItem('current_award')||'';
localStorage.setItem('prev_award',prev);
localStorage.setItem('current_award',id);
resolve(localStorage.getItem('current_award'));
})
}
} }
$(function(){
BS.addAwards("一等奖",1).then(resp=>{ $(function () {
console.log(resp) $('#add').click(e => {
layer.open({
title:'增加',
content: `<div>
奖品名<input type="text" id="addname"></div><div>
数量 <input type="text" id="addnum">
</div>`,
yes: function () {
let name = $('#addname').val();
let num = $('#addnum').val();
BS.addAwards(name, num).then(resp => {
console.log(resp);
flushAwards()
}); });
BS.addAwards("二等奖",5).then(resp=>{ }
console.log(resp)
}); });
BS.addAwards("三等奖",10).then(resp=>{
console.log(resp)
}); });
BS.getAwards().then(resp=>{ $('#reset').click(e => {
console.log(resp); BS.fetch('/reset').then(resp => {
});
});
$(document).on('click','.set',e=>{
let aid = $(e.target).data('aid');
BS.setCurrent(aid).then((resp)=>{
console.log(resp)
})
}) })
flushAwards()
}); });
function flushAwards() {
BS.getAwards().then(resp => {
console.log(resp)
let ul = ''
resp.data.forEach((val) => {
let list = `<li><label>${val.award_name},${val.award_capacity}<a type="radio" class="button button-primary set" data-aid="${val.award_id}">设置成当前轮</a></label></li>`
ul += list;
})
$('ul').html(ul)
})
}

4
src/templates/index.html

@ -12,8 +12,8 @@
<body> <body>
<div class="content"> <div class="content">
<div class=" title"> <div class=" title">
<h3>当前奖项:二等奖</h3> <h3>当前奖项:<span id="currentAwardName">设置中</span> </h3>
<h4>抽取人数:1</h4> <h4>抽取人数:<span id="currentTimes">设置中</span></h4>
</div> </div>
<div class="row"> <div class="row">
<div class="left"> <div class="left">

10
src/templates/manage.html

@ -6,14 +6,22 @@
<link href='https://fonts.googleapis.com/css?family=Oswald&subset=latin,latin-ext' rel='stylesheet' type='text/css'> <link href='https://fonts.googleapis.com/css?family=Oswald&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="../static/web-fonts-with-css/css/fontawesome-all.min.css"> <link rel="stylesheet" href="../static/web-fonts-with-css/css/fontawesome-all.min.css">
<link rel="stylesheet" href="../static/buttons.css"> <link rel="stylesheet" href="../static/buttons.css">
<style>
ul{
list-style:none;
}
li{
margin:20px;
}
</style>
</head> </head>
<body> <body>
<ul> <ul>
<li></li>
</ul> </ul>
<a href="javascript:void (0)" class="button button-action button-rounded " id="add">增加</a> <a href="javascript:void (0)" class="button button-action button-rounded " id="add">增加</a>
<a href="javascript:void (0)" class="button button-action button-rounded " id="change">修改</a> <a href="javascript:void (0)" class="button button-action button-rounded " id="change">修改</a>
<a href="javascript:void (0)" class="button button-action button-rounded " id="remove">删除</a> <a href="javascript:void (0)" class="button button-action button-rounded " id="remove">删除</a>
<a href="javascript:void (0)" class="button button-action button-rounded " id="reset">reset</a>
<script type="text/javascript" src="../static/jquery-2.1.1.min.js"></script> <script type="text/javascript" src="../static/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../static/layer/layer.js"></script> <script type="text/javascript" src="../static/layer/layer.js"></script>
<script type="text/javascript" src="../static/manage.js"></script> <script type="text/javascript" src="../static/manage.js"></script>

Loading…
Cancel
Save