From 605d60ec7e022a77fcd8c923c193946d87709bf9 Mon Sep 17 00:00:00 2001 From: Kunagisa <1549184870@qq.com> Date: Thu, 31 Jul 2025 00:17:22 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E8=B5=9B=E4=BA=8B=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=EF=BC=88=E4=BF=AE=E6=94=B9=E6=A0=91=E7=8A=B6=E5=9B=BE?= =?UTF-8?q?=E5=89=8D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/tournament.js | 368 +++++----- src/router/index.js | 8 +- .../{index => competition}/AddContestant.vue | 106 +-- src/views/competition/Competition.vue | 657 ++++++++++++------ .../CompetitionDetail.vue | 103 ++- .../CompetitionSignUp.vue | 38 +- src/views/index/Competition.vue | 488 ------------- 7 files changed, 777 insertions(+), 991 deletions(-) rename src/views/{index => competition}/AddContestant.vue (87%) rename src/views/{index => competition}/CompetitionDetail.vue (91%) rename src/views/{index => competition}/CompetitionSignUp.vue (93%) delete mode 100644 src/views/index/Competition.vue diff --git a/src/api/tournament.js b/src/api/tournament.js index 3df7cb6..198e67a 100644 --- a/src/api/tournament.js +++ b/src/api/tournament.js @@ -3,239 +3,225 @@ import axiosInstance from './axiosConfig'; /** * 添加赛事 * @param {Object} tournamentData - 赛事数据 - * @param {string} tournamentData.name - 赛事名称 - * @param {string} tournamentData.format - 赛事类型(single, double, count) + * @param {number} tournamentData.id - 数据库中id + * @param {string} tournamentData.name - 名称 + * @param {string} tournamentData.format - 类型(single, double, count) * @param {string} tournamentData.organizer - 组织者 * @param {string} tournamentData.qq_code - QQ号 * @param {string} tournamentData.status - 状态(prepare, finish, starting) * @param {string} tournamentData.start_time - 开始时间(格式年/月/日,例2025/05/24) * @param {string} tournamentData.end_time - 结束时间(格式年/月/日,例2025/05/24) - * @returns {Promise} 返回添加赛事的响应数据 + * @returns {Promise} 返回添加赛事的响应数据 */ export const addTournament = async (tournamentData) => { try { - const response = await axiosInstance.post('/tournament/add', tournamentData) - return response.data + const response = await axiosInstance.post('/tournament/add', tournamentData); + return response.data; } catch (error) { - console.error('添加赛事失败:', { - status: error.response?.status, - data: error.response?.data, - message: error.message - }) - throw error + console.error('添加赛事失败:', error); + throw error; } -} +}; /** * 获取赛事列表 - * @returns {Promise} 返回赛事列表数据 + * @returns {Promise>} 返回赛事列表数据 */ export const getTournamentList = async () => { try { - const response = await axiosInstance.get('/tournament/getlist') - return response.data + const response = await axiosInstance.get('/tournament/getlist'); + return response.data; } catch (error) { - console.error('获取赛事列表失败:', { - status: error.response?.status, - data: error.response?.data, - message: error.message - }) - throw error + console.error('获取赛事列表失败:', error); + throw error; } -} +}; - -// 更新赛事 -export const updateTournament = async (id, data) => { +/** + * 更新赛事 + * @param {number} id - 赛事ID + * @param {Object} tournamentData - 赛事数据 + * @param {number} tournamentData.id - 数据库中id + * @param {string} tournamentData.name - 名称 + * @param {string} tournamentData.format - 类型(single, double, count) + * @param {string} tournamentData.organizer - 组织者 + * @param {string} tournamentData.qq_code - QQ号 + * @param {string} tournamentData.status - 状态(prepare, finish, starting) + * @param {string} tournamentData.start_time - 开始时间(格式年/月/日,例2025/05/24) + * @param {string} tournamentData.end_time - 结束时间(格式年/月/日,例2025/05/24) + * @returns {Promise} 返回更新赛事的响应数据 + */ +export const updateTournament = async (id, tournamentData) => { try { - console.log('更新赛事,发送数据:', data) - const response = await axiosInstance.put(`/tournament/update/${id}`, { - name: data.name, - format: data.format, - organizer: data.organizer, - qq_code: data.qq_code, - start_time: data.start_time, - end_time: data.end_time, - status: data.status - }) - return response.data + const response = await axiosInstance.put(`/tournament/update/${id}`, tournamentData); + return response.data; } catch (error) { - console.error('更新赛事失败:', error) - if (error.response) { - console.error('错误详情:', { - status: error.response.status, - data: error.response.data, - headers: error.response.headers, - config: error.config - }) - // 如果有详细的错误信息,抛出它 - if (error.response.data?.detail) { - throw new Error(error.response.data.detail) - } - } - throw error + console.error('更新赛事失败:', error); + throw error; } -} +}; -// 删除赛事 +/** + * 删除赛事 + * @param {number} id - 赛事ID + * @returns {Promise} 返回删除赛事的响应数据 + */ export const deleteTournament = async (id) => { try { - const response = await axiosInstance.delete(`/tournament/delete/${id}`) - return response.data + const response = await axiosInstance.delete(`/tournament/delete/${id}`); + return response.data; } catch (error) { - console.error('删除赛事失败:', error) - throw error + console.error('删除赛事失败:', error); + throw error; } -} +}; - -// 添加报名结果 -export const addSignUpResult = async (data) => { +/** + * 添加玩家报名 + * @param {Object} signupData - 报名数据 + * @param {number} signupData.id - 数据库中id + * @param {string} signupData.type - 类型 + * @param {string} signupData.teamname - 队伍名称 + * @param {string} signupData.faction - 阵营(allied、soviet、empire、ob、voice、random) + * @param {string} signupData.username - 用户名 + * @param {string} signupData.qq - QQ号 + * @returns {Promise} 返回添加报名的响应数据 + */ +export const addSignUp = async (signupData) => { try { - const response = await axiosInstance.post('/tournament/signup_result/add', { - tournament_id: parseInt(data.tournament_id), - tournament_name: data.tournament_name, - team_name: data.team_name, - sign_name: data.sign_name.trim(), - win: '0', - lose: '0', - status: 'tie' - }) - return response.data + const response = await axiosInstance.post('/tournament/signup/add', signupData); + return response.data; } catch (error) { - console.error('请求错误:', error) - if (error.response?.data?.detail) { - throw new Error(error.response.data.detail) - } - throw error + console.error('添加报名失败:', error); + throw error; } -} +}; -// 获取参赛结果列表 +/** + * 获取玩家报名列表 + * @returns {Promise>} 返回报名列表数据 + */ +export const getSignUpList = async () => { + try { + const response = await axiosInstance.get('/tournament/signup/getlist'); + return response.data; + } catch (error) { + console.error('获取报名列表失败:', error); + throw error; + } +}; + +/** + * 更新玩家报名 + * @param {number} id - 报名ID + * @param {Object} signupData - 报名数据 + * @param {number} signupData.id - 数据库中id + * @param {string} signupData.type - 类型 + * @param {string} signupData.teamname - 队伍名称 + * @param {string} signupData.faction - 阵营(allied、soviet、empire、ob、voice、random) + * @param {string} signupData.username - 用户名 + * @param {string} signupData.qq - QQ号 + * @returns {Promise} 返回更新报名的响应数据 + */ +export const updateSignUp = async (id, signupData) => { + try { + const response = await axiosInstance.put(`/tournament/signup/update/${id}`, signupData); + return response.data; + } catch (error) { + console.error('更新报名失败:', error); + throw error; + } +}; + +/** + * 删除玩家报名 + * @param {number} id - 报名ID + * @returns {Promise} 返回删除报名的响应数据 + */ +export const deleteSignUp = async (id) => { + try { + const response = await axiosInstance.delete(`/tournament/signup/delete/${id}`); + return response.data; + } catch (error) { + console.error('删除报名失败:', error); + throw error; + } +}; + +/** + * 添加报名结果 + * @param {Object} resultData - 结果数据 + * @param {number} resultData.tournament_id - 赛事id(int) + * @param {string} resultData.tournament_name - 赛事名称 + * @param {string} resultData.team_name - 队伍名称(可选) + * @param {string} resultData.sign_name - 参赛人员名称 + * @param {string} resultData.win - 参赛人员胜利局数(str) + * @param {string} resultData.lose - 参赛人员失败局数(str) + * @param {string} resultData.status - 参赛人员对局状态(win,lose,tie) + * @param {string} resultData.round - 轮数(str) + * @param {string} resultData.rival_name - 对方name(str) + * @returns {Promise} 返回添加报名结果的响应数据 + */ +export const addSignUpResult = async (resultData) => { + try { + const response = await axiosInstance.post('/tournament/signup_result/add', resultData); + return response.data; + } catch (error) { + console.error('添加报名结果失败:', error); + throw error; + } +}; + +/** + * 获取报名结果列表 + * @returns {Promise>} 返回报名结果列表数据 + */ export const getSignUpResultList = async () => { try { - const response = await axiosInstance.get('/tournament/signup_result/getlist') - return response.data + const response = await axiosInstance.get('/tournament/signup_result/getlist'); + return response.data; } catch (error) { - console.error('获取参赛结果列表失败:', { - status: error.response?.status, - data: error.response?.data, - message: error.message - }) - throw error + console.error('获取报名结果列表失败:', error); + throw error; } -} +}; -// 更新参赛结果 -export const updateSignUpResult = async (id, data) => { +/** + * 更新报名结果 + * @param {number} id - 结果ID + * @param {Object} resultData - 结果数据 + * @param {number} resultData.tournament_id - 赛事id(int) + * @param {string} resultData.tournament_name - 赛事名称 + * @param {string} resultData.team_name - 队伍名称(可选) + * @param {string} resultData.sign_name - 参赛人员名称 + * @param {string} resultData.win - 参赛人员胜利局数(str) + * @param {string} resultData.lose - 参赛人员失败局数(str) + * @param {string} resultData.status - 参赛人员对局状态(win,lose,tie) + * @param {string} resultData.round - 轮数(str) + * @param {string} resultData.rival_name - 对方name(str) + * @returns {Promise} 返回更新报名结果的响应数据 + */ +export const updateSignUpResult = async (id, resultData) => { try { - // // 更新报名信息 (这部分逻辑根据您的要求被注释掉) - // console.log('更新报名信息...') - // await axiosInstance.put(`/tournament/signup/update/${id}`, { - // tournament_id: parseInt(data.tournament_id), - // type: data.team_name ? 'teamname' : 'individual', - // teamname: data.team_name || '', - // faction: data.faction || 'random', - // username: data.sign_name, - // qq: data.qq || '' - // }) - // console.log('报名信息更新成功') - - // 更新报名结果 - console.log('更新报名结果...') - await axiosInstance.put(`/tournament/signup_result/update/${id}`, { - tournament_id: parseInt(data.tournament_id), - tournament_name: data.tournament_name, - team_name: data.team_name || null, - sign_name: data.sign_name, - win: data.win || '0', - lose: data.lose || '0', - status: data.status || 'tie' - }) - console.log('报名结果更新成功') - - return { success: true } + const response = await axiosInstance.put(`/tournament/signup_result/update/${id}`, resultData); + return response.data; } catch (error) { - console.error('更新参赛结果失败:', { - status: error.response?.status, - data: error.response?.data, - message: error.message - }) - throw error + console.error('更新报名结果失败:', error); + throw error; } -} +}; -// 删除参赛选手 +/** + * 删除报名结果 + * @param {number} id - 结果ID + * @returns {Promise} 返回删除报名结果的响应数据 + */ export const deleteSignUpResult = async (id) => { try { - // 删除报名结果 - console.log('删除报名结果...') - await axiosInstance.delete(`/tournament/signup_result/delete/${id}`) - console.log('报名结果删除成功') - - // // 删除报名信息 (这部分逻辑根据您的要求被注释掉) - // console.log('删除报名信息...') - // await axiosInstance.delete(`/tournament/signup/delete/${id}`) - // console.log('报名信息删除成功') - - return { success: true } + const response = await axiosInstance.delete(`/tournament/signup_result/delete/${id}`); + return response.data; } catch (error) { - console.error('删除参赛选手失败:', { - status: error.response?.status, - data: error.response?.data, - message: error.message - }) - throw error + console.error('删除报名结果失败:', error); + throw error; } -} - -// 添加报名 -export const addSignUp = async (data) => { - try { - console.log('开始报名流程,数据:', data) - - // 调用报名 API - console.log('调用报名 API...') - await axiosInstance.post('/tournament/signup/add', { - tournament_id: data.id, - type: data.type, - teamname: data.team_name || '', - faction: data.faction || 'random', - username: data.sign_name, - qq: data.qq || '' - }) - console.log('报名 API 调用成功') - - // 调用报名结果 API - console.log('调用报名结果 API...') - await axiosInstance.post('/tournament/signup_result/add', { - tournament_id: data.id, - tournament_name: data.tournament_name, - team_name: data.team_name || null, - sign_name: data.sign_name, - win: '0', - lose: '0', - status: 'tie' - }) - console.log('报名结果 API 调用成功') - - return { - signup: { success: true }, - result: { success: true } - } - } catch (error) { - console.error('报名请求错误:', { - message: error.message, - response: error.response?.data, - status: error.response?.status, - config: error.config - }) - - // 如果是服务器返回的错误信息,直接使用 - if (error.response?.data?.detail) { - throw new Error(error.response.data.detail) - } - // 其他错误,包装成更友好的错误信息 - throw new Error('报名失败,请检查网络连接后重试') - } -} \ No newline at end of file +}; \ No newline at end of file diff --git a/src/router/index.js b/src/router/index.js index 9c61737..e3ab972 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -60,26 +60,26 @@ const routes = [ { path: 'competition', name: 'Competition', - component: () => import('@/views/index/Competition.vue'), + component: () => import('@/views/competition/Competition.vue'), // meta: { requiresAuth: true, requiredPrivilege: ['lv-admin','lv-competitor'] } meta: { requiresAuth: true} }, { path: 'competition/add', name: 'AddCompetition', - component: () => import('@/views/index/AddContestant.vue'), + component: () => import('@/views/competition/AddContestant.vue'), meta: { requiresAuth: true } }, { path: 'competition/detail', name: 'CompetitionDetail', - component: () => import('@/views/index/CompetitionDetail.vue'), + component: () => import('@/views/competition/CompetitionDetail.vue'), meta: { requiresAuth: true } }, { path: 'competition/signup', name: 'CompetitionSignUp', - component: () => import('@/views/index/CompetitionSignUp.vue'), + component: () => import('@/views/competition/CompetitionSignUp.vue'), meta: { requiresAuth: true } }, // { diff --git a/src/views/index/AddContestant.vue b/src/views/competition/AddContestant.vue similarity index 87% rename from src/views/index/AddContestant.vue rename to src/views/competition/AddContestant.vue index fe7d7c3..82e27a0 100644 --- a/src/views/index/AddContestant.vue +++ b/src/views/competition/AddContestant.vue @@ -3,62 +3,62 @@ - -
-
-

