chore: 基本服务器版本完成
This commit is contained in:
@@ -35,9 +35,10 @@
|
||||
<div class="top-nav">
|
||||
<h1 class="nav-title">📊 百人大战管理系统</h1>
|
||||
<div class="nav-actions">
|
||||
<span class="welcome-text">欢迎您,{{ currentUser.username }}!</span>
|
||||
<button @click="logout" class="logout-btn">退出登录</button>
|
||||
</div>
|
||||
<span class="welcome-text">欢迎您,{{ currentUser.username }}!</span>
|
||||
<button @click="handleRefreshData" class="refresh-btn" style="margin-right: 10px;">刷新数据</button>
|
||||
<button @click="logout" class="logout-btn">退出登录</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 功能选项卡 -->
|
||||
@@ -319,6 +320,44 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 奖金设置 -->
|
||||
<div v-if="currentTab === 'bonus'" class="bonus-config-content">
|
||||
<h2 class="config-title">🎯 奖金设置</h2>
|
||||
<div class="config-section">
|
||||
<h3>🏆 奖金规则配置</h3>
|
||||
<div class="bonus-rules-list">
|
||||
<div
|
||||
v-for="(rule, index) in localBonusRules"
|
||||
:key="index"
|
||||
class="bonus-rule-item"
|
||||
>
|
||||
<div class="rule-form">
|
||||
<div class="form-group">
|
||||
<label>名次范围:</label>
|
||||
<input v-model="rule.rank" type="text" class="form-input" placeholder="如: 1-3">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>规则描述:</label>
|
||||
<input v-model="rule.description" type="text" class="form-input" placeholder="如: 前三名">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>个人奖励:</label>
|
||||
<input v-model="rule.individualBonus" type="text" class="form-input" placeholder="如: ¥10000, ¥8000, ¥5000">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label>团队奖励:</label>
|
||||
<input v-model="rule.teamBonus" type="text" class="form-input" placeholder="如: ¥50000, ¥30000, ¥20000">
|
||||
</div>
|
||||
<div class="form-actions">
|
||||
<button @click="deleteBonusRule(index)" class="delete-btn">🗑️ 删除</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<button @click="addBonusRule" class="add-btn" style="margin-top: 20px;">➕ 添加奖金规则</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 战鼓配置 -->
|
||||
<div v-if="currentTab === 'drum'" class="drum-config-content">
|
||||
<h2 class="config-title">🥁 战鼓配置管理</h2>
|
||||
@@ -652,20 +691,24 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive } from 'vue';
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import {
|
||||
individualRankings,
|
||||
teamRankings,
|
||||
systemUsers,
|
||||
saveIndividualRankings,
|
||||
import {
|
||||
individualRankings,
|
||||
teamRankings,
|
||||
systemUsers,
|
||||
bonusRules,
|
||||
saveIndividualRankings,
|
||||
saveTeamRankings,
|
||||
saveBonusRules,
|
||||
displayConfig,
|
||||
saveDisplayConfig,
|
||||
battleEndTime,
|
||||
saveBattleEndTime,
|
||||
drumConfig,
|
||||
saveDrumConfig
|
||||
saveDrumConfig,
|
||||
refreshData,
|
||||
initializeData
|
||||
} from '../data/mockData.js';
|
||||
|
||||
const router = useRouter();
|
||||
@@ -688,21 +731,80 @@ const currentUser = ref({});
|
||||
const tabs = [
|
||||
{ key: 'individual', label: '个人排名' },
|
||||
{ key: 'team', label: '战队排名' },
|
||||
{ key: 'bonus', label: '奖金设置' },
|
||||
{ key: 'config', label: '显示配置' },
|
||||
{ key: 'endTime', label: '结束时间设置' },
|
||||
{ key: 'drum', label: '战鼓配置' }
|
||||
];
|
||||
|
||||
// 刷新数据
|
||||
const handleRefreshData = () => {
|
||||
try {
|
||||
const success = refreshData();
|
||||
// 重新加载本地数据副本
|
||||
localIndividualRankings.value = [...individualRankings];
|
||||
localTeamRankings.value = [...teamRankings];
|
||||
localBonusRules.value = [...bonusRules];
|
||||
localDisplayConfig.value = {...displayConfig};
|
||||
localBattleEndTime.value = {...battleEndTime};
|
||||
localDrumConfig.value = {...drumConfig};
|
||||
|
||||
// 重新处理强拍位置
|
||||
if (localDrumConfig.value.pattern && localDrumConfig.value.pattern.strongBeats) {
|
||||
localDrumConfig.value.pattern.strongBeatsStr =
|
||||
localDrumConfig.value.pattern.strongBeats.join(',') || '1,4';
|
||||
}
|
||||
|
||||
if (success) {
|
||||
alert('数据刷新成功!');
|
||||
} else {
|
||||
alert('数据刷新失败,请重试。');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('数据刷新失败:', error);
|
||||
alert('数据刷新失败,请重试。');
|
||||
}
|
||||
};
|
||||
const currentTab = ref('individual');
|
||||
|
||||
// 本地数据副本
|
||||
const localIndividualRankings = ref([...individualRankings]);
|
||||
const localTeamRankings = ref([...teamRankings]);
|
||||
const localBonusRules = ref([...bonusRules]);
|
||||
const localDisplayConfig = ref({...displayConfig});
|
||||
const localBattleEndTime = ref({...battleEndTime});
|
||||
// 初始化本地战鼓配置副本
|
||||
const localDrumConfig = ref({...drumConfig});
|
||||
// 添加强拍位置的字符串表示,用于输入框
|
||||
localDrumConfig.value.pattern.strongBeatsStr = localDrumConfig.value.pattern.strongBeats?.join(',') || '1,4';
|
||||
if (localDrumConfig.value.pattern && localDrumConfig.value.pattern.strongBeats) {
|
||||
localDrumConfig.value.pattern.strongBeatsStr = localDrumConfig.value.pattern.strongBeats.join(',') || '1,4';
|
||||
} else {
|
||||
localDrumConfig.value.pattern = localDrumConfig.value.pattern || {};
|
||||
localDrumConfig.value.pattern.strongBeats = [1, 4];
|
||||
localDrumConfig.value.pattern.strongBeatsStr = '1,4';
|
||||
}
|
||||
|
||||
// 组件挂载时初始化数据
|
||||
onMounted(async () => {
|
||||
try {
|
||||
await initializeData();
|
||||
// 重新加载本地数据副本
|
||||
localIndividualRankings.value = [...individualRankings];
|
||||
localTeamRankings.value = [...teamRankings];
|
||||
localBonusRules.value = [...bonusRules];
|
||||
localDisplayConfig.value = {...displayConfig};
|
||||
localBattleEndTime.value = {...battleEndTime};
|
||||
localDrumConfig.value = {...drumConfig};
|
||||
|
||||
// 重新处理强拍位置
|
||||
if (localDrumConfig.value.pattern && localDrumConfig.value.pattern.strongBeats) {
|
||||
localDrumConfig.value.pattern.strongBeatsStr =
|
||||
localDrumConfig.value.pattern.strongBeats.join(',') || '1,4';
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('初始化数据失败:', error);
|
||||
}
|
||||
});
|
||||
|
||||
// 更新强拍位置数组
|
||||
const updateStrongBeats = () => {
|
||||
@@ -783,24 +885,45 @@ const goBack = () => {
|
||||
};
|
||||
|
||||
// 保存数据
|
||||
const saveData = () => {
|
||||
// 按分数重新排序
|
||||
localIndividualRankings.value.sort((a, b) => b.score - a.score);
|
||||
localTeamRankings.value.sort((a, b) => b.totalScore - a.totalScore);
|
||||
|
||||
// 调用保存方法
|
||||
saveIndividualRankings(localIndividualRankings.value);
|
||||
saveTeamRankings(localTeamRankings.value);
|
||||
saveDisplayConfig(localDisplayConfig.value);
|
||||
saveBattleEndTime(localBattleEndTime.value);
|
||||
// 保存战鼓配置前,确保强拍位置数组是最新的
|
||||
updateStrongBeats();
|
||||
// 移除临时的字符串表示,避免保存到配置中
|
||||
const configToSave = {...localDrumConfig.value};
|
||||
delete configToSave.pattern.strongBeatsStr;
|
||||
saveDrumConfig(configToSave);
|
||||
|
||||
alert('数据保存成功!');
|
||||
const saveData = async () => {
|
||||
try {
|
||||
// 按分数重新排序
|
||||
localIndividualRankings.value.sort((a, b) => b.score - a.score);
|
||||
localTeamRankings.value.sort((a, b) => b.totalScore - a.totalScore);
|
||||
|
||||
// 保存战鼓配置前,确保强拍位置数组是最新的
|
||||
updateStrongBeats();
|
||||
// 移除临时的字符串表示,避免保存到配置中
|
||||
const configToSave = {...localDrumConfig.value};
|
||||
delete configToSave.pattern.strongBeatsStr;
|
||||
|
||||
// 导入必要的配置服务函数
|
||||
const { readConfig, writeConfig } = await import('../services/configService');
|
||||
|
||||
// 一次性读取、修改并保存所有配置,避免竞态条件
|
||||
const currentConfig = await readConfig();
|
||||
|
||||
// 更新所有配置项
|
||||
currentConfig.individualRankings = localIndividualRankings.value;
|
||||
currentConfig.teamRankings = localTeamRankings.value;
|
||||
currentConfig.bonusRules = localBonusRules.value;
|
||||
currentConfig.displayConfig = localDisplayConfig.value;
|
||||
currentConfig.battleEndTime = localBattleEndTime.value;
|
||||
currentConfig.drumConfig = configToSave;
|
||||
|
||||
// 一次性保存所有配置
|
||||
const result = await writeConfig(currentConfig);
|
||||
|
||||
// 检查保存是否成功
|
||||
if (result) {
|
||||
alert('数据保存成功!');
|
||||
} else {
|
||||
alert('数据保存失败,请检查网络连接后重试。');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('保存数据时发生错误:', error);
|
||||
alert('保存数据失败,请重试。');
|
||||
}
|
||||
};
|
||||
|
||||
// 添加/编辑个人
|
||||
@@ -904,6 +1027,23 @@ const deleteTeam = (id) => {
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
// 添加奖金规则
|
||||
const addBonusRule = () => {
|
||||
localBonusRules.value.push({
|
||||
rank: '',
|
||||
description: '',
|
||||
individualBonus: '',
|
||||
teamBonus: ''
|
||||
});
|
||||
};
|
||||
|
||||
// 删除奖金规则
|
||||
const deleteBonusRule = (index) => {
|
||||
if (confirm('确定要删除这条奖金规则吗?')) {
|
||||
localBonusRules.value.splice(index, 1);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user