LingxinMeng vor 10 Monaten
Ursprung
Commit
4b0e522192
4 geänderte Dateien mit 56 neuen und 3 gelöschten Zeilen
  1. 31 2
      electron/main.js
  2. 4 0
      electron/preload.js
  3. BIN
      src/assets/pji-logo.jpg
  4. 21 1
      src/views/ReportView.vue

+ 31 - 2
electron/main.js

@@ -98,8 +98,6 @@ ipcMain.handle('dialog:open', async (event, options = {}) => {
 
 
 ipcMain.on('docker-import', (event, sudoPassword, filePath, tag) => {
-
-
     const command = 'echo "' + sudoPassword + '" | sudo -S  docker import ' + filePath + ' pji_nav:' + tag
     console.log('导入算法镜像文件:', command);
     exec(command, (error, stdout, stderr) => {
@@ -111,3 +109,34 @@ ipcMain.on('docker-import', (event, sudoPassword, filePath, tag) => {
         console.error(`stderr: ${stderr}`);
     });
 });
+
+ipcMain.on('generate-world', (event, rosbag_path) => {
+    // const command = 'sh /home/cicv/work/pji_desktop/run_map2gazabo.sh'
+    //
+    // exec(command, (error, stdout, stderr) => {
+    //     if (error) {
+    //         console.error(`exec error: ${error}`);
+    //         return;
+    //     }
+    //     console.log(`stdout: ${stdout}`);
+    //     console.error(`stderr: ${stderr}`);
+    // });
+
+    // 在 Electron 应用启动后执行本地脚本
+    const serviceScript = 'sh /home/cicv/work/pji_desktop/run_map2gazabo.sh';
+
+    // 使用 spawn 启动脚本
+    const serviceProcess = spawn(serviceScript, [], { detached: true });
+
+    // 设置为后台进程
+    serviceProcess.unref();
+
+    // 监听输出
+    serviceProcess.stdout.on('data', (data) => {
+        console.log(`Service output: ${data}`);
+    });
+
+    serviceProcess.stderr.on('data', (data) => {
+        console.error(`Service error: ${data}`);
+    });
+});

+ 4 - 0
electron/preload.js

@@ -34,6 +34,10 @@ contextBridge.exposeInMainWorld('electronAPI', {
         // 发送事件到主进程,并带上文件路径和文件名作为参数
         ipcRenderer.send('docker-import',sudoPassword, filePath, tag);
     },
+    generateWorld: (rosbag_path) => {
+        // 发送事件到主进程
+        ipcRenderer.send('generate-world', rosbag_path);
+    },
 
 });
 

BIN
src/assets/pji-logo.jpg


+ 21 - 1
src/views/ReportView.vue

@@ -155,7 +155,7 @@
           <el-table-column prop="callbackTime" label="上报时间"/>
           <el-table-column prop="dataStateName" label="数据状态"/>
           <el-table-column width="300" fixed="right" label="操作">
-            <el-button size="small" type="danger" @click="goToDetail">生成world</el-button>
+            <el-button size="small" type="danger" @click="generateWorld">生成world</el-button>
             <el-button size="small" type="danger" @click="goToDetail">仿真测试</el-button>
             <!--            <el-button size="small" type="danger" @click="goToDetail">算法评价</el-button>-->
           </el-table-column>
@@ -341,6 +341,26 @@ const rviz = () => {
   }
 }
 
+
+const generateWorld = () => {
+  // if (rvizState.value) {
+  //   if (window.electronAPI) {
+  //     window.electronAPI.generateWorld();
+  //   } else {
+  //     console.error('electronAPI is not defined');
+  //   }
+  // } else {
+  //   if (window.electronAPI) {
+  //     window.electronAPI.closeRviz();
+  //   } else {
+  //     console.error('electronAPI is not defined');
+  //   }
+  // }
+  console.log("11111")
+
+  window.electronAPI.generateWorld()
+}
+
 const queryLine = reactive({
   dataName: '',
   equipmentName: '',