Browse Source

refactor(system): 重构游戏分数模块

- 移除 GameScore 组件中的加分编辑功能
- 新增 GameScoreBonus 组件专门用于加分编辑
- 优化 GameAthlete 组件中的状态显示
- 调整路由配置,移除未使用的导入
zhou 1 month ago
parent
commit
e9db5f3406

+ 1 - 1
src/router/index.ts

@@ -1,4 +1,4 @@
-import { createWebHistory, createRouter, RouteRecordRaw } from 'vue-router';
+import { createWebHistory, createRouter, RouteRecordRaw } from 'vue-router';
 /* Layout */
 import Layout from '@/layout/index.vue';
 

+ 6 - 2
src/views/system/gameAthlete/index.vue

@@ -83,7 +83,11 @@
         <!-- <el-table-column label="T恤尺码" align="center" prop="tshirtSize" v-if="columns[12].visible" /> -->
         <!-- <el-table-column label="组别" align="center" prop="groupType" v-if="columns[13].visible" /> -->
         <!-- <el-table-column label="号码" align="center" prop="number" v-if="columns[14].visible" /> -->
-        <el-table-column label="状态" align="center" prop="status" v-if="columns[9].visible" />
+        <el-table-column label="状态" align="center" prop="status" v-if="columns[9].visible" >
+          <template #default="scope">
+            <dict-tag :options="game_event_status" :value="scope.row.status" />
+          </template>
+        </el-table-column>
         <el-table-column label="备注" align="center" prop="remark" v-if="columns[10].visible" />
         <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
           <template #default="scope">
@@ -193,7 +197,7 @@ import { GameEventVO } from '@/api/system/gameEvent/types';
 import { globalHeaders } from '@/utils/request';
 
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
-const { sys_user_sex } = toRefs<any>(proxy?.useDict('sys_user_sex'));
+const { sys_user_sex, game_event_status } = toRefs<any>(proxy?.useDict('sys_user_sex','game_event_status'));
 const defaultEvent = ref<GameEventVO | null>(null); // 默认赛事信息
 
 const gameTeamList = ref<GameTeamVO[]>([]); // 队伍列表

+ 261 - 0
src/views/system/gameScore/gameScoreBonus.vue

