Эх сурвалжийг харах

feat(gameScore): 优化成绩打印功能并更新状态标签

- 将“打印成绩(前3名)”按钮文案改为“打印成绩”
- 修改状态选项标签:“等待处理”改为“进行中”,“处理完毕”改为“完赛”
- 打印成绩时增加用户输入框,可自定义打印前N名数据
- 默认打印前3名,用户可修改打印条数
- 更新打印标题和内容中的“前3名”为动态显示用户设定的前N名
- 在构建打印HTML时动态设置排名样式,仅对前3名应用特殊样式
- 引入ElMessageBox和ElLoading以支持打印设置弹窗和加载提示
zhou 3 долоо хоног өмнө
parent
commit
4757c3ea30

+ 2 - 2
src/router/index.ts

@@ -128,7 +128,7 @@ export const constantRoutes: RouteRecordRaw[] = [
         path: '/system/gameEvent/rankingBoardPage/:eventId',
         name: 'RankingBoardPage',
         component: () => import('@/views/system/gameEvent/RankingBoardPage.vue'),
-        meta: { title: '比赛数据' }
+        meta: { title: '排行榜' }
       }
     ]
   },
@@ -141,7 +141,7 @@ export const constantRoutes: RouteRecordRaw[] = [
         path: 'edit/:projectId/:projectName/:projectType/:eventId/:classification',
         component: () => import('@/views/system/gameScore/gameScoreEdit.vue'),
         name: 'GameScoreEdit',
-        meta: { title: '修改成绩', icon: 'form' }
+        meta: { title: '成绩详情', icon: 'form' }
       },
       {
         path: 'print/:projectId',

+ 39 - 12
src/views/system/gameScore/index.vue

@@ -33,7 +33,7 @@
             <el-button type="primary" @click="refreshData">刷新</el-button>
           </el-col>
           <el-col :span="1.5">
-            <el-button type="primary" @click="printScores">打印成绩(前3名)</el-button>
+            <el-button type="primary" @click="printScores">打印成绩</el-button>
           </el-col>
           <el-col :span="1.5">
             <el-button type="warning" plain icon="DataAnalysis" @click="handleGameDataDefault" v-hasPermi="['system:gameEvent:gameData']"
@@ -83,8 +83,8 @@
         <el-table-column label="状态" align="center" prop="status" v-if="columns[4].visible">
           <template #default="scope">
             <el-select v-model="scope.row.status" placeholder="请选择状态">
-              <el-option label="等待处理" value="0"></el-option>
-              <el-option label="处理完毕" value="1"></el-option>
+              <el-option label="进行中" value="0"></el-option>
+              <el-option label="完赛" value="1"></el-option>
             </el-select>
           </template>
         </el-table-column>
@@ -114,6 +114,7 @@ import { GameScoreVO, GameScoreQuery, GameScoreForm } from '@/api/system/gameSco
 import { GameEventProjectVO, GameEventProjectQuery } from '@/api/system/gameEventProject/types';
 import { GameEventVO } from '@/api/system/gameEvent/types';
 import { useGameEventStore } from '@/store/modules/gameEvent';
+import { ElMessageBox, ElLoading } from 'element-plus';
 
 const { proxy } = getCurrentInstance() as ComponentInternalInstance;
 const { game_project_type } = toRefs<any>(proxy?.useDict('game_project_type'));
@@ -401,13 +402,34 @@ const getList = async () => {
 const refreshData = async () => {
   await loadProjects();
 };
+
 // 打印成绩
 const printScores = async () => {
   try {
+    // 首先让用户输入要打印的前n名
+    const { value } = await ElMessageBox.prompt(
+      '请输入要打印的数据条数',
+      '打印设置',
+      {
+        confirmButtonText: '确定',
+        cancelButtonText: '取消',
+        inputPattern: /^[1-9]\d*$/,
+        inputErrorMessage: '请输入有效的数字(大于0的整数)',
+        inputPlaceholder: '例如:3',
+        inputValue: '3' // 默认值
+      }
+    );
+
+    const topCount = parseInt(value);
+    if (topCount <= 0) {
+      proxy?.$modal.msgWarning('请输入大于0的数字');
+      return;
+    }
+
     // 显示加载状态
     const loadingInstance = ElLoading.service({
       lock: true,
-      text: '正在准备打印数据...',
+      text: `正在准备打印前${topCount}名数据...`,
       background: 'rgba(0, 0, 0, 0.7)'
     });
 
@@ -451,11 +473,11 @@ const printScores = async () => {
           // 获取成绩数据并补充队伍和运动员信息
           const scores = scoreRes.rows || [];
 
-          // 按积分排序,取前3名
+          // 按积分排序,取前n名(使用用户输入的数量)
           const sortedScores = scores
             .filter(score => score.scorePoint && score.scorePoint > 0) // 只显示有积分的成绩
             .sort((a: any, b: any) => (b.scorePoint || 0) - (a.scorePoint || 0)) // 按积分降序排列
-            .slice(0, 3); // 只取前3名
+            .slice(0, topCount); // 使用用户输入的数量
 
           const scoresWithDetails = await Promise.all(
             sortedScores.map(async (score: any) => {
@@ -503,8 +525,8 @@ const printScores = async () => {
     // 关闭加载状态
     loadingInstance.close();
 
-    // 构建打印HTML内容
-    const printHtml = buildPrintHtml(projectsWithScores);
+    // 构建打印HTML内容,传递topCount参数
+    const printHtml = buildPrintHtml(projectsWithScores, topCount);
 
     // 使用 Blob 和 URL.createObjectURL 来避免弹窗拦截问题
     const blob = new Blob([printHtml], { type: 'text/html' });
@@ -564,7 +586,7 @@ const printScores = async () => {
 /**
  * 构建打印HTML内容
  */
-const buildPrintHtml = (projects: any[]) => {
+const buildPrintHtml = (projects: any[], topCount: number = 3) => {
   const printTime = new Date().toLocaleString('zh-CN');
 
   let html = `
@@ -572,7 +594,7 @@ const buildPrintHtml = (projects: any[]) => {
     <html>
     <head>
       <meta charset="UTF-8">
-      <title>赛事成绩打印 - 前3名</title>
+      <title>赛事成绩打印 - 前${topCount}名</title>
       <style>
         body { font-family: Arial, sans-serif; margin: 20px; }
         .print-header { text-align: center; margin-bottom: 30px; border-bottom: 2px solid #333; padding-bottom: 20px; }
@@ -593,7 +615,7 @@ const buildPrintHtml = (projects: any[]) => {
     </head>
     <body>
       <div class="print-header">
-        <h1>赛事管理系统 - 成绩打印(前3名)</h1>
+        <h1>赛事管理系统 - 成绩打印(前${topCount}名)</h1>
         <p>打印时间: ${printTime}</p>
       </div>
   `;
@@ -626,7 +648,12 @@ const buildPrintHtml = (projects: any[]) => {
 
     if (scores.length > 0) {
       scores.forEach((score: any, index: number) => {
-        const rankClass = index === 0 ? 'rank-1' : index === 1 ? 'rank-2' : 'rank-3';
+        // 动态设置排名样式,只对前3名应用特殊样式
+        let rankClass = '';
+        if (index === 0) rankClass = 'rank-1';
+        else if (index === 1) rankClass = 'rank-2';
+        else if (index === 2) rankClass = 'rank-3';
+        
         html += `
           <tr class="${rankClass}">
             <td>${score.classification === '0' ? '个人项目' : '团体项目'}</td>