From a284ad7ba25d98763f8cd3a44ecf059f7a62b9b7 Mon Sep 17 00:00:00 2001 From: "ex_zhangwenlei@exiot.cmcc" <15196725410@139.com> Date: Sat, 27 Jan 2024 00:43:09 +0800 Subject: [PATCH] fix: fix and new feature --- .../NumberSeparate/EditSeparateDialog.vue | 14 ++-- src/store/data.ts | 46 ++++++++++- src/store/globalConfig.ts | 4 +- src/store/prizeConfig.ts | 52 +++++-------- src/utils/index.ts | 3 +- src/views/Config/Global/FaceConfig.vue | 17 +--- src/views/Config/Person/PersonAll.vue | 20 ++--- src/views/Config/Prize/PrizeConfig.vue | 76 ++++++++++-------- src/views/Home/PrizeList.vue | 76 ++++++++++++++---- src/views/Home/index.vue | 77 +++++++++++-------- 10 files changed, 236 insertions(+), 149 deletions(-) diff --git a/src/components/NumberSeparate/EditSeparateDialog.vue b/src/components/NumberSeparate/EditSeparateDialog.vue index 8cc31be..1791d6a 100644 --- a/src/components/NumberSeparate/EditSeparateDialog.vue +++ b/src/components/NumberSeparate/EditSeparateDialog.vue @@ -2,7 +2,6 @@ import { ref, watch, onMounted, toRefs } from 'vue' import { Separate } from '@/types/storeType' - const props = defineProps({ totalNumber: { type: Number, @@ -14,7 +13,7 @@ const props = defineProps({ } }) -const emits = defineEmits(['clearData']) +const emits = defineEmits(['submitData']) const separatedNumberRef = ref() const { separatedNumber, totalNumber } = toRefs(props) @@ -34,16 +33,16 @@ const editScale = (item: number) => { } } const clearData = () => { - emits('clearData',separatedNumber.value) + emits('submitData', separatedNumber.value) separatedNumberRef.value.close() } watch(scaleList, (val: number[]) => { - separatedNumber.value = [] + separatedNumber.value.length=0 for (let i = 1; i < scaleList.value.length; i++) { - separatedNumber.value[i-1] = { + separatedNumber.value[i - 1] = { id: i.toString(), count: val[i] - val[i - 1], - isUsedCount:0, + isUsedCount: 0, } } }, { deep: true }) @@ -53,6 +52,7 @@ watch(totalNumber, (val) => { return } separatedNumberRef.value.showModal() + // scaleList.value = [0, val] scaleList.value = new Array(separatedNumber.value.length + 1).fill(totalNumber.value) for (let i = separatedNumber.value.length - 1; i >= 0; i--) { scaleList.value[i] = scaleList.value[i + 1] - separatedNumber.value[i].count @@ -79,7 +79,7 @@ onMounted(() => {
-
{{ item }}
diff --git a/src/store/data.ts b/src/store/data.ts index 4acac7c..0d61231 100644 --- a/src/store/data.ts +++ b/src/store/data.ts @@ -67,7 +67,7 @@ export const defaultPrizeList = [ name: '三等奖', sort: 1, isAll: false, - count: 12, + count: 3, isUsedCount: 0, picture: { id: '2', @@ -88,7 +88,7 @@ export const defaultPrizeList = [ name: '二等奖', sort: 2, isAll: false, - count: 1, + count: 2, isUsedCount: 0, picture: { id: '1', @@ -168,6 +168,48 @@ export const defaultPrizeList = [ frequency: 1, } ] +export const defaultCurrentPrize = { + id: '001', + name: '三等奖', + sort: 1, + isAll: false, + count: 12, + isUsedCount: 0, + picture: { + id: '2', + name: '三等奖', + url: 'https://24years.top/resource/image/image3.png' + }, + separateCount: { + enable: true, + countList: [] + }, + desc: '三等奖', + isShow: true, + isUsed: false, + frequency: 1, +} +export const defaultTemporaryPrize = { + id: '', + name: '', + sort: 0, + isAll: false, + count: 1, + isUsedCount: 0, + picture: { + id: '-1', + name: '', + url: '' + }, + separateCount: { + enable: true, + countList: [] + }, + desc: '', + isShow: false, + isUsed: false, + frequency: 1, +} export const defaultImageList = [ { diff --git a/src/store/globalConfig.ts b/src/store/globalConfig.ts index ea58c13..5f3aba8 100644 --- a/src/store/globalConfig.ts +++ b/src/store/globalConfig.ts @@ -10,7 +10,7 @@ export const useGlobalConfig = defineStore('global', { isSHowPrizeList: true, topTitle: '大明内阁六部御前奏对', theme: { - name: 'dark', + name: 'dracula', detail: { primary: '#0f5fd3' }, cardColor: '#ff79c6', cardWidth: 140, @@ -215,7 +215,7 @@ export const useGlobalConfig = defineStore('global', { isSHowPrizeList: true, topTitle: '大明内阁六部御前奏对', theme: { - name: 'dark', + name: 'dracula', detail: { primary: '#0f5fd3' }, cardColor: '#ff79c6', cardWidth: 140, diff --git a/src/store/prizeConfig.ts b/src/store/prizeConfig.ts index 5642139..f434a55 100644 --- a/src/store/prizeConfig.ts +++ b/src/store/prizeConfig.ts @@ -1,32 +1,12 @@ import { defineStore } from 'pinia'; import { IPrizeConfig } from '@/types/storeType'; -import { defaultPrizeList } from './data'; +import { defaultPrizeList, defaultCurrentPrize } from './data'; export const usePrizeConfig = defineStore('prize', { state() { return { prizeConfig: { prizeList: defaultPrizeList, - currentPrize: { - id: '001', - name: '三等奖', - sort: 1, - isAll: false, - count: 12, - isUsedCount: 0, - picture: { - id: '2', - name: '三等奖', - url: 'https://24years.top/resource/image/image3.png' - }, - separateCount: { - enable: true, - countList: [] - }, - desc: '三等奖', - isShow: true, - isUsed: false, - frequency: 1, - } as IPrizeConfig, + currentPrize: defaultCurrentPrize, temporaryPrize: { id: '', name: '', @@ -144,6 +124,10 @@ export const usePrizeConfig = defineStore('prize', { name: '', url: '' }, + separateCount: { + enable: true, + countList: [] + }, desc: '', isShow: false, isUsed: false, @@ -154,28 +138,28 @@ export const usePrizeConfig = defineStore('prize', { resetDefault() { this.prizeConfig = { prizeList: defaultPrizeList, - currentPrize: { - id: '001', - name: '三等奖', - sort: 1, + currentPrize: defaultCurrentPrize, + temporaryPrize: { + id: '', + name: '', + sort: 0, isAll: false, - count: 12, + count: 1, isUsedCount: 0, picture: { - id: '2', - name: '三等奖', - url: 'https://24years.top/resource/image/image3.png' + id: '-1', + name: '', + url: '' }, separateCount: { enable: true, countList: [] }, - desc: '三等奖', - isShow: true, + desc: '', + isShow: false, isUsed: false, frequency: 1, - } as IPrizeConfig, - temporaryPrize: {} as IPrizeConfig + } as IPrizeConfig } } }, diff --git a/src/utils/index.ts b/src/utils/index.ts index e7b9d8f..2d5eca9 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -11,7 +11,6 @@ export const filterData = (tableData: any[], localRowCount: number, startIndex = tableData[i].y = j; tableData[i].id = i; // 是否中奖 - tableData[i].isWin = false } return tableData @@ -20,11 +19,13 @@ export const filterData = (tableData: any[], localRowCount: number, startIndex = export const addOtherInfo = (personList: any[]) => { const len = personList.length; for (let i = 0; i < len; i++) { + personList[i].id = i personList[i].createTime = dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss'); personList[i].updateTime = dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss'); personList[i].prizeName = [] as string[]; personList[i].prizeTime = [] as string[]; personList[i].prizeId = []; + personList[i].isWin = false } return personList diff --git a/src/views/Config/Global/FaceConfig.vue b/src/views/Config/Global/FaceConfig.vue index 69a9f93..8bb5f16 100644 --- a/src/views/Config/Global/FaceConfig.vue +++ b/src/views/Config/Global/FaceConfig.vue @@ -1,7 +1,6 @@ @@ -75,7 +115,7 @@ onMounted(() => {
获奖人数
- - +
- +
@@ -195,10 +248,7 @@ onMounted(() => {
- - -
diff --git a/src/views/Home/index.vue b/src/views/Home/index.vue index 4dd30ba..dbed422 100644 --- a/src/views/Home/index.vue +++ b/src/views/Home/index.vue @@ -68,16 +68,18 @@ function initTableData() { return } const totalCount = rowCount.value * 7 - tableData.value = JSON.parse(JSON.stringify(allPersonList.value)) - const tableDataLength = tableData.value.length - if (tableDataLength < totalCount) { - const repeatCount = Math.ceil(totalCount / tableDataLength) + const orginPersonData = JSON.parse(JSON.stringify(allPersonList.value)) + const orginPersonLength = orginPersonData.length + if (orginPersonLength < totalCount) { + const repeatCount = Math.ceil(totalCount / orginPersonLength) // 复制数据 for (let i = 0; i < repeatCount; i++) { - tableData.value = tableData.value.concat(JSON.parse(JSON.stringify(tableData.value))) + tableData.value = tableData.value.concat(JSON.parse(JSON.stringify(orginPersonData))) } } - + else{ + tableData.value=orginPersonData.slice(0, totalCount) + } tableData.value = filterData(tableData.value.slice(0, totalCount), rowCount.value) } const init = () => { @@ -354,9 +356,11 @@ const enterLottery = async () => { randomBallData() } if (patternList.value.length) { - patternList.value.forEach((item: number) => { - objects.value[item - 1].element.style.backgroundColor = rgba(cardColor.value, Math.random() * 0.5 + 0.25) - }) + for(let i=0;i { return; } - currentStatus.value = 2 - rollBall(10, 3000) -} - -const stopLottery = async () => { - if (!canOperate.value) { - return - } - clearInterval(intervalTimer.value) - intervalTimer.value = null - canOperate.value = false - rollBall(0, 1) luckyCount.value = 10 // 自定义抽奖个数 - + let leftover = currentPrize.value.count - currentPrize.value.isUsedCount - const customCount=currentPrize.value.separateCount - if(customCount&&customCount.enable&&customCount.countList.length>0){ - for(let i=0;i 0) { + for (let i = 0; i < customCount.countList.length; i++) { + if (customCount.countList[i].isUsedCount < customCount.countList[i].count) { + leftover = customCount.countList[i].count - customCount.countList[i].isUsedCount break; } } @@ -424,6 +416,25 @@ const stopLottery = async () => { personPool.value.splice(randomIndex, 1) } } + toast.open({ + message: `现在抽取${currentPrize.value.name} ${leftover}人`, + type:'default', + position: 'top-right', + duration: 8000 + }) + currentStatus.value = 2 + rollBall(10, 3000) +} + +const stopLottery = async () => { + if (!canOperate.value) { + return + } + clearInterval(intervalTimer.value) + intervalTimer.value = null + canOperate.value = false + rollBall(0, 1) + const windowSize = { width: window.innerWidth, height: window.innerHeight } luckyTargets.value.forEach((person: IPersonConfig, index: number) => { let cardIndex = selectCard(luckyCardList.value, tableData.value.length, person.id) @@ -465,11 +476,11 @@ const continueLottery = async () => { return } - const customCount=currentPrize.value.separateCount - if(customCount&&customCount.enable&&customCount.countList.length>0){ - for(let i=0;i 0) { + for (let i = 0; i < customCount.countList.length; i++) { + if (customCount.countList[i].isUsedCount < customCount.countList[i].count) { + customCount.countList[i].isUsedCount += luckyCount.value break; } } @@ -576,7 +587,7 @@ const listenKeyboard = () => { if (e.keyCode === 27 && currentStatus.value === 3) { quitLottery() } - if(e.keyCode!==32){ + if (e.keyCode !== 32) { return } switch (currentStatus.value) {