修复投票计数与状态同步,完善票据与戳显示

修复投票系统:禁止重复投票、恢复状态、同步大屏

完善投票流程与展示:计数准确、状态可恢复、样式统一
This commit is contained in:
empty
2026-01-28 21:37:05 +08:00
parent 66ca67c137
commit d090c80e50
27 changed files with 1541 additions and 1023 deletions

View File

@@ -18,6 +18,15 @@ export interface ProgramConfig {
id: string;
name: string;
teamName: string;
performer?: string; // 表演者
order: number;
remark?: string; // 节目备注
}
export interface AwardConfig {
id: string;
name: string;
icon: string;
order: number;
}
@@ -28,6 +37,7 @@ export interface ProgramSettings {
export interface ProgramConfigFile {
programs: ProgramConfig[];
awards: AwardConfig[];
settings: ProgramSettings;
}
@@ -49,8 +59,19 @@ class ProgramConfigService {
this.config = JSON.parse(content);
logger.info({
programCount: this.config?.programs.length,
awardCount: this.config?.awards?.length || 0,
configPath: this.configPath
}, 'Program config loaded');
// Validate: programs.length === awards.length
if (this.config?.programs && this.config?.awards) {
if (this.config.programs.length !== this.config.awards.length) {
logger.warn({
programCount: this.config.programs.length,
awardCount: this.config.awards.length
}, 'Warning: program count does not match award count');
}
}
} else {
logger.warn({ configPath: this.configPath }, 'Program config file not found, using defaults');
this.config = this.getDefaults();
@@ -67,14 +88,22 @@ class ProgramConfigService {
private getDefaults(): ProgramConfigFile {
return {
programs: [
{ id: 'p1', name: '龙腾四海', teamName: '市场部', order: 1 },
{ id: 'p2', name: '金马奔腾', teamName: '技术部', order: 2 },
{ id: 'p3', name: '春风得意', teamName: '人力资源部', order: 3 },
{ id: 'p4', name: '鸿运当头', teamName: '财务部', order: 4 },
{ id: 'p5', name: '马到成功', teamName: '运营部', order: 5 },
{ id: 'p6', name: '一马当先', teamName: '产品部', order: 6 },
{ id: 'p7', name: '万马奔腾', teamName: '设计部', order: 7 },
{ id: 'p8', name: '龙马精神', teamName: '销售部', order: 8 },
{ id: 'p1', name: '龙腾四海', teamName: '市场部', performer: '待定', order: 1, remark: '赞美节目如琥珀般凝固了某个经典、美好、闪光的瞬间。' },
{ id: 'p2', name: '金马奔腾', teamName: '技术部', performer: '待定', order: 2, remark: '强调节目留下了值得回味的"声音"。' },
{ id: 'p3', name: '春风得意', teamName: '人力资源部', performer: '待定', order: 3, remark: '赞美节目引发了跨越时代的共鸣。' },
{ id: 'p4', name: '鸿运当头', teamName: '财务部', performer: '待定', order: 4, remark: '形容节目用声音和表演编织了一个时代的梦境。' },
{ id: 'p5', name: '马到成功', teamName: '运营部', performer: '待定', order: 5, remark: '既指复刻了过去的潮流,也指创造了今晚的潮流。' },
{ id: 'p6', name: '一马当先', teamName: '产品部', performer: '待定', order: 6, remark: '强调节目的独特韵味与精心打磨。' },
{ id: 'p7', name: '万马奔腾', teamName: '设计部', performer: '待定', order: 7, remark: '赞美节目与"复古70-80"主题高度契合。' },
],
awards: [
{ id: 'time_amber', name: '时光琥珀奖', icon: '🏆', order: 1 },
{ id: 'echo_years', name: '岁月留声奖', icon: '🎵', order: 2 },
{ id: 'resonance', name: '风华共鸣奖', icon: '🎭', order: 3 },
{ id: 'dream_weaver', name: '光影织梦奖', icon: '✨', order: 4 },
{ id: 'trend_mark', name: '潮流印记奖', icon: '🌊', order: 5 },
{ id: 'craftsmanship', name: '匠心独韵奖', icon: '💎', order: 6 },
{ id: 'in_sync', name: '同频时代奖', icon: '📻', order: 7 },
],
settings: {
allowLateCatch: true,
@@ -90,6 +119,20 @@ class ProgramConfigService {
return this.config?.programs || this.getDefaults().programs;
}
/**
* Get all awards
*/
getAwards(): AwardConfig[] {
return this.config?.awards || this.getDefaults().awards;
}
/**
* Get award by id
*/
getAwardById(id: string): AwardConfig | undefined {
return this.getAwards().find(a => a.id === id);
}
/**
* Convert config programs to VotingProgram format (with runtime fields)
*/
@@ -135,6 +178,24 @@ class ProgramConfigService {
}
}
/**
* Update awards and save to file
*/
async updateAwards(awards: AwardConfig[]): Promise<{ success: boolean; error?: string }> {
try {
if (!this.config) {
this.config = this.getDefaults();
}
this.config.awards = awards;
await this.saveToFile();
logger.info({ awardCount: awards.length }, 'Awards updated');
return { success: true };
} catch (error) {
logger.error({ error }, 'Failed to update awards');
return { success: false, error: (error as Error).message };
}
}
/**
* Update settings and save to file
*/