a8e64a63 by zhangyongfeng

增加名单导入功能

1 parent b36225d0
...@@ -13,8 +13,14 @@ ...@@ -13,8 +13,14 @@
13 <div id="tags"> 13 <div id="tags">
14 <ul v-for="item in datas" :key="item.key"> 14 <ul v-for="item in datas" :key="item.key">
15 <li> 15 <li>
16 <a href="javascript:void(0);" :style="style(item)"> 16 <a
17 {{ item.key }} 17 href="javascript:void(0);"
18 :style="{
19 color:
20 !running && allresult.includes(item.key) ? '#ff2200' : '#fff'
21 }"
22 >
23 {{ item.name ? item.name : item.key }}
18 </a> 24 </a>
19 </li> 25 </li>
20 </ul> 26 </ul>
...@@ -22,6 +28,7 @@ ...@@ -22,6 +28,7 @@
22 <transition name="bounce"> 28 <transition name="bounce">
23 <div id="resbox" v-show="showRes"> 29 <div id="resbox" v-show="showRes">
24 <p @click="showRes = false">{{ categoryName }}抽奖结果:</p> 30 <p @click="showRes = false">{{ categoryName }}抽奖结果:</p>
31 <div class="container">
25 <span 32 <span
26 v-for="item in resArr" 33 v-for="item in resArr"
27 :key="item" 34 :key="item"
...@@ -29,8 +36,32 @@ ...@@ -29,8 +36,32 @@
29 :style="resCardStyle" 36 :style="resCardStyle"
30 @click="showRes = false" 37 @click="showRes = false"
31 > 38 >
39 <span
40 class="key"
41 :style="{
42 fontSize: list[item] && list[item].name ? '36px' : null,
43 lineHeight: list[item] && list[item].name ? '80px' : null
44 }"
45 v-if="list[item] && list[item].name"
46 >
32 {{ item }} 47 {{ item }}
33 </span> 48 </span>
49 <span
50 class="cont"
51 :style="{
52 fontSize: list[item] && list[item].name ? '36px' : null,
53 lineHeight: list[item] && list[item].name ? '80px' : null
54 }"
55 >
56 <span v-if="list[item] && list[item].name">
57 {{ list[item].name }}
58 </span>
59 <span v-else>
60 {{ item }}
61 </span>
62 </span>
63 </span>
64 </div>
34 </div> 65 </div>
35 </transition> 66 </transition>
36 67
...@@ -52,7 +83,8 @@ import { ...@@ -52,7 +83,8 @@ import {
52 configField, 83 configField,
53 resultField, 84 resultField,
54 newLotteryField, 85 newLotteryField,
55 conversionCategoryName 86 conversionCategoryName,
87 listField
56 } from '@/helper/index'; 88 } from '@/helper/index';
57 import { luckydrawHandler } from '@/helper/algorithm'; 89 import { luckydrawHandler } from '@/helper/algorithm';
58 import Result from '@/components/Result'; 90 import Result from '@/components/Result';
...@@ -87,6 +119,9 @@ export default { ...@@ -87,6 +119,9 @@ export default {
87 this.$store.commit('setResult', val); 119 this.$store.commit('setResult', val);
88 } 120 }
89 }, 121 },
122 list() {
123 return this.$store.state.list;
124 },
90 allresult() { 125 allresult() {
91 let allresult = []; 126 let allresult = [];
92 for (const key in this.result) { 127 for (const key in this.result) {
...@@ -100,8 +135,10 @@ export default { ...@@ -100,8 +135,10 @@ export default {
100 datas() { 135 datas() {
101 const datas = []; 136 const datas = [];
102 for (let index = 0; index < this.config.number; index++) { 137 for (let index = 0; index < this.config.number; index++) {
138 const listData = this.list.find(d => d.key === index);
103 datas.push({ 139 datas.push({
104 key: index + 1 140 key: index + 1,
141 name: listData ? listData.name : ''
105 }); 142 });
106 } 143 }
107 return datas; 144 return datas;
...@@ -131,6 +168,11 @@ export default { ...@@ -131,6 +168,11 @@ export default {
131 }); 168 });
132 this.$store.commit('setConfig', config); 169 this.$store.commit('setConfig', config);
133 } 170 }
171
172 const list = getData(listField);
173 if (list) {
174 this.$store.commit('setList', list);
175 }
134 }, 176 },
135 177
136 data() { 178 data() {
...@@ -147,13 +189,6 @@ export default { ...@@ -147,13 +189,6 @@ export default {
147 this.startTagCanvas(); 189 this.startTagCanvas();
148 }, 190 },
149 methods: { 191 methods: {
150 style() {
151 const style = { color: '#fff' };
152 // if (!this.running && this.allresult.includes(item.key)) {
153 // style.color = 'yellow';
154 // }
155 return style;
156 },
157 speed() { 192 speed() {
158 return [0.1 * Math.random() + 0.01, -(0.1 * Math.random() + 0.01)]; 193 return [0.1 * Math.random() + 0.01, -(0.1 * Math.random() + 0.01)];
159 }, 194 },
...@@ -183,8 +218,10 @@ export default { ...@@ -183,8 +218,10 @@ export default {
183 const { speed, config } = this; 218 const { speed, config } = this;
184 if (this.running) { 219 if (this.running) {
185 window.TagCanvas.SetSpeed('rootcanvas', speed()); 220 window.TagCanvas.SetSpeed('rootcanvas', speed());
186 this.reloadTagCanvas();
187 this.showRes = true; 221 this.showRes = true;
222 this.$nextTick(() => {
223 this.reloadTagCanvas();
224 });
188 } else { 225 } else {
189 this.showRes = false; 226 this.showRes = false;
190 const { number } = config; 227 const { number } = config;
...@@ -270,7 +307,7 @@ export default { ...@@ -270,7 +307,7 @@ export default {
270 307
271 #resbox { 308 #resbox {
272 position: absolute; 309 position: absolute;
273 top: 45%; 310 top: 50%;
274 left: 50%; 311 left: 50%;
275 width: 1000px; 312 width: 1000px;
276 transform: translateX(-50%) translateY(-50%); 313 transform: translateX(-50%) translateY(-50%);
...@@ -280,9 +317,13 @@ export default { ...@@ -280,9 +317,13 @@ export default {
280 font-size: 50px; 317 font-size: 50px;
281 line-height: 120px; 318 line-height: 120px;
282 } 319 }
320 .container {
321 display: flex;
322 justify-content: center;
323 flex-wrap: wrap;
324 }
283 .itemres { 325 .itemres {
284 background: #fff; 326 background: #fff;
285 display: inline-block;
286 width: 160px; 327 width: 160px;
287 height: 160px; 328 height: 160px;
288 border-radius: 4px; 329 border-radius: 4px;
...@@ -292,6 +333,13 @@ export default { ...@@ -292,6 +333,13 @@ export default {
292 margin-right: 20px; 333 margin-right: 20px;
293 margin-top: 20px; 334 margin-top: 20px;
294 cursor: pointer; 335 cursor: pointer;
336 display: flex;
337 flex-direction: column;
338 align-items: center;
339 justify-content: center;
340 .key {
341 color: red;
342 }
295 } 343 }
296 } 344 }
297 </style> 345 </style>
......
...@@ -150,11 +150,15 @@ export default { ...@@ -150,11 +150,15 @@ export default {
150 onSubmit() { 150 onSubmit() {
151 setData(configField, this.form); 151 setData(configField, this.form);
152 this.$emit('update:visible', false); 152 this.$emit('update:visible', false);
153 this.$emit('resetconfig'); 153
154 this.$message({ 154 this.$message({
155 message: '保存成功', 155 message: '保存成功',
156 type: 'success' 156 type: 'success'
157 }); 157 });
158
159 this.$nextTick(() => {
160 this.$emit('resetconfig');
161 });
158 }, 162 },
159 addLottery() { 163 addLottery() {
160 this.showAddLottery = true; 164 this.showAddLottery = true;
......
1 <template> 1 <template>
2 <div id="tool"> 2 <div id="tool">
3 <el-button @click="startHandler" size="mini">{{ 3 <el-button @click="startHandler" type="primary" size="mini">{{
4 running ? '停止' : '开始' 4 running ? '停止' : '开始'
5 }}</el-button> 5 }}</el-button>
6 <el-button size="mini" @click="resetConfig"> 6 <el-button size="mini" @click="resetConfig">
7 重置 7 重置
8 </el-button> 8 </el-button>
9 <el-button size="mini" @click="showImport = true">
10 导入名单
11 </el-button>
9 <el-dialog 12 <el-dialog
10 :append-to-body="true" 13 :append-to-body="true"
11 :visible.sync="showSetwat" 14 :visible.sync="showSetwat"
...@@ -70,6 +73,30 @@ ...@@ -70,6 +73,30 @@
70 </el-form-item> 73 </el-form-item>
71 </el-form> 74 </el-form>
72 </el-dialog> 75 </el-dialog>
76
77 <el-dialog
78 :append-to-body="true"
79 :visible.sync="showImport"
80 class="import-dialog"
81 width="400px"
82 >
83 <el-input
84 type="textarea"
85 :rows="10"
86 placeholder="请输入对应的号码和名单(可直接从excel复制),格式(号码 名字),导入的名单将代替号码显示在抽奖中。如:
87 1 张三
88 2 李四
89 3 王五
90 "
91 v-model="listStr"
92 ></el-input>
93 <div class="footer">
94 <el-button size="mini" type="primary" @click="transformList"
95 >确定</el-button
96 >
97 <el-button size="mini" @click="showImport = false">取消</el-button>
98 </div>
99 </el-dialog>
73 </div> 100 </div>
74 </template> 101 </template>
75 102
...@@ -118,12 +145,14 @@ export default { ...@@ -118,12 +145,14 @@ export default {
118 data() { 145 data() {
119 return { 146 return {
120 showSetwat: false, 147 showSetwat: false,
148 showImport: false,
121 form: { 149 form: {
122 category: '', 150 category: '',
123 mode: 1, 151 mode: 1,
124 qty: 1, 152 qty: 1,
125 allin: false 153 allin: false
126 } 154 },
155 listStr: ''
127 }; 156 };
128 }, 157 },
129 methods: { 158 methods: {
...@@ -136,11 +165,15 @@ export default { ...@@ -136,11 +165,15 @@ export default {
136 .then(() => { 165 .then(() => {
137 clearData(); 166 clearData();
138 this.$store.commit('setClearStore'); 167 this.$store.commit('setClearStore');
139 this.$emit('resetConfig'); 168
140 this.$message({ 169 this.$message({
141 type: 'success', 170 type: 'success',
142 message: '重置成功!' 171 message: '重置成功!'
143 }); 172 });
173
174 this.$nextTick(() => {
175 this.$emit('resetConfig');
176 });
144 }) 177 })
145 .catch(() => { 178 .catch(() => {
146 this.$message({ 179 this.$message({
...@@ -181,6 +214,38 @@ export default { ...@@ -181,6 +214,38 @@ export default {
181 } else { 214 } else {
182 this.showSetwat = true; 215 this.showSetwat = true;
183 } 216 }
217 },
218 transformList() {
219 const { listStr } = this;
220 if (!listStr) {
221 this.$message.error('没有数据');
222 }
223 const list = [];
224 const rows = listStr.split('\n');
225 if (rows && rows.length > 0) {
226 rows.forEach(item => {
227 const rowList = item.split('\t');
228 if (rowList.length >= 2) {
229 const key = Number(rowList[0].trim());
230 const name = rowList[1].trim();
231 key &&
232 list.push({
233 key,
234 name
235 });
236 }
237 });
238 }
239 this.$store.commit('setList', list);
240
241 this.$message({
242 message: '保存成功',
243 type: 'success'
244 });
245 this.showImport = false;
246 this.$nextTick(() => {
247 this.$emit('resetConfig');
248 });
184 } 249 }
185 } 250 }
186 }; 251 };
...@@ -209,4 +274,11 @@ export default { ...@@ -209,4 +274,11 @@ export default {
209 font-weight: bold; 274 font-weight: bold;
210 } 275 }
211 } 276 }
277 .import-dialog {
278 .footer {
279 height: 50px;
280 line-height: 50px;
281 text-align: center;
282 }
283 }
212 </style> 284 </style>
......
...@@ -36,6 +36,7 @@ export function getDomData(element, dataName) { ...@@ -36,6 +36,7 @@ export function getDomData(element, dataName) {
36 export const configField = 'config'; // 配置数据 36 export const configField = 'config'; // 配置数据
37 export const resultField = 'result'; // 抽奖结果 37 export const resultField = 'result'; // 抽奖结果
38 export const newLotteryField = 'newLottery'; // 新增奖项 38 export const newLotteryField = 'newLottery'; // 新增奖项
39 export const listField = 'list'; // 名单
39 40
40 export function conversionCategoryName(key) { 41 export function conversionCategoryName(key) {
41 let name = ''; 42 let name = '';
......
1 import Vue from 'vue'; 1 import Vue from 'vue';
2 import Vuex from 'vuex'; 2 import Vuex from 'vuex';
3 import { setData, resultField, newLotteryField } from '@/helper/index'; 3 import {
4 setData,
5 resultField,
6 newLotteryField,
7 listField
8 } from '@/helper/index';
4 9
5 Vue.use(Vuex); 10 Vue.use(Vuex);
6 11
...@@ -24,7 +29,8 @@ export default new Vuex.Store({ ...@@ -24,7 +29,8 @@ export default new Vuex.Store({
24 fourthPrize: [], 29 fourthPrize: [],
25 fifthPrize: [] 30 fifthPrize: []
26 }, 31 },
27 newLottery: [] 32 newLottery: [],
33 list: []
28 }, 34 },
29 mutations: { 35 mutations: {
30 setClearStore(state) { 36 setClearStore(state) {
...@@ -47,6 +53,7 @@ export default new Vuex.Store({ ...@@ -47,6 +53,7 @@ export default new Vuex.Store({
47 fifthPrize: [] 53 fifthPrize: []
48 }; 54 };
49 state.newLottery = []; 55 state.newLottery = [];
56 state.list = [];
50 }, 57 },
51 setConfig(state, config) { 58 setConfig(state, config) {
52 state.config = config; 59 state.config = config;
...@@ -62,6 +69,20 @@ export default new Vuex.Store({ ...@@ -62,6 +69,20 @@ export default new Vuex.Store({
62 } 69 }
63 state.newLottery.push(newLottery); 70 state.newLottery.push(newLottery);
64 setData(newLotteryField, state.newLottery); 71 setData(newLotteryField, state.newLottery);
72 },
73 setList(state, list) {
74 const arr = state.list;
75 list.forEach(item => {
76 const arrItem = arr.find(data => data.key === item.key);
77 if (arrItem) {
78 arrItem.name === item.name;
79 } else {
80 arr.push(item);
81 }
82 });
83 state.list = arr;
84
85 setData(listField, arr);
65 } 86 }
66 }, 87 },
67 actions: {}, 88 actions: {},
......