|
@@ -96,7 +96,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup name="GameScore" lang="ts">
|
|
|
-import { listGameScore, getGameScore, delGameScore, addGameScore, updateGameScore, getProjectScoreData, exportScoresSummary } from '@/api/system/gameScore';
|
|
|
+import { listGameScore, getGameScore, delGameScore, addGameScore, updateGameScore, getProjectScoreData } from '@/api/system/gameScore';
|
|
|
import { getDefaultEvent } from '@/api/system/gameEvent'
|
|
|
import { listGameEventProject } from '@/api/system/gameEventProject';
|
|
|
import { getGameTeam } from '@/api/system/gameTeam';
|
|
@@ -106,7 +106,7 @@ import { GameEventVO, GameEventQuery } from '@/api/system/gameEvent/types';
|
|
|
import { GameEventProjectVO, GameEventProjectQuery } from '@/api/system/gameEventProject/types';
|
|
|
import { GameTeamVO } from '@/api/system/gameTeam/types';
|
|
|
import { GameAthleteVO } from '@/api/system/gameAthlete/types';
|
|
|
-import { ElLoading, ElMessage } from 'element-plus';
|
|
|
+import { ElMessage } from 'element-plus';
|
|
|
import { useGameEventStore } from '@/store/modules/gameEvent';
|
|
|
|
|
|
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
|
@@ -476,104 +476,24 @@ const getProjectTypeName = (type: string) => {
|
|
|
return typeMap[type] || '未知';
|
|
|
};
|
|
|
|
|
|
-const exportScoresNames = async () => {
|
|
|
- try {
|
|
|
- // 显示加载状态
|
|
|
- const loadingInstance = ElLoading.service({
|
|
|
- lock: true,
|
|
|
- text: '正在导出成绩汇总表...',
|
|
|
- background: 'rgba(0, 0, 0, 0.7)'
|
|
|
- });
|
|
|
-
|
|
|
- // 获取默认赛事ID
|
|
|
- const event = gameEventStore.defaultEventInfo;
|
|
|
- const eventId = event?.eventId;
|
|
|
-
|
|
|
- if (!eventId) {
|
|
|
- proxy?.$modal.msgWarning('未指定赛事,无法导出');
|
|
|
- loadingInstance.close();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 调用导出接口
|
|
|
- const response = await exportScoresSummary(eventId);
|
|
|
-
|
|
|
- // 校验响应是否为有效的二进制数据
|
|
|
- if (!response || !response.data || !(response.data instanceof Blob)) {
|
|
|
- proxy?.$modal.msgError('导出失败:服务器返回数据异常');
|
|
|
- loadingInstance.close();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // 创建Blob时,明确指定类型
|
|
|
- const blob = new Blob([response.data], {
|
|
|
- type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
|
- });
|
|
|
-
|
|
|
- // 验证Blob大小是否合理(防止空文件)
|
|
|
- if (blob.size === 0) {
|
|
|
- proxy?.$modal.msgError('导出失败:生成的文件为空');
|
|
|
- loadingInstance.close();
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const url = window.URL.createObjectURL(blob);
|
|
|
- const link = document.createElement('a');
|
|
|
- link.href = url;
|
|
|
- link.download = `成绩汇总表_${new Date().toLocaleDateString()}.xlsx`;
|
|
|
- document.body.appendChild(link);
|
|
|
- link.click();
|
|
|
- document.body.removeChild(link);
|
|
|
- window.URL.revokeObjectURL(url);
|
|
|
-
|
|
|
- loadingInstance.close();
|
|
|
- proxy?.$modal.msgSuccess('导出成功');
|
|
|
-
|
|
|
- } catch (error) {
|
|
|
- console.error('导出失败:', error);
|
|
|
- let errorMessage = '未知错误';
|
|
|
-
|
|
|
- if (error instanceof Error) {
|
|
|
- errorMessage = error.message;
|
|
|
- } else if (typeof error === 'string') {
|
|
|
- errorMessage = error;
|
|
|
- } else if (error && typeof error === 'object' && 'message' in error) {
|
|
|
- errorMessage = String(error.message);
|
|
|
- }
|
|
|
-
|
|
|
- // 尝试获取更详细的错误信息
|
|
|
- if (error && typeof error === 'object' && 'response' in error) {
|
|
|
- const response = (error as any).response;
|
|
|
- if (response && response.data) {
|
|
|
- try {
|
|
|
- if (response.data instanceof Blob) {
|
|
|
- // 如果是blob,尝试读取错误信息
|
|
|
- const reader = new FileReader();
|
|
|
- reader.onload = function(e) {
|
|
|
- try {
|
|
|
- const text = e.target?.result as string;
|
|
|
- const errorObj = JSON.parse(text);
|
|
|
- if (errorObj.msg) {
|
|
|
- errorMessage = errorObj.msg;
|
|
|
- }
|
|
|
- } catch (parseError) {
|
|
|
- console.warn('无法解析错误响应:', parseError);
|
|
|
- }
|
|
|
- };
|
|
|
- reader.readAsText(response.data);
|
|
|
- } else if (typeof response.data === 'string') {
|
|
|
- errorMessage = response.data;
|
|
|
- } else if (response.data.msg) {
|
|
|
- errorMessage = response.data.msg;
|
|
|
- }
|
|
|
- } catch (parseError) {
|
|
|
- console.warn('解析错误响应失败:', parseError);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- proxy?.$modal.msgError('导出失败:' + errorMessage);
|
|
|
+const exportScoresNames = () => {
|
|
|
+ // 获取默认赛事ID
|
|
|
+ const event = gameEventStore.defaultEventInfo;
|
|
|
+ const eventId = event?.eventId;
|
|
|
+
|
|
|
+ if (!eventId) {
|
|
|
+ proxy?.$modal.msgWarning('未指定赛事,无法导出');
|
|
|
+ return;
|
|
|
}
|
|
|
+
|
|
|
+ // 使用 proxy?.download 方式导出
|
|
|
+ proxy?.download(
|
|
|
+ 'system/gameScore/exportScoresSummary',
|
|
|
+ {
|
|
|
+ eventId: eventId
|
|
|
+ },
|
|
|
+ `成绩汇总表_${new Date().toLocaleDateString()}.xlsx`
|
|
|
+ );
|
|
|
};
|
|
|
|
|
|
/**
|