|
@@ -319,7 +319,7 @@ const basicForm = ref<GameEventForm>({
|
|
|
refereeUrl: '',
|
|
|
registerUrl: '',
|
|
|
unit: '',
|
|
|
- isDefault: '0',
|
|
|
+ isDefault: '1',
|
|
|
status: '0',
|
|
|
remark: ''
|
|
|
});
|
|
@@ -343,6 +343,26 @@ onMounted(async () => {
|
|
|
currentEventId.value = Number(eventId);
|
|
|
await loadEventData(eventId);
|
|
|
} else {
|
|
|
+ // 新增模式,确保清除所有可能残留的数据
|
|
|
+ isEdit.value = false;
|
|
|
+ currentEventId.value = undefined;
|
|
|
+ // 重置表单数据,确保不包含eventId
|
|
|
+ basicForm.value = {
|
|
|
+ eventCode: '',
|
|
|
+ eventName: '',
|
|
|
+ eventType: '',
|
|
|
+ location: '',
|
|
|
+ purpose: '',
|
|
|
+ startTime: '',
|
|
|
+ endTime: '',
|
|
|
+ eventUrl: '',
|
|
|
+ refereeUrl: '',
|
|
|
+ registerUrl: '',
|
|
|
+ unit: '',
|
|
|
+ isDefault: '1',
|
|
|
+ status: '0',
|
|
|
+ remark: ''
|
|
|
+ };
|
|
|
// 新增模式,加载图片配置模板
|
|
|
// await loadImageConfigTemplates();
|
|
|
}
|
|
@@ -378,7 +398,10 @@ const loadEventData = async (eventId: string | number) => {
|
|
|
const handleStatusChange = async (row: GameEventVO) => {
|
|
|
const text = row.isDefault === '0' ? '启用' : '停用';
|
|
|
try {
|
|
|
- await loadEventData(row.eventId);
|
|
|
+ // 只有在编辑模式下才加载数据
|
|
|
+ if (isEdit.value && row.eventId) {
|
|
|
+ await loadEventData(row.eventId);
|
|
|
+ }
|
|
|
proxy?.$modal.msgSuccess(text + '成功');
|
|
|
} catch {
|
|
|
return;
|
|
@@ -700,6 +723,9 @@ const saveconfigData = async (eventId: string | number) => {
|
|
|
|
|
|
// 保存赛事信息
|
|
|
const saveEvent = async () => {
|
|
|
+ let formData: GameEventForm;
|
|
|
+ let savedEventId: string;
|
|
|
+
|
|
|
try {
|
|
|
// 验证基本信息表单
|
|
|
await basicFormRef.value?.validate();
|
|
@@ -707,28 +733,60 @@ const saveEvent = async () => {
|
|
|
saveLoading.value = true;
|
|
|
|
|
|
// 合并表单数据
|
|
|
- const formData: GameEventForm = {
|
|
|
+ formData = {
|
|
|
...basicForm.value
|
|
|
};
|
|
|
-
|
|
|
- let savedEventId: string;
|
|
|
- // 如果设置为默认赛事,则取消其他赛事的默认状态
|
|
|
- if (basicForm.value.isDefault === '0') {
|
|
|
- handleStatusChange({
|
|
|
- eventId: basicForm.value.eventId,
|
|
|
- isDefault: basicForm.value.isDefault,
|
|
|
- eventName: basicForm.value.eventName
|
|
|
- } as GameEventVO);
|
|
|
- }
|
|
|
-
|
|
|
- // 保存基本信息
|
|
|
+
|
|
|
+ // 新增模式下,确保不包含eventId字段,避免主键冲突
|
|
|
if (!isEdit.value) {
|
|
|
+ console.log('新增模式,开始保存赛事信息');
|
|
|
+ console.log('保存前的formData:', formData);
|
|
|
+
|
|
|
+ // 三重保险:确保eventId被完全清除
|
|
|
+ delete formData.eventId;
|
|
|
+ delete basicForm.value.eventId;
|
|
|
+
|
|
|
+ // 再次检查formData中是否还有eventId
|
|
|
+ if (formData.eventId !== undefined) {
|
|
|
+ console.warn('检测到formData中仍有eventId,强制清除:', formData.eventId);
|
|
|
+ delete formData.eventId;
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('清除eventId后的formData:', formData);
|
|
|
+
|
|
|
+ // 如果设置为默认赛事,则取消其他赛事的默认状态
|
|
|
+ if (basicForm.value.isDefault === '0') {
|
|
|
+ console.log('设置为默认赛事,调用handleStatusChange');
|
|
|
+ handleStatusChange({
|
|
|
+ eventId: '', // 新增时没有eventId
|
|
|
+ isDefault: basicForm.value.isDefault,
|
|
|
+ eventName: basicForm.value.eventName
|
|
|
+ } as GameEventVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存基本信息
|
|
|
+ console.log('调用addGameEvent API');
|
|
|
const addRes = await addGameEvent(formData);
|
|
|
- // 假设返回的数据中包含新创建的赛事ID
|
|
|
+ console.log('addGameEvent 响应:', addRes);
|
|
|
+ // 获取新创建的赛事ID
|
|
|
savedEventId = addRes?.data as string;
|
|
|
+ console.log('获取到的新赛事ID:', savedEventId);
|
|
|
} else {
|
|
|
savedEventId = route.params.id as string;
|
|
|
+
|
|
|
+ // 编辑模式下,如果设置为默认赛事,则取消其他赛事的默认状态
|
|
|
+ if (basicForm.value.isDefault === '0') {
|
|
|
+ handleStatusChange({
|
|
|
+ eventId: basicForm.value.eventId,
|
|
|
+ isDefault: basicForm.value.isDefault,
|
|
|
+ eventName: basicForm.value.eventName
|
|
|
+ } as GameEventVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新基本信息
|
|
|
+ await updateGameEvent(formData);
|
|
|
}
|
|
|
+
|
|
|
// 保存图片配置数据
|
|
|
await saveImageConfigData(savedEventId);
|
|
|
// 保存赛事配置项数据
|
|
@@ -736,11 +794,6 @@ const saveEvent = async () => {
|
|
|
// 保存菜单数据
|
|
|
await saveMenuData(savedEventId);
|
|
|
|
|
|
- // 保存基本信息
|
|
|
- if (isEdit.value) {
|
|
|
- await updateGameEvent(formData);
|
|
|
- }
|
|
|
-
|
|
|
proxy?.$modal.msgSuccess('保存成功');
|
|
|
|
|
|
// 保存成功后,设置一个标识,表示需要刷新列表数据
|
|
@@ -748,7 +801,14 @@ const saveEvent = async () => {
|
|
|
goBack();
|
|
|
} catch (error) {
|
|
|
console.error('保存失败:', error);
|
|
|
- proxy?.$modal.msgError('保存失败');
|
|
|
+ console.error('错误详情:', {
|
|
|
+ message: error instanceof Error ? error.message : String(error),
|
|
|
+ stack: error instanceof Error ? error.stack : undefined,
|
|
|
+ formData: formData,
|
|
|
+ isEdit: isEdit.value,
|
|
|
+ currentEventId: currentEventId.value
|
|
|
+ });
|
|
|
+ proxy?.$modal.msgError(`保存失败: ${error instanceof Error ? error.message : String(error)}`);
|
|
|
} finally {
|
|
|
saveLoading.value = false;
|
|
|
}
|