Parcourir la source

Merge branch 'dev_zlt' into dev

zhou il y a 11 heures
Parent
commit
a86c6b9712

+ 11 - 2
src/App.vue

@@ -13,8 +13,17 @@ const appStore = useAppStore();
 
 onMounted(() => {
   nextTick(() => {
-    // 初始化主题样式
-    handleThemeStyle(useSettingsStore().theme);
+    try {
+      // 初始化主题样式,添加错误处理
+      const settingsStore = useSettingsStore();
+      const theme = settingsStore.theme;
+      console.log('初始化主题:', theme);
+      handleThemeStyle(theme);
+    } catch (error) {
+      console.warn('主题初始化失败,使用默认主题:', error);
+      // 使用默认主题色
+      handleThemeStyle('#409EFF');
+    }
   });
 });
 </script>

+ 11 - 1
src/utils/theme.ts

@@ -1,5 +1,10 @@
 // 处理主题样式
-export const handleThemeStyle = (theme: string) => {
+export const handleThemeStyle = (theme: string | null | undefined) => {
+  // 添加空值检查,使用默认主题色
+  if (!theme || typeof theme !== 'string') {
+    theme = '#409EFF'; // 使用默认主题色
+  }
+  
   document.documentElement.style.setProperty('--el-color-primary', theme);
   for (let i = 1; i <= 9; i++) {
     document.documentElement.style.setProperty(`--el-color-primary-light-${i}`, `${getLightColor(theme, i / 10)}`);
@@ -11,6 +16,11 @@ export const handleThemeStyle = (theme: string) => {
 
 // hex颜色转rgb颜色
 export const hexToRgb = (str: string): string[] => {
+  // 添加空值检查
+  if (!str || typeof str !== 'string') {
+    return ['0', '0', '0']; // 返回默认黑色
+  }
+  
   str = str.replace('#', '');
   const hexs = str.match(/../g);
   for (let i = 0; i < 3; i++) {

+ 38 - 15
src/views/system/gameEvent/RefereeForm.vue

@@ -57,24 +57,47 @@ const allProjects = ref<{key: string, label: string }[]>([]);
 const eventId = ref<string>(''); // 新增:用于存储赛事ID
 
 const loadProjects = async () => {
-  const res = await listGameEventProject({
-    eventId: eventId.value, // 使用传递进来的赛事ID
-    pageNum: 1,
-    pageSize: 10,
-    orderByColumn: undefined,
-    isAsc: undefined,
-  });
-  allProjects.value = res.rows.map(item => ({
-    key: String(item.projectId),
-    label: `${item.projectName} - ${item.groupType}`
-  }));
-  console.log(allProjects.value);
+  try {
+    const res = await listGameEventProject({
+      eventId: eventId.value, // 使用传递进来的赛事ID
+      pageNum: 1,
+      pageSize: 1000, // 增加页面大小,确保获取所有项目
+      orderByColumn: undefined,
+      isAsc: undefined,
+    });
+    
+    allProjects.value = res.rows.map(item => ({
+      key: String(item.projectId),
+      label: item.projectName || '未命名项目' // 只显示项目名称,不拼接组别
+    }));
+    
+  } catch (error) {
+    console.error('加载项目失败:', error);
+    ElMessage.error('加载项目失败');
+  }
 };
 
 const openDialog = async (eventIdParam: string) => {
-  eventId.value = eventIdParam; // 接收并设置赛事ID
-  await loadProjects();
-  dialog.visible = true;
+  try {
+    
+    if (!eventIdParam) {
+      ElMessage.error('赛事ID不能为空');
+      return;
+    }
+    
+    eventId.value = eventIdParam; // 接收并设置赛事ID
+    
+    // 重置表单数据
+    form.account = '';
+    form.password = '';
+    form.projectIds = [];
+    
+    await loadProjects();
+    dialog.visible = true;
+  } catch (error) {
+    console.error('打开对话框失败:', error);
+    ElMessage.error('打开对话框失败');
+  }
 };
 
 const cancel = () => {

+ 82 - 22
src/views/system/gameEvent/edit.vue

@@ -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;
   }

+ 37 - 8
src/views/system/gameEvent/index.vue

@@ -664,10 +664,25 @@ const handleAddParticipant = (row: GameEventVO) => {
   });
 };
 
-// 添加裁判按钮操作                                                                                                         1
+// 添加裁判按钮操作
 const handleAddReferee = async (row: GameEventVO) => {
-  // 打开裁判表单对话框并传递 eventId
-  refereeFormRef.value?.openDialog(String(row.eventId));
+  try {
+    if (!row.eventId) {
+      proxy?.$modal.msgError('赛事ID不能为空');
+      return;
+    }
+    
+    if (!refereeFormRef.value) {
+      proxy?.$modal.msgError('裁判表单组件未初始化');
+      return;
+    }
+    
+    // 打开裁判表单对话框并传递 eventId
+    refereeFormRef.value.openDialog(String(row.eventId));
+  } catch (error) {
+    console.error('添加裁判失败:', error);
+    proxy?.$modal.msgError('添加裁判失败');
+  }
 };
 
 // 预览按钮点击事件
@@ -909,12 +924,19 @@ const handleAddParticipantDefault = async () => {
 
 /** 添加裁判(默认赛事) */
 const handleAddRefereeDefault = async () => {
-  const defaultEvent = gameEventStore.defaultEventInfo;
-  if (!defaultEvent) {
-    proxy?.$modal.msgError('请先设置默认赛事');
-    return;
+  try {
+    const defaultEvent = gameEventStore.defaultEventInfo;
+    
+    if (!defaultEvent) {
+      proxy?.$modal.msgError('请先设置默认赛事');
+      return;
+    }
+    
+    await handleAddReferee(defaultEvent);
+  } catch (error) {
+    console.error('默认赛事添加裁判失败:', error);
+    proxy?.$modal.msgError('添加裁判失败');
   }
-  handleAddReferee(defaultEvent);
 };
 
 /** 预览(默认赛事) */
@@ -964,6 +986,13 @@ onMounted(() => {
   // 获取默认赛事信息
   gameEventStore.fetchDefaultEvent();
   getList();
+  
+  // 检查组件引用是否正确初始化
+  nextTick(() => {
+    console.log('组件引用检查:');
+    console.log('refereeFormRef.value:', refereeFormRef.value);
+    console.log('bibViewerDialogRef.value:', bibViewerDialogRef.value);
+  });
 });
 
 // 监听路由变化,当从编辑页返回时检查是否需要刷新列表

+ 1 - 1
src/views/system/gameReferee/index.vue

@@ -290,7 +290,7 @@ const loadProjects = async () => {
   // 赛事项目穿梭框可选数据拼接
   allProjects.value = res.rows.map(item => ({
     key: String(item.projectId),
-    label: `${item.projectName}-${item.groupType}` 
+    label: `${item.projectName}` 
   }));
 };