Browse Source

更新UI和抽奖效果

master
左文祺 8 years ago
parent
commit
2b58cebff3
  1. 3494
      src/static/animate.css
  2. 108
      src/static/index.css
  3. 304
      src/static/index.js
  4. 207
      src/static/js/index.js
  5. 25
      src/static/manage.js
  6. 3
      src/templates/index.html

3494
src/static/animate.css vendored

File diff suppressed because it is too large Load Diff

108
src/static/index.css

@ -21,118 +21,145 @@ body { @@ -21,118 +21,145 @@ body {
overflow: hidden;
background: url("./images/bg.jpg") no-repeat;
background-color: #141a48;
font-family:"Microsoft YaHei","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;
.content {
width: 1024px;
height: 768px;
min-width: 800px;
margin: 0 auto;
/*border:1px solid white;*/
}
.holder{
width:800px;
min-height:600px;
.holder {
width: 800px;
min-height: 600px;
/*margin:0 auto;*/
}
.btns{
.btns {
text-align: center;
}
.btns button{
.btns button {
margin-left: 10px;
margin-right: 10px;
}
.btns button i{
.btns button i {
margin-right: 6px;
}
.title{
.title {
display: flex;
color: white;
align-items: center;
}
/*.result{
display: none;
width:111px;
}*/
h3{
h3 {
font-size: 35px;
}
h4{
h4 {
margin-left: 40px;
font-size: 25px;
}
.row{
.row {
display: flex;
align-items:flex-start;
align-items: flex-start;
}
.row >div{
.row > div {
}
.luckerList{
width:800px;
height:550px;
.luckerList {
width: 800px;
height: 550px;
}
.left ul {
width: 111px;
list-style:none;
list-style: none;
font-size: 18px;
color: white;
}
.left ul li{
.left ul li {
margin-top: 10px;
margin-bottom: 10px;
}
.left ul li i{
.left ul li i {
margin-left: 10px;
margin-right: 5px;
color: #ffffff;
}
.luckerList h5{
.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);
text-align: center;
}
.luckerList{
.luckerList {
padding-left: 10px;
padding-right: 10px;
box-sizing: border-box;
}
.luckerList ul{
.luckerList ul {
padding-left: 10px;
padding-right: 10px;
padding-right: 50px;
box-sizing: border-box;
list-style: none;
width: 100%;
}
.luckerList ul li:first-child{
.luckerList ul li:first-child {
border-top: none;
}
.luckerList ul li{
.luckerList ul li {
box-sizing: border-box;
font-size: 16px;
font-size: 18px;
padding-bottom: 10px;
display: inline-block;
text-align: right;
width: 28%;
/*border-bottom: 1px solid rgba(34, 36, 38, .15);*/
}
.luckerList ul li span{
.luckerList ul li span {
font-size: 12px;
}
.mask {
-webkit-filter:blur(5px);
-webkit-filter: blur(5px);
}
.result {
position: absolute;
height: 320px;
width: 100%;
left: 0; top: 50%;
left: 0;
top: 50%;
margin-top: -160px;
text-align: center;
padding: 10px;
display: none;
}
.result span {
display: inline-block;
font-size: 25px;
@ -144,4 +171,17 @@ h4{ @@ -144,4 +171,17 @@ h4{
border-radius: 10px;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.8);
padding: 10px 0;
}
.result span i {
font-style: normal;
display: block;
}
.luckerList ul li.sp,
.result span.sp i {
color: #f35626;
background-image: -webkit-linear-gradient(92deg, #f35626, #feab3a);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}

304
src/static/index.js

@ -1,304 +0,0 @@ @@ -1,304 +0,0 @@
$(document).ready(function () {
new Index();
});
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 run() {
return this.fetch('/run');
}
static stopAndResult(award_id) {
return this.fetch('/draw_lottery', {award_id});
}
static getLucklessUsers() {
return this.fetch('/luckless_users');
}
static getLuckyUsers() {
return this.fetch('/lucky_users');
}
static getAwards() {
return this.fetch('/awards');
}
static getAward(award_id) {
return this.fetch('/award', {
award_id
});
}
static getUsers() {
return this.fetch('/users');
}
}
class Index {
constructor() {
this.running = false;
this.currentAward = '';
this.entries = [];
this.settings = {
width: 800,
height: 600,
radius: '65%',
radiusMin: 75,
bgDraw: true,
bgColor: 'none',
opacityOver: 0.90,
opacityOut: 0.05,
opacitySpeed: 1,
fov: 450,
speed: 1,
fontFamily: 'FZShuTi,Microsoft YaHei,Oswald,Arial, sans-serif',
fontSize: '28',
hoverFontSize: '55',
fontColor: '#fff',
fontWeight: 'normal',//bold
fontStyle: 'normal',//italic
fontStretch: 'extra-expanded',//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
};
this.buildCloud().then(() => {
this.svg3DTagCloud = new SVG3DTagCloud(document.getElementById('holder'), this.settings);
});
this.bindEvent();
this.initVisualSocket();
}
buildCloud() {
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;
}
BS.run().then(resp => {
console.log(resp);
this.svg3DTagCloud.speed(6);
this.running = true;
});
});
$('#end').click(() => {
if (!this.running) {
return;
}
console.log('click');
BS.stopAndResult(this.currentAward).then(resp => {
this.running = false;
console.log(resp);
if (resp.status === 200) {
this.render(resp.data, 0);
}
});
});
$('#luckyUsers').click(() => {
this.list();
});
}
render(data, i) {
// debugger
if (i >= data.length) {
this.currentlist(data);
this.rebuild();
return;
}
this.chose(data[i]).then(() => {
i++;
this.render(data, i);
});
}
stop() {
this.svg3DTagCloud.reset();
this.svg3DTagCloud.speed(1);
}
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 = `<li><i class="fa fa-user"></i>${name}</li>`;
$('.current-list').append(currentList);
setTimeout(() => {
// this.stop()
resolve();
}, 1 * 1000)
}).then(() => {
return new Promise((resolve) => {
this.stop();
setTimeout(() => {
resolve();
}, 0)
});
})
}
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() {
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({
type: 1,
area: '800px',
skin: 'layui-layer-lan', //样式类名
offset: [offset.top, offset.left],
closeBtn: 1, //不显示关闭按钮
anim: 3,
title: '所有中奖名单',
shadeClose: false, //开启遮罩关闭
content: `
<div class="luckerList">${content}
</div>`
});
});
}
}

207
src/static/js/index.js

@ -53,30 +53,36 @@ class BS { @@ -53,30 +53,36 @@ class BS {
}
class Tag{
constructor(entries){
this.entries=entries;
class Tag {
constructor(entries) {
this.id = 'myCanvas';
this.entries = entries;
this.createCanvas();
}
createHTML(){
let html = [ '<ul>' ];
createHTML() {
let html = ['<ul>'];
$(this.entries).each((i, val) => {
let color = (val.role===2||val.role===3)? 'yellow' : 'white';
let color = val.award_id ? 'yellow' : 'white';
html.push(`<li><a href="javascript:void(0)" style="color: ${color};" data-uid="${val.uid}" data-role="${val.role}">${val.name}</a></li>`);
// html.push(`<li><a href="#" style="color:${color};">' + item.name + '</a></li>`);
});
html.push('</ul>');
return html.join('');
};
static speed(){
static speed() {
return [0.1 * Math.random() + 0.01, -(0.1 * Math.random() + 0.01)];
};
createCanvas(){
createCanvas() {
let canvas = document.createElement('canvas');
canvas.id = 'myCanvas';
canvas.id = this.id;
canvas.width = 1024;
canvas.height = 600;
document.getElementById('holder').appendChild(canvas);
this.canvas = canvas;
canvas.innerHTML = this.createHTML();
TagCanvas.Start('myCanvas', '', {
textColour: null,
@ -85,89 +91,45 @@ class Tag{ @@ -85,89 +91,45 @@ class Tag{
textHeight: 14
});
}
fast(){
TagCanvas.SetSpeed('myCanvas', [5, 1]);
markYellow(users) {
let color = 'yellow';
for (let user of users) {
$(this.canvas).find(`[data-uid=${user.uid}]`).css('color', color);
}
TagCanvas.Reload(this.id);
}
stop(){
TagCanvas.SetSpeed('myCanvas', Tag.speed());
TagCanvas.Reload('myCanvas');
fast() {
TagCanvas.SetSpeed(this.id, [5, 1]);
}
stop() {
TagCanvas.SetSpeed(this.id, Tag.speed());
TagCanvas.Reload(this.id);
}
}
class Index {
constructor() {
this.running = false;
this.currentAward = '';
this.entries = [];
this.settings = {
width: 800,
height: 600,
radius: '65%',
radiusMin: 75,
bgDraw: true,
bgColor: 'none',
opacityOver: 0.90,
opacityOut: 0.05,
opacitySpeed: 1,
fov: 450,
speed: 1,
fontFamily: 'FZShuTi,Microsoft YaHei,Oswald,Arial, sans-serif',
fontSize: '28',
hoverFontSize: '55',
fontColor: '#fff',
fontWeight: 'normal',//bold
fontStyle: 'normal',//italic
fontStretch: 'extra-expanded',//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
};
this.buildCloud().then(() => {
this.svg3DTagCloud= new Tag(this.entries)
// this.svg3DTagCloud = new SVG3DTagCloud(document.getElementById('holder'), this.settings);
this.canvas3DTagCloud = new Tag(this.entries)
});
this.bindEvent();
this.initVisualSocket();
}
buildCloud() {
return BS.getLucklessUsers().then((resp) => {
return BS.getUsers().then((resp) => {
console.log(resp);
let entry = [];
$(resp.data).each((i, val) => {
entry.push({
label: val.name,
name:val.name,
uid: val.uid,
role: val.role,
url: 'javascript:void(0)',
target: '_top'
})
});
this.entries = entry;
// this.settings.entries = this.entries;
this.entries = resp.data;
})
}
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');
@ -177,7 +139,7 @@ class Index { @@ -177,7 +139,7 @@ class Index {
this.currentAward = tempAwardId;
this.refreshCurrentAward();
}
}, 2 * 1000);
}, 1000);
}
refreshCurrentAward() {
@ -200,9 +162,9 @@ class Index { @@ -200,9 +162,9 @@ class Index {
alert('正在抽奖');
return;
}
this.canvas3DTagCloud.fast();
BS.run().then(resp => {
console.log(resp);
this.svg3DTagCloud.fast();
this.running = true;
});
});
@ -212,15 +174,14 @@ class Index { @@ -212,15 +174,14 @@ class Index {
}
console.log('click');
BS.stopAndResult(this.currentAward).then(resp => {
this.running = false;
console.log(resp);
if (resp.status === 200) {
this.stopLottery(resp.data);
this.running = false;
}
});
});
$(document).on('click',function () {
$(document).on('click', function () {
$('#result').hide();
$('.holder').removeClass('mask');
});
@ -229,100 +190,64 @@ class Index { @@ -229,100 +190,64 @@ class Index {
});
}
stopLottery(data){
this.svg3DTagCloud.stop();
this.currentlist(data);
}
render(data, i) {
stopLottery(data) {
this.canvas3DTagCloud.stop();
this.currentlist(data);
this.rebuild();
// debugger
/* if (i >= data.length) {
this.currentlist(data);
this.rebuild();
return;
}
this.chose(data[i]).then(() => {
i++;
this.render(data, i);
});*/
}
stop() {
this.svg3DTagCloud.reset();
this.svg3DTagCloud.speed(1);
}
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 = `<li><i class="fa fa-user"></i>${name}</li>`;
$('.current-list').append(currentList);
setTimeout(() => {
// this.stop()
resolve();
}, 1 * 1000)
}).then(() => {
return new Promise((resolve) => {
this.stop();
setTimeout(() => {
resolve();
}, 0)
});
})
this.canvas3DTagCloud.markYellow(data)
}
/**
* 当前轮结果
* @param data
*/
currentlist(data) {
let offset = $(".holder").offset();
// let offset = $(".holder").offset();
let DOM = '';
for (let user of data) {
DOM += `<span>${user.name}<br>${user.uid}</span>`;
DOM += `<span class="${(user.role === 2 || user.role === 3) ? 'sp animated flash' : ''}"><i>${user.name}<br>${user.uid}</i></span>`;
}
DOM += ``;
$('#result').show().html(DOM);
setTimeout(function(){
setTimeout(function () {
$('.holder').addClass('mask');
}, 300);
}, 10);
}
/**
* 所有结果
*/
list() {
let offset = $(".holder").offset();
let awards={};
let load=layer.load(2);
BS.getAwards().then(resp=>{
resp.data.map((val)=>{
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]={};
if (typeof awards[val.award_id] === "undefined") {
awards[val.award_id] = {};
}
awards[val.award_id].name = val.award_name;
awards[val.award_id].data=[];
awards[val.award_id].data = [];
})
}).then(()=>{
}).then(() => {
return BS.getLuckyUsers().then(resp => {
resp.data.map(val=>{
resp.data.map(val => {
awards[val.award_id].data.push(val)
})
});
}).then(()=>{
}).then(() => {
layer.close(load);
console.log(awards);
let content = ``;
for(let key of Object.keys(awards)){
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>`
let lisArray = award.data.map((data) => {
return `<li class="${data.role == 2 || data.role == 3 ? 'sp' : ''}">${data.name}<span>【${data.uid}】</span></li>`
});
content+=`
content += `
<section>
<h5>${award.name}</h5>
<ul>

25
src/static/manage.js

@ -26,6 +26,7 @@ class BS { @@ -26,6 +26,7 @@ class BS {
award_name, award_capacity
});
}
static removeAwards(award_id) {
return this.fetch('/remove_award', {
award_id
@ -85,21 +86,23 @@ $(function () { @@ -85,21 +86,23 @@ $(function () {
$(document).on('click', '.js-set', e => {
let aid = $(e.target).data('aid');
let $lis = $('#awardList').find('li');
BS.setCurrent(aid).then((resp) => {
BS.setCurrent(aid).then(() => {
$lis.removeClass('cur');
$(e.target).closest('li').addClass('cur');
})
}).on('click', '.js-remove', e => {
let aid = $(e.target).data('aid');
layer.confirm('确认要删除该项?',(index)=>{
BS.removeAwards(aid).then((resp)=>{
if(resp.status===200){
flushAwards()
layer.close(index)
}else {
layer.alert(resp.msg)
}
})
layer.confirm('确认要删除该项?', () => {
let aid = $(e.target).data('aid');
let loadIndex= layer.load(2);
BS.removeAwards(aid).then((resp) => {
if (resp.status === 200) {
flushAwards();
layer.close(loadIndex)
} else {
layer.close(loadIndex);
layer.alert(resp.msg)
}
})
})
});
flushAwards()

3
src/templates/index.html

@ -2,12 +2,13 @@ @@ -2,12 +2,13 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<title>运营技术中心2018年会抽奖</title>
<link rel="stylesheet" href="../static/index.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/buttons.css">
<link rel="stylesheet" href="../static/animate.css">
</head>
<body>
<div class="content">

Loading…
Cancel
Save