@@ -0,0 +1,261 @@
+<template>
+  <div class="p-2">
+    <el-card shadow="never">
+      <template #header>
+        <el-row :gutter="10" class="mb8">
+          <el-col :span="1.5">
+            <el-button type="primary" @click="saveBonusChanges" :loading="saveLoading">
+              <el-icon><Check /></el-icon> 保存修改
+            </el-button>
+          </el-col>
+          <el-col :span="1.5">
+            <el-button type="success" @click="exportBonusData" :loading="exportLoading">
+              <el-icon><Download /></el-icon> 导出Excel
+            </el-button>
+          </el-col>
+          <el-col :span="1.5">
+            <el-button @click="refreshBonusData">
+              <el-icon><Refresh /></el-icon> 刷新数据
+            </el-button>
+          </el-col>
+          <right-toolbar v-model:showSearch="showSearch" @queryTable="loadBonusData" :columns="columns"></right-toolbar>
+        </el-row>
+      </template>
+      
+      <el-table 
+        v-loading="bonusLoading" 
+        border 
+        :data="bonusDataList" 
+        @selection-change="handleBonusSelectionChange">
+        <el-table-column type="selection" width="55" align="center" />
+        <el-table-column label="序号" align="center" width="80">
+          <template #default="scope">
+            {{ scope.$index + 1 }}
+          </template>
+        </el-table-column>
+        <el-table-column label="代表队名称" align="center" prop="teamName" width="150" />
+        <el-table-column label="排名" align="center" prop="rank" width="80" />
+        <el-table-column label="总分" align="center" prop="totalScore" width="100" />
+        
+        <!-- 动态项目列 -->
+        <el-table-column 
+          v-for="project in bonusProjectList" 
+          :key="project.projectId" 
+          :label="project.projectName" 
+          align="center" 
+          width="120">
+          <template #default="scope">
+            {{ scope.row.projectScores[project.projectName] || 0 }}
+          </template>
+        </el-table-column>
+        
+        <!-- 领导加分列 - 可编辑 -->
+        <el-table-column label="领导加分" align="center" width="120">
+          <template #default="scope">
+            <el-input 
+              v-model="scope.row.leaderPoint" 
+              type="number" 
+              step="0.01"
+              size="small"
+              @input="calculateTotalScore(scope.row)"
+              @blur="calculateTotalScore(scope.row)" />
+          </template>
+        </el-table-column>
+        
+        <!-- 额外加分列 - 可编辑 -->
+        <el-table-column label="额外加分" align="center" width="120">
+          <template #default="scope">
+            <el-input 
+              v-model="scope.row.extraPoint" 
+              type="number" 
+              step="0.01"
+              size="small"
+              @input="calculateTotalScore(scope.row)"
+              @blur="calculateTotalScore(scope.row)" />
+          </template>
+        </el-table-column>
+      </el-table>
+    </el-card>
+  </div>
+</template>
+
+<script setup name="GameScoreBonus" lang="ts">
+import { getBonusData, updateBonusData, exportBonusExcel } from '@/api/system/gameScore';
+import { useGameEventStore } from '@/store/modules/gameEvent';
+
+const { proxy } = getCurrentInstance() as ComponentInternalInstance;
+
+// 默认赛事信息
+const gameEventStore = useGameEventStore();
+
+const bonusLoading = ref(false);
+const saveLoading = ref(false);
+const exportLoading = ref(false);
+const showSearch = ref(true);
+
+const bonusDataList = ref<any[]>([]);
+const bonusProjectList = ref<any[]>([]);
+const selectedBonusRows = ref<any[]>([]);
+
+// 列显隐数据
+const columns = ref<FieldOption[]>([
+  { key: 0, label: '序号', visible: true },
+  { key: 1, label: '代表队名称', visible: true },
+  { key: 2, label: '排名', visible: true },
+  { key: 3, label: '总分', visible: true },
+  { key: 4, label: '领导加分', visible: true },
+  { key: 5, label: '额外加分', visible: true },
+]);
+
+// 加载加分数据
+const loadBonusData = async () => {
+  bonusLoading.value = true;
+  try {
+    const event = gameEventStore.defaultEventInfo;
+    const eventId = event?.eventId;
+    
+    if (!eventId) {
+      proxy?.$modal.msgWarning('未指定赛事,无法加载加分数据');
+      return;
+    }
+    
+    const response = await getBonusData({
+      eventId: eventId
+    });
+    
+    bonusDataList.value = response.data.rows || [];
+    bonusProjectList.value = response.data.projects || [];
+    
+    // 初始化加分字段
+    bonusDataList.value.forEach((row: any) => {
+      if (!row.leaderPoint) row.leaderPoint = 0;
+      if (!row.extraPoint) row.extraPoint = 0;
+      calculateTotalScore(row);
+    });
+  } catch (error) {
+    console.error("加载加分数据失败:", error);
+    proxy?.$modal.msgError("加载加分数据失败");
+  } finally {
+    bonusLoading.value = false;
+  }
+};
+
+// 计算总分
+const calculateTotalScore = (row: any) => {
+  let totalScore = 0;
+  
+  // 累加各项目积分
+  Object.values(row.projectScores || {}).forEach((score: any) => {
+    totalScore += Number(score) || 0;
+  });
+  
+  // 加上领导加分和额外加分
+  totalScore += Number(row.leaderPoint) || 0;
+  totalScore += Number(row.extraPoint) || 0;
+  
+  row.totalScore = totalScore;
+  
+  // 重新计算排名
+  calculateBonusRankings();
+};
+
+// 计算excel表排名
+const calculateBonusRankings = () => {
+  // 按总分排序
+  const sortedData = [...bonusDataList.value].sort((a, b) => b.totalScore - a.totalScore);
+  
+  // 更新排名
+  sortedData.forEach((row, index) => {
+    row.rank = index + 1;
+  });
+  
+  // 更新原数组
+  bonusDataList.value = sortedData;
+};
+
+// 选择变化处理
+const handleBonusSelectionChange = (selection: any[]) => {
+  selectedBonusRows.value = selection;
+};
+
+// 保存加分修改
+const saveBonusChanges = async () => {
+  try {
+    saveLoading.value = true;
+    
+    const event = gameEventStore.defaultEventInfo;
+    const eventId = event?.eventId;
+    
+    if (!eventId) {
+      proxy?.$modal.msgWarning('未指定赛事,无法保存');
+      return;
+    }
+    
+    const updateData = bonusDataList.value.map(row => ({
+      teamId: row.teamId,
+      leaderPoint: Number(row.leaderPoint) || 0,
+      extraPoint: Number(row.extraPoint) || 0,
+      totalScore: row.totalScore,
+      rank: row.rank
+    }));
+    
+    await updateBonusData({
+      eventId: eventId,
+      data: updateData
+    });
+    
+    proxy?.$modal.msgSuccess("保存成功");
+  } catch (error) {
+    console.error("保存失败:", error);
+    proxy?.$modal.msgError("保存失败,请稍后再试");
+  } finally {
+    saveLoading.value = false;
+  }
+};
+
+// 导出加分数据方法
+const exportBonusData = async () => {
+  try {
+    exportLoading.value = true;
+    
+    const event = gameEventStore.defaultEventInfo;
+    const eventId = event?.eventId;
+    
+    if (!eventId) {
+      proxy?.$modal.msgWarning('未指定默认赛事,无法导出');
+      return;
+    }
+    
+    // 使用 proxy?.download 方法,传递JSON字符串参数
+    proxy?.download(
+      '/system/gameScore/exportBonusExcel',
+      {
+        eventId: eventId,
+        data: JSON.stringify(bonusDataList.value),
+        projects: JSON.stringify(bonusProjectList.value)
+      },
+      `总成绩排名表_${new Date().toLocaleDateString()}.xlsx`
+    );
+    
+    proxy?.$modal.msgSuccess("导出成功");
+  } catch (error) {
+    console.error("导出失败:", error);
+    proxy?.$modal.msgError("导出失败,请稍后再试");
+  } finally {
+    exportLoading.value = false;
+  }
+};
+
+// 刷新加分数据
+const refreshBonusData = async () => {
+  await loadBonusData();
+};
+
+onMounted(async () => {
+  // 先加载默认赛事信息
+  await gameEventStore.fetchDefaultEvent();
+  // 然后加载加分数据
+  await loadBonusData();
+});
+</script>
+

