feat: add reset all data in global config

This commit is contained in:
ex_zhangwenlei@exiot.cmcc
2024-01-24 22:55:08 +08:00
parent 6ae32114a6
commit 00655fa3fd
6 changed files with 111 additions and 82 deletions

View File

@@ -76,15 +76,7 @@ export const defaultPrizeList = <IPrizeConfig[]>[
}, },
separateCount: { separateCount: {
enable: true, enable: true,
countList: [{ countList: []
id: '0',
count: 6,
isUsedCount: 0,
}, {
id: '1',
count: 6,
isUsedCount: 0,
}]
}, },
desc: '三等奖', desc: '三等奖',
isShow: true, isShow: true,

View File

@@ -1,14 +1,14 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { defaultMusicList,defaultImageList,defaultPatternList } from './data' import { defaultMusicList, defaultImageList, defaultPatternList } from './data'
import {IMusic,IImage} from '@/types/storeType'; import { IMusic, IImage } from '@/types/storeType';
// import { IPrizeConfig } from '@/types/storeType'; // import { IPrizeConfig } from '@/types/storeType';
export const useGlobalConfig = defineStore('global', { export const useGlobalConfig = defineStore('global', {
state() { state() {
return { return {
globalConfig: { globalConfig: {
rowCount: 17, rowCount: 17,
isSHowPrizeList:true, isSHowPrizeList: true,
topTitle:'大明内阁六部御前奏对', topTitle: '大明内阁六部御前奏对',
theme: { theme: {
name: 'dark', name: 'dark',
detail: { primary: '#0f5fd3' }, detail: { primary: '#0f5fd3' },
@@ -16,17 +16,17 @@ export const useGlobalConfig = defineStore('global', {
cardWidth: 140, cardWidth: 140,
cardHeight: 200, cardHeight: 200,
textColor: '#ffffff', textColor: '#ffffff',
luckyCardColor:'#ECB1AC', luckyCardColor: '#ECB1AC',
textSize: 30, textSize: 30,
patternColor:'#1b66c9', patternColor: '#1b66c9',
patternList:defaultPatternList as number[], patternList: defaultPatternList as number[],
}, },
musicList: defaultMusicList as IMusic[], musicList: defaultMusicList as IMusic[],
imageList:defaultImageList as IImage[], imageList: defaultImageList as IImage[],
}, },
currentMusic: { currentMusic: {
item:defaultMusicList[0], item: defaultMusicList[0],
paused:true, paused: true,
}, },
}; };
}, },
@@ -71,11 +71,11 @@ export const useGlobalConfig = defineStore('global', {
return state.globalConfig.theme.textSize; return state.globalConfig.theme.textSize;
}, },
// 获取图案颜色 // 获取图案颜色
getPatterColor(state){ getPatterColor(state) {
return state.globalConfig.theme.patternColor; return state.globalConfig.theme.patternColor;
}, },
// 获取图案列表 // 获取图案列表
getPatternList(state){ getPatternList(state) {
return state.globalConfig.theme.patternList; return state.globalConfig.theme.patternList;
}, },
// 获取音乐列表 // 获取音乐列表
@@ -164,10 +164,10 @@ export const useGlobalConfig = defineStore('global', {
} }
}, },
// 设置当前播放音乐 // 设置当前播放音乐
setCurrentMusic(musicItem: IMusic,paused:boolean=true) { setCurrentMusic(musicItem: IMusic, paused: boolean = true) {
this.currentMusic={ this.currentMusic = {
item:musicItem, item: musicItem,
paused:paused, paused: paused,
} }
}, },
// 重置音乐列表 // 重置音乐列表
@@ -179,7 +179,7 @@ export const useGlobalConfig = defineStore('global', {
this.globalConfig.musicList = [] as IMusic[]; this.globalConfig.musicList = [] as IMusic[];
}, },
// 添加图片 // 添加图片
addImage(image:IImage){ addImage(image: IImage) {
for (let i = 0; i < this.globalConfig.imageList.length; i++) { for (let i = 0; i < this.globalConfig.imageList.length; i++) {
if (this.globalConfig.imageList[i].name === image.name) { if (this.globalConfig.imageList[i].name === image.name) {
return; return;
@@ -211,29 +211,28 @@ export const useGlobalConfig = defineStore('global', {
// 重置所有配置 // 重置所有配置
reset() { reset() {
this.globalConfig = { this.globalConfig = {
rowCount: 12, rowCount: 17,
topTitle:'大明内阁六部御前奏对', isSHowPrizeList: true,
isSHowPrizeList:true, topTitle: '大明内阁六部御前奏对',
theme: { theme: {
name: 'dark', name: 'dark',
detail: { primary: '#0f5fd3' }, detail: { primary: '#0f5fd3' },
cardColor: 'rgba(0, 255, 255)', cardColor: '#ff79c6',
luckyCardColor:'#ECB1AC', cardWidth: 140,
cardWidth: 200, cardHeight: 200,
cardHeight: 140,
textColor: '#ffffff', textColor: '#ffffff',
luckyCardColor: '#ECB1AC',
textSize: 30, textSize: 30,
patternColor: '#1b66c9', patternColor: '#1b66c9',
patternList:defaultPatternList, patternList: defaultPatternList as number[],
}, },
musicList: defaultMusicList as IMusic[], musicList: defaultMusicList as IMusic[],
imageList:defaultImageList as IImage[], imageList: defaultImageList as IImage[],
}, },
this.currentMusic= { this.currentMusic = {
item:defaultMusicList[0] as IMusic, item: defaultMusicList[0],
paused:true, paused: true,
} }
} }
}, },
persist: { persist: {

View File

@@ -30,8 +30,8 @@ export const usePersonConfig = defineStore('person', {
const data = state.personConfig.allPersonList.filter((item: IPersonConfig) => { const data = state.personConfig.allPersonList.filter((item: IPersonConfig) => {
return !item.prizeId.includes(currentPrize.id as string); return !item.prizeId.includes(currentPrize.id as string);
}); });
return data return data
}, },
// 获取已中奖人员名单 // 获取已中奖人员名单
getAlreadyPersonList(state) { getAlreadyPersonList(state) {
@@ -99,7 +99,7 @@ return data
} }
} }
for (let i = 0; i < alreadyPersonListLength; i++) { for (let i = 0; i < alreadyPersonListLength; i++) {
this.personConfig.alreadyPersonList = this.personConfig.alreadyPersonList.filter((item: IPersonConfig) => this.personConfig.alreadyPersonList = this.personConfig.alreadyPersonList.filter((item: IPersonConfig) =>
item.id !== person.id item.id !== person.id
) )
} }

View File

@@ -8,33 +8,41 @@ export const usePrizeConfig = defineStore('prize', {
prizeList: defaultPrizeList, prizeList: defaultPrizeList,
currentPrize: { currentPrize: {
id: '001', id: '001',
name: '等奖', name: '等奖',
sort: 1, sort: 1,
isAll: true, isAll: false,
count: 1, count: 12,
isUsedCount:0, isUsedCount: 0,
picture: { picture: {
id: '0', id: '2',
name: '等奖', name: '等奖',
url: 'https://24years.top/resource/image/image1.png' url: 'https://24years.top/resource/image/image3.png'
}, },
desc: '一等奖', separateCount: {
enable: true,
countList: []
},
desc: '三等奖',
isShow: true, isShow: true,
isUsed: false, isUsed: false,
frequency: 1, frequency: 1,
} as IPrizeConfig, } as IPrizeConfig,
temporaryPrize:{ temporaryPrize: {
id: '', id: '',
name: '', name: '',
sort: 0, sort: 0,
isAll: false, isAll: false,
count: 1, count: 1,
isUsedCount:0, isUsedCount: 0,
picture: { picture: {
id: '-1', id: '-1',
name: '', name: '',
url: '' url: ''
}, },
separateCount: {
enable: true,
countList: []
},
desc: '', desc: '',
isShow: false, isShow: false,
isUsed: false, isUsed: false,
@@ -50,7 +58,7 @@ export const usePrizeConfig = defineStore('prize', {
}, },
// 获取奖品列表 // 获取奖品列表
getPrizeConfig(state) { getPrizeConfig(state) {
return state.prizeConfig.prizeList; return state.prizeConfig.prizeList;
}, },
// 根据id获取配置 // 根据id获取配置
getPrizeConfigById(state) { getPrizeConfigById(state) {
@@ -63,7 +71,7 @@ return state.prizeConfig.prizeList;
return state.prizeConfig.currentPrize; return state.prizeConfig.currentPrize;
}, },
// 获取临时的奖项 // 获取临时的奖项
getTemporaryPrize(state){ getTemporaryPrize(state) {
return state.prizeConfig.temporaryPrize; return state.prizeConfig.temporaryPrize;
}, },
@@ -83,16 +91,16 @@ return state.prizeConfig.prizeList;
}, },
// 更新奖项数据 // 更新奖项数据
updatePrizeConfig(prizeConfigItem: IPrizeConfig) { updatePrizeConfig(prizeConfigItem: IPrizeConfig) {
const prizeListLength=this.prizeConfig.prizeList.length; const prizeListLength = this.prizeConfig.prizeList.length;
if(prizeConfigItem.isUsed&&prizeListLength){ if (prizeConfigItem.isUsed && prizeListLength) {
for(let i=0;i<prizeListLength;i++){ for (let i = 0; i < prizeListLength; i++) {
if(!this.prizeConfig.prizeList[i].isUsed){ if (!this.prizeConfig.prizeList[i].isUsed) {
this.setCurrentPrize(this.prizeConfig.prizeList[i]); this.setCurrentPrize(this.prizeConfig.prizeList[i]);
break; break;
} }
} }
} }
else{ else {
return return
} }
this.resetTemporaryPrize() this.resetTemporaryPrize()
@@ -107,19 +115,19 @@ return state.prizeConfig.prizeList;
}, },
// 设置临时奖项 // 设置临时奖项
setTemporaryPrize(prizeItem: IPrizeConfig) { setTemporaryPrize(prizeItem: IPrizeConfig) {
if(prizeItem.isShow==false){ if (prizeItem.isShow == false) {
for(let i=0;i<this.prizeConfig.prizeList.length;i++){ for (let i = 0; i < this.prizeConfig.prizeList.length; i++) {
if(this.prizeConfig.prizeList[i].isUsed==false){ if (this.prizeConfig.prizeList[i].isUsed == false) {
this.setCurrentPrize(this.prizeConfig.prizeList[i]); this.setCurrentPrize(this.prizeConfig.prizeList[i]);
break break
} }
} }
this.resetTemporaryPrize() this.resetTemporaryPrize()
return return
} }
this.prizeConfig.temporaryPrize = prizeItem this.prizeConfig.temporaryPrize = prizeItem
}, },
// 重置临时奖项 // 重置临时奖项
@@ -130,7 +138,7 @@ return
sort: 0, sort: 0,
isAll: false, isAll: false,
count: 1, count: 1,
isUsedCount:0, isUsedCount: 0,
picture: { picture: {
id: '-1', id: '-1',
name: '', name: '',
@@ -148,22 +156,26 @@ return
prizeList: defaultPrizeList, prizeList: defaultPrizeList,
currentPrize: { currentPrize: {
id: '001', id: '001',
name: '等奖', name: '等奖',
sort: 1, sort: 1,
isAll: true, isAll: false,
count: 1, count: 12,
isUsedCount:0, isUsedCount: 0,
picture: { picture: {
id: '0', id: '2',
name: '等奖', name: '等奖',
url: 'https://24years.top/resource/image/image1.png' url: 'https://24years.top/resource/image/image3.png'
}, },
desc: '一等奖', separateCount: {
enable: true,
countList: []
},
desc: '三等奖',
isShow: true, isShow: true,
isUsed: false, isUsed: false,
frequency: 1, frequency: 1,
} as IPrizeConfig, } as IPrizeConfig,
temporaryPrize:{} as IPrizeConfig temporaryPrize: {} as IPrizeConfig
} }
} }
}, },

View File

@@ -13,10 +13,11 @@ import PatternSetting from './components/PatternSetting.vue'
const globalConfig = useStore().globalConfig const globalConfig = useStore().globalConfig
const personConfig = useStore().personConfig const personConfig = useStore().personConfig
const prizeConfig= useStore().prizeConfig
const { getTopTitle: topTitle, getTheme: localTheme, getPatterColor: patternColor, getPatternList: patternList, getCardColor: cardColor, getLuckyColor: luckyCardColor, getTextColor: textColor, getCardSize: cardSize, getTextSize: textSize, getRowCount: rowCount, getIsShowPrizeList: isShowPrizeList } = storeToRefs(globalConfig) const { getTopTitle: topTitle, getTheme: localTheme, getPatterColor: patternColor, getPatternList: patternList, getCardColor: cardColor, getLuckyColor: luckyCardColor, getTextColor: textColor, getCardSize: cardSize, getTextSize: textSize, getRowCount: rowCount, getIsShowPrizeList: isShowPrizeList } = storeToRefs(globalConfig)
const { getAlreadyPersonList: alreadyPersonList, getNotPersonList: notPersonList } = storeToRefs(personConfig) const { getAlreadyPersonList: alreadyPersonList, getNotPersonList: notPersonList } = storeToRefs(personConfig)
const colorPickerRef = ref() const colorPickerRef = ref()
const resetDataDialogRef=ref()
interface ThemeDaType { interface ThemeDaType {
[key: string]: any [key: string]: any
} }
@@ -87,6 +88,14 @@ const resetPattern = () => {
globalConfig.resetPatternList() globalConfig.resetPatternList()
} }
const resetData=()=>{
globalConfig.reset();
personConfig.reset();
prizeConfig.resetDefault();
// 刷新页面
window.location.reload()
}
// const handleChangeShowFields = (fieldItem: any) => { // const handleChangeShowFields = (fieldItem: any) => {
// formData.value.showField.map((item) => { // formData.value.showField.map((item) => {
// if (item.label === fieldItem.label) { // if (item.label === fieldItem.label) {
@@ -144,7 +153,24 @@ onMounted(() => {
</script> </script>
<template> <template>
<dialog id="my_modal_1" ref="resetDataDialogRef" class="border-none modal">
<div class="modal-box">
<h3 class="text-lg font-bold">提示!</h3>
<p class="py-4">该操作会重置所有数据是否继续</p>
<div class="modal-action">
<form method="dialog" class="flex gap-3">
<!-- if there is a button in form, it will close the modal -->
<button class="btn" @click="resetDataDialogRef.close()">取消</button>
<button class="btn" @click="resetData">确定</button>
</form>
</div>
</div>
</dialog>
<div> <div>
<h2>全局配置</h2>
<div class="mb-8">
<button class="btn btn-sm btn-primary" @click="resetDataDialogRef.showModal()">重置所有数据</button>
</div>
<label class="flex flex-row items-center w-full gap-24 mb-10 form-control"> <label class="flex flex-row items-center w-full gap-24 mb-10 form-control">
<div class=""> <div class="">
<div class="label"> <div class="label">

View File

@@ -135,7 +135,7 @@ onMounted(() => {
<dialog id="my_modal_1" ref="resetDataDialog" class="border-none modal"> <dialog id="my_modal_1" ref="resetDataDialog" class="border-none modal">
<div class="modal-box"> <div class="modal-box">
<h3 class="text-lg font-bold">提示!</h3> <h3 class="text-lg font-bold">提示!</h3>
<p class="py-4">该操作会重置所有人员数据是否继续</p> <p class="py-4">该操作会清空人员中奖信息是否继续</p>
<div class="modal-action"> <div class="modal-action">
<form method="dialog" class="flex gap-3"> <form method="dialog" class="flex gap-3">
<!-- if there is a button in form, it will close the modal --> <!-- if there is a button in form, it will close the modal -->
@@ -161,7 +161,7 @@ onMounted(() => {
<div class="min-w-1000px"> <div class="min-w-1000px">
<h2>人员管理</h2> <h2>人员管理</h2>
<div class="flex gap-3 justify-"> <div class="flex gap-3">
<button class="btn btn-error btn-sm" @click="delAllDataDialog.showModal()">全部删除</button> <button class="btn btn-error btn-sm" @click="delAllDataDialog.showModal()">全部删除</button>
<div class="tooltip tooltip-bottom" data-tip="下载文件后请在excel中填写数据并保存为xlsx格式"> <div class="tooltip tooltip-bottom" data-tip="下载文件后请在excel中填写数据并保存为xlsx格式">
<a class="no-underline btn btn-secondary btn-sm" download="人口登记表.xlsx" target="_blank" <a class="no-underline btn btn-secondary btn-sm" download="人口登记表.xlsx" target="_blank"
@@ -180,7 +180,7 @@ onMounted(() => {
<!-- <button class="btn btn-primary btn-sm">上传excel</button> --> <!-- <button class="btn btn-primary btn-sm">上传excel</button> -->
</div> </div>
<button class="btn btn-error btn-sm" @click="resetDataDialog.showModal()">重置数据</button> <button class="btn btn-error btn-sm" @click="resetDataDialog.showModal()">重置人员数据</button>
<button class="btn btn-accent btn-sm" @click="exportData">导出结果</button> <button class="btn btn-accent btn-sm" @click="exportData">导出结果</button>
<div> <div>
<span>中奖人数</span> <span>中奖人数</span>