feat: new
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import { useUserStore } from './user';
|
||||
|
||||
import {usePersonConfig} from './personConfig';
|
||||
import { usePrizeConfig } from './prizeConfig';
|
||||
export default function useStore() {
|
||||
return {
|
||||
user: useUserStore(),
|
||||
personConfig:usePersonConfig(),
|
||||
prizeConfig:usePrizeConfig()
|
||||
};
|
||||
}
|
||||
|
||||
102
src/store/personConfig.ts
Normal file
102
src/store/personConfig.ts
Normal file
@@ -0,0 +1,102 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { IPersonConfig } from '@/types/personConfig';
|
||||
export const usePersonConfig = defineStore('person', {
|
||||
state() {
|
||||
return {
|
||||
personConfig:{
|
||||
alreadyPersonList:[] as IPersonConfig[],
|
||||
notPersonList:[] as IPersonConfig[],
|
||||
tableRowCount:12,
|
||||
showField:[] as any[]
|
||||
}
|
||||
};
|
||||
},
|
||||
getters: {
|
||||
// 获取全部配置
|
||||
getPersonConfig(state) {
|
||||
return state.personConfig;
|
||||
},
|
||||
// 获取已中奖人员名单
|
||||
getAlreadyPersonList(state) {
|
||||
return state.personConfig.alreadyPersonList;
|
||||
},
|
||||
// 获取未中奖人员名单
|
||||
getNotPersonList(state) {
|
||||
return state.personConfig.notPersonList;
|
||||
},
|
||||
// 获取table列数
|
||||
getTableRowCount(state) {
|
||||
return state.personConfig.tableRowCount;
|
||||
},
|
||||
// 获取要展示那些字段
|
||||
getShowField(state) {
|
||||
return state.personConfig.showField;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
// 添加未中奖人员
|
||||
addNotPersonList(personList: IPersonConfig[]) {
|
||||
if(personList.length<=0){
|
||||
return
|
||||
}
|
||||
personList.forEach((item: IPersonConfig) => {
|
||||
this.personConfig.notPersonList.push(item);
|
||||
});
|
||||
},
|
||||
// 添加已中奖人员
|
||||
addAlreadyPersonList(personList: IPersonConfig[]) {
|
||||
if(personList.length<=0){
|
||||
return
|
||||
}
|
||||
personList.forEach((item: IPersonConfig) => {
|
||||
this.personConfig.alreadyPersonList.push(item);
|
||||
this.personConfig.notPersonList = this.personConfig.notPersonList.filter((item: IPersonConfig) => item.id!== item.id);
|
||||
});
|
||||
},
|
||||
// 删除所有人员
|
||||
deleteAllPerson() {
|
||||
this.personConfig.alreadyPersonList = [];
|
||||
this.personConfig.notPersonList = [];
|
||||
},
|
||||
// 设置table列数
|
||||
setTableRowCount(tableRowCount: number) {
|
||||
this.personConfig.tableRowCount = tableRowCount;
|
||||
},
|
||||
// 设置要展示那些字段
|
||||
setShowFields(showField: any[]) {
|
||||
this.personConfig.showField = showField;
|
||||
},
|
||||
// 重置所有人员
|
||||
resetPerson() {
|
||||
this.personConfig.alreadyPersonList = [];
|
||||
this.personConfig.notPersonList = [];
|
||||
},
|
||||
// 重置已中奖人员
|
||||
resetAlreadyPerson() {
|
||||
// 把已中奖人员合并到未中奖人员,要验证是否已存在
|
||||
if(this.personConfig.alreadyPersonList.length>0){
|
||||
this.personConfig.notPersonList = this.personConfig.notPersonList.concat(this.personConfig.alreadyPersonList);
|
||||
this.personConfig.alreadyPersonList = [];
|
||||
}
|
||||
},
|
||||
// 重置所有配置
|
||||
reset() {
|
||||
this.personConfig = {
|
||||
alreadyPersonList:[] as IPersonConfig[],
|
||||
notPersonList:[] as IPersonConfig[],
|
||||
tableRowCount:12,
|
||||
showField:[] as string[]
|
||||
}
|
||||
},
|
||||
},
|
||||
persist: {
|
||||
enabled: true,
|
||||
strategies: [
|
||||
{
|
||||
// 如果要存储在localStorage中
|
||||
storage: localStorage,
|
||||
key: 'personConfig',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
59
src/store/prizeConfig.ts
Normal file
59
src/store/prizeConfig.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import { IPrizeConfig } from '@/types/prizeConfig';
|
||||
export const usePrizeConfig = defineStore('prize', {
|
||||
state() {
|
||||
return {
|
||||
prizeConfig:{
|
||||
prizeList:[] as IPrizeConfig[],
|
||||
}
|
||||
};
|
||||
},
|
||||
getters: {
|
||||
// 获取全部配置
|
||||
getPrizeConfig(state) {
|
||||
return state.prizeConfig.prizeList;
|
||||
},
|
||||
// 根据id获取配置
|
||||
getPrizeConfigById(state) {
|
||||
return (id: number|string) => {
|
||||
return state.prizeConfig.prizeList.find(item => item.id === id);
|
||||
}
|
||||
},
|
||||
|
||||
},
|
||||
actions: {
|
||||
// 设置奖项
|
||||
setPrizeConfig(prizeList:IPrizeConfig[]) {
|
||||
this.prizeConfig.prizeList = prizeList;
|
||||
},
|
||||
// 添加奖项
|
||||
addPrizeConfig(prizeConfigItem: IPrizeConfig) {
|
||||
this.prizeConfig.prizeList.push(prizeConfigItem);
|
||||
},
|
||||
// 删除奖项
|
||||
deletePrizeConfig(prizeConfigItemId: number|string) {
|
||||
this.prizeConfig.prizeList = this.prizeConfig.prizeList.filter(item => item.id!== prizeConfigItemId);
|
||||
},
|
||||
// 更新奖项数据
|
||||
updatePrizeConfig(prizeConfigItem: IPrizeConfig) {
|
||||
const index = this.prizeConfig.prizeList.findIndex(item => item.id === prizeConfigItem.id);
|
||||
this.prizeConfig.prizeList[index] = prizeConfigItem;
|
||||
},
|
||||
// 重置所有配置
|
||||
reset() {
|
||||
this.prizeConfig = {
|
||||
prizeList:[] as IPrizeConfig[],
|
||||
}
|
||||
},
|
||||
},
|
||||
persist: {
|
||||
enabled: true,
|
||||
strategies: [
|
||||
{
|
||||
// 如果要存储在localStorage中
|
||||
storage: localStorage,
|
||||
key: 'personConfig',
|
||||
},
|
||||
],
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user