HeWang 10 місяців тому
батько
коміт
25ef1b567d
3 змінених файлів з 40 додано та 12 видалено
  1. 6 3
      electron/main.js
  2. 3 1
      electron/preload.js
  3. 31 8
      src/views/ReportView.vue

+ 6 - 3
electron/main.js

@@ -113,7 +113,7 @@ ipcMain.on('docker-import', (event, sudoPassword, filePath, tag) => {
     });
 });
 
-ipcMain.on('generate-world', (event, rosbag_path) => {
+ipcMain.on('generate-world', (event, {rosbag_path}) => {
 
     // 使用 spawn 启动脚本
     const serviceProcess = spawn('bash', ["/home/cicv/work/pji_desktop/run_map2gazebo.sh"], { detached: true });
@@ -137,17 +137,20 @@ ipcMain.on('generate-world', (event, rosbag_path) => {
 
     // 监听关闭
     serviceProcess.on('close', (data) => {
-        console.log(`第个脚本已关闭: ${data}`);
+        console.log(`第个脚本已关闭: ${data}`);
     });
 
     function startSecondScript() {
         // 启动第二个脚本
-        const script2 = exec('bash /home/cicv/work/pji_desktop/play_rosbag.sh /home/cicv/work/pji_desktop/map_bag/map.bag', (error, stdout, stderr) => {
+        const script2 = exec('bash /home/cicv/work/pji_desktop/play_rosbag.sh ' + rosbag_path, (error, stdout, stderr) => {
             if (error) {
                 console.error(`执行第二个脚本时出错: ${error}`);
+                event.sender.send('generate-world-result', { success: false, output: error });
                 return;
             }
             console.log(`第二个脚本的输出: ${stdout}`);
+
+            event.sender.send('generate-world-result', { success: true, output: stdout });
         });
 
         script2.on('exit', (code) => {

+ 3 - 1
electron/preload.js

@@ -36,8 +36,9 @@ contextBridge.exposeInMainWorld('electronAPI', {
     },
     generateWorld: (rosbag_path) => {
         // 发送事件到主进程
-        ipcRenderer.send('generate-world', rosbag_path);
+        ipcRenderer.send('generate-world', {rosbag_path});
     },
+    generateWorldResult: (callback) =>  ipcRenderer.on('generate-world-result', callback),
     downloadFile: async (url, fileName, savePath) => {
         try {
             return await ipcRenderer.invoke('download-file', { url, fileName, savePath });
@@ -47,6 +48,7 @@ contextBridge.exposeInMainWorld('electronAPI', {
         }
     },
 
+
 });
 
 

+ 31 - 8
src/views/ReportView.vue

@@ -63,7 +63,7 @@
               v-model="mapDialogVisible"
               title="地图续扫提醒"
               width="400"
-              :before-close="handleClose"
+              :before-close="handleMapClose"
           >
             <el-form :model="mapRescanForm">
               <el-form-item label="请输入地图续扫提醒阈值" label-width="170">
@@ -149,7 +149,7 @@
             v-model="worldDialogVisible"
             title="生成world"
             width="400"
-            :before-close="handleClose"
+            :before-close="handleWorldClose"
         >
           <el-steps style="max-width: 600px" :active="world_active" finish-status="success">
             <el-step title="数据准备"/>
@@ -158,7 +158,8 @@
           </el-steps>
 
           <template #footer>
-            <el-button @click="goToMapUpdate" :disabled="world_active !== 2">去部署</el-button>
+            <el-button @click="nextToUpload" v-if="world_active != 2" :disabled="world_active !== 1">下一步</el-button>
+            <el-button @click="nextToUpload" v-if="world_active == 2" >上传</el-button>
           </template>
         </el-dialog>
         <el-table stripe style="background-color: rgba(255,0,0,99%);width: 100%" border :data="tableData"
@@ -205,10 +206,8 @@
 import {onBeforeMount, ref} from "vue";
 import axios from "axios";
 import {reactive} from 'vue'
-import {ElTable} from "element-plus";
-import { ElMessage } from "element-plus";
+import {ElTable, ElLoading, ElMessage} from "element-plus";
 import {useRouter} from 'vue-router'; // 导入 Vue Router 的 useRouter 钩子
-import * as fs from "fs";
 
 
 const value
@@ -226,9 +225,21 @@ const mapDialogVisible = ref(false)
 const updateDialogVisible = ref(false)
 const worldDialogVisible = ref(false)
 
+const loading = ref(true)
+
+
 const handleClose = (done: () => void) => {
   done()
 }
+const handleWorldClose = (done: () => void) => {
+  done()
+}
+const handleMapClose = (done: () => void) => {
+  done()
+}
+const nextToUpload = () => {
+  world_active.value = 2
+}
 
 const multipleSelection = ref<[]>([])
 
@@ -369,7 +380,7 @@ const rviz = () => {
 const generateWorld = async (id) => {
 
   console.log("id", id);
-  console.log("Starting generating world...")
+  console.log("Starting download: map.bag...")
   worldDialogVisible.value = true
 
   // axios.get('http://127.0.0.1:8888/map/downloadmapbagfile?id=1820978518251540482',
@@ -413,8 +424,20 @@ const generateWorld = async (id) => {
   } else {
     console.log('File downloaded successfully:', result.filePath);
     world_active.value = 1
+    console.log("Starting world generation...")
+    window.electronAPI.generateWorld(result.filePath);
+    const loadingInstance = ElLoading.service({fullscreen: false, target: '.el-dialog'})
+
+    window.electronAPI.generateWorldResult( (event, result) => {
+      loadingInstance.close()
+      if (result.success) {
+        console.log('脚本执行成功');
+      } else {
+        console.error('脚本执行失败');
+        ElMessage.error("world生成发生错误!");
+      }
+    });
   }
-
 }