黎海 месяцев назад: 2
Родитель
Сommit
d025473075
3 измененных файлов с 346 добавлено и 346 удалено
  1. 62 19
      src/components/audioPlayer/index.js
  2. 1 26
      src/pages/home/home.js
  3. 283 301
      src/pages/projectDetail/projectDetail.js

+ 62 - 19
src/components/audioPlayer/index.js

@@ -23,31 +23,74 @@ const AudioPlayerComponent = ({ audioPath, label, onPlay, onPause }) => {
23 23
   });
24 24
   
25 25
   useEffect(() => {
26
-    if (audioPath) {
27
-      // 设置文件路径
28
-      setAudioFile(audioPath);
29
-      
30
-      // 提取文件名
31
-      const fileName = path.basename(audioPath);
32
-      
33
-      // 获取文件大小信息
26
+    if (audioPath && typeof audioPath === 'string' && audioPath.trim() !== '') {
34 27
       try {
35
-        // 通过Electron的fs模块获取文件信息
36
-        window.electron.ipcRenderer.invoke('get-file-stats', audioPath)
37
-          .then(stats => {
38
-            if (stats) {
39
-              setAudioInfo({
40
-                fileName,
41
-                fileSize: formatFileSize(stats.size)
28
+        // 设置文件路径
29
+        setAudioFile(audioPath);
30
+        
31
+        // 安全地提取文件名
32
+        let fileName = '未知文件';
33
+        try {
34
+          if (path && typeof path.basename === 'function') {
35
+            fileName = path.basename(audioPath);
36
+          } else {
37
+            // 如果path模块不可用,使用简单方法获取文件名
38
+            const parts = audioPath.split(/[/\\]/);
39
+            fileName = parts[parts.length - 1];
40
+          }
41
+        } catch (pathError) {
42
+          console.error('提取文件名时出错:', pathError);
43
+          // 使用简单方法获取文件名作为备选
44
+          const parts = audioPath.split(/[/\\]/);
45
+          fileName = parts[parts.length - 1];
46
+        }
47
+        
48
+        // 获取文件大小信息
49
+        try {
50
+          // 通过Electron的fs模块获取文件信息
51
+          if (window.electron && window.electron.ipcRenderer) {
52
+            window.electron.ipcRenderer.invoke('get-file-stats', audioPath)
53
+              .then(stats => {
54
+                if (stats) {
55
+                  setAudioInfo({
56
+                    fileName,
57
+                    fileSize: formatFileSize(stats.size)
58
+                  });
59
+                }
60
+              })
61
+              .catch(err => {
62
+                console.error('获取音频文件信息时出错:', err);
63
+                // 设置基本信息,不包含文件大小
64
+                setAudioInfo({
65
+                  fileName,
66
+                  fileSize: '未知大小'
67
+                });
42 68
               });
43
-            }
44
-          })
45
-          .catch(err => {
46
-            console.error('获取音频文件信息时出错:', err);
69
+          } else {
70
+            // 如果electron不可用,只设置文件名
71
+            setAudioInfo({
72
+              fileName,
73
+              fileSize: '未知大小'
74
+            });
75
+          }
76
+        } catch (error) {
77
+          console.error('处理音频文件信息时出错:', error);
78
+          // 设置基本信息作为备选
79
+          setAudioInfo({
80
+            fileName,
81
+            fileSize: '未知大小'
47 82
           });
83
+        }
48 84
       } catch (error) {
49 85
         console.error('处理音频文件路径时出错:', error);
50 86
       }
87
+    } else {
88
+      // 如果路径无效,重置状态
89
+      setAudioFile(null);
90
+      setAudioInfo({
91
+        fileName: '',
92
+        fileSize: ''
93
+      });
51 94
     }
52 95
   }, [audioPath]);
53 96
   

+ 1 - 26
src/pages/home/home.js

@@ -470,7 +470,7 @@ const Home = forwardRef((props, ref) => {
470 470
 
471 471
               <AudioUpload onAudioSelected={(audioFile) => setProjectAudioFile(audioFile)} />
472 472
               
473
-              <VideoDownload />
473
+              {/* <VideoDownload /> */}
474 474
 
475 475
               <SubtitleUpload 
476 476
                 onProjectCreated={backToHome} 
@@ -480,31 +480,6 @@ const Home = forwardRef((props, ref) => {
480 480
             </>
481 481
           )}
482 482
 
483
-          {/* 底部数据库路径链接 */}
484
-          <div className="footer-links">
485
-            <div className="d-flex justify-content-between">
486
-              <button
487
-                className="btn-link"
488
-                onClick={openDatabasePath}
489
-              >
490
-                打开数据库文件夹
491
-              </button>
492
-              
493
-              <button
494
-                className="btn-link"
495
-                onClick={openResourcesPath}
496
-              >
497
-                打开资源文件夹
498
-              </button>
499
-              
500
-              <button
501
-                className="btn-link"
502
-                onClick={handleOpenApiSettings}
503
-              >
504
-                Coze API设置
505
-              </button>
506
-            </div>
507
-          </div>
508 483
         </Container>
509 484
       </div>
510 485
       

Разница между файлами не показана из-за своего большого размера
+ 283 - 301
src/pages/projectDetail/projectDetail.js