Skip to content

Commit

Permalink
新增自定义奖
Browse files Browse the repository at this point in the history
  • Loading branch information
vitozyf committed Dec 27, 2019
1 parent b142e67 commit 9ed78b3
Show file tree
Hide file tree
Showing 9 changed files with 204 additions and 102 deletions.
34 changes: 28 additions & 6 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import {
getData,
configField,
resultField,
newLotteryField,
conversionCategoryName
} from '@/helper/index';
import { luckydrawHandler } from '@/helper/algorithm';
Expand Down Expand Up @@ -99,6 +100,18 @@ export default {
if (result) {
this.$store.commit('setResult', result);
}
const newLottery = getData(newLotteryField);
if (newLottery) {
const config = this.config;
newLottery.forEach(item => {
this.$store.commit('setNewLottery', item);
if (!config[item.key]) {
this.$set(config, item.key, 0);
}
});
this.$store.commit('setConfig', config);
}
},
data() {
Expand All @@ -115,11 +128,11 @@ export default {
this.startTagCanvas();
},
methods: {
style(item) {
style() {
const style = { color: '#fff' };
if (this.allresult.includes(item.key)) {
style.color = 'yellow';
}
// if (!this.running && this.allresult.includes(item.key)) {
// style.color = 'yellow';
// }
return style;
},
speed() {
Expand Down Expand Up @@ -173,11 +186,19 @@ export default {
num
);
this.resArr = resArr;
this.category = category;
if (this.result[category]) {
this.$set(this.result, category, []);
}
const oldRes = this.result[category] || [];
this.result = {
const data = Object.assign({}, this.result, {
[category]: oldRes.concat(resArr)
};
});
this.result = data;
window.TagCanvas.SetSpeed('rootcanvas', [5, 1]);
}
this.running = !this.running;
Expand Down Expand Up @@ -206,6 +227,7 @@ export default {
position: absolute;
top: 17px;
padding: 0;
z-index: 9999;
&.con {
right: 20px;
}
Expand Down
8 changes: 4 additions & 4 deletions src/assets/style/animation.scss
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
@-webkit-keyframes slowMovingToLeft {
from {
left: 1000px;
left: 100%;
}

to {
left: -1500px;
left: -400%;
}
}
@keyframes slowMovingToLeft {
from {
left: 1000px;
left: 100%;
}

to {
left: -1500px;
left: -400%;
}
}
6 changes: 6 additions & 0 deletions src/assets/style/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ body {
padding-top: 20px !important;
padding-bottom: 20px !important;
}
.el-dialog {
margin-top: 0 !important;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
117 changes: 91 additions & 26 deletions src/components/LotteryConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,88 @@
<el-dialog
:visible="visible"
:append-to-body="true"
title="抽奖配置"
width="400px"
:lock-scroll="true"
@close="$emit('update:visible', false)"
class="c-LotteryConfig"
>
<div class="c-LotteryConfigtitle" slot="title">
<span :style="{ fontSize: '16px', marginRight: '20px' }">
抽奖配置
</span>
<el-button size="mini" @click="addLottery">增加奖项</el-button>
<el-button size="mini" type="primary" @click="onSubmit"
>保存配置</el-button
>
<el-button size="mini" @click="$emit('update:visible', false)"
>取消</el-button
>
</div>
<el-form ref="form" :model="form" label-width="100px" size="mini">
<el-form-item label="抽奖标题">
<el-input v-model="form.name"></el-input>
</el-form-item>
<el-form-item label="抽奖总人数">
<el-input v-model="form.number"></el-input>
<el-input type="number" v-model="form.number"></el-input>
</el-form-item>
<el-form-item label="特等奖人数">
<el-input v-model="form.specialAward"></el-input>
<el-input type="number" v-model="form.specialAward"></el-input>
</el-form-item>
<el-form-item label="一等奖人数">
<el-input v-model="form.firstPrize"></el-input>
<el-input type="number" v-model="form.firstPrize"></el-input>
</el-form-item>
<el-form-item label="二等奖人数">
<el-input v-model="form.secondPrize"></el-input>
<el-input type="number" v-model="form.secondPrize"></el-input>
</el-form-item>
<el-form-item label="三等奖人数">
<el-input v-model="form.thirdPrize"></el-input>
<el-input type="number" v-model="form.thirdPrize"></el-input>
</el-form-item>
<el-form-item label="四等奖人数">
<el-input v-model="form.fourthPrize"></el-input>
<el-input type="number" v-model="form.fourthPrize"></el-input>
</el-form-item>
<el-form-item label="五等奖人数">
<el-input v-model="form.fifthPrize"></el-input>
</el-form-item>
<el-form-item label="追加奖(1)人数">
<el-input v-model="form.additionalPrize1"></el-input>
</el-form-item>
<el-form-item label="追加奖(2)人数">
<el-input v-model="form.additionalPrize2"></el-input>
</el-form-item>
<el-form-item label="追加奖(3)人数">
<el-input v-model="form.additionalPrize3"></el-input>
</el-form-item>
<el-form-item label="追加奖(4)人数">
<el-input v-model="form.additionalPrize4"></el-input>
</el-form-item>
<el-form-item label="追加奖(5)人数">
<el-input v-model="form.additionalPrize5"></el-input>
<el-input type="number" v-model="form.fifthPrize"></el-input>
</el-form-item>

<el-form-item>
<el-button type="primary" @click="onSubmit">保存配置</el-button>
<el-button @click="$emit('update:visible', false)">取消</el-button>
<el-form-item
:label="newitem.name"
v-for="newitem in storeNewLottery"
:key="newitem.key"
>
<el-input
type="number"
v-model="form[newitem.key]"
@change="
val => {
form[newitem.key] = Number(val);
}
"
></el-input>
</el-form-item>
</el-form>

<el-dialog
:visible.sync="showAddLottery"
:append-to-body="true"
width="300px"
class="dialog-showAddLottery"
>
<div class="add-title" slot="title">增加奖项</div>
<el-form ref="newLottery" :model="newLottery" size="mini">
<el-form-item label="奖项名称">
<el-input v-model="newLottery.name"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="addHandler">增加奖项</el-button>
<el-button @click="showAddLottery = false">取消</el-button>
</el-form-item>
</el-form>
</el-dialog>
</el-dialog>
</template>
<script>
import { setData, configField } from '@/helper/index';
import { randomNum } from '@/helper/algorithm';
export default {
name: 'LotteryConfig',
props: {
Expand All @@ -71,8 +97,17 @@ export default {
set(val) {
this.$store.commit('setConfig', val);
}
},
storeNewLottery() {
return this.$store.state.newLottery;
}
},
data() {
return {
showAddLottery: false,
newLottery: { name: '' }
};
},
methods: {
onSubmit() {
setData(configField, this.form);
Expand All @@ -82,11 +117,41 @@ export default {
message: '保存成功',
type: 'success'
});
},
addLottery() {
this.showAddLottery = true;
},
randomField() {
const str = 'abcdefghijklmnopqrstuvwxyz';
let fieldStr = '';
for (let index = 0; index < 10; index++) {
fieldStr += str.split('')[randomNum(1, 27) - 1];
}
return `${fieldStr}${Date.now()}`;
},
addHandler() {
const field = this.randomField();
const data = {
key: field,
name: this.newLottery.name
};
this.$store.commit('setNewLottery', data);
this.showAddLottery = false;
}
}
};
</script>
<style lang="scss">
.c-LotteryConfig {
.el-dialog__body {
height: 340px;
overflow-y: auto;
}
}
.dialog-showAddLottery {
.el-dialog {
height: 186px;
}
}
</style>
91 changes: 43 additions & 48 deletions src/components/Publicity.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
<template>
<div class="c-Publicity">
<div class="message">
<span class="title">
{{ config.name }}
</span>
<span v-html="message"> </span>
</div>
<el-carousel
height="50px"
:autoplay="true"
indicator-position="none"
arrow="never"
:interval="3000"
>
<el-carousel-item v-for="item in message" :key="item.key">
<div class="item" :class="{ actiname: item.key === 0 }">
<span v-if="item.title" class="title"> {{ item.title }}</span>
<span v-if="item.value" class="value">
{{ item.value }}
</span>
</div>
</el-carousel-item>
</el-carousel>
</div>
</template>
<script>
Expand All @@ -21,39 +31,21 @@ export default {
return this.$store.state.result;
},
message() {
const {
specialAward,
additionalPrize1,
additionalPrize2,
additionalPrize3
} = this.config;
const fields = [
'firstPrize',
'secondPrize',
'thirdPrize',
'fourthPrize',
'fifthPrize'
];
if (specialAward > 0) {
fields.unshift('specialAward');
}
if (additionalPrize1 > 0) {
fields.push('additionalPrize1');
}
if (additionalPrize2 > 0) {
fields.push('additionalPrize2');
}
if (additionalPrize3 > 0) {
fields.push('additionalPrize3');
}
const { result } = this;
const { result, config } = this;
const fields = Object.keys(config);
let message = '';
fields.forEach(item => {
let message = [{ key: 0, title: config.name }];
fields.forEach((item, index) => {
let label = conversionCategoryName(item);
message += `&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;${label}抽奖结果: ${
result[item].length > 0 ? result[item].join('') : '暂未抽取'
}`;
if (result[item] && config[item] > 0) {
message.push({
key: index + 1,
title: `${label}抽奖结果:`,
value: `${
result[item].length > 0 ? result[item].join('') : '暂未抽取'
}`
});
}
});
return message;
Expand All @@ -64,23 +56,26 @@ export default {
<style lang="scss">
.c-Publicity {
height: 100%;
width: 1000px;
// width: 1000px;
background-color: rgba(0, 0, 0, 0.2);
margin: 0 auto;
position: relative;
overflow: hidden;
.message {
font-size: 16px;
.item {
text-align: center;
color: #fff;
position: absolute;
left: 500px;
animation-name: slowMovingToLeft;
animation-iteration-count: infinite;
animation-timing-function: linear;
animation-direction: normal;
animation-duration: 40s;
font-size: 16px;
.title {
color: #ff2200;
color: #ccc;
}
.value {
margin-left: 10px;
}
&.actiname {
.title {
color: red;
font-size: 20px;
}
}
}
}
Expand Down
Loading

0 comments on commit 9ed78b3

Please sign in to comment.