通过Excel导入赛事信息

-
- -
- -

点击或拖拽Excel文件到此处

-
-
-
-

赛事信息表预览

- - - - - - - - - - - -
{{ h }}
{{ item[h] }}
-
-
-

选手报名表预览

- - - - - - - - - - - -
{{ h }}
{{ item[h] }}
-
-
- - -
-
-
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
@@ -119,7 +119,7 @@ - + + \ No newline at end of file diff --git a/src/views/index/CompetitionDetail.vue b/src/views/competition/CompetitionDetail.vue similarity index 91% rename from src/views/index/CompetitionDetail.vue rename to src/views/competition/CompetitionDetail.vue index bcc1a46..1edf4b5 100644 --- a/src/views/index/CompetitionDetail.vue +++ b/src/views/competition/CompetitionDetail.vue @@ -24,14 +24,14 @@ {{ statusMap[competition.status] }}
-
+
@@ -46,6 +46,8 @@ 玩家名称 队伍名称 + 阵营 + QQ 胜场 负场 状态 @@ -55,12 +57,14 @@ {{ player.sign_name }} - {{ player.team_name || '个人' }} + {{ player.team_name === ' ' ? '个人' : player.team_name}} + {{ formatFaction(player.faction) }} + {{ player.qq || '-' }} {{ player.win }} {{ player.lose }} {{ player.status }} - + @@ -238,11 +242,13 @@ import { getTournamentList, updateTournament, deleteTournament, + getSignUpList, getSignUpResultList, updateSignUpResult, - deleteSignUpResult -} from '@/api/tournament' -import { getStoredUser } from '@/utils/jwt' + deleteSignUpResult, + deleteSignUp +} from '@/api/tournament.js' +import { getStoredUser } from '@/utils/jwt.js' import SuccessDialog from '@/components/SuccessDialog.vue' import ErrorDialog from '@/components/ErrorDialog.vue' @@ -324,10 +330,18 @@ const formatType = (type) => { return formatMap[type] || type } -// // 格式化阵营 -// const formatFaction = (faction) => { -// return factionMap[faction] || faction -// } +// 格式化阵营 +const formatFaction = (faction) => { + const factionMap = { + 'allied': '盟军', + 'soviet': '苏联', + 'empire': '帝国', + 'ob': 'OB', + 'voice': '解说', + 'random': '随机' + } + return factionMap[faction] || faction +} // 返回列表 const handleBack = () => { @@ -482,15 +496,40 @@ const fetchTournamentDetail = async () => { const fetchRegisteredPlayers = async () => { try { const tournamentId = parseInt(route.query.id) - const response = await getSignUpResultList() - // 调试日志 - console.log('报名玩家原始数据:', response) + + // 同时获取报名信息和结果信息 + const [signupList, resultList] = await Promise.all([ + getSignUpList(), + getSignUpResultList() + ]) + + console.log('报名信息原始数据:', signupList) + console.log('结果信息原始数据:', resultList) console.log('当前赛事ID:', tournamentId) - // 只保留 tournament_id 等于当前赛事 id 的玩家 - registeredPlayers.value = response.filter(player => - player.tournament_id === tournamentId + + // 筛选当前赛事的报名信息 + const tournamentSignups = signupList.filter(signup => + signup.tournament_id === tournamentId ) - console.log('筛选后的玩家数据:', registeredPlayers.value) + + // 筛选当前赛事的结果信息 + const tournamentResults = resultList.filter(result => + result.tournament_id === tournamentId + ) + + // 合并报名信息和结果信息,添加阵营信息 + registeredPlayers.value = tournamentResults.map(result => { + // 查找对应的报名信息 + const signup = tournamentSignups.find(s => s.username === result.sign_name) + + return { + ...result, + faction: signup?.faction || 'random', // 添加阵营信息 + qq: signup?.qq || '' // 添加QQ信息 + } + }) + + console.log('合并后的玩家数据:', registeredPlayers.value) } catch (error) { console.error('获取报名玩家列表失败:', error) } @@ -501,7 +540,33 @@ const handleRemovePlayer = async (playerId) => { if (!confirm('确定要移除该玩家吗?')) return try { - await deleteSignUpResult(playerId) + // 获取玩家信息,用于查找对应的报名记录 + const player = registeredPlayers.value.find(p => p.id === playerId) + if (!player) { + throw new Error('未找到玩家信息') + } + + // 获取报名列表,查找对应的报名记录 + const signupList = await getSignUpList() + const signupRecord = signupList.find(s => + s.tournament_id === parseInt(route.query.id) && + s.username === player.sign_name + ) + + // 同时删除报名信息和报名结果 + const deletePromises = [] + + // 删除报名结果 + deletePromises.push(deleteSignUpResult(playerId)) + + // 如果找到对应的报名记录,也删除报名信息 + if (signupRecord) { + deletePromises.push(deleteSignUp(signupRecord.id)) + } + + // 等待所有删除操作完成 + await Promise.all(deletePromises) + await fetchRegisteredPlayers() // 刷新列表 successDialog.value = { visible: true, message: '移除成功!' } } catch (error) { diff --git a/src/views/index/CompetitionSignUp.vue b/src/views/competition/CompetitionSignUp.vue similarity index 93% rename from src/views/index/CompetitionSignUp.vue rename to src/views/competition/CompetitionSignUp.vue index 105aea3..6c23db2 100644 --- a/src/views/index/CompetitionSignUp.vue +++ b/src/views/competition/CompetitionSignUp.vue @@ -142,7 +142,7 @@ - - \ No newline at end of file