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.css b/src/static/index.css index 6cfbbc5..08e7db1 100644 --- a/src/static/index.css +++ b/src/static/index.css @@ -21,27 +21,28 @@ body { overflow: hidden; background: url("./images/bg.jpg") no-repeat; 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{ width:1024px; height:768px; min-width:800px; margin:0 auto; - border:1px solid white; + /*border:1px solid white;*/ } .holder{ width:800px; + min-height:600px; /*margin:0 auto;*/ } .btns{ text-align: center; } -.btns a{ +.btns button{ margin-left: 10px; margin-right: 10px; } -.btns a i{ +.btns button i{ margin-right: 6px; } .title{ @@ -84,4 +85,35 @@ h4{ margin-left: 10px; margin-right: 5px; 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; } \ No newline at end of file diff --git a/src/static/index.js b/src/static/index.js index 278432a..17f5414 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(); + new Index(); }); -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,45 @@ 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(){ - return this.fetch('/luckless_users'); + static getLuckyUsers() { + return this.fetch('/lucky_users'); } - static getAwards(){ + + static getAwards() { return this.fetch('/awards'); } - static getUsers(){ + + static getAward(award_id) { + return this.fetch('/award', { + award_id + }); + } + + static getUsers() { return this.fetch('/users'); } + } -class UI { + +class Index { 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.currentAward = ''; + this.entries = []; this.settings = { - entries: this.entries, width: 800, height: 600, radius: '65%', @@ -298,85 +91,213 @@ class UI { // tooltipDiffY: 10 }; - this.svg3DTagCloud = new SVG3DTagCloud(document.getElementById('holder'), this.settings); - this.buildCloud(); + this.buildCloud().then(() => { + this.svg3DTagCloud = new SVG3DTagCloud(document.getElementById('holder'), this.settings); + }); this.bindEvent(); - } + this.initVisualSocket(); + } buildCloud() { - BS.getUsers().then((resp)=>{ - console.log(resp) + return BS.getLucklessUsers().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; + 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() { $('#start').click(() => { if (this.running) { alert('正在抽奖'); return; } - this.svg3DTagCloud.speed(6); - this.running = true; - + BS.run().then(resp => { + console.log(resp); + this.svg3DTagCloud.speed(6); + this.running = true; + }); }); $('#end').click(() => { + if (!this.running) { + return; + } console.log('click'); - this.stop(); - this.render(1); + BS.stopAndResult(this.currentAward).then(resp => { + this.running = false; + console.log(resp); + if (resp.status === 200) { + this.render(resp.data, 0); + } + }); }); - $('#test').click(() => { + $('#luckyUsers').click(() => { this.list(); }); } - render(i) { - console.log(i); - if (i >= 5) { - setTimeout(() => { - this.stop(); - setTimeout(()=>{ - this.list(); - },1000) - }, 1000); + render(data, i) { + // debugger + if (i >= data.length) { + this.currentlist(data); + this.rebuild(); return; } - setTimeout(() => { - this.stop(); - setTimeout(() => { - this.chose(i); - this.render(++i); - }, 500) - }, 2500) + this.chose(data[i]).then(() => { + i++; + this.render(data, i); + }); } stop() { - this.running = false; this.svg3DTagCloud.reset(); this.svg3DTagCloud.speed(1); } - chose(i) { - this.svg3DTagCloud.chose([{ - index: 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([{ + index + }]); + let currentList = `
  • ${name}
  • `; + $('.current-list').append(currentList); + setTimeout(() => { + // this.stop() + resolve(); + }, 3 * 1000) + }).then(() => { + return new Promise((resolve) => { + this.stop(); + setTimeout(() => { + resolve(); + }, 500) + }); - let currentList = `
  • 张三三
  • `; - $('.current-list').append(currentList); + }) } - list() { + currentlist(data) { let offset = $(".holder").offset(); + let DOM = '`; layer.open({ type: 1, area: '800px', + skin: 'layui-layer-lan', //样式类名 offset: [offset.top, offset.left], closeBtn: 1, //不显示关闭按钮 anim: 3, - title: '中奖名单', + title: '本次中奖名单', shadeClose: false, //开启遮罩关闭 - content: '
    ' + content: `
    ${DOM}
    ` + }); + } + + list() { + 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 `
  • ${data.name}【${data.uid}】
  • ` + }); + content+=` +
    +
    ${award.name}
    + +
    `; + } + layer.open({ + type: 1, + area: '800px', + skin: 'layui-layer-lan', //样式类名 + offset: [offset.top, offset.left], + closeBtn: 1, //不显示关闭按钮 + anim: 3, + title: '所有中奖名单', + shadeClose: false, //开启遮罩关闭 + content: ` +
    ${content} +
    ` + }); }); } } 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..9885a4a 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 ); @@ -277,6 +280,7 @@ THE SOFTWARE. } entry.index = index; + entry.uid = entryObj.uid; entry.mouseOver = false; entry.vectorPosition = { x:x, y:y, z:z }; diff --git a/src/static/manage.css b/src/static/manage.css new file mode 100644 index 0000000..91e0d14 --- /dev/null +++ b/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; +} \ No newline at end of file diff --git a/src/static/manage.js b/src/static/manage.js new file mode 100644 index 0000000..3f43688 --- /dev/null +++ b/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: ` +
    奖品名
    +
    数 量
    +`, + 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 = ` +
  • +
    + 设置成当前轮 + +
    +
    + 奖项名称:${val.award_name},数量:${val.award_capacity} +
    +
  • `; + ul += list; + }) + $('#awardList').html(ul) + }) +} \ No newline at end of file diff --git a/src/templates/index.html b/src/templates/index.html index 04bfea1..3ca713e 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -12,20 +12,21 @@
    -

    当前奖项:二等奖

    -

    抽取人数:1

    +

    当前奖项:设置中

    +

    抽取人数:设置中

      +

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

    diff --git a/src/templates/manage.html b/src/templates/manage.html index 566549b..7d57269 100644 --- a/src/templates/manage.html +++ b/src/templates/manage.html @@ -3,8 +3,19 @@ Title + + + + +增加 +reset + + + + \ 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 + } + ]