Forráskód Böngészése

获取上传文件路径

jiejie.liu 2 hónapja
szülő
commit
4b3eb7f4fc

BIN
.DS_Store


+ 66 - 53
jg/electron/main.mjs

@@ -1,4 +1,4 @@
-import { app, BrowserWindow, ipcMain } from "electron";
+import { app, BrowserWindow, ipcMain, dialog } from "electron";
 import { fileURLToPath } from "url";
 import path from "path";
 import { execFile } from "child_process";
@@ -22,7 +22,7 @@ function createWindow() {
       allowRunningInsecureContent: false,
     },
   });
-    //环境判断引入不同的页面
+  //环境判断引入不同的页面
   if (process.env.NODE_ENV === "development") {
     mainWindow.loadURL("http://localhost:5173");
     mainWindow.webContents.openDevTools();
@@ -31,63 +31,76 @@ function createWindow() {
     mainWindow.loadFile(path.join(__dirname, "../dist/index.html"));
     mainWindow.webContents.openDevTools();
   }
+  // **🔹 监听渲染进程调用 Python EXE**
+  ipcMain.handle("run-python-exe", async (event, apiName, params = {}) => {
+    return new Promise((resolve, reject) => {
+      let pythonExePath = null;
+      if (process.env.NODE_ENV === "development") {
+        // **开发环境**
+        pythonExePath = path.join(__dirname, "../serves/dist/api_test.exe");
+      } else {
+        //这里需要区分开发环境还是生产环境 生产环境用到这个路径
+        pythonExePath = path.join(
+          process.resourcesPath, // `app.asar.unpacked` 的默认路径
+          "app.asar.unpacked",
+          "serves",
+          "dist",
+          "api_test.exe"
+        );
+      }
+      // **修改 Python EXE 的路径**
 
-  mainWindow.on("closed", () => {
-    mainWindow = null;
-  });
-}
-
-// **🔹 监听渲染进程调用 Python EXE**
-ipcMain.handle("run-python-exe", async (event, apiName, params = {}) => {
-  return new Promise((resolve, reject) => {
-    let pythonExePath = null;
-    if (process.env.NODE_ENV === "development") {
-      // **开发环境**
-      pythonExePath = path.join(__dirname, "../serves/dist/api_test.exe");
-    } else {
-      //这里需要区分开发环境还是生产环境 生产环境用到这个路径
-      pythonExePath = path.join(
-        process.resourcesPath, // `app.asar.unpacked` 的默认路径
-        "app.asar.unpacked",
-        "serves",
-        "dist",
-        "api_test.exe"
-      );
-    }
-    // **修改 Python EXE 的路径**
-
-    console.log("🔹 正在执行 Python EXE:", pythonExePath);
-    if (!fs.existsSync(pythonExePath)) {
-      reject(`Python EXE 不存在: ${pythonExePath}`);
-      return;
-    }
-
-    // **参数列表:API 名称 + JSON 格式参数**
-    const args = [apiName, JSON.stringify(params)];
-
-    console.log("📡 调用 Python EXE:", pythonExePath, "参数:", args);
-
-    execFile(pythonExePath, args, (error, stdout, stderr) => {
-      if (error) {
-        console.error("❌ Python EXE 运行失败:", error);
-        reject(`Error: ${error.message}`);
+      console.log("🔹 正在执行 Python EXE:", pythonExePath);
+      if (!fs.existsSync(pythonExePath)) {
+        reject(`Python EXE 不存在: ${pythonExePath}`);
         return;
       }
-      if (stderr) {
-        console.warn("⚠️ Python EXE 输出警告:", stderr);
-      }
+      // **参数列表:API 名称 + JSON 格式参数**
+      const args = [apiName, JSON.stringify(params)];
+      console.log("📡 调用 Python EXE:", pythonExePath, "参数:", args);
+      execFile(pythonExePath, args, (error, stdout, stderr) => {
+        if (error) {
+          console.error("❌ Python EXE 运行失败:", error);
+          reject(`Error: ${error.message}`);
+          return;
+        }
+        if (stderr) {
+          console.warn("⚠️ Python EXE 输出警告:", stderr);
+        }
 
-      // **尝试解析 JSON**
-      try {
-        console.log("✅ Python EXE 输出:", stdout);
-        resolve(JSON.parse(stdout)); // 返回 JSON 数据
-      } catch (parseError) {
-        console.warn("⚠️ Python EXE 返回的不是 JSON:", stdout);
-        resolve(stdout.trim()); // 返回原始文本
-      }
+        // **尝试解析 JSON**
+        try {
+          console.log("✅ Python EXE 输出:", stdout);
+          resolve(JSON.parse(stdout)); // 返回 JSON 数据
+        } catch (parseError) {
+          console.warn("⚠️ Python EXE 返回的不是 JSON:", stdout);
+          resolve(stdout.trim()); // 返回原始文本
+        }
+      });
     });
   });
-});
+  // 监听 get-file-path 事件 监听渲染进程请求文件路径
+  ipcMain.handle("get-file-path", async () => {
+    try {
+      const { filePaths } = await dialog.showOpenDialog({
+        properties: ["openFile", "multiSelections"], // ✅ 允许选择多个文件
+      });
+      if (filePaths.length > 0) {
+        console.log("用户选择的文件路径:", filePaths[0]);
+        return filePaths[0]; // 返回文件路径
+      } else {
+        console.log("用户取消了选择");
+        return null; // 用户没有选择文件
+      }
+    } catch (error) {
+      console.error("获取文件路径失败:", error);
+      return null;
+    }
+  });
+  mainWindow.on("closed", () => {
+    mainWindow = null;
+  });
+}
 
 app.whenReady().then(createWindow);
 

+ 2 - 4
jg/electron/preload.mjs

@@ -1,8 +1,5 @@
-console.log("Preload script loaded");
-
-// import { contextBridge, ipcRenderer } from "electron";
-// 修改后的 preload.js
 const { contextBridge, ipcRenderer } = require("electron");
+
 // 使用 contextBridge 暴露渲染进程 API
 contextBridge.exposeInMainWorld("electronAPI", {
   // sendMessage: 用于发送消息到主进程
@@ -21,4 +18,5 @@ contextBridge.exposeInMainWorld("electronAPI", {
       callback(data);
     });
   },
+  getFilePath: () => ipcRenderer.invoke("get-file-path"), // ✅ 返回数组
 });

+ 3 - 12
jg/package.json

@@ -1,24 +1,15 @@
 {
   "main": "electron/main.mjs",
   "name": "meet-admin",
-  "type": "module",
+   "type": "module",
   "version": "0.0.1",
   "private": true,
   "description": "meet-admin open source management system",
   "author": {
-    "name": "Meet you",
-    "email": "wjp_github@163.com",
-    "url": "https://blog.wjp.plus"
+    "name": "Meet you"
   },
   "license": "MIT",
-  "homepage": "https://admin.wjp.plus",
-  "repository": {
-    "type": "git",
-    "url": "https://github.com/wjp980108/meet-admin.git"
-  },
-  "bugs": {
-    "url": "https://github.com/wjp980108/meet-admin/issues"
-  },
+ 
   "keywords": [
     "admin",
     "meet-admin",

+ 6 - 6
jg/src/layouts/components/LayHeader/components/Avatar.vue

@@ -35,25 +35,25 @@ function handleSelect(val: string) {
       alt="头像"
     />
     <template #dropdown>
-      <el-dropdown-menu>
-        <!-- <el-dropdown-item :icon="renderIcon('User')" command="userCenter">
+      <!-- <el-dropdown-menu> -->
+      <!-- <el-dropdown-item :icon="renderIcon('User')" command="userCenter">
           {{ t("userCenter") }}
         </el-dropdown-item> -->
-        <!-- <el-dropdown-item
+      <!-- <el-dropdown-item
           :icon="renderIcon('teenyicons:password-outline')"
           command="editPassword"
           divided
         >
           {{ t("editPassword") }}
         </el-dropdown-item> -->
-        <el-dropdown-item
+      <!-- <el-dropdown-item
           :icon="renderIcon('Notification')"
           command="loginOut"
           divided
         >
           {{ t("loginOut") }}
-        </el-dropdown-item>
-      </el-dropdown-menu>
+        </el-dropdown-item> -->
+      <!-- </el-dropdown-menu> -->
     </template>
   </el-dropdown>
 </template>

+ 1 - 1
jg/src/layouts/components/LayHeader/index.vue

@@ -81,7 +81,7 @@ watch(
         <!-- 系统设置 -->
         <LaySettings />
       </template>
-      <Avatar />
+      <!-- <Avatar /> -->
     </app-flex>
   </app-flex>
   <!-- 搜索菜单弹窗 -->

+ 2 - 2
jg/src/layouts/components/LayMenu/components/SearchMenu.vue

@@ -201,13 +201,13 @@ registerShortcut();
       <el-empty v-else :description="$t('components.searchMenu.noData')" />
       <template #footer>
         <el-space class="w-full" :size="15">
-          <div class="flex-y-center">
+          <!-- <div class="flex-y-center">
             <div class="commands">ctrl</div>
             <div class="commands">k</div>
             <span class="text-14">{{
               $t("components.searchMenu.ctrl-k")
             }}</span>
-          </div>
+          </div> -->
           <div class="flex-y-center">
             <div class="commands">
               <app-icon icon="fluent:arrow-enter-left-24-regular" />

+ 1 - 1
jg/src/main.ts

@@ -26,7 +26,7 @@ async function setupApp() {
   app.config.globalProperties.$formatDateTWO = function (
     timestamp: string | number | Date
   ) {
-    console.log(timestamp, "formatDateTWO");
+    // console.log(timestamp, "formatDateTWO");
     const date = new Date(timestamp);
     const year = date.getFullYear();
     const month = String(date.getMonth() + 1).padStart(2, "0");

+ 3 - 3
jg/src/views/laserRangeFinder/components/descrBox.vue

@@ -1,7 +1,7 @@
 <!--
  * @Author: your name
  * @Date: 2024-12-09 16:24:28
- * @LastEditTime: 2025-03-05 17:39:32
+ * @LastEditTime: 2025-03-24 13:39:39
  * @LastEditors: bogon
  * @Description: In User Settings Edit
  * @FilePath: /performance-test/src/views/laserRangeFinder/components/descrBox.vue
@@ -146,7 +146,7 @@
         </el-descriptions-item>
       </el-descriptions>
     </div>
-    <el-table
+    <!-- <el-table
       ref="singleTable"
       :data="tableData"
       :current-row-key="currentIndex"
@@ -180,7 +180,7 @@
         label="塔筒采集频率Hz"
       >
       </el-table-column>
-    </el-table>
+    </el-table> -->
   </div>
 </template>
 <script>

+ 32 - 16
jg/src/views/laserRangeFinder/index.vue

@@ -4,6 +4,18 @@
     <el-card class="box-card">
       <div class="searchbox">
         <el-collapse v-model="activeNames">
+          <el-button
+            size="small"
+            @click="validateAndHandleChange"
+            type="primary"
+            >导入测量数据</el-button
+          >
+          <el-button
+            size="small"
+            @click="validateAndHandleChange"
+            type="primary"
+            >导入定位数据</el-button
+          >
           <el-collapse-item title="数据筛选" name="1">
             <template #title>
               <div class="titleLeft">数据筛选</div>
@@ -11,6 +23,7 @@
                 <el-button type="primary" @click.stop="getTableData">
                   查询
                 </el-button>
+
                 <el-button
                   v-if="tabActiveName === 'list'"
                   type="primary"
@@ -27,10 +40,10 @@
             >
               <el-row :gutter="10">
                 <el-col :xs="16" :sm="8" :md="7" :lg="6" :xl="4">
-                  <el-form-item label="单位">
+                  <el-form-item label="场站">
                     <selecttree
                       style="width: 220px"
-                      placeholder="请选择上级单位"
+                      placeholder="请选择场站"
                       :list="parentOpt"
                       type="1"
                       v-model="formInline.companyCode"
@@ -240,6 +253,7 @@ export default {
         unitvalue: "", //风机
         timevalue: "", //时间
       },
+      fileList: [],
       companyCode: "", //单位表格中展示
       parentOpt: [], //风场
       tableData: [], // 假设是来自父组件的数据
@@ -269,9 +283,23 @@ export default {
     console.log("process.env.NODE_ENV", process.env.NODE_ENV);
     this.fetchA1();
     this.fetchA2();
-    console.log("路由", this.$router.getRoutes());
   },
   methods: {
+    // 验证并处理文件变化
+    async validateAndHandleChange() {
+      // 直接获取文件路径(通常无效)
+      try {
+        const absolutePath = await window.electronAPI.getFilePath(); // ✅ 修正:不传 file
+        if (absolutePath) {
+          console.log("文件绝对路径:", absolutePath);
+        } else {
+          console.log("未选择文件或路径获取失败");
+        }
+      } catch (error) {
+        console.error("获取文件路径失败:", error);
+      }
+    },
+
     async fetchA1() {
       try {
         const result = await window.electronAPI.callPythonAPI("a1");
@@ -351,9 +379,7 @@ export default {
       });
       return processedData;
     },
-    handleWindTuebineData(data) {
-      this.windTurbineName = this.getWindTurbineLabel(data);
-    },
+    handleWindTuebineData(data) {},
     parentChange(data) {
       this.windName = data && data.companyName;
       this.maplist = data;
@@ -402,12 +428,6 @@ export default {
       this.currentCopyIndex = ind; // 更新当前索引
     },
 
-    getWindTurbineLabel(companyCode) {
-      const selectedOption = this.unitoptions?.find(
-        (option) => option.engineCode === companyCode
-      );
-      return selectedOption ? selectedOption.engineName : "";
-    },
     onSubmit() {
       if (this.tableData.length > 0) {
         this.$refs.multilevelTable.outputFile();
@@ -501,8 +521,4 @@ export default {
   width: 100%;
   height: 280px;
 }
-
-// .line-chart {
-//   position: relative;
-// }
 </style>