diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..cedc407 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +bottle==0.12.13 +tinydb==3.7.0 diff --git a/src/static/index.js b/src/static/index.js index 278432a..6b1060d 100644 --- a/src/static/index.js +++ b/src/static/index.js @@ -1,118 +1,19 @@ $(document).ready(function () { - /* var running; - - 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: '
' - }); - }*/ new UI(); }); -class BS{ - constructor(){ + +class BS { + constructor() { } - static fetch(url,data,type){ - return new Promise((resolve)=>{ + + static fetch(url, data, type) { + return new Promise((resolve) => { $.ajax({ - type:type?type:'GET', - data:data?data:{}, + type: type ? type : 'GET', + data: data ? data : {}, url, - success(resp){ + success(resp) { resolve(resp) } }) @@ -120,153 +21,38 @@ class BS{ } - static run(award_id){ - return this.fetch('/run',{ - award_id - },'POST'); + static run() { + return this.fetch('/run'); } - 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'); } - static getLuckyUsers(){ + + static getLuckyUsers() { return this.fetch('/luckless_users'); } - static getAwards(){ + + static getAwards() { return this.fetch('/awards'); } - static getUsers(){ + + static getUsers() { return this.fetch('/users'); } } + class UI { constructor() { this.running = false; - 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.entries = []; this.settings = { - entries: this.entries, width: 800, height: 600, radius: '65%', @@ -298,15 +84,26 @@ class UI { // tooltipDiffY: 10 }; - this.svg3DTagCloud = new SVG3DTagCloud(document.getElementById('holder'), this.settings); - this.buildCloud(); + this.buildCloud().then(()=>{ + this.settings.entries = this.entries; + this.svg3DTagCloud = new SVG3DTagCloud(document.getElementById('holder'), this.settings); + }); this.bindEvent(); } - - buildCloud() { - BS.getUsers().then((resp)=>{ - console.log(resp) + return BS.getUsers().then((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; }) } @@ -316,14 +113,23 @@ class UI { alert('正在抽奖'); return; } - this.svg3DTagCloud.speed(6); - this.running = true; - + //todo + BS.run().then(resp=>{ + console.log(resp); + this.svg3DTagCloud.speed(6); + this.running = true; + }); }); $('#end').click(() => { console.log('click'); - this.stop(); - this.render(1); + //todo + BS.stopAndResult("9f7cfd85a39e40f2975e7a62ca9dbca5").then(resp=>{ + console.log(resp); + this.stop(); + let uid= 'G0001'; + let index = $(`[data-uid=${uid}]`).data('index'); + this.render(index); + }); }); $('#test').click(() => { this.list(); @@ -332,13 +138,14 @@ class UI { } render(i) { - console.log(i); + this.chose(i); + /* console.log(i); if (i >= 5) { setTimeout(() => { this.stop(); - setTimeout(()=>{ + setTimeout(() => { this.list(); - },1000) + }, 1000) }, 1000); return; } @@ -348,7 +155,7 @@ class UI { this.chose(i); this.render(++i); }, 500) - }, 2500) + }, 2500)*/ } stop() { diff --git a/src/static/jquery-svg3dtagcloud-plugin-master/js/jquery.svg3dtagcloud.js b/src/static/jquery-svg3dtagcloud-plugin-master/js/jquery.svg3dtagcloud.js index 4dee8b5..21ab389 100644 --- a/src/static/jquery-svg3dtagcloud-plugin-master/js/jquery.svg3dtagcloud.js +++ b/src/static/jquery-svg3dtagcloud-plugin-master/js/jquery.svg3dtagcloud.js @@ -261,6 +261,9 @@ THE SOFTWARE. entry.link = document.createElementNS( svgNS, 'a' ); entry.link.setAttributeNS( 'http://www.w3.org/1999/xlink', 'xlink:href', entryObj.url ); 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( 'mouseout', mouseOutHandler, true ); entry.link.appendChild( entry.element ); diff --git a/src/static/manage.js b/src/static/manage.js new file mode 100644 index 0000000..6a839f8 --- /dev/null +++ b/src/static/manage.js @@ -0,0 +1,44 @@ +/** + * 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){ + console.log(); + return this.fetch('/add_award',{ + award_name,award_capacity + }); + } + static getAwards(){ + return this.fetch('/awards'); + } +} +$(function(){ + BS.addAwards("一等奖",1).then(resp=>{ + console.log(resp) + }); + BS.addAwards("二等奖",5).then(resp=>{ + console.log(resp) + }); + BS.addAwards("三等奖",10).then(resp=>{ + console.log(resp) + }); + BS.getAwards().then(resp=>{ + console.log(resp); + }) +}); \ No newline at end of file diff --git a/src/templates/index.html b/src/templates/index.html index 04bfea1..a953652 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -18,6 +18,7 @@
@@ -25,7 +26,7 @@

开始 停止 - 中奖 + 中奖结果

diff --git a/src/templates/manage.html b/src/templates/manage.html index 566549b..8442e33 100644 --- a/src/templates/manage.html +++ b/src/templates/manage.html @@ -3,8 +3,19 @@ Title + + + - + +增加 +修改 +删除 + + + \ No newline at end of file diff --git a/src/users_db.py b/src/users_db.py index d6c5859..e83a083 100644 --- a/src/users_db.py +++ b/src/users_db.py @@ -3,4 +3,35 @@ 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 + } + ]