LingxinMeng 10 місяців тому
батько
коміт
cbe5d3ee1e
5 змінених файлів з 138 додано та 40 видалено
  1. 2 0
      README.md
  2. 24 3
      electron/main.js
  3. 18 1
      electron/preload.js
  4. 0 7
      src/views/AboutView.vue
  5. 94 29
      src/views/ReportView.vue

+ 2 - 0
README.md

@@ -1,5 +1,7 @@
 # pji-desktop
 
+# element-plus
+
 This template should help get you started developing with Vue 3 in Vite.
 
 ## Recommended IDE Setup

+ 24 - 3
electron/main.js

@@ -1,7 +1,7 @@
-import { app, BrowserWindow, ipcMain } from 'electron';
-import { exec } from 'child_process';
+import {app, BrowserWindow, ipcMain, dialog} from 'electron';
+import {exec} from 'child_process';
 import path from 'path';
-import { fileURLToPath } from 'url';
+import {fileURLToPath} from 'url';
 
 const __filename = fileURLToPath(import.meta.url);
 const __dirname = path.dirname(__filename);
@@ -89,3 +89,24 @@ ipcMain.on('close-rviz', (event, arg) => {
     });
 });
 
+
+ipcMain.handle('dialog:open', async (event, options = {}) => {
+    const result = await dialog.showOpenDialog(BrowserWindow.getFocusedWindow() || BrowserWindow.getAllWindows()[0], options);
+    return result.canceled ? null : result.filePaths;
+});
+
+
+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) => {
+        if (error) {
+            console.error(`exec error: ${error}`);
+            return;
+        }
+        console.log(`stdout: ${stdout}`);
+        console.error(`stderr: ${stderr}`);
+    });
+});

+ 18 - 1
electron/preload.js

@@ -1,5 +1,5 @@
 console.log('Preload script loaded');
