luoning 8 years ago
parent
commit
1201f7ca32
  1. 2
      requirements.txt
  2. 40
      src/static/index.css
  3. 441
      src/static/index.js
  4. 4
      src/static/jquery-svg3dtagcloud-plugin-master/js/jquery.svg3dtagcloud.js
  5. 47
      src/static/manage.css
  6. 117
      src/static/manage.js
  7. 11
      src/templates/index.html
  8. 11
      src/templates/manage.html
  9. 33
      src/users_db.py

2
requirements.txt

@ -0,0 +1,2 @@
bottle==0.12.13
tinydb==3.7.0

40
src/static/index.css

@ -21,27 +21,28 @@ body {
overflow: hidden; overflow: hidden;
background: url("./images/bg.jpg") no-repeat; background: url("./images/bg.jpg") no-repeat;
background-color: #141a48; background-color: #141a48;
font-family:"Microsoft YaHei UI","Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; font-family:"Microsoft YaHei","Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
} }
.content{ .content{
width:1024px; width:1024px;
height:768px; height:768px;
min-width:800px; min-width:800px;
margin:0 auto; margin:0 auto;
border:1px solid white; /*border:1px solid white;*/
} }
.holder{ .holder{
width:800px; width:800px;
min-height:600px;
/*margin:0 auto;*/ /*margin:0 auto;*/
} }
.btns{ .btns{
text-align: center; text-align: center;
} }
.btns a{ .btns button{
margin-left: 10px; margin-left: 10px;
margin-right: 10px; margin-right: 10px;
} }
.btns a i{ .btns button i{
margin-right: 6px; margin-right: 6px;
} }
.title{ .title{
@ -85,3 +86,34 @@ h4{
margin-right: 5px; margin-right: 5px;
color: #ffffff; color: #ffffff;
} }
.luckerList h5{
font-size: 22px;
margin-top: 10px;
margin-bottom: 10px;
padding-bottom: 8px;
padding-top: 8px;
border-bottom: 1px solid rgba(34, 36, 38, .15);
}
.luckerList{
padding-left: 10px;
padding-right: 10px;
box-sizing: border-box;
}
.luckerList ul{
padding-left: 10px;
padding-right: 10px;
box-sizing: border-box;
list-style: none;
}
.luckerList ul li:first-child{
border-top: none;
}
.luckerList ul li{
box-sizing: border-box;
font-size: 16px;
padding-bottom: 10px;
/*border-bottom: 1px solid rgba(34, 36, 38, .15);*/
}
.luckerList ul li span{
font-size: 12px;
}

441
src/static/index.js

@ -1,111 +1,12 @@
$(document).ready(function () { $(document).ready(function () {
/* var running; new Index();
var settings = {
entries: entries,
width: 800,
height: 600,
radius: '65%',
radiusMin: 75,
bgDraw: true,
bgColor: 'none',
opacityOver: 0.90,
opacityOut: 0.05,
opacitySpeed: 1,
fov: 500,
speed: 1,
fontFamily: 'Oswald, Arial, sans-serif',
fontSize: '15',
hoverFontSize: '55',
fontColor: '#fff',
fontWeight: 'normal',//bold
fontStyle: 'normal',//italic
fontStretch: 'wider',//wider, narrower, ultra-condensed, extra-condensed, condensed, semi-condensed, semi-expanded, expanded, extra-expanded, ultra-expanded
fontToUpperCase: true,
// tooltipFontFamily: 'Oswald, Arial, sans-serif',
// tooltipFontSize: '11',
// tooltipFontColor: '#fff',
// tooltipFontWeight: 'normal',//bold
// tooltipFontStyle: 'normal',//italic
// tooltipFontStretch: 'normal',//wider, narrower, ultra-condensed, extra-condensed, condensed, semi-condensed, semi-expanded, expanded, extra-expanded, ultra-expanded
// tooltipFontToUpperCase: false,
// tooltipTextAnchor: 'left',
// tooltipDiffX: 0,
// tooltipDiffY: 10
};
var svg3DTagCloud = new SVG3DTagCloud(document.getElementById('holder'), settings);*/
/* $('#start').click(function () {
if (running) {
alert('正在抽奖');
return;
}
svg3DTagCloud.speed(6);
running = true;
});
$('#end').click(function () {
stop();
render(1);
}); });
$('#test').click(function () {
list();
});*/
// $( '#holder' ).svg3DTagCloud( settings );
/* function render(i) {
console.log(i);
if (i === 5) {
setTimeout(function () {
list();
stop();
}, 1000);
return;
}
;
setTimeout(function () {
stop();
setTimeout(function () {
chose(i);
render(++i);
}, 500)
}, 2500)
}
function stop() {
running = false;
svg3DTagCloud.reset();
svg3DTagCloud.speed(1);
}
function chose(i) {
svg3DTagCloud.chose([{
index: i
}]);
}
function list() {
var offset = $(".holder").offset();
layer.open({
type: 1,
area: '800px',
offset: [offset.top, offset.left],
closeBtn: 1, //不显示关闭按钮
anim: 3,
title: '中奖名单',
shadeClose: false, //开启遮罩关闭
content: '<div class="luckerList"><ul><li>1111</li><li>111</li><li>2222</li></ul></div>'
});
}*/
new UI();
});
class BS { class BS {
constructor() { constructor() {
} }
static fetch(url, data, type) { static fetch(url, data, type) {
return new Promise((resolve) => { return new Promise((resolve) => {
$.ajax({ $.ajax({
@ -120,153 +21,45 @@ class BS{
} }
static run(award_id){ static run() {
return this.fetch('/run',{ return this.fetch('/run');
award_id
},'POST');
} }
static stopAndResult(){
return this.fetch('/draw_lottery'); static stopAndResult(award_id) {
return this.fetch('/draw_lottery', {award_id});
} }
static getLucklessUsers() { static getLucklessUsers() {
return this.fetch('/luckless_users'); return this.fetch('/luckless_users');
} }
static getLuckyUsers(){
return this.fetch('/luckless_users');
static getLuckyUsers() {
return this.fetch('/lucky_users');
} }
static getAwards() { static getAwards() {
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 Index {
constructor() { constructor() {
this.running = false; this.running = false;
this.entries = [ this.currentAward = '';
this.entries = [];
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '张三三', url:'javascript:void(0)', target: '_top', id: 'admin'},
{label: '李四', url: 'http://www.flashforum.de/', target: '_top'},
{label: '王污污', url: 'http://www.jqueryscript.net/', target: '_top'},
{label: '赵六六', url: 'http://www.jqueryscript.net/', target: '_top'},
{label: '赵六六', url: 'http://www.jqueryscript.net/', target: '_top'},
];
this.settings = { this.settings = {
entries: this.entries,
width: 800, width: 800,
height: 600, height: 600,
radius: '65%', radius: '65%',
@ -298,85 +91,213 @@ class UI {
// tooltipDiffY: 10 // tooltipDiffY: 10
}; };
this.buildCloud().then(() => {
this.svg3DTagCloud = new SVG3DTagCloud(document.getElementById('holder'), this.settings); this.svg3DTagCloud = new SVG3DTagCloud(document.getElementById('holder'), this.settings);
this.buildCloud(); });
this.bindEvent(); this.bindEvent();
} this.initVisualSocket();
}
buildCloud() { buildCloud() {
BS.getUsers().then((resp)=>{ return BS.getLucklessUsers().then((resp) => {
console.log(resp) console.log(resp);
let entry = [];
$(resp.data).each((i, val) => {
entry.push({
label: val.name,
uid: val.uid,
role: val.role,
url: 'javascript:void(0)',
target: '_top'
})
});
this.entries = entry;
this.settings.entries = this.entries;
})
}
rebuild() {
this.buildCloud().then(() => {
$('.holder').empty();
this.svg3DTagCloud = new SVG3DTagCloud(document.getElementById('holder'), this.settings);
})
}
initVisualSocket() {
// this.refreshCurrentAward();
let tempAwardId = '';
setInterval(() => {
tempAwardId = localStorage.getItem('current_award');
if (this.currentAward !== tempAwardId) {
/*change*/
// window.location.reload(1);
this.currentAward = tempAwardId;
this.refreshCurrentAward();
}
}, 2 * 1000);
}
refreshCurrentAward() {
if (this.currentAward === '') return;
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;
} }
BS.run().then(resp => {
console.log(resp);
this.svg3DTagCloud.speed(6); this.svg3DTagCloud.speed(6);
this.running = true; this.running = true;
});
}); });
$('#end').click(() => { $('#end').click(() => {
if (!this.running) {
return;
}
console.log('click'); console.log('click');
this.stop(); BS.stopAndResult(this.currentAward).then(resp => {
this.render(1); this.running = false;
console.log(resp);
if (resp.status === 200) {
this.render(resp.data, 0);
}
}); });
$('#test').click(() => { });
$('#luckyUsers').click(() => {
this.list(); this.list();
}); });
} }
render(i) { render(data, i) {
console.log(i); // debugger
if (i >= 5) { if (i >= data.length) {
setTimeout(() => { this.currentlist(data);
this.stop(); this.rebuild();
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() {
this.running = false;
this.svg3DTagCloud.reset(); this.svg3DTagCloud.reset();
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',
skin: 'layui-layer-lan', //样式类名
offset: [offset.top, offset.left],
closeBtn: 1, //不显示关闭按钮
anim: 3,
title: '本次中奖名单',
shadeClose: false, //开启遮罩关闭
content: `<div class="luckerList">${DOM}</div>`
});
} }
list() { list() {
let offset = $(".holder").offset(); let offset = $(".holder").offset();
let awards={};
let load=layer.load(2);
BS.getAwards().then(resp=>{
resp.data.map((val)=>{
console.log(val);
if(typeof awards[val.award_id]==="undefined"){
awards[val.award_id]={};
}
awards[val.award_id].name = val.award_name;
awards[val.award_id].data=[];
})
}).then(()=>{
return BS.getLuckyUsers().then(resp => {
resp.data.map(val=>{
awards[val.award_id].data.push(val)
})
});
}).then(()=>{
layer.close(load);
console.log(awards);
let content = ``;
for(let key of Object.keys(awards)){
let award = awards[key];
let lisArray=award.data.map((data)=>{
return `<li class="${data.role==2||data.role==3?'sp':''}">${data.name}<span>【${data.uid}】</span></li>`
});
content+=`
<section>
<h5>${award.name}</h5>
<ul>
${lisArray.join("")}
</ul>
</section>`;
}
layer.open({ layer.open({
type: 1, type: 1,
area: '800px', area: '800px',
skin: 'layui-layer-lan', //样式类名
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">${content}
</div>`
});
}); });
} }
} }

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

@ -261,6 +261,9 @@ THE SOFTWARE.
entry.link = document.createElementNS( svgNS, 'a' ); entry.link = document.createElementNS( svgNS, 'a' );
entry.link.setAttributeNS( 'http://www.w3.org/1999/xlink', 'xlink:href', entryObj.url ); entry.link.setAttributeNS( 'http://www.w3.org/1999/xlink', 'xlink:href', entryObj.url );
entry.link.setAttribute( 'target', entryObj.target ); entry.link.setAttribute( 'target', entryObj.target );
entry.link.setAttribute( 'data-uid', entryObj.uid );
entry.link.setAttribute( 'data-role', entryObj.role );
entry.link.setAttribute( 'data-index', index );
// entry.link.addEventListener( 'mouseover', mouseOverHandler, true ); // entry.link.addEventListener( 'mouseover', mouseOverHandler, true );
// entry.link.addEventListener( 'mouseout', mouseOutHandler, true ); // entry.link.addEventListener( 'mouseout', mouseOutHandler, true );
entry.link.appendChild( entry.element ); entry.link.appendChild( entry.element );
@ -277,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 };

47
src/static/manage.css

@ -0,0 +1,47 @@
.fr {
float: right;
}
.list {
padding: 0;
display: block;
list-style: none;
}
.list > li:hover {
background: #f0f0f0;
}
.list > li {
padding-top: 5px;
padding-bottom: 5px;
display: list-item;
box-sizing: border-box;
border-top: 1px solid rgba(34, 36, 38, .15);
}
.list > li.cur .fr:before {
content: '当前轮';
font-size: 12px;
}
.list > li > div {
display: block;
vertical-align: middle;
}
.list > li:after {
content: "";
clear: both;
display: block;
height: 0;
}
.list > li .content {
font-size: 16px;
line-height: 1.5;
}
.list > li:first-child {
border-top: none;
}

117
src/static/manage.js

@ -0,0 +1,117 @@
/**
* Created by zuowenqi on 2018/2/2 0002
*/
class BS {
constructor() {
}
static fetch(url, data, type) {
return new Promise((resolve) => {
$.ajax({
type: type ? type : 'GET',
data: data ? data : {},
url,
success(resp) {
resolve(resp)
}
})
})
}
static addAwards(award_name, award_capacity) {
award_capacity *= 1;
return this.fetch('/add_award', {
award_name, award_capacity
});
}
static getAwards() {
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'));
})
}
static getCurrent() {
return localStorage.getItem('current_award');
}
}
$(function () {
$('#add').click(e => {
layer.open({
title: '增加',
content: `
<div>奖品名<input type="text" id="addname"></div>
<div>&emsp;<input type="text" id="addnum"></div>
`,
yes: function (index) {
let name = $('#addname').val();
let num = $('#addnum').val();
BS.addAwards(name, num).then(resp => {
console.log(resp);
flushAwards();
if (resp.status === 200) {
layer.close(index);
} else {
alert(resp.msg);
}
});
}
});
});
$('#reset').click(e => {
layer.confirm('确定要重置吗', (index) => {
BS.fetch('/reset').then(resp => {
if (resp.status === 200) {
layer.close(index);
}
});
});
});
$(document).on('click', '.js-set', e => {
let aid = $(e.target).data('aid');
let $lis = $('#awardList').find('li');
BS.setCurrent(aid).then((resp) => {
$lis.removeClass('cur');
$(e.target).closest('li').addClass('cur');
})
}).on('click', '.js-remove', e => {
let aid = $(e.target).data('aid');
layer.confirm('确认要删除该项?',()=>{
layer.alert('暂不支持')
})
});
flushAwards()
});
function flushAwards() {
let currentAward = BS.getCurrent();
BS.getAwards().then(resp => {
console.log(resp);
let ul = '';
resp.data.forEach((val) => {
let list = `
<li class="${currentAward === val.award_id ? 'cur' : ''}">
<div class="fr">
<a type="radio" class="button button-primary button-rounded button-small js-set" data-aid="${val.award_id}">设置成当前轮</a>
<a type="radio" class="button button-caution button-circle js-remove" data-aid="${val.award_id}"><i class="fa fa-trash"></i></a>
</div>
<div class="content">
奖项名称${val.award_name}数量${val.award_capacity}
</div>
</li>`;
ul += list;
})
$('#awardList').html(ul)
})
}

11
src/templates/index.html

@ -12,20 +12,21 @@
<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">
<ul class="current-list"> <ul class="current-list">
</ul> </ul>
</div> </div>
<div id='holder' class="holder"></div> <div id='holder' class="holder"></div>
</div> </div>
<p class="btns"> <p class="btns">
<a href="javascript:void (0)" class="button button-3d button-action button-rounded " id="start"><i class="fa fa-camera"></i>开始</a> <button href="javascript:void (0)" class="button button-3d button-action button-rounded " id="start" ><i class="fa fa-play-circle"></i>开始</button>
<a href="javascript:void (0)" class="button button-3d button-primary button-rounded" id="end"><i class="fa fa-hand-paper"></i>停止</a> <button href="javascript:void (0)" class="button button-3d button-primary button-rounded" id="end"><i class="fa fa-hand-paper"></i>停止</button>
<a href="javascript:void (0)" class="button button-3d button-primary button-rounded" id="test">中奖</a> <button href="javascript:void (0)" class="button button-3d button-primary button-rounded " id="luckyUsers" >中奖结果</button>
</p> </p>
</div> </div>

11
src/templates/manage.html

@ -3,8 +3,19 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Title</title> <title>Title</title>
<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/buttons.css">
<link rel="stylesheet" href="../static/manage.css">
</head> </head>
<body> <body>
<a href="javascript:void (0)" class="button button-primary button-rounded " id="add">增加</a>
<a href="javascript:void (0)" class="button button-caution button-rounded " id="reset">reset</a>
<ul id="awardList" class="list">
</ul>
<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/manage.js"></script>
</body> </body>
</html> </html>

33
src/users_db.py

@ -3,4 +3,35 @@
def load(): def load():
return [] return [
{
"uid": "G0001",
"name": "谷歌",
"award_id": None,
"role": 0
},
{
"uid": "G0002",
"name": "百度",
"award_id": None,
"role": 1
},
{
"uid": "G0003",
"name": "搜狗",
"award_id": None,
"role": 2
},
{
"uid": "G0004",
"name": "360",
"award_id": None,
"role": 3
},
{
"uid": "G0005",
"name": "亚马逊",
"award_id": None,
"role": 1
}
]

Loading…
Cancel
Save