|
|
@@ -285,7 +285,7 @@
|
|
|
<script setup name="GameEventEdit" lang="ts">
|
|
|
import { getGameEvent, addGameEvent, updateGameEvent, changeEventDefault } from '@/api/system/gameEvent';
|
|
|
import { GameEventVO, GameEventForm } from '@/api/system/gameEvent/types';
|
|
|
-import { listGameEventConfig, addGameEventConfig, updateGameEventConfig, delGameEventConfig } from '@/api/system/gameEventConfig';
|
|
|
+import { listGameEventConfig, delGameEventConfig, saveBatchGameEventConfig } from '@/api/system/gameEventConfig';
|
|
|
import { GameEventConfigForm } from '@/api/system/gameEventConfig/types';
|
|
|
import { listGameEventConfigType } from '@/api/system/gameEventConfigType'; // 添加导入
|
|
|
import { GameEventConfigTypeVO } from '@/api/system/gameEventConfigType/types'; // 添加导入
|
|
|
@@ -304,19 +304,6 @@ const isEdit = ref(false);
|
|
|
const activeTab = ref('basic');
|
|
|
const saveLoading = ref(false);
|
|
|
|
|
|
-// 判断是否为默认赛事操作
|
|
|
-const isDefaultEventOperation = () => {
|
|
|
- return basicForm.value.isDefault === '0';
|
|
|
-};
|
|
|
-
|
|
|
-// 获取有效的赛事ID(默认赛事返回空字符串,否则返回实际ID)
|
|
|
-const getEffectiveEventId = (eventId?: string | number): string => {
|
|
|
- if (isDefaultEventOperation()) {
|
|
|
- return '';
|
|
|
- }
|
|
|
- return String(eventId || (route.params.id as string) || '');
|
|
|
-};
|
|
|
-
|
|
|
// 表单引用
|
|
|
const basicFormRef = ref<ElFormInstance>();
|
|
|
|
|
|
@@ -497,16 +484,6 @@ const confirmAddMenuItems = async () => {
|
|
|
try {
|
|
|
// 将选中的菜单添加到菜单列表中(无需重复检查,因为列表已经过滤掉了重复项)
|
|
|
menuItems.value.push(...selectedMenus.value);
|
|
|
-
|
|
|
- // 如果是编辑模式,立即保存菜单数据到数据库
|
|
|
- // if (isEdit.value && currentEventId.value) {
|
|
|
- // await saveMenuData(currentEventId.value);
|
|
|
- // proxy?.$modal.msgSuccess(`成功添加 ${selectedMenus.value.length} 个菜单项并保存到数据库`);
|
|
|
- // } else {
|
|
|
- // // 新增模式下,菜单数据会在最终保存赛事时一起保存
|
|
|
- // proxy?.$modal.msgSuccess(`成功添加 ${selectedMenus.value.length} 个菜单项(将在保存赛事时一起保存)`);
|
|
|
- // }
|
|
|
-
|
|
|
menuSelectDialogVisible.value = false;
|
|
|
} catch (error) {
|
|
|
console.error('添加菜单项失败:', error);
|
|
|
@@ -615,55 +592,6 @@ const loadImageConfigData = async (eventId: string | number) => {
|
|
|
imageConfigItems.value = [];
|
|
|
}
|
|
|
};
|
|
|
-// 刷新图片配置
|
|
|
-const refreshImageConfigs = async () => {
|
|
|
- const eventId = route.params.id as string;
|
|
|
- if (eventId && eventId !== 'add') {
|
|
|
- await loadImageConfigData(getEffectiveEventId(eventId));
|
|
|
- } else {
|
|
|
- // 新增模式,只加载配置模板
|
|
|
- // await loadImageConfigTemplates();
|
|
|
- }
|
|
|
-};
|
|
|
-// 保存图片配置数据
|
|
|
-const saveImageConfigData = async (eventId?: string | number) => {
|
|
|
- try {
|
|
|
- // 如果是默认赛事操作,使用空字符串作为eventId
|
|
|
- const targetEventId = eventId === '' ? '' : eventId || (route.params.id as string);
|
|
|
- const updates: GameEventConfigForm[] = [];
|
|
|
- const adds: GameEventConfigForm[] = [];
|
|
|
-
|
|
|
- // 收集需要更新和添加的数据
|
|
|
- for (const item of imageConfigItems.value) {
|
|
|
- if (item.configKey) {
|
|
|
- const configData: GameEventConfigForm = {
|
|
|
- ...item,
|
|
|
- eventId: targetEventId,
|
|
|
- configType: 'IMAGE'
|
|
|
- };
|
|
|
-
|
|
|
- if (item.configId && item.configValue) {
|
|
|
- updates.push(configData);
|
|
|
- } else if (!item.configId && item.configValue) {
|
|
|
- adds.push(configData);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 批量更新
|
|
|
- if (updates.length > 0) {
|
|
|
- await Promise.all(updates.map(updateGameEventConfig));
|
|
|
- }
|
|
|
-
|
|
|
- // 批量添加
|
|
|
- if (adds.length > 0) {
|
|
|
- await Promise.all(adds.map(addGameEventConfig));
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- console.error('保存图片配置数据失败:', error);
|
|
|
- throw new Error('保存图片配置失败');
|
|
|
- }
|
|
|
-};
|
|
|
|
|
|
// 处理标签页切换
|
|
|
const handleTabClick = () => {
|
|
|
@@ -730,25 +658,7 @@ const removeConfigItem = (index: number) => {
|
|
|
};
|
|
|
|
|
|
// 保存赛事配置数据
|
|
|
-const saveconfigData = async (eventId: string | number) => {
|
|
|
- try {
|
|
|
- for (const item of configItems.value) {
|
|
|
- // 确保eventId被正确设置
|
|
|
- const configData = { ...item, eventId };
|
|
|
-
|
|
|
- if (item.configId) {
|
|
|
- // 更新现有队伍
|
|
|
- await updateGameEventConfig(configData);
|
|
|
- } else if (item.configDesc) {
|
|
|
- // 只有有名称的新队伍才保存
|
|
|
- await addGameEventConfig(configData);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (error) {
|
|
|
- console.error('保存赛事配置信息失败:', error);
|
|
|
- throw new Error('保存赛事配置信息失败');
|
|
|
- }
|
|
|
-};
|
|
|
+
|
|
|
|
|
|
// 保存赛事信息
|
|
|
const saveEvent = async () => {
|
|
|
@@ -807,12 +717,36 @@ const saveEvent = async () => {
|
|
|
await updateGameEvent(formData);
|
|
|
}
|
|
|
|
|
|
- // 保存图片配置数据
|
|
|
- await saveImageConfigData(savedEventId);
|
|
|
- // 保存赛事配置项数据
|
|
|
- await saveconfigData(savedEventId);
|
|
|
- // 保存菜单数据
|
|
|
- await saveMenuData(savedEventId);
|
|
|
+ // 收集所有需要保存的赛事配置数据(包括图片配置和常规配置项)
|
|
|
+ const allConfigs: GameEventConfigForm[] = [];
|
|
|
+ const targetEventId = savedEventId === '' ? '' : savedEventId || (route.params.id as string);
|
|
|
+
|
|
|
+ // 1. 收集图片配置项
|
|
|
+ for (const item of imageConfigItems.value) {
|
|
|
+ if (item.configKey && item.configValue) {
|
|
|
+ allConfigs.push({
|
|
|
+ ...item,
|
|
|
+ eventId: targetEventId,
|
|
|
+ configType: 'IMAGE'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 收集普通配置项
|
|
|
+ for (const item of configItems.value) {
|
|
|
+ if (item.configId || item.configDesc) {
|
|
|
+ allConfigs.push({
|
|
|
+ ...item,
|
|
|
+ eventId: targetEventId
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 并发保存聚合后的配置列表和菜单数据
|
|
|
+ await Promise.all([
|
|
|
+ allConfigs.length > 0 ? saveBatchGameEventConfig(allConfigs) : Promise.resolve(),
|
|
|
+ saveMenuData(savedEventId)
|
|
|
+ ]);
|
|
|
|
|
|
proxy?.$modal.msgSuccess('保存成功');
|
|
|
|
|
|
@@ -820,7 +754,6 @@ const saveEvent = async () => {
|
|
|
sessionStorage.setItem('needRefreshGameEventList', 'true');
|
|
|
goBack();
|
|
|
} catch (error) {
|
|
|
- console.error('保存失败:', error);
|
|
|
console.error('错误详情:', {
|
|
|
message: error instanceof Error ? error.message : String(error),
|
|
|
stack: error instanceof Error ? error.stack : undefined,
|