RankingBoardPage.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546
  1. <template>
  2. <div class="ranking-board-page">
  3. <!-- 赛事名称标题 -->
  4. <div class="event-title">
  5. <h2>{{defaultEventInfo ? defaultEventInfo.eventName : '赛事排行榜'}}</h2>
  6. <p>随时掌握运动会情况</p>
  7. </div>
  8. <el-row :gutter="20" class="ranking-row">
  9. <el-col :span="8">
  10. <el-card shadow="hover" class="ranking-card">
  11. <template #header>
  12. <div class="card-header header-one">
  13. <span>个人积分排行榜</span>
  14. </div>
  15. </template>
  16. <div class="ranking-list ranking-list-full">
  17. <div v-for="(item, index) in athleteScoreList" :key="index" class="ranking-item">
  18. <div class="item-content">
  19. <span class="item-rank">{{ getRankDisplay(item, index, athleteScoreList) }}</span>
  20. <span class="item-name">{{ item.athleteName }}</span>
  21. <span class="item-team">{{ item.teamName }}</span>
  22. <span class="item-time">{{ item.totalScore }}</span>
  23. </div>
  24. </div>
  25. </div>
  26. </el-card>
  27. </el-col>
  28. <el-col :span="8">
  29. <el-card shadow="hover" class="ranking-card">
  30. <template #header>
  31. <div class="card-header header-three">
  32. <div class="team-ranking-header">
  33. <span>团队积分排行榜</span>
  34. <!-- 添加分组筛选下拉框 -->
  35. <el-select
  36. v-model="selectedRankGroupId"
  37. placeholder="选择分组"
  38. clearable
  39. size="small"
  40. @change="handleRankGroupChange"
  41. style="margin-left: 10px; width: 120px;"
  42. >
  43. <el-option label="全部队伍" :value="null"></el-option>
  44. <el-option
  45. v-for="group in rankGroupOptions"
  46. :key="group.rgId"
  47. :label="group.rgName"
  48. :value="group.rgId"
  49. />
  50. </el-select>
  51. </div>
  52. </div>
  53. </template>
  54. <div class="ranking-list ranking-list-full">
  55. <div v-for="(item, index) in filteredTeamScores" :key="index" class="ranking-item">
  56. <div class="item-content">
  57. <span class="item-rank">{{ getRankDisplay(item, index, filteredTeamScores) }}</span>
  58. <span class="item-team-name">{{ item.teamName }}</span>
  59. <span class="item-score">{{ item.score }}分</span>
  60. </div>
  61. </div>
  62. </div>
  63. </el-card>
  64. </el-col>
  65. <el-col :span="8">
  66. <el-card shadow="hover" class="ranking-card">
  67. <template #header>
  68. <div class="card-header header-two">
  69. <span>项目进度</span>
  70. </div>
  71. </template>
  72. <div class="progress-info">
  73. <p>{{ completedTasks }} / {{ totalTasks }}</p>
  74. <el-progress :percentage="progressPercentage" />
  75. </div>
  76. <div class="ranking-list ranking-list-full">
  77. <div v-for="(item, index) in projectProgress" :key="index" class="ranking-item">
  78. <div class="item-content">
  79. <span class="item-name">{{ item.projectName }}</span>
  80. <span class="item-type">{{ getProjectTypeText(item.projectType) }} {{ item.classification === '0' ? '个人' : '团体' }}</span>
  81. <span class="item-time">{{ formatTime(item.startTime) }}</span>
  82. </div>
  83. <!-- 如果有组别信息,显示组别详情 -->
  84. <div v-if="item.groups && item.groups.length > 0" class="group-details">
  85. <div v-for="group in item.groups" :key="group.groupId" class="group-item">
  86. <span class="group-name">{{ group.groupName }}</span>
  87. <span class="group-time">{{ formatTimeOnly(group.beginTime) }}</span>
  88. <span class="group-status" :class="'status-' + group.status">{{ group.statusText }}</span>
  89. </div>
  90. </div>
  91. </div>
  92. </div>
  93. </el-card>
  94. </el-col>
  95. </el-row>
  96. </div>
  97. </template>
  98. <script setup lang="ts">
  99. import { ref, computed, onMounted } from 'vue';
  100. import { listScoreRanking, listPersonalRanking, listTeamRanking } from '@/api/system/gameEvent/eventRank';
  101. import { listGameScore } from '@/api/system/gameScore';
  102. import { listGameTeam } from '@/api/system/gameTeam';
  103. import { getProjectProgress } from '@/api/system/gameEvent/projectProgress';
  104. import { useRouter,useRoute } from 'vue-router';
  105. import { GameTeamVO } from '@/api/system/gameTeam/types';
  106. import { ProjectProgressVo, GroupProgressVo } from '@/api/system/gameEvent/types';
  107. import { useGameEventStore } from '@/store/modules/gameEvent';
  108. import { storeToRefs } from 'pinia';
  109. import { listRankGroup } from '@/api/system/rankGroup'; // 新增导入
  110. import { RankGroupVO } from '@/api/system/rankGroup/types'; // 新增导入
  111. // 定义队伍积分排行榜的数据结构
  112. interface TeamScore {
  113. rgId: string | number;
  114. teamId: string | number;
  115. teamName: string;
  116. score: number;
  117. rank: number;
  118. }
  119. const { proxy } = getCurrentInstance() as ComponentInternalInstance;
  120. const { game_project_type } = toRefs<any>(proxy?.useDict('game_project_type'));
  121. // const route = useRoute();
  122. // const eventId = route.params.eventId as string;
  123. //从pinia中获取默认赛事信息
  124. const gameEventStore = useGameEventStore();
  125. const { defaultEventInfo } = storeToRefs(gameEventStore);
  126. const athleteScoreList = ref([]);
  127. const completedTasks = ref(0);
  128. const totalTasks = ref(0);
  129. const progressPercentage = computed(() => totalTasks.value > 0 ? (completedTasks.value / totalTasks.value) * 100 : 0);
  130. const projectProgress = ref<ProjectProgressVo[]>([]);
  131. const teamScores = ref<TeamScore[]>([]);
  132. const filteredTeamScores = ref<TeamScore[]>([]); // 用于显示筛选后的队伍积分
  133. // 分组相关数据
  134. const rankGroupOptions = ref<RankGroupVO[]>([]);
  135. const selectedRankGroupId = ref<number | null>(null);
  136. // 获取队伍积分排行榜
  137. const loadTeamScores = async () => {
  138. // 获取所有成绩数据
  139. const scoreRes = await listGameScore({
  140. eventId: defaultEventInfo.value.eventId,
  141. pageNum: 1,
  142. pageSize: 1000,
  143. orderByColumn: '',
  144. isAsc: ''
  145. });
  146. const scores = scoreRes.rows;
  147. // 获取所有队伍信息
  148. const teamRes = await listGameTeam({
  149. eventId: defaultEventInfo.value.eventId,
  150. pageNum: 1,
  151. pageSize: 1000,
  152. orderByColumn: '',
  153. isAsc: ''
  154. });
  155. const teams = teamRes.rows;
  156. // 计算每个队伍的总积分
  157. const teamScoreMap = new Map();
  158. scores.forEach(score => {
  159. const teamId = score.teamId;
  160. if (teamId) {
  161. if (teamScoreMap.has(teamId)) {
  162. teamScoreMap.set(teamId, teamScoreMap.get(teamId) + score.scorePoint);
  163. } else {
  164. teamScoreMap.set(teamId, score.scorePoint);
  165. }
  166. }
  167. });
  168. // 将队伍信息和积分结合
  169. const teamScoreList = teams.map(team => {
  170. return {
  171. teamId: team.teamId,
  172. teamName: team.teamName,
  173. score: teamScoreMap.get(team.teamId) || 0,
  174. rank: 0, // 占位符,稍后设置
  175. rgId: team.rgId // 添加分组ID
  176. };
  177. });
  178. // 按积分从高到低排序
  179. teamScoreList.sort((a, b) => b.score - a.score);
  180. // 添加排名(支持并列排名)
  181. let currentRank = 1;
  182. for (let i = 0; i < teamScoreList.length; i++) {
  183. const team = teamScoreList[i];
  184. const currentScore = team.score || 0;
  185. // 如果不是第一个,检查是否与前一个积分相同
  186. if (i > 0) {
  187. const previousScore = teamScoreList[i - 1].score || 0;
  188. if (currentScore !== previousScore) {
  189. currentRank = i + 1;
  190. }
  191. }
  192. team.rank = currentRank;
  193. }
  194. teamScores.value = teamScoreList;
  195. // 默认显示所有队伍
  196. filteredTeamScores.value = teamScoreList;
  197. };
  198. // 处理分组筛选变化
  199. const handleRankGroupChange = (rgId: number | null) => {
  200. if (rgId === null) {
  201. // 显示所有队伍
  202. filteredTeamScores.value = teamScores.value;
  203. } else {
  204. // 筛选指定分组的队伍
  205. filteredTeamScores.value = teamScores.value.filter(team => team.rgId === rgId);
  206. }
  207. // 重新计算排名
  208. let currentRank = 1;
  209. for (let i = 0; i < filteredTeamScores.value.length; i++) {
  210. const team = filteredTeamScores.value[i];
  211. const currentScore = team.score || 0;
  212. if (i > 0) {
  213. const previousScore = filteredTeamScores.value[i - 1].score || 0;
  214. if (currentScore !== previousScore) {
  215. currentRank = i + 1;
  216. }
  217. }
  218. team.rank = currentRank;
  219. }
  220. };
  221. // 获取分组选项
  222. const loadRankGroupOptions = async () => {
  223. try {
  224. const res = await listRankGroup({
  225. eventId: defaultEventInfo.value.eventId,
  226. pageNum: 1,
  227. pageSize: 1000,
  228. orderByColumn: undefined,
  229. isAsc: undefined,
  230. status: '0'
  231. });
  232. rankGroupOptions.value = res.rows;
  233. } catch (error) {
  234. console.error('获取分组列表失败:', error);
  235. }
  236. };
  237. // 加载项目进度信息
  238. const loadProjectProgress = async () => {
  239. try {
  240. const res = await getProjectProgress(defaultEventInfo.value.eventId);
  241. projectProgress.value = res.data || [];
  242. // 计算已完成和总任务数
  243. let completed = 0;
  244. let total = 0;
  245. projectProgress.value.forEach(project => {
  246. if (project.groups && project.groups.length > 0) {
  247. // 有组别的项目,统计组别
  248. project.groups.forEach(group => {
  249. total++;
  250. if (group.status === '2') { // 已完成
  251. completed++;
  252. }
  253. });
  254. } else {
  255. // 没有组别的项目,直接统计项目
  256. total++;
  257. if (project.status === '2') { // 已完成
  258. completed++;
  259. }
  260. }
  261. });
  262. completedTasks.value = completed;
  263. totalTasks.value = total;
  264. // 前端也可以做一次排序确保,虽然后端已经排序了
  265. // 按完整时间排序(项目时间或最早组别时间)
  266. projectProgress.value.sort((a, b) => {
  267. const getEarliestTime = (project: ProjectProgressVo) => {
  268. if (project.groups && project.groups.length > 0) {
  269. // 有组别,找到最早的组别时间
  270. const groupTimes = project.groups
  271. .map(g => g.beginTime ? new Date(g.beginTime).getTime() : 0)
  272. .filter(time => time > 0);
  273. if (groupTimes.length > 0) {
  274. return Math.min(...groupTimes);
  275. }
  276. }
  277. // 没有组别或组别时间无效,使用项目时间
  278. return project.startTime ? new Date(project.startTime).getTime() : 0;
  279. };
  280. const aTime = getEarliestTime(a);
  281. const bTime = getEarliestTime(b);
  282. return aTime - bTime;
  283. });
  284. } catch (error) {
  285. console.error('加载项目进度失败:', error);
  286. }
  287. };
  288. // 获取项目类型文本
  289. const getProjectTypeText = (projectType: string) => {
  290. if (!game_project_type.value || !projectType) return '未知';
  291. const typeItem = game_project_type.value.find((item: any) => item.value === projectType);
  292. return typeItem ? typeItem.label : '未知';
  293. };
  294. // 格式化时间显示(包含日期)
  295. const formatTime = (timeStr: string) => {
  296. if (!timeStr) return '-';
  297. try {
  298. const date = new Date(timeStr);
  299. // 检查是否是有效日期
  300. if (isNaN(date.getTime())) {
  301. return timeStr;
  302. }
  303. return date.toLocaleString('zh-CN', {
  304. month: '2-digit',
  305. day: '2-digit',
  306. hour: '2-digit',
  307. minute: '2-digit',
  308. hour12: false
  309. });
  310. } catch (error) {
  311. return timeStr;
  312. }
  313. };
  314. // 格式化时间显示(仅时间,用于组别详情)
  315. const formatTimeOnly = (timeStr: string) => {
  316. if (!timeStr) return '-';
  317. try {
  318. const date = new Date(timeStr);
  319. // 检查是否是有效日期
  320. if (isNaN(date.getTime())) {
  321. return timeStr;
  322. }
  323. return date.toLocaleTimeString('zh-CN', {
  324. hour: '2-digit',
  325. minute: '2-digit',
  326. hour12: false
  327. });
  328. } catch (error) {
  329. return timeStr;
  330. }
  331. };
  332. // 获取排名显示文本(支持并列排名,排名数值连续)
  333. const getRankDisplay = (item: any, index: number, list: any[]) => {
  334. // 如果项目有rank字段(如团队排名),直接使用
  335. if (item.rank !== undefined) {
  336. return `第${item.rank}名`;
  337. }
  338. // 个人排名逻辑(排名数值连续)
  339. // 计算当前项目的实际排名
  340. // 排名 = 比当前积分高的不同积分数量 + 1
  341. const currentScore = item.totalScore || 0;
  342. const higherScores = new Set();
  343. for (let i = 0; i < list.length; i++) {
  344. if (list[i].totalScore > currentScore) {
  345. higherScores.add(list[i].totalScore);
  346. }
  347. }
  348. const actualRank = higherScores.size + 1;
  349. return `第${actualRank}名`;
  350. };
  351. onMounted(async () => {
  352. try{
  353. const res = await listScoreRanking(defaultEventInfo.value.eventId.toString());
  354. // 按照totalScore字段降序排序(分数高的在前面)
  355. athleteScoreList.value = res.data.sort((a, b) => b.totalScore - a.totalScore);
  356. // 加载队伍积分排行榜
  357. await loadTeamScores();
  358. // 加载分组选项
  359. await loadRankGroupOptions();
  360. // 加载项目进度信息
  361. await loadProjectProgress();
  362. } catch (error) {
  363. console.error('加载数据失败:', error);
  364. }
  365. });
  366. </script>
  367. <style scoped>
  368. .ranking-board-page {
  369. padding: 20px;
  370. height: calc(100vh - 120px);
  371. }
  372. /* 赛事名称标题样式 */
  373. .event-title {
  374. margin-bottom: 20px;
  375. text-align: center;
  376. }
  377. .event-title h2 {
  378. font-size: 24px;
  379. margin: 0;
  380. }
  381. .event-title p {
  382. font-size: 16px;
  383. color: #666;
  384. margin: 5px 0 0;
  385. }
  386. .ranking-row {
  387. height: calc(100% - 70px); /* 调整高度以适应新增标题区域 */
  388. }
  389. .ranking-card {
  390. width: 100%;
  391. height: 100%;
  392. display: flex;
  393. flex-direction: column;
  394. }
  395. .card-header {
  396. font-weight: bold;
  397. font-size: 16px;
  398. color: black;
  399. text-align: center;
  400. }
  401. /* 团队排行榜头部样式 */
  402. .team-ranking-header {
  403. display: flex;
  404. justify-content: center;
  405. align-items: center;
  406. }
  407. .progress-info {
  408. margin-bottom: 15px;
  409. }
  410. .ranking-list {
  411. max-height: 800px;
  412. overflow-y: auto;
  413. }
  414. .ranking-list-full {
  415. flex: 1;
  416. overflow-y: auto;
  417. }
  418. .ranking-item {
  419. padding: 10px 0;
  420. border-bottom: 1px solid #f0f0f0;
  421. }
  422. .ranking-item:last-child {
  423. border-bottom: none;
  424. }
  425. .item-content {
  426. display: flex;
  427. justify-content: space-between;
  428. }
  429. .item-name {
  430. flex: 2;
  431. text-align: left;
  432. }
  433. .item-team,
  434. .item-time,
  435. .item-type,
  436. .item-rank,
  437. .item-team-name,
  438. .item-score {
  439. flex: 1;
  440. text-align: center;
  441. }
  442. /* 组别详情样式 */
  443. .group-details {
  444. margin-top: 8px;
  445. padding-left: 20px;
  446. border-left: 2px solid #e0e0e0;
  447. }
  448. .group-item {
  449. display: flex;
  450. justify-content: space-between;
  451. align-items: center;
  452. padding: 4px 0;
  453. font-size: 12px;
  454. color: #666;
  455. }
  456. .group-name {
  457. flex: 3;
  458. text-align: left;
  459. }
  460. .group-time {
  461. flex: 2;
  462. text-align: center;
  463. }
  464. .group-status {
  465. flex: 1;
  466. text-align: center;
  467. padding: 2px 6px;
  468. border-radius: 10px;
  469. font-size: 10px;
  470. }
  471. .status-0 {
  472. background-color: #f0f0f0;
  473. color: #999;
  474. }
  475. .status-1 {
  476. background-color: #e6f7ff;
  477. color: #1890ff;
  478. }
  479. .status-2 {
  480. background-color: #f6ffed;
  481. color: #52c41a;
  482. }
  483. </style>