From 7b2b67564c3b67c9e35aeb0a2c736deb35b343eb Mon Sep 17 00:00:00 2001 From: shaoleiliu-netizen123 <480188199@qq.com> Date: Thu, 25 Jun 2026 16:09:20 +0800 Subject: [PATCH] =?UTF-8?q?Electron=20=E6=89=93=E5=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.production | 5 ++-- electron/main.cjs | 36 +++++++++++++++++++++++++ package.json | 23 +++++++++++++++- src/utils/request.ts | 11 +++++++- src/views/biz/concessionApply/index.vue | 4 +-- 5 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 electron/main.cjs diff --git a/.env.production b/.env.production index 7b19521..d067b94 100644 --- a/.env.production +++ b/.env.production @@ -1,11 +1,12 @@ # 页面标题 -VITE_APP_TITLE = 若依管理系统 +VITE_APP_TITLE = 伊特机械MES # 生产环境配置 VITE_APP_ENV = 'production' # 若依管理系统/生产环境 #VITE_APP_BASE_API = '/prod-api' -VITE_APP_BASE_API = 'https://api.evo-techina.com' +# VITE_APP_BASE_API = 'https://api.evo-techina.com' +VITE_APP_BASE_API = 'http://192.168.6.107:8888/api' # 是否在打包时开启压缩,支持 gzip 和 brotli VITE_BUILD_COMPRESS = gzip \ No newline at end of file diff --git a/electron/main.cjs b/electron/main.cjs new file mode 100644 index 0000000..96bcc55 --- /dev/null +++ b/electron/main.cjs @@ -0,0 +1,36 @@ +const { app, BrowserWindow, Menu } = require('electron') +const path = require('path') + +Menu.setApplicationMenu(null) + +let mainWin = null +function createWindow() { + mainWin = new BrowserWindow({ + width: 1400, + height: 900, + title: "伊特机械MES", + //关键配置,隐藏顶部File/Edit菜单栏 + autoHideMenBar: true,//按ALTE可临时调出 + menu: null, + webPreferences: { + nodeIntegration: true, + contextIsolation: false + } + }) + + // 区分 本地开发 / 打包exe 两种环境 + if (app.isPackaged) { + // 打包后:读取 asar 内部资源,不能走磁盘本地路径 + mainWin.loadFile(path.join(__dirname, "../dist/index.html")) + } else { + // 本地 npm run electron:dev 预览 + mainWin.loadFile(path.join(__dirname, "../dist/index.html")) + // 开发时自动打开调试面板 + mainWin.webContents.openDevTools() + } +} + +app.whenReady().then(createWindow) +app.on('window-all-closed', () => { + if (process.platform !== 'darwin') app.quit() +}) \ No newline at end of file diff --git a/package.json b/package.json index 50cf148..ec3f4a4 100644 --- a/package.json +++ b/package.json @@ -3,11 +3,14 @@ "version": "1.0.0", "private": true, "type": "module", + "main": "electron/main.cjs", "scripts": { "dev": "vite", "build": "vite build", "preview": "vite preview", - "postinstall": "node scripts/copy-draco.js" + "postinstall": "node scripts/copy-draco.js", + "electron:dev": "npm run build && electron .", + "electron:build": "npm run build && electron-builder" }, "dependencies": { "@vicons/ionicons5": "^0.12.0", @@ -30,9 +33,27 @@ "@types/node": "^20.11.5", "@types/three": "^0.184.1", "@vitejs/plugin-vue": "^5.0.3", + "electron": "^42.5.0", + "electron-builder": "^26.15.3", "sass": "^1.70.0", "typescript": "^5.3.3", "vite": "^5.0.11", "vue-tsc": "^1.8.27" + }, + "build": { + "appId": "com.mes.viewer", + "productName": "伊特机械MES", + "win": { + "target": "nsis" + }, + "asar": true, + "files": [ + "electron/**/*", + "dist/**/*" + ], + "nsis": { + "oneClick": false, + "allowToChangeInstallationDirectory": true + } } } diff --git a/src/utils/request.ts b/src/utils/request.ts index b499d5e..2f5fe72 100644 --- a/src/utils/request.ts +++ b/src/utils/request.ts @@ -1,6 +1,8 @@ import axios, { type AxiosInstance, type AxiosRequestConfig, type AxiosResponse } from 'axios' import { useUserStore } from '@/stores/user' +const BASE_API = import.meta.env.VITE_APP_BASE_API + // API响应结构 interface ApiResponse { code: number @@ -114,7 +116,8 @@ async function decryptResponseData(data: string): Promise { // 创建axios实例 // 后端 API 统一使用 /api 前缀 const service: AxiosInstance = axios.create({ - baseURL: '/api', + // baseURL:'/api', + baseURL: BASE_API, timeout: 30000 }) @@ -151,6 +154,12 @@ service.interceptors.response.use( return response.data } + if (response.config.responseType === 'arraybuffer') { + // 二进制流不走code校验,直接完整返回ArrayBuffer + return response.data + } + + const res = response.data if (res.code !== 200) { diff --git a/src/views/biz/concessionApply/index.vue b/src/views/biz/concessionApply/index.vue index 5d2c14f..b2601e3 100644 --- a/src/views/biz/concessionApply/index.vue +++ b/src/views/biz/concessionApply/index.vue @@ -253,8 +253,8 @@ import { SearchOutline, RefreshOutline, AddOutline, TrashOutline, CreateOutline, import { concessionApplyApi, DetailModel, type ConcessionApply } from '@/api/concessionApply' import { dictDataApi } from '@/api/org' -import html2canvas from 'html2canvas' -import { jsPDF } from 'jspdf' +// import html2canvas from 'html2canvas' +// import { jsPDF } from 'jspdf' import * as dd from 'dingtalk-jsapi';