+ 98 - 172
src/views/system/gameScore/index.vue

@@ -35,14 +35,14 @@
           <el-col :span="1.5">
             <el-button type="primary" @click="printScores">打印成绩(前3名)</el-button>
           </el-col>
-          <el-col :span="1.5">
+          <!-- <el-col :span="1.5">
             <el-button type="primary" @click="exportScoresNames">导出成绩(全部)</el-button>
-          </el-col>
-          <el-col :span="1.5">
+          </el-col> -->
+          <!-- <el-col :span="1.5">
             <el-button type="warning" @click="openBonusDialog" :loading="bonusLoading">
               <el-icon><Edit /></el-icon> 加分
             </el-button>
-          </el-col>
+          </el-col> -->
           <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
         </el-row>
       </template>
@@ -97,80 +97,6 @@
       <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
     </el-card>
 
-    <!-- 加分编辑弹窗 -->
-    <el-dialog 
-      title="加分编辑" 
-      v-model="bonusDialog.visible" 
-      width="80%" 
-      :close-on-click-modal="false"
-      append-to-body>
-      <div class="mb-4">
-        <el-button type="primary" @click="saveBonusChanges" :loading="saveLoading">
-          <el-icon><Check /></el-icon> 保存修改
-        </el-button>
-        <el-button type="success" @click="exportBonusData" :loading="exportLoading">
-          <el-icon><Download /></el-icon> 导出Excel
-        </el-button>
-        <el-button @click="refreshBonusData">
-          <el-icon><Refresh /></el-icon> 刷新数据
-        </el-button>
-      </div>
-      
-      <el-table 
-        v-loading="bonusLoading" 
-        border 
-        :data="bonusDataList" 
-        max-height="600"
-        @selection-change="handleBonusSelectionChange">
-        <el-table-column type="selection" width="55" align="center" />
-        <el-table-column label="序号" align="center" width="80">
-          <template #default="scope">
-            {{ scope.$index + 1 }}
-          </template>
-        </el-table-column>
-        <el-table-column label="代表队名称" align="center" prop="teamName" width="150" />
-        <el-table-column label="排名" align="center" prop="rank" width="80" />
-        <el-table-column label="总分" align="center" prop="totalScore" width="100" />
-        
-        <!-- 动态项目列 -->
-        <el-table-column 
-          v-for="project in bonusProjectList" 
-          :key="project.projectId" 
-          :label="project.projectName" 
-          align="center" 
-          width="120">
-          <template #default="scope">
-            {{ scope.row.projectScores[project.projectName] || 0 }}
-          </template>
-        </el-table-column>
-        
-        <!-- 领导加分列 - 可编辑 -->
-        <el-table-column label="领导加分" align="center" width="120">
-          <template #default="scope">
-            <el-input 
-              v-model="scope.row.leaderPoint" 
-              type="number" 
-              step="0.01"
-              size="small"
-              @input="calculateTotalScore(scope.row)"
-              @blur="calculateTotalScore(scope.row)" />
-          </template>
-        </el-table-column>
-        
-        <!-- 额外加分列 - 可编辑 -->
-        <el-table-column label="额外加分" align="center" width="120">
-          <template #default="scope">
-            <el-input 
-              v-model="scope.row.extraPoint" 
-              type="number" 
-              step="0.01"
-              size="small"
-              @input="calculateTotalScore(scope.row)"
-              @blur="calculateTotalScore(scope.row)" />
-          </template>
-        </el-table-column>
-      </el-table>
-    </el-dialog>
   </div>
 </template>
 