-const { contextBridge, ipcRenderer } = require('electron');
+const {contextBridge, ipcRenderer} = require('electron');
 
 contextBridge.exposeInMainWorld('electronAPI', {
     openGazebo: () => {
@@ -18,6 +18,23 @@ contextBridge.exposeInMainWorld('electronAPI', {
         console.log('关闭 rviz');
         ipcRenderer.send('close-rviz');
     },
+    openFileManager: async () => {
+        try {
+            const result = await ipcRenderer.invoke('dialog:open');
+            return result;
+        } catch (error) {
+            console.error('打开文件管理器时出错:', error);
+            throw error;
+        }
+    },
+    // dockerImport 函数现在接受两个参数:filePath 和 tag
+    dockerImport: (sudoPassword, filePath, tag) => {
+        console.log('sudo密码为:', sudoPassword);
+        console.log('docker导入算法镜像文件:', filePath, '本地镜像版本:', tag);
+        // 发送事件到主进程,并带上文件路径和文件名作为参数
+        ipcRenderer.send('docker-import',sudoPassword, filePath, tag);
+    },
+
 });
 
 

+ 0 - 7
src/views/AboutView.vue

@@ -134,13 +134,6 @@ const formInline = reactive({
 const dialogVisible = ref(false)
 
 const handleClose = (done: () => void) => {
-  // ElMessageBox.confirm('是否关闭对话框?')
-  //     .then(() => {
-  //       done()
-  //     })
-  //     .catch(() => {
-  //       // catch error
-  //     })
   done()
 }
 

+ 94 - 29
src/views/ReportView.vue

@@ -36,35 +36,67 @@
             <el-button type="danger" @click="onSubmit">重置</el-button>
           </el-form-item>
         </el-form>
-        <el-button type="primary" @click="onSubmit">算法镜像导入</el-button>
-        <el-button style="margin-left: 100px;" type="primary" @click="onSubmit">选择算法镜像版本</el-button>
+        <el-button type="primary" @click="algorithmImport">地图更新</el-button>
+        <el-button type="primary" @click="algorithmImport">地图更新统计</el-button>
+        <el-button type="primary" @click="algorithmImport">地图续扫提醒阈值</el-button>
+        <el-button type="primary" @click="algorithmImport">地图续扫提醒</el-button>
+        <el-button type="primary" @click="dialogVisible = true">算法镜像导入</el-button>
+        <el-dialog
+            v-model="dialogVisible"
+            title="请输入算法版本"
+            width="300"
+            :before-close="handleClose"
+        >
+          <template #footer>
+            <div class="dialog-footer">
+              <el-form :model="form" label-width="auto">
+                <el-form-item style="margin-bottom: 10px" label="sudo密码:">
+                  <el-input v-model="form.sudoPassword"/>
+                </el-form-item>
+                <el-form-item style="margin-bottom: 10px" label="算法版本:">
+                  <el-input v-model="form.tag"/>
+                </el-form-item>
+              </el-form>
+              <!--            -->
+              <!--            <el-button @click="dialogVisible = false">取消</el-button>-->
+              <el-button type="primary" @click="algorithmImport">选择镜像文件</el-button>
+            </div>
+          </template>
+        </el-dialog>
+        <el-button style="margin-left: 10px;"  type="primary" @click="onSubmit">算法镜像选择</el-button>
         <el-switch
-            v-model="algorithmContainerState"
-            class="ml-2"
-            inline-prompt
-            style="margin-left: 100px;--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
-            active-text="算法容器已开启"
-            inactive-text="算法容器已关闭"
+            style="margin-left: 10px;"
+            v-model="value"
+            size="large"
+            inactive-text="算法容器"
         />
-        <el-switch
-            v-model="gazeboState"
-            class="ml-2"
-            inline-prompt
-            style="margin-left: 100px; --el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
-            active-text="Gazebo 已开启"
-            inactive-text="Gazebo 已关闭"
-            @click="gazebo"
-        />
-        <el-switch
-            v-model="rvizState"
-            class="ml-2"
-            inline-prompt
-            style="margin-left: 100px;--el-switch-on-color: #13ce66; --el-switch-off-color: #ff4949"
-            active-text="Rviz 已开启"
-            inactive-text="Rviz 已关闭"
-            @click="rviz"
-        />
-        <el-button style="margin-left: 100px;" type="primary" @click="onSubmit">地图更新</el-button>
+<!--        <el-switch-->
+<!--            v-model="algorithmContainerState"-->
+<!--            class="ml-2"-->
+<!--            inline-prompt-->
+<!--            style="margin-left: 100px;&#45;&#45;el-switch-on-color: #13ce66; &#45;&#45;el-switch-off-color: #ff4949"-->
+<!--            active-text="算法容器已开启"-->
+<!--            inactive-text="算法容器已关闭"-->
+<!--        />-->
+  <!--        <el-switch-->
+  <!--            v-model="gazeboState"-->
+  <!--            class="ml-2"-->
+  <!--            inline-prompt-->
+  <!--            style="margin-left: 100px; &#45;&#45;el-switch-on-color: #13ce66; &#45;&#45;el-switch-off-color: #ff4949"-->
+  <!--            active-text="Gazebo 已开启"-->
+  <!--            inactive-text="Gazebo 已关闭"-->
+  <!--            @click="gazebo"-->
+  <!--        />-->
+  <!--        <el-switch-->
+  <!--            v-model="rvizState"-->
+  <!--            class="ml-2"-->
+  <!--            inline-prompt-->
+  <!--            style="margin-left: 100px;&#45;&#45;el-switch-on-color: #13ce66; &#45;&#45;el-switch-off-color: #ff4949"-->
+  <!--            active-text="Rviz 已开启"-->
+  <!--            inactive-text="Rviz 已关闭"-->
+  <!--            @click="rviz"-->
+  <!--        />-->
+        <el-button style="margin-left: 100px;" type="primary" @click="onSubmit">仿真测试记录</el-button>
         <br>
         <br>
         <el-table stripe style="background-color: rgba(255,0,0,99%);width: 100%" border :data="tableData"
@@ -79,8 +111,9 @@
           <el-table-column prop="callbackTime" label="上报时间"/>
           <el-table-column prop="dataStateName" label="数据状态"/>
           <el-table-column width="100" fixed="right" label="操作">
+            <el-button size="small" type="danger" @click="goToDetail">生成world</el-button>
             <el-button size="small" type="danger" @click="goToDetail">仿真测试</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>
         </el-table>
 
@@ -109,14 +142,46 @@ import {onBeforeMount, ref} from "vue";
 import axios from "axios";
 import {reactive} from 'vue'
 import {ElTable} from "element-plus";
-import { useRouter } from 'vue-router'; // 导入 Vue Router 的 useRouter 钩子
+import {useRouter} from 'vue-router'; // 导入 Vue Router 的 useRouter 钩子
+
 
+const value = ref(true)
 const router = useRouter();
 const algorithmContainerState = ref(false)
 const gazeboState = ref(false)
 const rvizState = ref(false)
 const multipleTableRef = ref<InstanceType<typeof ElTable>>
 
+const dialogVisible = ref(false)
+
+const handleClose = (done: () => void) => {
+  done()
+}
+
+// do not use same name with ref
+const form = reactive({
+  sudoPassword: '',
+  tag: '',
+  // date1: '',
+  // date2: '',
+  // delivery: false,
+  // type: [],
+  // resource: '',
+  // desc: '',
+})
+const currentTag = ref('')
+
+
+const algorithmImport = async () => {
+  dialogVisible.value = false
+  try {
+    const result = await window.electronAPI.openFileManager();
+    console.log('用户选择的文件路径为:', result, ',版本为:', form.tag);
+    window.electronAPI.dockerImport(form.sudoPassword, result, form.tag)
+  } catch (error) {
+    console.error('打开文件管理器时出错:', error);
+  }
+};
 
 const goToDetail = () => {
   router.push('/about')