Quellcode durchsuchen

feat 打包配置

Funny vor 3 Jahren
Ursprung
Commit
bbe61d061a
8 geänderte Dateien mit 35 neuen und 11 gelöschten Zeilen
  1. 2 1
      .env.development
  2. 2 1
      .env.production
  3. 2 1
      .env.test
  4. 1 1
      package.json
  5. 6 1
      src/App.vue
  6. 19 6
      src/background.js
  7. 2 0
      src/preload.js
  8. 1 0
      vue.config.js

+ 2 - 1
.env.development

@@ -1,3 +1,4 @@
 NODE_ENV = 'development'
 VUE_APP_BASE_URL = 'http://153.37.175.42:8086/'
-WEBPACK_DEV_SERVER_URL = 'http://pctest.liebaoai.cn:88/#/login'
+WEBPACK_DEV_SERVER_URL = 'http://pctest.liebaoai.cn:88/#/login'
+ELECTRON_NODE_INTEGRATION = true

+ 2 - 1
.env.production

@@ -1,3 +1,4 @@
 NODE_ENV = 'production'
 VUE_APP_BASE_URL = 'https://api.liebaoai.cn/'
-WEBPACK_DEV_SERVER_URL = 'https://pc.liebaoai.cn/#/login'
+WEBPACK_DEV_SERVER_URL = 'https://pc.liebaoai.cn/#/login'
+ELECTRON_NODE_INTEGRATION = true

+ 2 - 1
.env.test

@@ -1,3 +1,4 @@
 NODE_ENV = 'test'
 VUE_APP_BASE_URL = 'http://153.37.175.42:8086/'
-WEBPACK_DEV_SERVER_URL = 'http://pctest.liebaoai.cn:88/#/login'
+WEBPACK_DEV_SERVER_URL = 'http://pctest.liebaoai.cn:88/#/login'
+ELECTRON_NODE_INTEGRATION = true

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "liebao-web",
-  "version": "0.2.0",
+  "version": "0.3.0",
   "private": true,
   "author": "[15151556015@163.com/Funny]",
   "description": "有运力的地方,就有猎豹AI。",

+ 6 - 1
src/App.vue

@@ -26,7 +26,6 @@ import { getPrintOrderInfos } from "./api/order.js";
 import bus from "./common/bus.js";
 import UsbAutoPrint from "./common/UsbAutoPrint";
 import { mapGetters } from "vuex";
-// import { ipcRenderer } from "electron";
 export default {
   name: "App",
   data() {
@@ -76,6 +75,7 @@ export default {
   },
   created() {},
   mounted() {
+    window.addEventListener("contextmenu", this.rightClick, false);
     // 进来准备关闭新订单提醒声音了
     bus.$on("closeGetSoundMsg", () => {
       console.log("进来准备关闭新订单提醒声音了");
@@ -130,11 +130,16 @@ export default {
     // });
   },
   beforeDestroy() {
+    window.removeEventListener("contextmenu", this.rightClick, false);
     clearInterval(this.timer);
     this.timer = null;
   },
   destroyed() {},
   methods: {
+    rightClick() {
+      console.log("----右击------");
+      window.ipcRenderer && window.ipcRenderer.send("show-context-menu");
+    },
     printOver(isRemove) {
       // 是否需要去除已打印的对象
       if (isRemove) {

+ 19 - 6
src/background.js

@@ -1,6 +1,6 @@
 'use strict'
 
-import { app, protocol, BrowserWindow, Menu, ipcMain } from 'electron'
+import { app, protocol, BrowserWindow, Menu, MenuItem, ipcMain } from 'electron'
 import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
 import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer'
 const path = require('path')
@@ -18,6 +18,7 @@ protocol.registerSchemesAsPrivileged([
 async function createWindow() {
   // 隐藏菜单栏
   Menu.setApplicationMenu(null)
+
   // Create the browser window.
   win = new BrowserWindow({
     width: 1200,
@@ -28,24 +29,36 @@ async function createWindow() {
       // Use pluginOptions.nodeIntegration, leave this alone
       // See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info
       nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION,
-      contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION
+      contextIsolation: !process.env.ELECTRON_NODE_INTEGRATION,
+      preload: path.join(__dirname, 'preload.js')
     }
   })
   // 检查更新
   // updateHandle();
 
   // 修改成加载项目地址
-  console.log('项目环境:',process.env.NODE_ENV);
   if (process.env.WEBPACK_DEV_SERVER_URL) {
+    console.log('项目环境:', process.env.NODE_ENV);
     // Load the url of the dev server if in development mode
     await win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
-    if (!process.env.IS_TEST) win.webContents.openDevTools()
+    if (isDevelopment) win.webContents.openDevTools()
   } else {
     createProtocol('app')
     // Load the index.html when not in development
-    win.loadURL('app://./index.html')
+    // win.loadURL('app://./index.html')
+    win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
   }
-
+  ipcMain.on('show-context-menu', (event) => {
+    const template = [
+      { label: '复制', role: 'copy' },
+      { label: '粘贴', role: 'paste' },
+      { label: '刷新', role: 'reload' },
+      { label: '强制刷新', role: 'forceReload' },
+      { label: '开发者工具', role: 'toggleDevTools' },
+    ]
+    const menu = Menu.buildFromTemplate(template)
+    menu.popup(BrowserWindow.fromWebContents(event.sender))
+  })
   // // 32位 64位
   // if (process.arch === 'x64') {
   //   uploadUrl = uploadUrl + 'dist_electron';

+ 2 - 0
src/preload.js

@@ -0,0 +1,2 @@
+import { ipcRenderer } from 'electron'
+window.ipcRenderer = ipcRenderer

+ 1 - 0
vue.config.js

@@ -19,6 +19,7 @@ module.exports = {
     },
     // 桌面应用打包配置
     electronBuilder: {
+      preload : 'src/preload.js',
       builderOptions: {
         // build配置在此处
         // options placed here will be merged with default configuration and passed to electron-builder