@@ -200,14 +126,14 @@ const single = ref(true);
 const multiple = ref(true);
 const total = ref(0);
 
-// 加分弹窗相关数据
-const bonusLoading = ref(false);
-const saveLoading = ref(false);
-const exportLoading = ref(false);
-const bonusDialog = reactive({
-  visible: false,
-  title: '加分编辑'
-});
+// // 加分弹窗相关数据
+// const bonusLoading = ref(false);
+// const saveLoading = ref(false);
+// const exportLoading = ref(false);
+// const bonusDialog = reactive({
+//   visible: false,
+//   title: '加分编辑'
+// });
 
 const bonusDataList = ref<any[]>([]);
 const bonusProjectList = ref<any[]>([]);
@@ -263,30 +189,30 @@ const { queryParams, form, rules } = toRefs(data);
 
 // 加分相关方法
 // 打开加分弹窗
-const openBonusDialog = async () => {
-  try {
-    bonusLoading.value = true;
-    bonusDialog.visible = true;
+// const openBonusDialog = async () => {
+//   try {
+//     bonusLoading.value = true;
+//     bonusDialog.visible = true;
     
-    // 获取默认赛事ID
-    const event = gameEventStore.defaultEventInfo;
-    const eventId = event?.eventId;
-
-    if (!eventId) {
-      proxy?.$modal.msgWarning('未指定赛事,无法进行加分操作');
-      bonusDialog.visible = false;
-      return;
-    }
+//     // 获取默认赛事ID
+//     const event = gameEventStore.defaultEventInfo;
+//     const eventId = event?.eventId;
+
+//     if (!eventId) {
+//       proxy?.$modal.msgWarning('未指定赛事,无法进行加分操作');
+//       bonusDialog.visible = false;
+//       return;
+//     }
     
-    // 获取加分数据
-    await loadBonusData(eventId);
-  } catch (error) {
-    console.error("打开加分弹窗失败:", error);
-    proxy?.$modal.msgError("加载加分数据失败");
-  } finally {
-    bonusLoading.value = false;
-  }
-};
+//     // 获取加分数据
+//     await loadBonusData(eventId);
+//   } catch (error) {
+//     console.error("打开加分弹窗失败:", error);
+//     proxy?.$modal.msgError("加载加分数据失败");
+//   } finally {
+//     bonusLoading.value = false;
+//   }
+// };
 
 // 加载加分数据
 const loadBonusData = async (eventId: string | number) => {
@@ -349,85 +275,85 @@ const handleBonusSelectionChange = (selection: any[]) => {
 };
 
 // 保存加分修改
-const saveBonusChanges = async () => {
-  try {
-    saveLoading.value = true;
+// const saveBonusChanges = async () => {
+//   try {
+//     saveLoading.value = true;
     
-    const event = gameEventStore.defaultEventInfo;
-    const eventId = event?.eventId;
+//     const event = gameEventStore.defaultEventInfo;
+//     const eventId = event?.eventId;
     
-    if (!eventId) {
-      proxy?.$modal.msgWarning('未指定赛事,无法保存');
-      return;
-    }
+//     if (!eventId) {
+//       proxy?.$modal.msgWarning('未指定赛事,无法保存');
+//       return;
+//     }
     
-    const updateData = bonusDataList.value.map(row => ({
-      teamId: row.teamId,
-      leaderPoint: Number(row.leaderPoint) || 0,
-      extraPoint: Number(row.extraPoint) || 0,
-      totalScore: row.totalScore,
-      rank: row.rank
-    }));
+//     const updateData = bonusDataList.value.map(row => ({
+//       teamId: row.teamId,
+//       leaderPoint: Number(row.leaderPoint) || 0,
+//       extraPoint: Number(row.extraPoint) || 0,
+//       totalScore: row.totalScore,
+//       rank: row.rank
+//     }));
     
-    await updateBonusData({
-      eventId: eventId,
-      data: updateData
-    });
+//     await updateBonusData({
+//       eventId: eventId,
+//       data: updateData
+//     });
     
-    proxy?.$modal.msgSuccess("保存成功");
+//     proxy?.$modal.msgSuccess("保存成功");
     
-    // 刷新主页面数据
-    // await refreshData();
-  } catch (error) {
-    console.error("保存失败:", error);
-    proxy?.$modal.msgError("保存失败,请稍后再试");
-  } finally {
-    saveLoading.value = false;
-  }
-};
+//     // 刷新主页面数据
+//     // await refreshData();
+//   } catch (error) {
+//     console.error("保存失败:", error);
+//     proxy?.$modal.msgError("保存失败,请稍后再试");
+//   } finally {
+//     saveLoading.value = false;
+//   }
+// };
 
 // 导出加分数据方法
-const exportBonusData = async () => {
-  try {
-    exportLoading.value = true;
+// const exportBonusData = async () => {
+//   try {
+//     exportLoading.value = true;
     
-    const event = gameEventStore.defaultEventInfo;
-    const eventId = event?.eventId;
+//     const event = gameEventStore.defaultEventInfo;
+//     const eventId = event?.eventId;
     
-    if (!eventId) {
-      proxy?.$modal.msgWarning('未指定默认赛事,无法导出');
-      return;
-    }
+//     if (!eventId) {
+//       proxy?.$modal.msgWarning('未指定默认赛事,无法导出');
+//       return;
+//     }
     
-    // 使用 proxy?.download 方法,传递JSON字符串参数
-    proxy?.download(
-      '/system/gameScore/exportBonusExcel',
-      {
-        eventId: eventId,
-        data: JSON.stringify(bonusDataList.value),
-        projects: JSON.stringify(bonusProjectList.value)
-      },
-      `总成绩排名表_${new Date().toLocaleDateString()}.xlsx`
-    );
+//     // 使用 proxy?.download 方法,传递JSON字符串参数
+//     proxy?.download(
+//       '/system/gameScore/exportBonusExcel',
+//       {
+//         eventId: eventId,
+//         data: JSON.stringify(bonusDataList.value),
+//         projects: JSON.stringify(bonusProjectList.value)
+//       },
+//       `总成绩排名表_${new Date().toLocaleDateString()}.xlsx`
+//     );
     
-    proxy?.$modal.msgSuccess("导出成功");
-  } catch (error) {
-    console.error("导出失败:", error);
-    proxy?.$modal.msgError("导出失败,请稍后再试");
-  } finally {
-    exportLoading.value = false;
-  }
-};
+//     proxy?.$modal.msgSuccess("导出成功");
+//   } catch (error) {
+//     console.error("导出失败:", error);
+//     proxy?.$modal.msgError("导出失败,请稍后再试");
+//   } finally {
+//     exportLoading.value = false;
+//   }
+// };
 
 // 刷新加分数据
-const refreshBonusData = async () => {
-  const event = gameEventStore.defaultEventInfo;
-  const eventId = event?.eventId;
+// const refreshBonusData = async () => {
+//   const event = gameEventStore.defaultEventInfo;
+//   const eventId = event?.eventId;
   
-  if (eventId) {
-    await loadBonusData(eventId);
-  }
-};
+//   if (eventId) {
+//     await loadBonusData(eventId);
+//   }
+// };
 
 /** 查询成绩列表 */
 const getList = async () => {